MDL-9561 Langimport does not ignore langlist when langcache used
authorskodak <skodak>
Tue, 24 Apr 2007 16:14:16 +0000 (16:14 +0000)
committerskodak <skodak>
Tue, 24 Apr 2007 16:14:16 +0000 (16:14 +0000)
MDL-9563 Improve refreshing of langcache, detect permission problems

merged from MOODLE_18_STABLE

admin/cron.php
admin/lang.php
admin/langimport.php
lib/moodlelib.php

index dbc2a3027ba38893c7edf87a32849cc1dba3bf93..b703bc292a29356a932dca77a727d04601c439aa 100644 (file)
 
     if (!empty($CFG->langcache)) {
         mtrace('Updating languages cache');
-        get_list_of_languages();
+        get_list_of_languages(true);
     }
 
     mtrace('Removing expired enrolments ...', '');     // See MDL-8785
index 427eb5edd3e499fbd5a28eb5de569cea1ae49385..151d88ed3536b970b7c503a748ac557294e4a79a 100644 (file)
@@ -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("<a href=\"lang.php?mode=missing\">$strmissingstrings</a>");
         print_heading("<a href=\"lang.php?mode=compare\">$streditstrings</a>");
index 5e74a245731d0514d3d18bd6f9865a49557a105e..94a1b4bb84394ad37365df0dc3f4cb4468eff534 100755 (executable)
 
     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;
 
                 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
 
index 543d66f062e8a046a4a8688736eb3110951a77f0..4c1d0428bbd7362dd865bb90ede5dcadf28bc2eb 100644 (file)
@@ -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);
         }
     }