File: upgradelogs.php

package info (click to toggle)
moodle 1.6.3-2%2Betch3
  • links: PTS
  • area: main
  • in suites: etch
  • size: 37,172 kB
  • ctags: 51,688
  • sloc: php: 231,916; sql: 5,631; xml: 2,688; sh: 1,185; perl: 638; makefile: 48; pascal: 36
file content (133 lines) | stat: -rw-r--r-- 5,153 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
<?PHP  //$Id: upgradelogs.php,v 1.6 2006/03/07 11:13:57 skodak Exp $

    require_once('../config.php');

    $confirm = optional_param('confirm', 0, PARAM_BOOL);

    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.

    @set_time_limit(0);


/// 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");

    if (empty($confirm)) {
        notice_yesno(get_string("upgradelogsinfo", "admin"), 
                     "upgradelogs.php?confirm=true&sesskey=$USER->sesskey", 
                     "index.php");
        print_footer();
        exit;
    } else if (!confirm_sesskey()) {
        error(get_string('confirmsesskeybad', 'error'));
    }


/// 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";
        }

        if ($cmcount > 10) {
            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' 
                                 WHERE module = '$cm->name' AND url = 'report.php?id=$cm->id'", false);

                    execute_sql("UPDATE {$CFG->prefix}log SET cmid = '$cm->id' 
                                 WHERE module = '$cm->name' AND url = 'view.php?id=$cm->id'", false);
                    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();

?>