From 609cc46be3a278d6fa3605d9bb7f9031241834c2 Mon Sep 17 00:00:00 2001 From: Mihail Geshoski Date: Wed, 27 Jan 2021 12:37:11 +0800 Subject: [PATCH] MDL-70316 core: Detect category name changes in the emoji data generator The emoji data generator script is enabled to detect inconsistencies between the emoji category names used in the emoji-data library and the ones used in Moodle. These inconsistencies should be fixed, as soon as they are detected upon library upgrade. --- lib/emoji-data/generate_emoji_data.php | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/lib/emoji-data/generate_emoji_data.php b/lib/emoji-data/generate_emoji_data.php index bc7f85df190..cfbbb14184b 100644 --- a/lib/emoji-data/generate_emoji_data.php +++ b/lib/emoji-data/generate_emoji_data.php @@ -39,6 +39,8 @@ $rawdata = file_get_contents('./emoji_pretty.json'); $jsondata = json_decode($rawdata, true); $emojibycategory = []; $obsoletes = []; +// Emoji categories used in the emoji-data library. +$categories = []; foreach ($jsondata as $data) { $category = $data['category']; @@ -48,6 +50,10 @@ foreach ($jsondata as $data) { continue; } + if (!in_array($category, $categories)) { + $categories[] = $category; + } + if (!empty($data['obsoleted_by'])) { // Skip any obsolete emojis. We'll merge these short names into the // newer emoji later on. @@ -71,6 +77,17 @@ foreach ($jsondata as $data) { 'shortnames' => [$data['short_name']] ]; } +// Detect any category changes. +// Some emoji categories from the emoji-data library are missing. +if ($missingcategories = array_diff($categories, $categorysortorder)) { + die("The following categories are missing: " . implode(', ', $missingcategories) . + ". For more details on how to properly fix this issue, please see /lib/emoji-data/readme_moodle.txt"); +} +// Some emoji categories are not being used anymore in the emoji-data library. +if ($unusedcategories = array_diff($categorysortorder, $categories)) { + die("The following categories are no longer used: " . implode(', ', $unusedcategories) . + ". For more details on how to properly fix this issue, please see /lib/emoji-data/readme_moodle.txt"); +} $emojibycategory = array_values($emojibycategory); // Sort the emojis within each category into the order specified in the raw data.