if (!empty($CFG->langcache)) {
mtrace('Updating languages cache');
- get_list_of_languages();
+ get_list_of_languages(true);
}
mtrace('Removing expired enrolments ...', ''); // See MDL-8785
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("<a href=\"lang.php?mode=missing\">$strmissingstrings</a>");
print_heading("<a href=\"lang.php?mode=compare\">$streditstrings</a>");
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){
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;
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
$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
echo '<form id="uninstallform" action="langimport.php?mode=4" method="post">';
echo '<fieldset class="invisiblefieldset">';
echo '<input name="sesskey" type="hidden" value="'.sesskey().'" />';
- unset($CFG->langlist); // ignore admin's langlist
- $installedlangs = get_list_of_languages();
+ $installedlangs = get_list_of_languages(false, true);
/// display installed langs here
/**
* 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;
$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) {
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...
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
}
}
- 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);
}
}