]> git.mjollnir.org Git - moodle.git/commitdiff
New functions get_list_of_modules() and moodle_needs_upgrading().
authormartin <martin>
Fri, 9 Aug 2002 02:45:15 +0000 (02:45 +0000)
committermartin <martin>
Fri, 9 Aug 2002 02:45:15 +0000 (02:45 +0000)
Used on the home page when admin is logged in, to check for any
upgrading of the databases that might need to be done.

admin/index.php
index.php
lib/moodlelib.php
mod/forum/version.php

index d28a15697fa8d38d6f5bdae6b6f4f0ee896fec6f..d5e38ccb4ddb4908b4cbecbaba62804a90a7b84b 100644 (file)
 
     // Find and check all modules and load them up or upgrade them if necessary
 
-    $dir = opendir("$CFG->dirroot/mod");
-    while ($mod = readdir($dir)) {
-        if ($mod == "." || $mod == ".." || $mod == "CVS") {
-            continue;
-        }
 
+    if (!$mods = get_list_of_modules() ) {
+        error("No modules installed!");
+    }
+
+    foreach ($mods as $mod) {
         $fullmod = "$CFG->dirroot/mod/$mod";
-        if (filetype($fullmod) != "dir") {
-            continue;
-        }
 
         unset($module);
 
-        include_once("$CFG->dirroot/mod/$mod/version.php");  # defines $module with version etc
+        include_once("$fullmod/version.php");  # defines $module with version etc
 
         if (!isset($module)) {
             continue;
index ec6ebcf6fcaf1a0e5849947cb77a2bad63e53424..f006657b58f35e2e1524dcc84540f81546b1ff18 100644 (file)
--- a/index.php
+++ b/index.php
         redirect("$CFG->wwwroot/admin/");
     }
 
-    if (isset($USER->id)) {
+    if (isadmin()) {
+        if (moodle_needs_upgrading()) {
+            redirect("$CFG->wwwroot/admin/");
+        }
         $headerbutton = update_course_icon($site->id);
     } else {
         $headerbutton = "<FONT SIZE=2><A HREF=\"login/\">".get_string("login")."</A></FONT>";
index 9672f4820461a64b96ad4eeece269ae74c67130e..b2ccff6a8c9038deda7fc73922b31ff3d4455b28 100644 (file)
@@ -1513,8 +1513,8 @@ function add_to_log($course, $module, $action, $url="", $info="") {
 }
 
 function generate_password($maxlen=10) {
-/* returns a randomly generated password of length $maxlen.  inspired by
- * http://www.phpbuilder.com/columns/jesus19990502.php3 */
+// returns a randomly generated password of length $maxlen.  inspired by
+// http://www.phpbuilder.com/columns/jesus19990502.php3 
 
     global $CFG;
 
@@ -1529,6 +1529,53 @@ function generate_password($maxlen=10) {
     return substr($word1 . $filler1 . $word2, 0, $maxlen);
 }
 
+function moodle_needs_upgrading() {
+// Checks version numbers of Main code and all modules to see
+// if there are any mismatches ... returns true or false
+    global $CFG;
+
+    include_once("$CFG->dirroot/version.php");  # defines $version and upgrades
+    if ($dversion = get_field("config", "value", "name", "version")) { 
+        if ($version > $dversion) {
+            return true;
+        }
+        if ($mods = get_list_of_modules()) {
+            foreach ($mods as $mod) {
+                $fullmod = "$CFG->dirroot/mod/$mod";
+                unset($module);
+                include_once("$fullmod/version.php");  # defines $module with version etc
+                if ($currmodule = get_record("modules", "name", $mod)) {
+                    if ($module->version > $currmodule->version) {
+                        return true;
+                    }
+                }
+            }
+        }
+    } else {
+        return true;
+    }
+    return false;
+
+
+}
+
+
+function get_list_of_modules() {
+    global $CFG;
+
+    $dir = opendir("$CFG->dirroot/mod");
+    while ($mod = readdir($dir)) {
+        if ($mod == "." || $mod == ".." || $mod == "CVS") {
+            continue;
+        }
+        if (filetype("$CFG->dirroot/mod/$mod") != "dir") {
+            continue;
+        }
+        $mods[] = $mod;
+    }
+    return $mods;
+}
+
 
 
 ?>
index b19e9a73b9c4eaf88a24f05c65f1f99314e5a30a..0cbf060551e4c23ff1727fc478b16def1da12be2 100644 (file)
@@ -5,7 +5,7 @@
 //  This fragment is called by /admin/index.php
 ////////////////////////////////////////////////////////////////////////////////
 
-$module->version  = 2002080500;
+$module->version  = 2002080503;
 $module->cron     = 60;
 
 function forum_upgrade($oldversion) {