Commit 53bfe78c authored by martin's avatar martin
Browse files

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.
parent 01cfc1a0
......@@ -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;
......
......@@ -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 = "<FONT SIZE=2><A HREF=\"login/\">".get_string("login")."</A></FONT>";
......
......@@ -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;
}
?>
......@@ -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) {
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment