b8a342d7 |
1 | <?php //$Id$ |
2 | |
3 | // This file keeps track of upgrades to |
4 | // the forum module |
5 | // |
6 | // Sometimes, changes between versions involve |
7 | // alterations to database structures and other |
8 | // major things that may break installations. |
9 | // |
10 | // The upgrade function in this file will attempt |
11 | // to perform all the necessary actions to upgrade |
12 | // your older installtion to the current version. |
13 | // |
14 | // If there's something it cannot do itself, it |
15 | // will tell you what you need to do. |
16 | // |
17 | // The commands in here will all be database-neutral, |
18 | // using the functions defined in lib/ddllib.php |
19 | |
20 | function xmldb_forum_upgrade($oldversion=0) { |
21 | |
22 | global $CFG, $THEME, $db; |
23 | |
24 | $result = true; |
25 | |
26 | /// And upgrade begins here. For each one, you'll need one |
27 | /// block of code similar to the next one. Please, delete |
28 | /// this comment lines once this file start handling proper |
29 | /// upgrade code. |
30 | |
31 | /// if ($result && $oldversion < YYYYMMDD00) { //New version in version.php |
32 | /// $result = result of "/lib/ddllib.php" function calls |
33 | /// } |
34 | |
f3c3a4d3 |
35 | if ($result && $oldversion < 2007101000) { |
36 | |
37 | /// Define field timemodified to be added to forum_queue |
38 | $table = new XMLDBTable('forum_queue'); |
39 | $field = new XMLDBField('timemodified'); |
40 | $field->setAttributes(XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null, null, '0', 'postid'); |
41 | |
42 | /// Launch add field timemodified |
43 | $result = $result && add_field($table, $field); |
44 | } |
45 | |
347037d8 |
46 | if ($result and $oldversion < 2007101511) { |
25220be3 |
47 | notify('Processing forum grades, this may take a while if there are many forums...', 'notifysuccess'); |
b30f2e92 |
48 | //MDL-13866 - send forum ratins to gradebook again |
49 | require_once($CFG->dirroot.'/mod/forum/lib.php'); |
50 | // too much debug output |
51 | $db->debug = false; |
52 | forum_update_grades(); |
53 | $db->debug = true; |
54 | } |
f3c3a4d3 |
55 | |
90f4745c |
56 | if ($result && $oldversion < 2007101512) { |
57 | |
58 | /// Cleanup the forum subscriptions |
59 | notify('Removing stale forum subscriptions', 'notifysuccess'); |
60 | |
61 | $roles = get_roles_with_capability('moodle/course:view', CAP_ALLOW); |
62 | $roles = array_keys($roles); |
63 | $roles = implode(',', $roles); |
64 | |
65 | $sql = "SELECT fs.userid, f.id AS forumid |
66 | FROM {$CFG->prefix}forum f |
67 | JOIN {$CFG->prefix}course c ON c.id = f.course |
68 | JOIN {$CFG->prefix}context ctx ON (ctx.instanceid = c.id AND ctx.contextlevel = ".CONTEXT_COURSE.") |
69 | JOIN {$CFG->prefix}forum_subscriptions fs ON fs.forum = f.id |
70 | LEFT JOIN {$CFG->prefix}role_assignments ra ON (ra.contextid = ctx.id AND ra.userid = fs.userid AND ra.roleid IN ($roles)) |
71 | WHERE ra.id IS NULL"; |
72 | |
73 | if ($rs = get_recordset_sql($sql)) { |
74 | $db->debug = false; |
75 | while ($remove = rs_fetch_next_record($rs)) { |
76 | delete_records('forum_subscriptions', 'userid', $remove->userid, 'forum', $remove->forumid); |
77 | echo '.'; |
78 | } |
79 | $db->debug = true; |
80 | rs_close($rs); |
81 | } |
82 | } |
83 | |
84 | |
b8a342d7 |
85 | return $result; |
86 | } |
87 | |
88 | ?> |