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.
This commit is contained in:
martin
2002-08-09 02:45:15 +00:00
parent 01cfc1a02a
commit 53bfe78cd4
4 changed files with 60 additions and 13 deletions
+49 -2
View 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;
}
?>