From 0a5ce9dd21ed6ae3ab8fc11d5f1a7fb692386c90 Mon Sep 17 00:00:00 2001 From: skodak Date: Tue, 24 Apr 2007 16:14:16 +0000 Subject: [PATCH] MDL-9561 Langimport does not ignore langlist when langcache used MDL-9563 Improve refreshing of langcache, detect permission problems merged from MOODLE_18_STABLE --- admin/cron.php | 2 +- admin/lang.php | 2 +- admin/langimport.php | 18 +++++++++++------- lib/moodlelib.php | 31 ++++++++++++++++++++----------- 4 files changed, 33 insertions(+), 20 deletions(-) diff --git a/admin/cron.php b/admin/cron.php index dbc2a3027b..b703bc292a 100644 --- a/admin/cron.php +++ b/admin/cron.php @@ -137,7 +137,7 @@ if (!empty($CFG->langcache)) { mtrace('Updating languages cache'); - get_list_of_languages(); + get_list_of_languages(true); } mtrace('Removing expired enrolments ...', ''); // See MDL-8785 diff --git a/admin/lang.php b/admin/lang.php index 427eb5edd3..151d88ed35 100644 --- a/admin/lang.php +++ b/admin/lang.php @@ -82,7 +82,7 @@ if (!$mode) { print_box_start(); $currlang = current_language(); - $langs = get_list_of_languages(); + $langs = get_list_of_languages(false, true); popup_form ("$CFG->wwwroot/$CFG->admin/lang.php?lang=", $langs, "chooselang", $currlang, "", "", "", false, 'self', $strcurrentlanguage.':'); print_heading("$strmissingstrings"); print_heading("$streditstrings"); diff --git a/admin/langimport.php b/admin/langimport.php index 5e74a24573..94a1b4bb84 100755 --- a/admin/langimport.php +++ b/admin/langimport.php @@ -29,6 +29,12 @@ admin_externalpage_print_header($adminroot); + //reset and diagnose lang cache permissions + @unlink($CFG->dataroot.'/cache/languages'); + if (file_exists($CFG->dataroot.'/cache/languages')) { + notify('Language cache can not be deleted, please check permissions in dataroot.'); + } + get_list_of_languages(true); //refresh lang cache switch ($mode){ @@ -56,7 +62,7 @@ break; case INSTALLED: - @unlink($CFG->dataroot.'/cache/languages'); + get_list_of_languages(true); //refresh lang cache redirect('langimport.php', get_string('langpackupdated','admin',$pack), -1, $adminroot); break; @@ -103,14 +109,14 @@ if (file_exists($dest2)){ $rm2 = remove_dir($dest2); } + get_list_of_languages(true); //refresh lang cache //delete the direcotries if ($rm1 or $rm2) { - redirect('langimport.php', get_string('langpackremoved','admin')); + redirect('langimport.php', get_string('langpackremoved','admin'), 3, $adminroot); } else { //nothing deleted, possibly due to permission error error('An error has occurred, language pack is not completely uninstalled, please check file permissions'); } } - @unlink($CFG->dataroot.'/cache/languages'); break; case UPDATE_ALL_LANG: //1 click update for all updatable language packs @@ -120,8 +126,7 @@ $source = 'http://download.moodle.org/lang16/languages.md5'; $md5array = array(); $updated = 0; //any packs updated? - unset($CFG->langlist); // ignore admin's langlist - $alllangs = array_keys(get_list_of_languages()); + $alllangs = array_keys(get_list_of_languages(false, true)); //get all available langs $lang16 = array(); //all the Moodle 1.6 unicode lang packs (updated and not updated) $packs = array(); //all the packs that needs updating @@ -247,8 +252,7 @@ echo '
'; echo '
'; echo ''; - unset($CFG->langlist); // ignore admin's langlist - $installedlangs = get_list_of_languages(); + $installedlangs = get_list_of_languages(false, true); /// display installed langs here diff --git a/lib/moodlelib.php b/lib/moodlelib.php index 543d66f062..4c1d0428bb 100644 --- a/lib/moodlelib.php +++ b/lib/moodlelib.php @@ -4531,10 +4531,10 @@ function get_strings($array, $module='') { /** * Returns a list of language codes and their full names * hides the _local files from everyone. - * @uses $CFG + * @param bool refreshcache force refreshing of lang cache * @return array An associative array with contents in the form of LanguageCode => LanguageName */ -function get_list_of_languages() { +function get_list_of_languages($refreshcache=false, $forceall=false) { global $CFG; @@ -4542,9 +4542,8 @@ function get_list_of_languages() { $filetocheck = 'langconfig.php'; - if ( (!defined('FULLME') || FULLME !== 'cron') - && !empty($CFG->langcache) && file_exists($CFG->dataroot .'/cache/languages')) { - // read from cache + if (!$refreshcache && !$forceall && !empty($CFG->langcache) && file_exists($CFG->dataroot .'/cache/languages')) { +/// read available langs from cache $lines = file($CFG->dataroot .'/cache/languages'); foreach ($lines as $line) { @@ -4557,7 +4556,8 @@ function get_list_of_languages() { return $languages; } - if (!empty($CFG->langlist)) { // use admin's list of languages + if (!$forceall && !empty($CFG->langlist)) { +/// return only languages allowed in langlist admin setting $langlist = explode(',', $CFG->langlist); // fix short lang names first - non existing langs are skipped anyway... @@ -4594,7 +4594,9 @@ function get_list_of_languages() { unset($string); } } + } else { +/// return all languages available in system /// Fetch langs from moodle/lang directory $langdirs = get_list_of_plugins('lang'); /// Fetch langs from moodledata/lang directory @@ -4632,12 +4634,19 @@ function get_list_of_languages() { } } - if ( defined('FULLME') && FULLME === 'cron' && !empty($CFG->langcache)) { - if ($file = fopen($CFG->dataroot .'/cache/languages', 'w')) { - foreach ($languages as $key => $value) { - fwrite($file, "$key $value\n"); + if ($refreshcache && !empty($CFG->langcache)) { + if ($forceall) { + // we have a list of all langs only, just delete old cache + @unlink($CFG->dataroot.'/cache/languages'); + + } else { + // store the list of allowed languages + if ($file = fopen($CFG->dataroot .'/cache/languages', 'w')) { + foreach ($languages as $key => $value) { + fwrite($file, "$key $value\n"); + } + fclose($file); } - fclose($file); } } -- 2.39.5