]> git.mjollnir.org Git - moodle.git/commitdiff
Improvements to the way the log upgrading works.
authormoodler <moodler>
Thu, 5 Feb 2004 09:55:50 +0000 (09:55 +0000)
committermoodler <moodler>
Thu, 5 Feb 2004 09:55:50 +0000 (09:55 +0000)
Centralised with an interface now.

admin/index.php
admin/upgrade_logs.php [deleted file]
admin/upgradelogs.php [new file with mode: 0644]
lib/db/mysql.php
lib/db/postgres7.php

index 6f562327aa1cd8ce455bc76fe9479b267b3a1017..7b33de008f288e6f289bd45c2d902730b562a3d8 100644 (file)
     print_simple_box_start("center", "100%", "$THEME->cellcontent2", 20);
     print_heading($stradministration);
 
+    if (!empty($CFG->upgrade)) {  // Print notice about extra upgrading that needs to be done
+        print_simple_box(get_string("upgrade$CFG->upgrade", "admin", 
+                                    "$CFG->wwwroot/$CFG->admin/upgrade$CFG->upgrade.php"), "center");
+        print_spacer(10,10);
+    }
+
     $table->tablealign = "right";
     $table->align = array ("right", "left");
     $table->wrap = array ("nowrap", "nowrap");
