From: moodler Date: Thu, 5 Feb 2004 09:55:50 +0000 (+0000) Subject: Improvements to the way the log upgrading works. X-Git-Url: http://git.mjollnir.org/gw?a=commitdiff_plain;h=4da1a0a1dbf92f5a743a36c97dd4fa8022d0a4c1;p=moodle.git Improvements to the way the log upgrading works. Centralised with an interface now. --- diff --git a/admin/index.php b/admin/index.php index 6f562327aa..7b33de008f 100644 --- a/admin/index.php +++ b/admin/index.php @@ -358,6 +358,12 @@ 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 index 8aa94098b5..0000000000 --- a/admin/upgrade_logs.php +++ /dev/null @@ -1,80 +0,0 @@ -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 index 0000000000..ff6c1c09e2 --- /dev/null +++ b/admin/upgradelogs.php @@ -0,0 +1,131 @@ +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", + "$stradministration -> $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(); + +?> diff --git a/lib/db/mysql.php b/lib/db/mysql.php index f43738dce0..821ec443be 100644 --- a/lib/db/mysql.php +++ b/lib/db/mysql.php @@ -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 '

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:

'; - echo "

$CFG->wwwroot/$CFG->admin/upgrade_logs.php

"; - 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; diff --git a/lib/db/postgres7.php b/lib/db/postgres7.php index 36bd38f050..2f33b51605 100644 --- a/lib/db/postgres7.php +++ b/lib/db/postgres7.php @@ -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 '

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:

'; - echo "

$CFG->wwwroot/$CFG->admin/upgrade_logs.php

"; - 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;