2004-02-05 09:55:50 +00:00
|
|
|
<?PHP //$Id$
|
|
|
|
|
2006-03-07 11:13:57 +00:00
|
|
|
require_once('../config.php');
|
2004-02-05 09:55:50 +00:00
|
|
|
|
2006-03-07 11:13:57 +00:00
|
|
|
$confirm = optional_param('confirm', 0, PARAM_BOOL);
|
2004-02-05 09:55:50 +00:00
|
|
|
|
|
|
|
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.
|
|
|
|
|
2004-05-18 14:12:21 +00:00
|
|
|
@set_time_limit(0);
|
2004-02-05 09:55:50 +00:00
|
|
|
|
|
|
|
|
|
|
|
/// 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");
|
|
|
|
|
2005-06-15 12:31:09 +00:00
|
|
|
if (empty($confirm)) {
|
2004-02-05 09:55:50 +00:00
|
|
|
notice_yesno(get_string("upgradelogsinfo", "admin"),
|
2004-10-04 13:50:37 +00:00
|
|
|
"upgradelogs.php?confirm=true&sesskey=$USER->sesskey",
|
2004-02-05 09:55:50 +00:00
|
|
|
"index.php");
|
|
|
|
print_footer();
|
|
|
|
exit;
|
2004-10-04 13:50:37 +00:00
|
|
|
} else if (!confirm_sesskey()) {
|
|
|
|
error(get_string('confirmsesskeybad', 'error'));
|
2004-02-05 09:55:50 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/// 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";
|
|
|
|
}
|
|
|
|
|
2004-02-05 09:57:18 +00:00
|
|
|
if ($cmcount > 10) {
|
2004-02-05 09:55:50 +00:00
|
|
|
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'
|
2004-02-05 09:57:18 +00:00
|
|
|
WHERE module = '$cm->name' AND url = 'report.php?id=$cm->id'", false);
|
2004-02-05 09:55:50 +00:00
|
|
|
|
|
|
|
execute_sql("UPDATE {$CFG->prefix}log SET cmid = '$cm->id'
|
2004-02-05 09:57:18 +00:00
|
|
|
WHERE module = '$cm->name' AND url = 'view.php?id=$cm->id'", false);
|
2004-02-05 09:55:50 +00:00
|
|
|
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();
|
|
|
|
|
|
|
|
?>
|