diff --git a/admin/upgrade_logs.php b/admin/upgrade_logs.php
deleted file mode 100644 (file)
index 8aa9409..0000000
+++ /dev/null
@@ -1,80 +0,0 @@
-<?PHP  //$Id$
-
-    require("../config.php");
-
-    require_login();
-
-    if (!isadmin()) {
-        error("You must be an admin to use this script");
-    }
-
-    if ($CFG->version < 2004013101) {
-        error("This script does not work with this old version of Moodle");
-    }
-
-/// Turn off time limits, sometimes upgrades can be slow.
-
-    set_time_limit(0);
-
-
-/// Print header
-
-    print_header("Upgrading old logs", "Upgrading old logs");
-
-
-/// Try and extract as many cmids as possible from the existing logs
-
-    if ($coursemodules = get_records_sql("SELECT cm.*, m.name 
-                                            FROM {$CFG->prefix}course_modules cm, 
-                                                 {$CFG->prefix}modules m
-                                            WHERE cm.module = m.id")) {
-        $cmcount = count($coursemodules);
-        $count = 0;
-        $starttime = time();
-        $sleeptime = 0;
-
-        if ($CFG->dbtype == "mysql") {
-            $LIKE = "LIKE";
-        } else {
-            $LIKE = "ILIKE";
-        }
-
-        if ($cmcount > 20) {
-            print_simple_box('This process may take a very long time ... please be patient and let it finish.', 
-                             'center', '', '#ffcccc');
-            $sleeptime = 1;
-        }
-        foreach ($coursemodules as $cm) {
-            execute_sql("UPDATE {$CFG->prefix}log SET cmid = '$cm->id' 
-                         WHERE module = '$cm->name' AND url $LIKE 'view.php?id=$cm->id%'", false);
-
-            if ($cm->name == "forum") {
-
-                execute_sql("UPDATE {$CFG->prefix}log SET cmid = '$cm->id' 
-                             WHERE module = 'forum' AND url $LIKE '%?f=$cm->instance%'", false);
-
-                if ($discussions = get_records("forum_discussions", "forum", $cm->instance)) {
-                    foreach ($discussions as $discussion) {
-                        execute_sql("UPDATE {$CFG->prefix}log SET cmid = '$cm->id' 
-                                     WHERE module = 'forum' AND url $LIKE '%?d=$discussion->id%'", false);
-                    }
-                }
-            }
-
-            $count++;
-            $elapsedtime = time() - $starttime;
-            $projectedtime = (int)(((float)$cmcount / (float)$count) * $elapsedtime) - $elapsedtime;
-
-            if ($cmcount > 10) {
-                notify("Processed $count of $cmcount coursemodules.  Estimated completion: ".format_time($projectedtime));
-                flush();
-                sleep($sleeptime);     // To help reduce database load
-            }
-        }
-    }
-
-    notify("Log upgrading was successful!");
-
-    print_footer();
-
-?>
diff --git a/admin/upgradelogs.php b/admin/upgradelogs.php
new file mode 100644 (file)
index 0000000..ff6c1c0
--- /dev/null
@@ -0,0 +1,131 @@
+<?PHP  //$Id$
+
+    require("../config.php");
+
+    optional_variable($confirm);
+
+    require_login();
+
+    if (!isadmin()) {
+        error("You must be an admin to use this script");
+    }
+
+    if ($CFG->version < 2004013101) {
+        error("This script does not work with this old version of Moodle");
+    }
+
+    if (!$site = get_site()) {
+        redirect("index.php");
+    }
+
+/// Turn off time limits, sometimes upgrades can be slow.
+
+    set_time_limit(0);
+
+
+/// Print header
+
+    $stradministration = get_string("administration");
+    $strupgradinglogs  = get_string("upgradinglogs", "admin");
+
+    print_header("$site->shortname: $stradministration: $strupgradinglogs", "$site->fullname", 
+                 "<a href=\"index.php\">$stradministration</a> -> $strupgradinglogs");
+
+    if (empty($_GET['confirm'])) {
+        notice_yesno(get_string("upgradelogsinfo", "admin"), 
+                     "upgradelogs.php?confirm=true", 
+                     "index.php");
+        print_footer();
+        exit;
+    }
+
+
+/// Try and extract as many cmids as possible from the existing logs
+
+    if ($coursemodules = get_records_sql("SELECT cm.*, m.name 
+                                            FROM {$CFG->prefix}course_modules cm, 
+                                                 {$CFG->prefix}modules m
+                                            WHERE cm.module = m.id")) {
+        $cmcount = count($coursemodules);
+        $count = 0;
+        $starttime = time();
+        $sleeptime = 0;
+
+        if ($CFG->dbtype == "mysql") {
+            $LIKE = "LIKE";
+        } else {
+            $LIKE = "ILIKE";
+        }
+
+        if ($cmcount > 20) {
+            print_simple_box('This process may take a very long time ... please be patient and let it finish.', 
+                             'center', '', '#ffcccc');
+            $sleeptime = 1;
+        }
+        foreach ($coursemodules as $cm) {
+
+            switch ($cm->name) { 
+                case "forum":
+                    execute_sql("UPDATE {$CFG->prefix}log SET cmid = '$cm->id' 
+                                 WHERE module = '$cm->name' AND url = 'view.php?id=$cm->id'", false);
+
+                    execute_sql("UPDATE {$CFG->prefix}log SET cmid = '$cm->id' 
+                                 WHERE module = '$cm->name' AND url = 'view.php?f=$cm->instance'", false);
+    
+                    if ($discussions = get_records("forum_discussions", "forum", $cm->instance)) {
+                        foreach ($discussions as $discussion) {
+                            execute_sql("UPDATE {$CFG->prefix}log SET cmid = '$cm->id' 
+                                         WHERE module = '$cm->name' AND url $LIKE 'discuss.php?d=$discussion->id%'", false);
+                        }
+                    }
+                    break;
+
+                case "glossary": 
+                    execute_sql("UPDATE {$CFG->prefix}log SET cmid = '$cm->id' 
+                                 WHERE module = '$cm->name' AND url $LIKE 'view.php?id=$cm->id%'", false);
+                    break;
+
+                case "quiz": 
+                    execute_sql("UPDATE {$CFG->prefix}log SET cmid = '$cm->id' 
+                                 WHERE module = '$cm->name' AND url = 'view.php?id=$cm->id'", false);
+                    break;
+
+                case "assignment": 
+                    execute_sql("UPDATE {$CFG->prefix}log SET cmid = '$cm->id' 
+                                 WHERE module = '$cm->name' AND url = 'view.php?id=$cm->id'", false);
+                    execute_sql("UPDATE {$CFG->prefix}log SET cmid = '$cm->id' 
+                                 WHERE module = '$cm->name' AND url = 'view.php?a=$cm->instance'", false);
+                    execute_sql("UPDATE {$CFG->prefix}log SET cmid = '$cm->id' 
+                                 WHERE module = '$cm->name' AND url = 'submissions.php?id=$cm->instance'", false);
+                    break;
+                    
+                case "journal": 
+                    execute_sql("UPDATE {$CFG->prefix}log SET cmid = '$cm->id' 
+                                 WHERE module = '$cm->name' AND url = 'report.php?id=$cm->id'");
+
+                    execute_sql("UPDATE {$CFG->prefix}log SET cmid = '$cm->id' 
+                                 WHERE module = '$cm->name' AND url = 'view.php?id=$cm->id'");
+                    break;
+
+            }
+
+            $count++;
+            $elapsedtime = time() - $starttime;
+            $projectedtime = (int)(((float)$cmcount / (float)$count) * $elapsedtime) - $elapsedtime;
+
+            if ($cmcount > 10) {
+                notify("Processed $count of $cmcount coursemodules.  Estimated completion: ".format_time($projectedtime));
+                flush();
+                sleep($sleeptime);     // To help reduce database load
+            }
+        }
+    }
+
+    delete_records("config", "name", "upgrade", "value", "logs");
+
+    notify("Log upgrading was successful!");
+
+
+    print_footer();
+
+?>
index f43738dce0c64621a54c20cfc430f313bbefb3a9..821ec443be5914f1e97977bf31343a32badde086 100644 (file)
@@ -636,42 +636,7 @@ function main_upgrade($oldversion=0) {
 
     if ($oldversion < 2004013101) {
         table_column("log", "", "cmid", "integer", "10", "unsigned", "0", "", "module");
-
-
-        if ($coursemodules = get_records_sql("SELECT cm.*, m.name 
-                                                FROM {$CFG->prefix}course_modules cm, 
-                                                     {$CFG->prefix}modules m
-                                                WHERE cm.module = m.id")) {
-
-            $cmcount = count($coursemodules);
-
-            if ($cmcount > 10) {   /// Process the logs later
-                print_simple_box_start("center", "", "#ffcccc");
-                echo '<p>Your old logs may need to be upgraded to take advantage of some new features.';
-                echo 'To upgrade your logs, go to this page AFTER Moodle is completely upgraded:</p>';
-                echo "<p>  $CFG->wwwroot/$CFG->admin/upgrade_logs.php</p>";
-                print_simple_box_end();
-
-            } else {               /// Process the logs now (there aren't that many)
-                notify("Upgrading old logs with new data from $cmcount coursemodules.");
-                foreach ($coursemodules as $cm) {
-                    execute_sql("UPDATE {$CFG->prefix}log SET cmid = '$cm->id' 
-                                 WHERE module = '$cm->name' AND url LIKE 'view.php?id=$cm->id%'");
-                    if ($cm->name == "forum") {
-                        execute_sql("UPDATE {$CFG->prefix}log SET cmid = '$cm->id' 
-                                     WHERE module = 'forum' AND url LIKE '%?f=$cm->instance%'");
-                        if ($discussions = get_records("forum_discussions", "forum", $cm->instance)) {
-                            notify("Processing ".count($discussions)." discussions");
-                            foreach ($discussions as $discussion) {
-                                execute_sql("UPDATE {$CFG->prefix}log SET cmid = '$cm->id' 
-                                             WHERE module = 'forum' AND url LIKE '%?d=$discussion->id%'");
-                            }
-                        }
-                    }
-                    flush();
-                }
-            }
-        }
+        set_config("upgrade", "logs");
     }
 
     return $result;
index 36bd38f050713519380a50988780664b13aa84cb..2f33b51605c364ff4d00f161216a37194c43f366 100644 (file)
@@ -382,42 +382,7 @@ function main_upgrade($oldversion=0) {
 
     if ($oldversion < 2004013101) {
         table_column("log", "", "cmid", "integer", "10", "unsigned", "0", "", "module");
-
-
-        if ($coursemodules = get_records_sql("SELECT cm.*, m.name 
-                                                FROM {$CFG->prefix}course_modules cm, 
-                                                     {$CFG->prefix}modules m
-                                                WHERE cm.module = m.id")) {
-
-            $cmcount = count($coursemodules);
-
-            if ($cmcount > 10) {   /// Process the logs later
-                print_simple_box_start("center", "", "#ffcccc");
-                echo '<p>Your old logs may need to be upgraded to take advantage of some new features.';
-                echo 'To upgrade your logs, go to this page AFTER Moodle is completely upgraded:</p>';
-                echo "<p>  $CFG->wwwroot/$CFG->admin/upgrade_logs.php</p>";
-                print_simple_box_end();
-
-            } else {               /// Process the logs now (there aren't that many)
-                notify("Upgrading old logs with new data from $cmcount coursemodules.");
-                foreach ($coursemodules as $cm) {
-                    execute_sql("UPDATE {$CFG->prefix}log SET cmid = '$cm->id' 
-                                 WHERE module = '$cm->name' AND url ILIKE 'view.php?id=$cm->id%'");
-                    if ($cm->name == "forum") {
-                        execute_sql("UPDATE {$CFG->prefix}log SET cmid = '$cm->id' 
-                                     WHERE module = 'forum' AND url ILIKE '%?f=$cm->instance%'");
-                        if ($discussions = get_records("forum_discussions", "forum", $cm->instance)) {
-                            notify("Processing ".count($discussions)." discussions");
-                            foreach ($discussions as $discussion) {
-                                execute_sql("UPDATE {$CFG->prefix}log SET cmid = '$cm->id' 
-                                             WHERE module = 'forum' AND url ILIKE '%?d=$discussion->id%'");
-                            }
-                        }
-                    }
-                    flush();
-                }
-            }
-        }
+        set_config("upgrade", "logs");
     }
 
     return $result;