Skip to content

Commit 47e9bc2

Browse files
committed
fix duplication entries in add_builtin_snippets
1 parent 5c8553e commit 47e9bc2

File tree

1 file changed

+10
-3
lines changed

1 file changed

+10
-3
lines changed

classes/snippets.php

+10-3
Original file line numberDiff line numberDiff line change
@@ -247,10 +247,12 @@ private static function get_builtin_snippet_paths() {
247247
*/
248248
public static function add_builtin_snippets() {
249249
global $DB;
250+
251+
// Get builtin snippets that are present on disk.
250252
$paths = self::get_builtin_snippet_paths();
251253

252254
// Get builtin snippets which are known in the database.
253-
$present = $DB->get_records(
255+
$snippets = $DB->get_records(
254256
'theme_boost_union_snippets',
255257
['source' => 'theme_boost_union'],
256258
'sortorder DESC',
@@ -260,10 +262,15 @@ public static function add_builtin_snippets() {
260262
);
261263

262264
// Get the highest sortorder present.
263-
$sortorder = empty($present) ? 0 : intval(reset($present)->sortorder) + 1;
265+
$sortorder = empty($snippets) ? 0 : intval(reset($snippets)->sortorder) + 1;
266+
267+
// Prepare an array with all the present builtin snippet paths.
268+
$presentpaths = array_map(function($snippet) {
269+
return $snippet->path;
270+
}, $snippets);
264271

265272
foreach ($paths as $path) {
266-
if (!array_key_exists($path, $present)) {
273+
if (!array_key_exists($path, $presentpaths)) {
267274
$DB->insert_record(
268275
'theme_boost_union_snippets',
269276
[

0 commit comments

Comments
 (0)