mirror of
https://github.com/moodle/moodle.git
synced 2025-06-02 06:05:31 +02:00
Improvements to the way the log upgrading works.
Centralised with an interface now.
This commit is contained in:
parent
14076f3ad7
commit
4da1a0a1db
@ -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");
|
||||
|
@ -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();
|
||||
|
||||
?>
|
131
admin/upgradelogs.php
Normal file
131
admin/upgradelogs.php
Normal file
@ -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();
|
||||
|
||||
?>
|
@ -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;
|
||||
|
@ -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;
|
||||
|
Loading…
x
Reference in New Issue
Block a user