Automatic installer.php lang files by installer_builder (20070726)
[moodle-linuxchix.git] / admin / upgradelogs.php
blob2803e2c2370ddd2d256da944d31e66a9dd5d11ff
1 <?PHP //$Id$
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.
20 @set_time_limit(0);
21 @ob_implicit_flush(true);
22 while(@ob_end_flush());
25 /// Print header
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();
36 exit;
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);
47 $count = 0;
48 $starttime = time();
49 $sleeptime = 0;
51 $LIKE = sql_ilike();
53 if ($cmcount > 10) {
54 print_simple_box('This process may take a very long time ... please be patient and let it finish.',
55 'center', '', '#ffcccc');
56 $sleeptime = 1;
58 foreach ($coursemodules as $cm) {
60 switch ($cm->name) {
61 case "forum":
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);
74 break;
76 case "glossary":
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);
79 break;
81 case "quiz":
82 execute_sql("UPDATE {$CFG->prefix}log SET cmid = '$cm->id'
83 WHERE module = '$cm->name' AND url = 'view.php?id=$cm->id'", false);
84 break;
86 case "assignment":
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);
93 break;
95 case "journal":
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);
101 break;
105 $count++;
106 $elapsedtime = time() - $starttime;
107 $projectedtime = (int)(((float)$cmcount / (float)$count) * $elapsedtime) - $elapsedtime;
109 if ($cmcount > 10) {
110 notify("Processed $count of $cmcount coursemodules. Estimated completion: ".format_time($projectedtime));
111 flush();
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();