[ Index ] |
PHP Cross Reference of Unnamed Project |
[Summary view] [Print] [Text view]
1 <?php 2 // This file is part of Moodle - http://moodle.org/ 3 // 4 // Moodle is free software: you can redistribute it and/or modify 5 // it under the terms of the GNU General Public License as published by 6 // the Free Software Foundation, either version 3 of the License, or 7 // (at your option) any later version. 8 // 9 // Moodle is distributed in the hope that it will be useful, 10 // but WITHOUT ANY WARRANTY; without even the implied warranty of 11 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 // GNU General Public License for more details. 13 // 14 // You should have received a copy of the GNU General Public License 15 // along with Moodle. If not, see <http://www.gnu.org/licenses/>. 16 17 /** 18 * This file keeps track of upgrades to 19 * the forum module 20 * 21 * Sometimes, changes between versions involve 22 * alterations to database structures and other 23 * major things that may break installations. 24 * 25 * The upgrade function in this file will attempt 26 * to perform all the necessary actions to upgrade 27 * your older installation to the current version. 28 * 29 * If there's something it cannot do itself, it 30 * will tell you what you need to do. 31 * 32 * The commands in here will all be database-neutral, 33 * using the methods of database_manager class 34 * 35 * Please do not forget to use upgrade_set_timeout() 36 * before any action that may take longer time to finish. 37 * 38 * @package mod_forum 39 * @copyright 2003 onwards Eloy Lafuente (stronk7) {@link http://stronk7.com} 40 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later 41 */ 42 43 defined('MOODLE_INTERNAL') || die(); 44 45 function xmldb_forum_upgrade($oldversion) { 46 global $CFG, $DB; 47 48 $dbman = $DB->get_manager(); // Loads ddl manager and xmldb classes. 49 50 if ($oldversion < 2014051201) { 51 52 // Incorrect values that need to be replaced. 53 $replacements = array( 54 11 => 20, 55 12 => 50, 56 13 => 100 57 ); 58 59 // Run the replacements. 60 foreach ($replacements as $old => $new) { 61 $DB->set_field('forum', 'maxattachments', $new, array('maxattachments' => $old)); 62 } 63 64 // Forum savepoint reached. 65 upgrade_mod_savepoint(true, 2014051201, 'forum'); 66 } 67 68 if ($oldversion < 2014081500) { 69 70 // Define index course (not unique) to be added to forum_discussions. 71 $table = new xmldb_table('forum_discussions'); 72 $index = new xmldb_index('course', XMLDB_INDEX_NOTUNIQUE, array('course')); 73 74 // Conditionally launch add index course. 75 if (!$dbman->index_exists($table, $index)) { 76 $dbman->add_index($table, $index); 77 } 78 79 // Forum savepoint reached. 80 upgrade_mod_savepoint(true, 2014081500, 'forum'); 81 } 82 83 if ($oldversion < 2014081900) { 84 85 // Define table forum_discussion_subs to be created. 86 $table = new xmldb_table('forum_discussion_subs'); 87 88 // Adding fields to table forum_discussion_subs. 89 $table->add_field('id', XMLDB_TYPE_INTEGER, '10', null, XMLDB_NOTNULL, XMLDB_SEQUENCE, null); 90 $table->add_field('forum', XMLDB_TYPE_INTEGER, '10', null, XMLDB_NOTNULL, null, null); 91 $table->add_field('userid', XMLDB_TYPE_INTEGER, '10', null, XMLDB_NOTNULL, null, null); 92 $table->add_field('discussion', XMLDB_TYPE_INTEGER, '10', null, XMLDB_NOTNULL, null, null); 93 $table->add_field('preference', XMLDB_TYPE_INTEGER, '1', null, XMLDB_NOTNULL, null, '1'); 94 95 // Adding keys to table forum_discussion_subs. 96 $table->add_key('primary', XMLDB_KEY_PRIMARY, array('id')); 97 $table->add_key('forum', XMLDB_KEY_FOREIGN, array('forum'), 'forum', array('id')); 98 $table->add_key('userid', XMLDB_KEY_FOREIGN, array('userid'), 'user', array('id')); 99 $table->add_key('discussion', XMLDB_KEY_FOREIGN, array('discussion'), 'forum_discussions', array('id')); 100 $table->add_key('user_discussions', XMLDB_KEY_UNIQUE, array('userid', 'discussion')); 101 102 // Conditionally launch create table for forum_discussion_subs. 103 if (!$dbman->table_exists($table)) { 104 $dbman->create_table($table); 105 } 106 107 // Forum savepoint reached. 108 upgrade_mod_savepoint(true, 2014081900, 'forum'); 109 } 110 111 if ($oldversion < 2014103000) { 112 // Find records with multiple userid/postid combinations and find the lowest ID. 113 // Later we will remove all those which don't match this ID. 114 $sql = " 115 SELECT MIN(id) as lowid, userid, postid 116 FROM {forum_read} 117 GROUP BY userid, postid 118 HAVING COUNT(id) > 1"; 119 120 if ($duplicatedrows = $DB->get_recordset_sql($sql)) { 121 foreach ($duplicatedrows as $row) { 122 $DB->delete_records_select('forum_read', 'userid = ? AND postid = ? AND id <> ?', array( 123 $row->userid, 124 $row->postid, 125 $row->lowid, 126 )); 127 } 128 } 129 $duplicatedrows->close(); 130 131 // Forum savepoint reached. 132 upgrade_mod_savepoint(true, 2014103000, 'forum'); 133 } 134 135 if ($oldversion < 2014110300) { 136 137 // Changing precision of field preference on table forum_discussion_subs to (10). 138 $table = new xmldb_table('forum_discussion_subs'); 139 $field = new xmldb_field('preference', XMLDB_TYPE_INTEGER, '10', null, XMLDB_NOTNULL, null, '1', 'discussion'); 140 141 // Launch change of precision for field preference. 142 $dbman->change_field_precision($table, $field); 143 144 // Forum savepoint reached. 145 upgrade_mod_savepoint(true, 2014110300, 'forum'); 146 } 147 148 // Moodle v2.8.0 release upgrade line. 149 // Put any upgrade step following this. 150 151 // Moodle v2.9.0 release upgrade line. 152 // Put any upgrade step following this. 153 if ($oldversion < 2015102900) { 154 // Groupid = 0 is never valid. 155 $DB->set_field('forum_discussions', 'groupid', -1, array('groupid' => 0)); 156 157 // Forum savepoint reached. 158 upgrade_mod_savepoint(true, 2015102900, 'forum'); 159 } 160 161 // Moodle v3.0.0 release upgrade line. 162 // Put any upgrade step following this. 163 164 if ($oldversion < 2015120800) { 165 166 // Add support for pinned discussions. 167 $table = new xmldb_table('forum_discussions'); 168 $field = new xmldb_field('pinned', XMLDB_TYPE_INTEGER, '1', null, XMLDB_NOTNULL, null, '0', 'timeend'); 169 170 if (!$dbman->field_exists($table, $field)) { 171 $dbman->add_field($table, $field); 172 } 173 174 // Forum savepoint reached. 175 upgrade_mod_savepoint(true, 2015120800, 'forum'); 176 } 177 // Moodle v3.1.0 release upgrade line. 178 // Put any upgrade step following this. 179 180 return true; 181 }
title
Description
Body
title
Description
Body
title
Description
Body
title
Body
Generated: Thu Aug 11 10:00:09 2016 | Cross-referenced by PHPXref 0.7.1 |