Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
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.
  • Loading branch information...
commit 53bfe78cd45cdfd6285ff33f774b969ff044d763 1 parent 01cfc1a
martin authored
View
15 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;
View
5 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 = "<FONT SIZE=2><A HREF=\"login/\">".get_string("login")."</A></FONT>";
View
51 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;
+}
+
?>
View
2  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) {
Please sign in to comment.
Something went wrong with that request. Please try again.