3 require_once('../config.php');
4 require_once($CFG->libdir
.'/adminlib.php');
6 admin_externalpage_setup('upgradelogs');
8 $confirm = optional_param('confirm', 0, PARAM_BOOL
);
10 if ($CFG->version
< 2004013101) {
11 error("This script does not work with this old version of Moodle");
14 if (!$site = get_site()) {
15 redirect("index.php");
18 /// Turn off time limits, sometimes upgrades can be slow.
21 @ob_implicit_flush
(true);
22 while(@ob_end_flush
());
27 $strupgradinglogs = get_string("upgradinglogs", "admin");
28 admin_externalpage_print_header();
29 print_heading($strupgradinglogs);
31 if (!data_submitted() or empty($confirm) or !confirm_sesskey()) {
32 $optionsyes = array('confirm'=>'1', 'sesskey'=>sesskey());
33 notice_yesno(get_string('upgradeforumreadinfo', 'admin'),
34 'upgradelogs.php', 'index.php', $optionsyes, NULL, 'post', 'get');
35 admin_externalpage_print_footer();
40 /// Try and extract as many cmids as possible from the existing logs
42 if ($coursemodules = get_records_sql("SELECT cm.*, m.name
43 FROM {$CFG->prefix}course_modules cm,
44 {$CFG->prefix}modules m
45 WHERE cm.module = m.id")) {
46 $cmcount = count($coursemodules);
54 print_simple_box('This process may take a very long time ... please be patient and let it finish.',
55 'center', '', '#ffcccc');
58 foreach ($coursemodules as $cm) {
62 execute_sql("UPDATE {$CFG->prefix}log SET cmid = '$cm->id'
63 WHERE module = '$cm->name' AND url = 'view.php?id=$cm->id'", false);
65 execute_sql("UPDATE {$CFG->prefix}log SET cmid = '$cm->id'
66 WHERE module = '$cm->name' AND url = 'view.php?f=$cm->instance'", false);
68 if ($discussions = get_records("forum_discussions", "forum", $cm->instance
)) {
69 foreach ($discussions as $discussion) {
70 execute_sql("UPDATE {$CFG->prefix}log SET cmid = '$cm->id'
71 WHERE module = '$cm->name' AND url $LIKE 'discuss.php?d=$discussion->id%'", false);
77 execute_sql("UPDATE {$CFG->prefix}log SET cmid = '$cm->id'
78 WHERE module = '$cm->name' AND url $LIKE 'view.php?id=$cm->id%'", false);
82 execute_sql("UPDATE {$CFG->prefix}log SET cmid = '$cm->id'
83 WHERE module = '$cm->name' AND url = 'view.php?id=$cm->id'", false);
87 execute_sql("UPDATE {$CFG->prefix}log SET cmid = '$cm->id'
88 WHERE module = '$cm->name' AND url = 'view.php?id=$cm->id'", false);
89 execute_sql("UPDATE {$CFG->prefix}log SET cmid = '$cm->id'
90 WHERE module = '$cm->name' AND url = 'view.php?a=$cm->instance'", false);
91 execute_sql("UPDATE {$CFG->prefix}log SET cmid = '$cm->id'
92 WHERE module = '$cm->name' AND url = 'submissions.php?id=$cm->instance'", false);
96 execute_sql("UPDATE {$CFG->prefix}log SET cmid = '$cm->id'
97 WHERE module = '$cm->name' AND url = 'report.php?id=$cm->id'", false);
99 execute_sql("UPDATE {$CFG->prefix}log SET cmid = '$cm->id'
100 WHERE module = '$cm->name' AND url = 'view.php?id=$cm->id'", false);
106 $elapsedtime = time() - $starttime;
107 $projectedtime = (int)(((float)$cmcount / (float)$count) * $elapsedtime) - $elapsedtime;
110 notify("Processed $count of $cmcount coursemodules. Estimated completion: ".format_time($projectedtime));
112 sleep($sleeptime); // To help reduce database load
117 delete_records("config", "name", "upgrade", "value", "logs");
119 notify('Log upgrading was successful!', 'notifysuccess');
121 print_continue('index.php');
123 admin_externalpage_print_footer();