mirror of
https://github.com/moodle/moodle.git
synced 2025-08-04 16:36:37 +02:00
MDL-41019 improve language caching
Includes: * no more hacky reloads, everything is written only once and kept until cache reset * lang menu list is now cached in MUC * both string and lang menu caches are compatible with local caches on cluster nodes * config-dist.php cleanup
This commit is contained in:
parent
99a9d8d937
commit
598a82c950
9 changed files with 134 additions and 179 deletions
|
@ -365,25 +365,6 @@ $CFG->admin = 'admin';
|
||||||
// Locking resolves race conditions and is strongly recommended for production servers.
|
// Locking resolves race conditions and is strongly recommended for production servers.
|
||||||
// $CFG->preventfilelocking = false;
|
// $CFG->preventfilelocking = false;
|
||||||
//
|
//
|
||||||
// If $CFG->langstringcache is enabled (which should always be in production
|
|
||||||
// environment), Moodle keeps aggregated strings in its own internal format
|
|
||||||
// optimised for performance. By default, this on-disk cache is created in
|
|
||||||
// $CFG->cachedir/lang. In cluster environment, you may wish to specify
|
|
||||||
// an alternative location of this cache so that each web server in the cluster
|
|
||||||
// uses its own local cache and does not need to access the shared dataroot.
|
|
||||||
// Make sure that the web server process has write permission to this location
|
|
||||||
// and that it has permission to remove the folder, too (so that the cache can
|
|
||||||
// be pruned).
|
|
||||||
//
|
|
||||||
// $CFG->langcacheroot = '/var/www/moodle/htdocs/altcache/lang';
|
|
||||||
//
|
|
||||||
// If $CFG->langcache is enabled (which should always be in production
|
|
||||||
// environment), Moodle stores the list of available languages in a cache file.
|
|
||||||
// By default, the file $CFG->dataroot/languages is used. You may wish to
|
|
||||||
// specify an alternative location of this cache file.
|
|
||||||
//
|
|
||||||
// $CFG->langmenucachefile = '/var/www/moodle/htdocs/altcache/languages';
|
|
||||||
//
|
|
||||||
// Site default language can be set via standard administration interface. If you
|
// Site default language can be set via standard administration interface. If you
|
||||||
// want to have initial error messages for eventual database connection problems
|
// want to have initial error messages for eventual database connection problems
|
||||||
// localized too, you have to set your language code here.
|
// localized too, you have to set your language code here.
|
||||||
|
@ -488,7 +469,7 @@ $CFG->admin = 'admin';
|
||||||
// Prevent JS caching
|
// Prevent JS caching
|
||||||
// $CFG->jsrev = -1; // NOT FOR PRODUCTION SERVERS!
|
// $CFG->jsrev = -1; // NOT FOR PRODUCTION SERVERS!
|
||||||
//
|
//
|
||||||
// Prevent core_string_manager on-disk cache
|
// Prevent core_string_manager application caching
|
||||||
// $CFG->langstringcache = false; // NOT FOR PRODUCTION SERVERS!
|
// $CFG->langstringcache = false; // NOT FOR PRODUCTION SERVERS!
|
||||||
//
|
//
|
||||||
// When working with production data on test servers, no emails or other messages
|
// When working with production data on test servers, no emails or other messages
|
||||||
|
|
|
@ -46,6 +46,7 @@ $string['cachedef_databasemeta'] = 'Database meta information';
|
||||||
$string['cachedef_eventinvalidation'] = 'Event invalidation';
|
$string['cachedef_eventinvalidation'] = 'Event invalidation';
|
||||||
$string['cachedef_groupdata'] = 'Course group information';
|
$string['cachedef_groupdata'] = 'Course group information';
|
||||||
$string['cachedef_htmlpurifier'] = 'HTML Purifier - cleaned content';
|
$string['cachedef_htmlpurifier'] = 'HTML Purifier - cleaned content';
|
||||||
|
$string['cachedef_langmenu'] = 'List of available languages';
|
||||||
$string['cachedef_locking'] = 'Locking';
|
$string['cachedef_locking'] = 'Locking';
|
||||||
$string['cachedef_observers'] = 'Event observers';
|
$string['cachedef_observers'] = 'Event observers';
|
||||||
$string['cachedef_plugininfo_base'] = 'Plugin info - base';
|
$string['cachedef_plugininfo_base'] = 'Plugin info - base';
|
||||||
|
|
|
@ -107,7 +107,6 @@ class core_string_manager_install implements core_string_manager {
|
||||||
if (isset($string['parentlanguage'])) {
|
if (isset($string['parentlanguage'])) {
|
||||||
$parent = $string['parentlanguage'];
|
$parent = $string['parentlanguage'];
|
||||||
}
|
}
|
||||||
unset($string);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -44,31 +44,30 @@ class core_string_manager_standard implements core_string_manager {
|
||||||
/** @var int get_string() counter */
|
/** @var int get_string() counter */
|
||||||
protected $countgetstring = 0;
|
protected $countgetstring = 0;
|
||||||
/** @var bool use disk cache */
|
/** @var bool use disk cache */
|
||||||
protected $usecache;
|
|
||||||
/** @var array limit list of translations */
|
|
||||||
protected $translist;
|
protected $translist;
|
||||||
/** @var string location of a file that caches the list of available translations */
|
/** @var cache stores list of available translations */
|
||||||
protected $menucache;
|
protected $menucache;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Create new instance of string manager
|
* Create new instance of string manager
|
||||||
*
|
*
|
||||||
* @param string $otherroot location of downlaoded lang packs - usually $CFG->dataroot/lang
|
* @param string $otherroot location of downloaded lang packs - usually $CFG->dataroot/lang
|
||||||
* @param string $localroot usually the same as $otherroot
|
* @param string $localroot usually the same as $otherroot
|
||||||
* @param bool $usecache use disk cache
|
|
||||||
* @param array $translist limit list of visible translations
|
* @param array $translist limit list of visible translations
|
||||||
* @param string $menucache the location of a file that caches the list of available translations
|
|
||||||
*/
|
*/
|
||||||
public function __construct($otherroot, $localroot, $usecache, $translist, $menucache) {
|
public function __construct($otherroot, $localroot, $translist) {
|
||||||
$this->otherroot = $otherroot;
|
$this->otherroot = $otherroot;
|
||||||
$this->localroot = $localroot;
|
$this->localroot = $localroot;
|
||||||
$this->usecache = $usecache;
|
if ($translist) {
|
||||||
$this->translist = $translist;
|
$this->translist = array_combine($translist, $translist);
|
||||||
$this->menucache = $menucache;
|
} else {
|
||||||
|
$this->translist = array();
|
||||||
|
}
|
||||||
|
|
||||||
if ($this->usecache) {
|
if ($this->get_revision() > 0) {
|
||||||
// We can use a proper cache, establish the cache using the 'String cache' definition.
|
// We can use a proper cache, establish the cache using the 'String cache' definition.
|
||||||
$this->cache = cache::make('core', 'string');
|
$this->cache = cache::make('core', 'string');
|
||||||
|
$this->menucache = cache::make('core', 'langmenu');
|
||||||
} else {
|
} else {
|
||||||
// We only want a cache for the length of the request, create a static cache.
|
// We only want a cache for the length of the request, create a static cache.
|
||||||
$options = array(
|
$options = array(
|
||||||
|
@ -76,6 +75,7 @@ class core_string_manager_standard implements core_string_manager {
|
||||||
'simpledata' => true
|
'simpledata' => true
|
||||||
);
|
);
|
||||||
$this->cache = cache::make_from_params(cache_store::MODE_REQUEST, 'core', 'string', array(), $options);
|
$this->cache = cache::make_from_params(cache_store::MODE_REQUEST, 'core', 'string', array(), $options);
|
||||||
|
$this->menucache = cache::make_from_params(cache_store::MODE_REQUEST, 'core', 'langmenu', array(), $options);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -103,22 +103,22 @@ class core_string_manager_standard implements core_string_manager {
|
||||||
* @param bool $disablelocal Do not use customized strings in xx_local language packs
|
* @param bool $disablelocal Do not use customized strings in xx_local language packs
|
||||||
* @return array of all string for given component and lang
|
* @return array of all string for given component and lang
|
||||||
*/
|
*/
|
||||||
public function load_component_strings($component, $lang, $disablecache=false, $disablelocal=false) {
|
public function load_component_strings($component, $lang, $disablecache = false, $disablelocal = false) {
|
||||||
global $CFG;
|
global $CFG;
|
||||||
|
|
||||||
list($plugintype, $pluginname) = core_component::normalize_component($component);
|
list($plugintype, $pluginname) = core_component::normalize_component($component);
|
||||||
if ($plugintype == 'core' and is_null($pluginname)) {
|
if ($plugintype === 'core' and is_null($pluginname)) {
|
||||||
$component = 'core';
|
$component = 'core';
|
||||||
} else {
|
} else {
|
||||||
$component = $plugintype . '_' . $pluginname;
|
$component = $plugintype . '_' . $pluginname;
|
||||||
}
|
}
|
||||||
|
|
||||||
$cachekey = $lang.'_'.$component;
|
$cachekey = $lang.'_'.$component.'_'.$this->get_key_suffix();
|
||||||
|
|
||||||
|
$cachedstring = $this->cache->get($cachekey);
|
||||||
if (!$disablecache and !$disablelocal) {
|
if (!$disablecache and !$disablelocal) {
|
||||||
$string = $this->cache->get($cachekey);
|
if ($cachedstring !== false) {
|
||||||
if ($string) {
|
return $cachedstring;
|
||||||
return $string;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -134,8 +134,7 @@ class core_string_manager_standard implements core_string_manager {
|
||||||
return array();
|
return array();
|
||||||
}
|
}
|
||||||
include("$CFG->dirroot/lang/en/$file.php");
|
include("$CFG->dirroot/lang/en/$file.php");
|
||||||
$originalkeys = array_keys($string);
|
$enstring = $string;
|
||||||
$originalkeys = array_flip($originalkeys);
|
|
||||||
|
|
||||||
// And then corresponding local if present and allowed.
|
// And then corresponding local if present and allowed.
|
||||||
if (!$disablelocal and file_exists("$this->localroot/en_local/$file.php")) {
|
if (!$disablelocal and file_exists("$this->localroot/en_local/$file.php")) {
|
||||||
|
@ -170,8 +169,7 @@ class core_string_manager_standard implements core_string_manager {
|
||||||
return array();
|
return array();
|
||||||
}
|
}
|
||||||
include("$location/lang/en/$file.php");
|
include("$location/lang/en/$file.php");
|
||||||
$originalkeys = array_keys($string);
|
$enstring = $string;
|
||||||
$originalkeys = array_flip($originalkeys);
|
|
||||||
// And then corresponding local english if present.
|
// And then corresponding local english if present.
|
||||||
if (!$disablelocal and file_exists("$this->localroot/en_local/$file.php")) {
|
if (!$disablelocal and file_exists("$this->localroot/en_local/$file.php")) {
|
||||||
include("$this->localroot/en_local/$file.php");
|
include("$this->localroot/en_local/$file.php");
|
||||||
|
@ -196,12 +194,14 @@ class core_string_manager_standard implements core_string_manager {
|
||||||
}
|
}
|
||||||
|
|
||||||
// We do not want any extra strings from other languages - everything must be in en lang pack.
|
// We do not want any extra strings from other languages - everything must be in en lang pack.
|
||||||
$string = array_intersect_key($string, $originalkeys);
|
$string = array_intersect_key($string, $enstring);
|
||||||
|
|
||||||
if (!$disablelocal) {
|
if (!$disablelocal) {
|
||||||
// Now we have a list of strings from all possible sources. put it into both in-memory and on-disk
|
// Now we have a list of strings from all possible sources,
|
||||||
// caches so we do not need to do all this merging and dependencies resolving again.
|
// cache it in MUC cache if not already there.
|
||||||
$this->cache->set($cachekey, $string);
|
if ($cachedstring === false) {
|
||||||
|
$this->cache->set($cachekey, $string);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
return $string;
|
return $string;
|
||||||
}
|
}
|
||||||
|
@ -235,7 +235,7 @@ class core_string_manager_standard implements core_string_manager {
|
||||||
*/
|
*/
|
||||||
public function get_string($identifier, $component = '', $a = null, $lang = null) {
|
public function get_string($identifier, $component = '', $a = null, $lang = null) {
|
||||||
$this->countgetstring++;
|
$this->countgetstring++;
|
||||||
// There are very many uses of these time formating strings without the 'langconfig' component,
|
// There are very many uses of these time formatting strings without the 'langconfig' component,
|
||||||
// it would not be reasonable to expect that all of them would be converted during 2.0 migration.
|
// it would not be reasonable to expect that all of them would be converted during 2.0 migration.
|
||||||
static $langconfigstrs = array(
|
static $langconfigstrs = array(
|
||||||
'strftimedate' => 1,
|
'strftimedate' => 1,
|
||||||
|
@ -275,26 +275,23 @@ class core_string_manager_standard implements core_string_manager {
|
||||||
// Identifier parentlanguage is a special string, undefined means use English if not defined.
|
// Identifier parentlanguage is a special string, undefined means use English if not defined.
|
||||||
return 'en';
|
return 'en';
|
||||||
}
|
}
|
||||||
if ($this->usecache) {
|
// Do not rebuild caches here!
|
||||||
// Maybe the on-disk cache is dirty - let the last attempt be to find the string in original sources,
|
// Devs need to learn to purge all caches after any change or disable $CFG->langstringcache.
|
||||||
// do NOT write the results to disk cache because it may end up in race conditions see MDL-31904.
|
|
||||||
$this->usecache = false;
|
|
||||||
$string = $this->load_component_strings($component, $lang, true);
|
|
||||||
$this->usecache = true;
|
|
||||||
}
|
|
||||||
if (!isset($string[$identifier])) {
|
if (!isset($string[$identifier])) {
|
||||||
// The string is still missing - should be fixed by developer.
|
// The string is still missing - should be fixed by developer.
|
||||||
list($plugintype, $pluginname) = core_component::normalize_component($component);
|
if (debugging('', DEBUG_DEVELOPER)) {
|
||||||
if ($plugintype == 'core') {
|
list($plugintype, $pluginname) = core_component::normalize_component($component);
|
||||||
$file = "lang/en/{$component}.php";
|
if ($plugintype === 'core') {
|
||||||
} else if ($plugintype == 'mod') {
|
$file = "lang/en/{$component}.php";
|
||||||
$file = "mod/{$pluginname}/lang/en/{$pluginname}.php";
|
} else if ($plugintype == 'mod') {
|
||||||
} else {
|
$file = "mod/{$pluginname}/lang/en/{$pluginname}.php";
|
||||||
$path = core_component::get_plugin_directory($plugintype, $pluginname);
|
} else {
|
||||||
$file = "{$path}/lang/en/{$plugintype}_{$pluginname}.php";
|
$path = core_component::get_plugin_directory($plugintype, $pluginname);
|
||||||
|
$file = "{$path}/lang/en/{$plugintype}_{$pluginname}.php";
|
||||||
|
}
|
||||||
|
debugging("Invalid get_string() identifier: '{$identifier}' or component '{$component}'. " .
|
||||||
|
"Perhaps you are missing \$string['{$identifier}'] = ''; in {$file}?", DEBUG_DEVELOPER);
|
||||||
}
|
}
|
||||||
debugging("Invalid get_string() identifier: '{$identifier}' or component '{$component}'. " .
|
|
||||||
"Perhaps you are missing \$string['{$identifier}'] = ''; in {$file}?", DEBUG_DEVELOPER);
|
|
||||||
return "[[$identifier]]";
|
return "[[$identifier]]";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -331,7 +328,7 @@ class core_string_manager_standard implements core_string_manager {
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns information about the string_manager performance.
|
* Returns information about the core_string_manager performance.
|
||||||
*
|
*
|
||||||
* @return array
|
* @return array
|
||||||
*/
|
*/
|
||||||
|
@ -379,7 +376,7 @@ class core_string_manager_standard implements core_string_manager {
|
||||||
* @param string $lang moodle translation language, null means use current
|
* @param string $lang moodle translation language, null means use current
|
||||||
* @param string $standard language list standard
|
* @param string $standard language list standard
|
||||||
* - iso6392: three-letter language code (ISO 639-2/T) => translated name
|
* - iso6392: three-letter language code (ISO 639-2/T) => translated name
|
||||||
* - iso6391: two-letter langauge code (ISO 639-1) => translated name
|
* - iso6391: two-letter language code (ISO 639-1) => translated name
|
||||||
* @return array language code => translated name
|
* @return array language code => translated name
|
||||||
*/
|
*/
|
||||||
public function get_list_of_languages($lang = null, $standard = 'iso6391') {
|
public function get_list_of_languages($lang = null, $standard = 'iso6391') {
|
||||||
|
@ -433,21 +430,8 @@ class core_string_manager_standard implements core_string_manager {
|
||||||
* @return bool true if exists
|
* @return bool true if exists
|
||||||
*/
|
*/
|
||||||
public function translation_exists($lang, $includeall = true) {
|
public function translation_exists($lang, $includeall = true) {
|
||||||
|
$translations = $this->get_list_of_translations($includeall);
|
||||||
if (strpos($lang, '_local') !== false) {
|
return isset($translations[$lang]);
|
||||||
// Local packs are not real translations.
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
if (!$includeall and !empty($this->translist)) {
|
|
||||||
if (!in_array($lang, $this->translist)) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if ($lang === 'en') {
|
|
||||||
// Part of distribution.
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
return file_exists("$this->otherroot/$lang/langconfig.php");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -461,84 +445,65 @@ class core_string_manager_standard implements core_string_manager {
|
||||||
|
|
||||||
$languages = array();
|
$languages = array();
|
||||||
|
|
||||||
if (!empty($CFG->langcache) and is_readable($this->menucache)) {
|
$cachekey = 'list_'.$this->get_key_suffix();
|
||||||
// Try to re-use the cached list of all available languages.
|
$cachedlist = $this->menucache->get($cachekey);
|
||||||
$cachedlist = json_decode(file_get_contents($this->menucache), true);
|
if ($cachedlist !== false) {
|
||||||
|
// The cache content is invalid.
|
||||||
if (is_array($cachedlist) and !empty($cachedlist)) {
|
if ($returnall or empty($this->translist)) {
|
||||||
// The cache file is restored correctly.
|
return $cachedlist;
|
||||||
|
}
|
||||||
if (!$returnall and !empty($this->translist)) {
|
// Return only enabled translations.
|
||||||
// Return just enabled translations.
|
foreach ($cachedlist as $langcode => $langname) {
|
||||||
foreach ($cachedlist as $langcode => $langname) {
|
if (isset($this->translist[$langcode])) {
|
||||||
if (in_array($langcode, $this->translist)) {
|
$languages[$langcode] = $langname;
|
||||||
$languages[$langcode] = $langname;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return $languages;
|
|
||||||
|
|
||||||
} else {
|
|
||||||
// Return all translations.
|
|
||||||
return $cachedlist;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
return $languages;
|
||||||
}
|
}
|
||||||
|
|
||||||
// The cached list of languages is not available, let us populate the list.
|
// Get all languages available in system.
|
||||||
if (!$returnall and !empty($this->translist)) {
|
$langdirs = get_list_of_plugins('', 'en', $this->otherroot);
|
||||||
// Return only some translations.
|
$langdirs["$CFG->dirroot/lang/en"] = 'en';
|
||||||
foreach ($this->translist as $lang) {
|
|
||||||
$lang = trim($lang); // Just trim spaces to be a bit more permissive.
|
// Loop through all langs and get info.
|
||||||
if (strstr($lang, '_local') !== false) {
|
foreach ($langdirs as $lang) {
|
||||||
continue;
|
if (strrpos($lang, '_local') !== false) {
|
||||||
}
|
// Just a local tweak of some other lang pack.
|
||||||
if (strstr($lang, '_utf8') !== false) {
|
continue;
|
||||||
continue;
|
|
||||||
}
|
|
||||||
if ($lang !== 'en' and !file_exists("$this->otherroot/$lang/langconfig.php")) {
|
|
||||||
// Some broken or missing lang - can not switch to it anyway.
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
$string = $this->load_component_strings('langconfig', $lang);
|
|
||||||
if (!empty($string['thislanguage'])) {
|
|
||||||
$languages[$lang] = $string['thislanguage'].' ('. $lang .')';
|
|
||||||
}
|
|
||||||
unset($string);
|
|
||||||
}
|
}
|
||||||
|
if (strrpos($lang, '_utf8') !== false) {
|
||||||
} else {
|
// Legacy 1.x lang pack.
|
||||||
// Return all languages available in system.
|
continue;
|
||||||
$langdirs = get_list_of_plugins('', '', $this->otherroot);
|
|
||||||
|
|
||||||
$langdirs = array_merge($langdirs, array("$CFG->dirroot/lang/en" => 'en'));
|
|
||||||
// Sort all.
|
|
||||||
|
|
||||||
// Loop through all langs and get info.
|
|
||||||
foreach ($langdirs as $lang) {
|
|
||||||
if (strstr($lang, '_local') !== false) {
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
if (strstr($lang, '_utf8') !== false) {
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
$string = $this->load_component_strings('langconfig', $lang);
|
|
||||||
if (!empty($string['thislanguage'])) {
|
|
||||||
$languages[$lang] = $string['thislanguage'].' ('. $lang .')';
|
|
||||||
}
|
|
||||||
unset($string);
|
|
||||||
}
|
}
|
||||||
|
if ($lang !== clean_param($lang, PARAM_SAFEDIR)) {
|
||||||
if (!empty($CFG->langcache) and !empty($this->menucache)) {
|
// Invalid lang pack name!
|
||||||
// Cache the list so that it can be used next time.
|
continue;
|
||||||
core_collator::asort($languages);
|
}
|
||||||
check_dir_exists(dirname($this->menucache), true, true);
|
$string = $this->load_component_strings('langconfig', $lang);
|
||||||
file_put_contents($this->menucache, json_encode($languages));
|
if (!empty($string['thislanguage'])) {
|
||||||
@chmod($this->menucache, $CFG->filepermissions);
|
$languages[$lang] = $string['thislanguage'].' ('. $lang .')';
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
core_collator::asort($languages);
|
core_collator::asort($languages);
|
||||||
|
|
||||||
|
// Cache the list so that it can be used next time.
|
||||||
|
$this->menucache->set($cachekey, $languages);
|
||||||
|
|
||||||
|
if ($returnall or empty($this->translist)) {
|
||||||
|
return $languages;
|
||||||
|
}
|
||||||
|
|
||||||
|
$cachedlist = $languages;
|
||||||
|
|
||||||
|
// Return only enabled translations.
|
||||||
|
$languages = array();
|
||||||
|
foreach ($cachedlist as $langcode => $langname) {
|
||||||
|
if (isset($this->translist[$langcode])) {
|
||||||
|
$languages[$langcode] = $langname;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
return $languages;
|
return $languages;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -564,11 +529,9 @@ class core_string_manager_standard implements core_string_manager {
|
||||||
* @param bool $phpunitreset true means called from our PHPUnit integration test reset
|
* @param bool $phpunitreset true means called from our PHPUnit integration test reset
|
||||||
*/
|
*/
|
||||||
public function reset_caches($phpunitreset = false) {
|
public function reset_caches($phpunitreset = false) {
|
||||||
global $CFG;
|
|
||||||
require_once("$CFG->libdir/filelib.php");
|
|
||||||
|
|
||||||
// Clear the on-disk disk with aggregated string files.
|
// Clear the on-disk disk with aggregated string files.
|
||||||
$this->cache->purge();
|
$this->cache->purge();
|
||||||
|
$this->menucache->purge();
|
||||||
|
|
||||||
if (!$phpunitreset) {
|
if (!$phpunitreset) {
|
||||||
// Increment the revision counter.
|
// Increment the revision counter.
|
||||||
|
@ -583,23 +546,37 @@ class core_string_manager_standard implements core_string_manager {
|
||||||
set_config('langrev', $next);
|
set_config('langrev', $next);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Clear the cache containing the list of available translations
|
|
||||||
// and re-populate it again.
|
|
||||||
fulldelete($this->menucache);
|
|
||||||
$this->get_list_of_translations(true);
|
|
||||||
|
|
||||||
// Lang packs use PHP files in dataroot, it is better to invalidate opcode caches.
|
// Lang packs use PHP files in dataroot, it is better to invalidate opcode caches.
|
||||||
if (function_exists('opcache_reset')) {
|
if (function_exists('opcache_reset')) {
|
||||||
opcache_reset();
|
opcache_reset();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns cache key suffix, this enables us to store string + lang menu
|
||||||
|
* caches in local caches on cluster nodes. We can not use prefix because
|
||||||
|
* it would cause problems when creating subdirs in cache file store.
|
||||||
|
* @return string
|
||||||
|
*/
|
||||||
|
protected function get_key_suffix() {
|
||||||
|
$rev = $this->get_revision();
|
||||||
|
if ($rev < 0) {
|
||||||
|
// Simple keys do not like minus char.
|
||||||
|
$rev = 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
return $rev;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns string revision counter, this is incremented after any string cache reset.
|
* Returns string revision counter, this is incremented after any string cache reset.
|
||||||
* @return int lang string revision counter, -1 if unknown
|
* @return int lang string revision counter, -1 if unknown
|
||||||
*/
|
*/
|
||||||
public function get_revision() {
|
public function get_revision() {
|
||||||
global $CFG;
|
global $CFG;
|
||||||
|
if (empty($CFG->langstringcache)) {
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
if (isset($CFG->langrev)) {
|
if (isset($CFG->langrev)) {
|
||||||
return (int)$CFG->langrev;
|
return (int)$CFG->langrev;
|
||||||
} else {
|
} else {
|
||||||
|
@ -607,8 +584,6 @@ class core_string_manager_standard implements core_string_manager {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// End of external API.
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Helper method that recursively loads all parents of the given language.
|
* Helper method that recursively loads all parents of the given language.
|
||||||
*
|
*
|
||||||
|
@ -637,13 +612,11 @@ class core_string_manager_standard implements core_string_manager {
|
||||||
include("$this->otherroot/$lang/langconfig.php");
|
include("$this->otherroot/$lang/langconfig.php");
|
||||||
|
|
||||||
if (empty($string['parentlanguage']) or $string['parentlanguage'] === 'en') {
|
if (empty($string['parentlanguage']) or $string['parentlanguage'] === 'en') {
|
||||||
unset($string);
|
|
||||||
return array_merge(array($lang), $stack);
|
return array_merge(array($lang), $stack);
|
||||||
|
|
||||||
} else {
|
|
||||||
$parentlang = $string['parentlanguage'];
|
|
||||||
unset($string);
|
|
||||||
return $this->populate_parent_languages($parentlang, array_merge(array($lang), $stack));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
$parentlang = $string['parentlanguage'];
|
||||||
|
return $this->populate_parent_languages($parentlang, array_merge(array($lang), $stack));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -29,8 +29,9 @@
|
||||||
$definitions = array(
|
$definitions = array(
|
||||||
|
|
||||||
// Used to store processed lang files.
|
// Used to store processed lang files.
|
||||||
// The keys used are the component of the string file.
|
// The keys used are the revision, lang and component of the string file.
|
||||||
// The persistent max size has been based upon student access of the site.
|
// The persistent max size has been based upon student access of the site.
|
||||||
|
// NOTE: this data may be safely stored in local caches on cluster nodes.
|
||||||
'string' => array(
|
'string' => array(
|
||||||
'mode' => cache_store::MODE_APPLICATION,
|
'mode' => cache_store::MODE_APPLICATION,
|
||||||
'simplekeys' => true,
|
'simplekeys' => true,
|
||||||
|
@ -39,6 +40,15 @@ $definitions = array(
|
||||||
'persistentmaxsize' => 30
|
'persistentmaxsize' => 30
|
||||||
),
|
),
|
||||||
|
|
||||||
|
// Used to store cache of all available translations.
|
||||||
|
// NOTE: this data may be safely stored in local caches on cluster nodes.
|
||||||
|
'langmenu' => array(
|
||||||
|
'mode' => cache_store::MODE_APPLICATION,
|
||||||
|
'simplekeys' => true,
|
||||||
|
'simpledata' => true,
|
||||||
|
'persistent' => true,
|
||||||
|
),
|
||||||
|
|
||||||
// Used to store database meta information.
|
// Used to store database meta information.
|
||||||
// The database meta information includes information about tables and there columns.
|
// The database meta information includes information about tables and there columns.
|
||||||
// Its keys are the table names.
|
// Its keys are the table names.
|
||||||
|
|
|
@ -6635,14 +6635,7 @@ function get_string_manager($forcereload=false) {
|
||||||
$translist = explode(',', $CFG->langlist);
|
$translist = explode(',', $CFG->langlist);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (empty($CFG->langmenucachefile)) {
|
$singleton = new core_string_manager_standard($CFG->langotherroot, $CFG->langlocalroot, $translist);
|
||||||
$langmenucache = $CFG->cachedir . '/languages';
|
|
||||||
} else {
|
|
||||||
$langmenucache = $CFG->langmenucachefile;
|
|
||||||
}
|
|
||||||
|
|
||||||
$singleton = new core_string_manager_standard($CFG->langotherroot, $CFG->langlocalroot,
|
|
||||||
!empty($CFG->langstringcache), $translist, $langmenucache);
|
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
$singleton = new core_string_manager_install();
|
$singleton = new core_string_manager_install();
|
||||||
|
|
|
@ -529,8 +529,7 @@ function get_exception_info($ex) {
|
||||||
// Remove some absolute paths from message and debugging info.
|
// Remove some absolute paths from message and debugging info.
|
||||||
$searches = array();
|
$searches = array();
|
||||||
$replaces = array();
|
$replaces = array();
|
||||||
$cfgnames = array('tempdir', 'cachedir', 'localcachedir', 'themedir',
|
$cfgnames = array('tempdir', 'cachedir', 'localcachedir', 'themedir', 'dataroot', 'dirroot');
|
||||||
'langmenucachefile', 'langcacheroot', 'dataroot', 'dirroot');
|
|
||||||
foreach ($cfgnames as $cfgname) {
|
foreach ($cfgnames as $cfgname) {
|
||||||
if (property_exists($CFG, $cfgname)) {
|
if (property_exists($CFG, $cfgname)) {
|
||||||
$searches[] = $CFG->$cfgname;
|
$searches[] = $CFG->$cfgname;
|
||||||
|
|
|
@ -13,6 +13,8 @@ information provided here is intended especially for developers.
|
||||||
* New $CFG->localcachedir setting useful for cluster nodes. Admins have to update X-Sendfile aliases if used.
|
* New $CFG->localcachedir setting useful for cluster nodes. Admins have to update X-Sendfile aliases if used.
|
||||||
* MS SQL Server drivers are now using NVARCHAR(MAX) instead of NTEXT and VARBINARY(MAX) instead of IMAGE,
|
* MS SQL Server drivers are now using NVARCHAR(MAX) instead of NTEXT and VARBINARY(MAX) instead of IMAGE,
|
||||||
this change should be fully transparent and it should help significantly with add-on compatibility.
|
this change should be fully transparent and it should help significantly with add-on compatibility.
|
||||||
|
* The string manager classes were renamed. Note that they should not be modified or used directly,
|
||||||
|
always use get_string_manager() to get instance of the string manager.
|
||||||
|
|
||||||
DEPRECATIONS:
|
DEPRECATIONS:
|
||||||
Various previously deprecated functions have now been altered to throw DEBUG_DEVELOPER debugging notices
|
Various previously deprecated functions have now been altered to throw DEBUG_DEVELOPER debugging notices
|
||||||
|
|
|
@ -3452,11 +3452,8 @@ function get_formatted_help_string($identifier, $component, $ajax = false) {
|
||||||
global $CFG, $OUTPUT;
|
global $CFG, $OUTPUT;
|
||||||
$sm = get_string_manager();
|
$sm = get_string_manager();
|
||||||
|
|
||||||
if (!$sm->string_exists($identifier, $component) ||
|
// Do not rebuild caches here!
|
||||||
!$sm->string_exists($identifier . '_help', $component)) {
|
// Devs need to learn to purge all caches after any change or disable $CFG->langstringcache.
|
||||||
// Strings in the on-disk cache may be dirty - try to rebuild it and check again.
|
|
||||||
$sm->load_component_strings($component, current_language(), true);
|
|
||||||
}
|
|
||||||
|
|
||||||
$data = new stdClass();
|
$data = new stdClass();
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue