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.
This commit is contained in:
Mihail Geshoski
2021-01-27 13:35:44 +08:00
parent fd840ab59c
commit 609cc46be3
+17
View File
@@ -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.