Bumping version for 1.8.10 release (note new convention for numbering)
[moodle.git] / admin / upgradelogs.php
bloba70327a964909dd5f3d8952d3a5ba99e3809a928
1 <?PHP //$Id$
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);
10 require_login();
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.
24 @set_time_limit(0);
25 @ob_implicit_flush(true);
26 while(@ob_end_flush());
29 /// Print header
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);
40 exit;
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);
51 $count = 0;
52 $starttime = time();
53 $sleeptime = 0;
55 $LIKE = sql_ilike();
57 if ($cmcount > 10) {
58 print_simple_box('This process may take a very long time ... please be patient and let it finish.',
59 'center', '', '#ffcccc');
60 $sleeptime = 1;
62 foreach ($coursemodules as $cm) {
64 switch ($cm->name) {
65 case "forum":
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);
78 break;
80 case "glossary":
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);
83 break;
85 case "quiz":
86 execute_sql("UPDATE {$CFG->prefix}log SET cmid = '$cm->id'
87 WHERE module = '$cm->name' AND url = 'view.php?id=$cm->id'", false);
88 break;
90 case "assignment":
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);
97 break;
99 case "journal":
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);
105 break;
109 $count++;
110 $elapsedtime = time() - $starttime;
111 $projectedtime = (int)(((float)$cmcount / (float)$count) * $elapsedtime) - $elapsedtime;
113 if ($cmcount > 10) {
114 notify("Processed $count of $cmcount coursemodules. Estimated completion: ".format_time($projectedtime));
115 flush();
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);