From 53bfe78cd45cdfd6285ff33f774b969ff044d763 Mon Sep 17 00:00:00 2001 From: martin Date: Fri, 9 Aug 2002 02:45:15 +0000 Subject: [PATCH] New functions get_list_of_modules() and moodle_needs_upgrading(). 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 | 15 +++++-------- index.php | 5 ++++- lib/moodlelib.php | 51 +++++++++++++++++++++++++++++++++++++++++-- mod/forum/version.php | 2 +- 4 files changed, 60 insertions(+), 13 deletions(-) diff --git a/admin/index.php b/admin/index.php index d28a15697f..d5e38ccb4d 100644 --- a/admin/index.php +++ b/admin/index.php @@ -76,20 +76,17 @@ // 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; diff --git a/index.php b/index.php index ec6ebcf6fc..f006657b58 100644 --- a/index.php +++ b/index.php @@ -10,7 +10,10 @@ 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 = "".get_string("login").""; diff --git a/lib/moodlelib.php b/lib/moodlelib.php index 9672f48204..b2ccff6a8c 100644 --- a/lib/moodlelib.php +++ b/lib/moodlelib.php @@ -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; +} + ?> diff --git a/mod/forum/version.php b/mod/forum/version.php index b19e9a73b9..0cbf060551 100644 --- a/mod/forum/version.php +++ b/mod/forum/version.php @@ -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) { -- 2.39.5