[ Index ] |
PHP Cross Reference of moodle-2.8 |
[Summary view] [Print] [Text view]
1 <?php 2 3 // This file is part of Moodle - http://moodle.org/ 4 // 5 // Moodle is free software: you can redistribute it and/or modify 6 // it under the terms of the GNU General Public License as published by 7 // the Free Software Foundation, either version 3 of the License, or 8 // (at your option) any later version. 9 // 10 // Moodle is distributed in the hope that it will be useful, 11 // but WITHOUT ANY WARRANTY; without even the implied warranty of 12 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 // GNU General Public License for more details. 14 // 15 // You should have received a copy of the GNU General Public License 16 // along with Moodle. If not, see <http://www.gnu.org/licenses/>. 17 18 /** 19 * This file keeps track of upgrades to 20 * the forum module 21 * 22 * Sometimes, changes between versions involve 23 * alterations to database structures and other 24 * major things that may break installations. 25 * 26 * The upgrade function in this file will attempt 27 * to perform all the necessary actions to upgrade 28 * your older installation to the current version. 29 * 30 * If there's something it cannot do itself, it 31 * will tell you what you need to do. 32 * 33 * The commands in here will all be database-neutral, 34 * using the methods of database_manager class 35 * 36 * Please do not forget to use upgrade_set_timeout() 37 * before any action that may take longer time to finish. 38 * 39 * @package mod_forum 40 * @copyright 2003 onwards Eloy Lafuente (stronk7) {@link http://stronk7.com} 41 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later 42 */ 43 44 function xmldb_forum_upgrade($oldversion) { 45 global $CFG, $DB, $OUTPUT; 46 47 $dbman = $DB->get_manager(); // Loads ddl manager and xmldb classes. 48 49 // Moodle v2.2.0 release upgrade line. 50 // Put any upgrade step following this. 51 52 // Moodle v2.3.0 release upgrade line. 53 // Put any upgrade step following this. 54 55 // Moodle v2.4.0 release upgrade line. 56 // Put any upgrade step following this. 57 58 if ($oldversion < 2013020500) { 59 60 // Define field displaywordcount to be added to forum. 61 $table = new xmldb_table('forum'); 62 $field = new xmldb_field('displaywordcount', XMLDB_TYPE_INTEGER, '1', null, XMLDB_NOTNULL, null, '0', 'completionposts'); 63 64 // Conditionally launch add field displaywordcount. 65 if (!$dbman->field_exists($table, $field)) { 66 $dbman->add_field($table, $field); 67 } 68 69 // Forum savepoint reached. 70 upgrade_mod_savepoint(true, 2013020500, 'forum'); 71 } 72 73 // Forcefully assign mod/forum:allowforcesubscribe to frontpage role, as we missed that when 74 // capability was introduced. 75 if ($oldversion < 2013021200) { 76 // If capability mod/forum:allowforcesubscribe is defined then set it for frontpage role. 77 if (get_capability_info('mod/forum:allowforcesubscribe')) { 78 assign_legacy_capabilities('mod/forum:allowforcesubscribe', array('frontpage' => CAP_ALLOW)); 79 } 80 // Forum savepoint reached. 81 upgrade_mod_savepoint(true, 2013021200, 'forum'); 82 } 83 84 85 // Moodle v2.5.0 release upgrade line. 86 // Put any upgrade step following this. 87 if ($oldversion < 2013071000) { 88 // Define table forum_digests to be created. 89 $table = new xmldb_table('forum_digests'); 90 91 // Adding fields to table forum_digests. 92 $table->add_field('id', XMLDB_TYPE_INTEGER, '10', null, XMLDB_NOTNULL, XMLDB_SEQUENCE, null); 93 $table->add_field('userid', XMLDB_TYPE_INTEGER, '10', null, XMLDB_NOTNULL, null, null); 94 $table->add_field('forum', XMLDB_TYPE_INTEGER, '10', null, XMLDB_NOTNULL, null, null); 95 $table->add_field('maildigest', XMLDB_TYPE_INTEGER, '1', null, XMLDB_NOTNULL, null, '-1'); 96 97 // Adding keys to table forum_digests. 98 $table->add_key('primary', XMLDB_KEY_PRIMARY, array('id')); 99 $table->add_key('userid', XMLDB_KEY_FOREIGN, array('userid'), 'user', array('id')); 100 $table->add_key('forum', XMLDB_KEY_FOREIGN, array('forum'), 'forum', array('id')); 101 $table->add_key('forumdigest', XMLDB_KEY_UNIQUE, array('forum', 'userid', 'maildigest')); 102 103 // Conditionally launch create table for forum_digests. 104 if (!$dbman->table_exists($table)) { 105 $dbman->create_table($table); 106 } 107 108 // Forum savepoint reached. 109 upgrade_mod_savepoint(true, 2013071000, 'forum'); 110 } 111 112 // Moodle v2.6.0 release upgrade line. 113 // Put any upgrade step following this. 114 115 if ($oldversion < 2014040400) { 116 117 // Define index userid-postid (not unique) to be dropped form forum_read. 118 $table = new xmldb_table('forum_read'); 119 $index = new xmldb_index('userid-postid', XMLDB_INDEX_NOTUNIQUE, array('userid', 'postid')); 120 121 // Conditionally launch drop index userid-postid. 122 if ($dbman->index_exists($table, $index)) { 123 $dbman->drop_index($table, $index); 124 } 125 126 127 // Define index postid-userid (not unique) to be added to forum_read. 128 $index = new xmldb_index('postid-userid', XMLDB_INDEX_NOTUNIQUE, array('postid', 'userid')); 129 130 // Conditionally launch add index postid-userid. 131 if (!$dbman->index_exists($table, $index)) { 132 $dbman->add_index($table, $index); 133 } 134 135 // Forum savepoint reached. 136 upgrade_mod_savepoint(true, 2014040400, 'forum'); 137 } 138 139 // Moodle v2.7.0 release upgrade line. 140 // Put any upgrade step following this. 141 142 if ($oldversion < 2014051201) { 143 144 // Incorrect values that need to be replaced. 145 $replacements = array( 146 11 => 20, 147 12 => 50, 148 13 => 100 149 ); 150 151 // Run the replacements. 152 foreach ($replacements as $old => $new) { 153 $DB->set_field('forum', 'maxattachments', $new, array('maxattachments' => $old)); 154 } 155 156 // Forum savepoint reached. 157 upgrade_mod_savepoint(true, 2014051201, 'forum'); 158 } 159 160 if ($oldversion < 2014081500) { 161 162 // Define index course (not unique) to be added to forum_discussions. 163 $table = new xmldb_table('forum_discussions'); 164 $index = new xmldb_index('course', XMLDB_INDEX_NOTUNIQUE, array('course')); 165 166 // Conditionally launch add index course. 167 if (!$dbman->index_exists($table, $index)) { 168 $dbman->add_index($table, $index); 169 } 170 171 // Forum savepoint reached. 172 upgrade_mod_savepoint(true, 2014081500, 'forum'); 173 } 174 175 if ($oldversion < 2014081900) { 176 177 // Define table forum_discussion_subs to be created. 178 $table = new xmldb_table('forum_discussion_subs'); 179 180 // Adding fields to table forum_discussion_subs. 181 $table->add_field('id', XMLDB_TYPE_INTEGER, '10', null, XMLDB_NOTNULL, XMLDB_SEQUENCE, null); 182 $table->add_field('forum', XMLDB_TYPE_INTEGER, '10', null, XMLDB_NOTNULL, null, null); 183 $table->add_field('userid', XMLDB_TYPE_INTEGER, '10', null, XMLDB_NOTNULL, null, null); 184 $table->add_field('discussion', XMLDB_TYPE_INTEGER, '10', null, XMLDB_NOTNULL, null, null); 185 $table->add_field('preference', XMLDB_TYPE_INTEGER, '1', null, XMLDB_NOTNULL, null, '1'); 186 187 // Adding keys to table forum_discussion_subs. 188 $table->add_key('primary', XMLDB_KEY_PRIMARY, array('id')); 189 $table->add_key('forum', XMLDB_KEY_FOREIGN, array('forum'), 'forum', array('id')); 190 $table->add_key('userid', XMLDB_KEY_FOREIGN, array('userid'), 'user', array('id')); 191 $table->add_key('discussion', XMLDB_KEY_FOREIGN, array('discussion'), 'forum_discussions', array('id')); 192 $table->add_key('user_discussions', XMLDB_KEY_UNIQUE, array('userid', 'discussion')); 193 194 // Conditionally launch create table for forum_discussion_subs. 195 if (!$dbman->table_exists($table)) { 196 $dbman->create_table($table); 197 } 198 199 // Forum savepoint reached. 200 upgrade_mod_savepoint(true, 2014081900, 'forum'); 201 } 202 203 if ($oldversion < 2014103000) { 204 // Find records with multiple userid/postid combinations and find the lowest ID. 205 // Later we will remove all those which don't match this ID. 206 $sql = " 207 SELECT MIN(id) as lowid, userid, postid 208 FROM {forum_read} 209 GROUP BY userid, postid 210 HAVING COUNT(id) > 1"; 211 212 if ($duplicatedrows = $DB->get_recordset_sql($sql)) { 213 foreach ($duplicatedrows as $row) { 214 $DB->delete_records_select('forum_read', 'userid = ? AND postid = ? AND id <> ?', array( 215 $row->userid, 216 $row->postid, 217 $row->lowid, 218 )); 219 } 220 } 221 $duplicatedrows->close(); 222 223 // Forum savepoint reached. 224 upgrade_mod_savepoint(true, 2014103000, 'forum'); 225 } 226 227 if ($oldversion < 2014110300) { 228 229 // Changing precision of field preference on table forum_discussion_subs to (10). 230 $table = new xmldb_table('forum_discussion_subs'); 231 $field = new xmldb_field('preference', XMLDB_TYPE_INTEGER, '10', null, XMLDB_NOTNULL, null, '1', 'discussion'); 232 233 // Launch change of precision for field preference. 234 $dbman->change_field_precision($table, $field); 235 236 // Forum savepoint reached. 237 upgrade_mod_savepoint(true, 2014110300, 'forum'); 238 } 239 240 // Moodle v2.8.0 release upgrade line. 241 // Put any upgrade step following this. 242 243 return true; 244 }
title
Description
Body
title
Description
Body
title
Description
Body
title
Body
Generated: Fri Nov 28 20:29:05 2014 | Cross-referenced by PHPXref 0.7.1 |