]> git.mjollnir.org Git - moodle.git/commitdiff
Quick version of script to upgrade the old logs to the new format
authormoodler <moodler>
Tue, 3 Feb 2004 03:46:29 +0000 (03:46 +0000)
committermoodler <moodler>
Tue, 3 Feb 2004 03:46:29 +0000 (03:46 +0000)
admin/upgrade_logs.php [new file with mode: 0644]

diff --git a/admin/upgrade_logs.php b/admin/upgrade_logs.php
new file mode 100644 (file)
index 0000000..ad9504b
--- /dev/null
@@ -0,0 +1,73 @@
+<?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");
+    }
+
+    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();
+
+?>