mirror of
https://github.com/moodle/moodle.git
synced 2025-06-01 05:35:55 +02:00
MDL-68697 core_h5p: Store missing translations as null
This commit is contained in:
parent
206e179df5
commit
0e809762d4
@ -62,7 +62,14 @@ class editor_framework implements H5peditorStorage {
|
|||||||
$librarykey = helper::get_cache_librarykey(core::record_to_string($library));
|
$librarykey = helper::get_cache_librarykey(core::record_to_string($library));
|
||||||
$cachekey = "{$librarykey}/{$lang}";
|
$cachekey = "{$librarykey}/{$lang}";
|
||||||
$translation = $langcache->get($cachekey);
|
$translation = $langcache->get($cachekey);
|
||||||
if ($translation) {
|
|
||||||
|
if ($translation !== false) {
|
||||||
|
// When there is no translation we store it in the cache as `null`.
|
||||||
|
// This API requires it be returned as `false`.
|
||||||
|
if ($translation === null) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
return $translation;
|
return $translation;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -88,14 +95,19 @@ class editor_framework implements H5peditorStorage {
|
|||||||
|
|
||||||
$result = $DB->get_record_sql($sql, $params);
|
$result = $DB->get_record_sql($sql, $params);
|
||||||
|
|
||||||
if (!empty($result)) {
|
if (empty($result)) {
|
||||||
// If the JS language file exists, its content should be returned.
|
// Save the fact that there is no translation into the cache.
|
||||||
|
// The cache API cannot handle setting a literal `false` value so conver to `null` instead.
|
||||||
|
$langcache->set($cachekey, null);
|
||||||
|
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Save translation into the cache, and return its content.
|
||||||
$fs = get_file_storage();
|
$fs = get_file_storage();
|
||||||
$file = $fs->get_file_by_hash($result->pathnamehash);
|
$file = $fs->get_file_by_hash($result->pathnamehash);
|
||||||
$translation = $file->get_content();
|
$translation = $file->get_content();
|
||||||
}
|
|
||||||
|
|
||||||
// Save translation into the cache (even if there is no translation for this language).
|
|
||||||
$langcache->set($cachekey, $translation);
|
$langcache->set($cachekey, $translation);
|
||||||
|
|
||||||
return $translation;
|
return $translation;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user