3 require_once('../config.php');
4 require_once($CFG->libdir
.'/adminlib.php');
5 $adminroot = admin_get_root();
6 admin_externalpage_setup('upgradelogs', $adminroot);
8 $confirm = optional_param('confirm', 0, PARAM_BOOL
);
12 require_capability('moodle/site:config', get_context_instance(CONTEXT_SYSTEM
, SITEID
));
14 if ($CFG->version
< 2004013101) {
15 error("This script does not work with this old version of Moodle");
18 if (!$site = get_site()) {
19 redirect("index.php");
22 /// Turn off time limits, sometimes upgrades can be slow.
25 @ob_implicit_flush
(true);
26 while(@ob_end_flush
());
31 $strupgradinglogs = get_string("upgradinglogs", "admin");
32 admin_externalpage_print_header($adminroot);
33 print_heading($strupgradinglogs);
35 if (!data_submitted() or empty($confirm) or !confirm_sesskey()) {
36 $optionsyes = array('confirm'=>'1', 'sesskey'=>sesskey());
37 notice_yesno(get_string('upgradeforumreadinfo', 'admin'),
38 'upgradelogs.php', 'index.php', $optionsyes, NULL, 'post', 'get');
39 admin_externalpage_print_footer($adminroot);
44 /// Try and extract as many cmids as possible from the existing logs
46 if ($coursemodules = get_records_sql("SELECT cm.*, m.name
47 FROM {$CFG->prefix}course_modules cm,
48 {$CFG->prefix}modules m
49 WHERE cm.module = m.id")) {
50 $cmcount = count($coursemodules);
58 print_simple_box('This process may take a very long time ... please be patient and let it finish.',
59 'center', '', '#ffcccc');
62 foreach ($coursemodules as $cm) {
66 execute_sql("UPDATE {$CFG->prefix}log SET cmid = '$cm->id'
67 WHERE module = '$cm->name' AND url = 'view.php?id=$cm->id'", false);
69 execute_sql("UPDATE {$CFG->prefix}log SET cmid = '$cm->id'
70 WHERE module = '$cm->name' AND url = 'view.php?f=$cm->instance'", false);
72 if ($discussions = get_records("forum_discussions", "forum", $cm->instance
)) {
73 foreach ($discussions as $discussion) {
74 execute_sql("UPDATE {$CFG->prefix}log SET cmid = '$cm->id'
75 WHERE module = '$cm->name' AND url $LIKE 'discuss.php?d=$discussion->id%'", false);
81 execute_sql("UPDATE {$CFG->prefix}log SET cmid = '$cm->id'
82 WHERE module = '$cm->name' AND url $LIKE 'view.php?id=$cm->id%'", false);
86 execute_sql("UPDATE {$CFG->prefix}log SET cmid = '$cm->id'
87 WHERE module = '$cm->name' AND url = 'view.php?id=$cm->id'", false);
91 execute_sql("UPDATE {$CFG->prefix}log SET cmid = '$cm->id'
92 WHERE module = '$cm->name' AND url = 'view.php?id=$cm->id'", false);
93 execute_sql("UPDATE {$CFG->prefix}log SET cmid = '$cm->id'
94 WHERE module = '$cm->name' AND url = 'view.php?a=$cm->instance'", false);
95 execute_sql("UPDATE {$CFG->prefix}log SET cmid = '$cm->id'
96 WHERE module = '$cm->name' AND url = 'submissions.php?id=$cm->instance'", false);
100 execute_sql("UPDATE {$CFG->prefix}log SET cmid = '$cm->id'
101 WHERE module = '$cm->name' AND url = 'report.php?id=$cm->id'", false);
103 execute_sql("UPDATE {$CFG->prefix}log SET cmid = '$cm->id'
104 WHERE module = '$cm->name' AND url = 'view.php?id=$cm->id'", false);
110 $elapsedtime = time() - $starttime;
111 $projectedtime = (int)(((float)$cmcount / (float)$count) * $elapsedtime) - $elapsedtime;
114 notify("Processed $count of $cmcount coursemodules. Estimated completion: ".format_time($projectedtime));
116 sleep($sleeptime); // To help reduce database load
121 delete_records("config", "name", "upgrade", "value", "logs");
123 notify('Log upgrading was successful!', 'notifysuccess');
125 print_continue('index.php');
127 admin_externalpage_print_footer($adminroot);