MDL-15977 create_file_from_storedfile should accept an original file object
[moodle.git] / mod / forum / db / upgrade.php
CommitLineData
b8a342d7 1<?php //$Id$
2
4e445355 3// This file keeps track of upgrades to
b8a342d7 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,
b1f93b15 18// using the methods of database_manager class
775f811a 19//
20// Please do not forget to use upgrade_set_timeout()
21// before any action that may take longer time to finish.
b8a342d7 22
775f811a 23function xmldb_forum_upgrade($oldversion) {
24 global $CFG, $DB;
b8a342d7 25
4e781c7b 26 $dbman = $DB->get_manager(); // loads ddl manager and xmldb classes
b8a342d7 27 $result = true;
28
f33e1ed4 29//===== 1.9.0 upgrade line ======//
f3c3a4d3 30
347037d8 31 if ($result and $oldversion < 2007101511) {
b30f2e92 32 //MDL-13866 - send forum ratins to gradebook again
33 require_once($CFG->dirroot.'/mod/forum/lib.php');
775f811a 34 forum_upgrade_grades();
04264aed 35 upgrade_mod_savepoint($result, 2007101511, 'forum');
b30f2e92 36 }
f3c3a4d3 37
90f4745c 38 if ($result && $oldversion < 2007101512) {
39
40 /// Cleanup the forum subscriptions
41 notify('Removing stale forum subscriptions', 'notifysuccess');
42
43 $roles = get_roles_with_capability('moodle/course:view', CAP_ALLOW);
44 $roles = array_keys($roles);
90f4745c 45
4e445355 46 list($usql, $params) = $DB->get_in_or_equal($roles);
90f4745c 47 $sql = "SELECT fs.userid, f.id AS forumid
219f652b 48 FROM {forum} f
49 JOIN {course} c ON c.id = f.course
50 JOIN {context} ctx ON (ctx.instanceid = c.id AND ctx.contextlevel = ".CONTEXT_COURSE.")
51 JOIN {forum_subscriptions} fs ON fs.forum = f.id
4e445355 52 LEFT JOIN {role_assignments} ra ON (ra.contextid = ctx.id AND ra.userid = fs.userid AND ra.roleid $usql)
90f4745c 53 WHERE ra.id IS NULL";
54
4e445355 55 if ($rs = $DB->get_recordset_sql($sql, $params)) {
f33e1ed4 56 $DB->set_debug(false);
219f652b 57 foreach ($rs as $remove) {
58 $DB->delete_records('forum_subscriptions', array('userid'=>$remove->userid, 'forum'=>$remove->forumid));
90f4745c 59 echo '.';
60 }
f33e1ed4 61 $DB->set_debug(true);
ca3c8973 62 $rs->close();
90f4745c 63 }
04264aed 64
65 upgrade_mod_savepoint($result, 2007101512, 'forum');
90f4745c 66 }
4e781c7b 67
4e781c7b 68 if ($result && $oldversion < 2008072800) {
69 /// Define field completiondiscussions to be added to forum
ba6d1638 70 $table = new xmldb_table('forum');
71 $field = new xmldb_field('completiondiscussions');
ee6a5a9d 72 $field->set_attributes(XMLDB_TYPE_INTEGER, '9', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null, null, '0', 'blockperiod');
4e781c7b 73
74 /// Launch add field completiondiscussions
75 if(!$dbman->field_exists($table,$field)) {
76 $dbman->add_field($table, $field);
77 }
78
ba6d1638 79 $field = new xmldb_field('completionreplies');
80 $field->set_attributes(XMLDB_TYPE_INTEGER, '9', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null, null, '0', 'completiondiscussions');
4e781c7b 81
82 /// Launch add field completionreplies
83 if(!$dbman->field_exists($table,$field)) {
84 $dbman->add_field($table, $field);
85 }
86
87 /// Define field completionposts to be added to forum
ba6d1638 88 $field = new xmldb_field('completionposts');
89 $field->set_attributes(XMLDB_TYPE_INTEGER, '9', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null, null, '0', 'completionreplies');
4e781c7b 90
91 /// Launch add field completionposts
92 if(!$dbman->field_exists($table,$field)) {
93 $dbman->add_field($table, $field);
94 }
95 upgrade_mod_savepoint($result, 2008072800, 'forum');
96 }
90f4745c 97
98
b8a342d7 99 return $result;
100}
101
102?>