[ 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 lesson 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_lesson 39 * @copyright 1999 onwards Martin Dougiamas {@link http://moodle.com} 40 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 o 41 */ 42 43 defined('MOODLE_INTERNAL') || die(); 44 45 /** 46 * 47 * @global stdClass $CFG 48 * @global moodle_database $DB 49 * @param int $oldversion 50 * @return bool 51 */ 52 function xmldb_lesson_upgrade($oldversion) { 53 global $CFG, $DB; 54 55 $dbman = $DB->get_manager(); 56 57 if ($oldversion < 2014091001) { 58 $table = new xmldb_table('lesson'); 59 $field = new xmldb_field('intro', XMLDB_TYPE_TEXT, null, null, null, null, null, 'name'); 60 // Conditionally launch add field. 61 if (!$dbman->field_exists($table, $field)) { 62 $dbman->add_field($table, $field); 63 } 64 $field = new xmldb_field('introformat', XMLDB_TYPE_INTEGER, '4', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, '0', 'intro'); 65 if (!$dbman->field_exists($table, $field)) { 66 $dbman->add_field($table, $field); 67 } 68 upgrade_mod_savepoint(true, 2014091001, 'lesson'); 69 } 70 71 if ($oldversion < 2014100600) { 72 // Previously there was no module intro in lesson so don't require 73 // it to be filled in for upgraded sites. 74 set_config('requiremodintro', 0, 'lesson'); 75 upgrade_mod_savepoint(true, 2014100600, 'lesson'); 76 } 77 78 // Moodle v2.8.0 release upgrade line. 79 // Put any upgrade step following this. 80 81 if ($oldversion < 2014112300) { 82 83 // Define field completionendreached to be added to lesson. 84 $table = new xmldb_table('lesson'); 85 $field = new xmldb_field('completionendreached', XMLDB_TYPE_INTEGER, '1', null, null, null, '0', 'timemodified'); 86 87 // Conditionally launch add field completionendreached. 88 if (!$dbman->field_exists($table, $field)) { 89 $dbman->add_field($table, $field); 90 } 91 92 // Define field completed to be added to lesson_timer. 93 $table = new xmldb_table('lesson_timer'); 94 $field = new xmldb_field('completed', XMLDB_TYPE_INTEGER, '1', null, null, null, '0', 'lessontime'); 95 96 // Conditionally launch add field completed. 97 if (!$dbman->field_exists($table, $field)) { 98 $dbman->add_field($table, $field); 99 } 100 // Lesson savepoint reached. 101 upgrade_mod_savepoint(true, 2014112300, 'lesson'); 102 } 103 104 if ($oldversion < 2014122900) { 105 106 // Changing precision of field grade on table lesson to (10). 107 $table = new xmldb_table('lesson'); 108 $field = new xmldb_field('grade', XMLDB_TYPE_INTEGER, '10', null, XMLDB_NOTNULL, null, '0', 'conditions'); 109 110 // Launch change of precision for field grade. 111 $dbman->change_field_precision($table, $field); 112 113 // Lesson savepoint reached. 114 upgrade_mod_savepoint(true, 2014122900, 'lesson'); 115 } 116 117 if ($oldversion < 2015030300) { 118 119 // Define field nextpageid to be added to lesson_branch. 120 $table = new xmldb_table('lesson_branch'); 121 $field = new xmldb_field('nextpageid', XMLDB_TYPE_INTEGER, '10', null, XMLDB_NOTNULL, null, '0', 'timeseen'); 122 123 // Conditionally launch add field nextpageid. 124 if (!$dbman->field_exists($table, $field)) { 125 $dbman->add_field($table, $field); 126 } 127 128 // Lesson savepoint reached. 129 upgrade_mod_savepoint(true, 2015030300, 'lesson'); 130 } 131 132 if ($oldversion < 2015030301) { 133 134 // Clean lesson answers that should be plain text. 135 // Unfortunately we can't use LESSON_PAGE_XX constants here as we can't include the files. 136 // 1 = LESSON_PAGE_SHORTANSWER, 8 = LESSON_PAGE_NUMERICAL, 20 = LESSON_PAGE_BRANCHTABLE. 137 138 $sql = 'SELECT a.* 139 FROM {lesson_answers} a 140 JOIN {lesson_pages} p ON p.id = a.pageid 141 WHERE a.answerformat <> :format 142 AND p.qtype IN (1, 8, 20)'; 143 $badanswers = $DB->get_recordset_sql($sql, array('format' => FORMAT_MOODLE)); 144 145 foreach ($badanswers as $badanswer) { 146 // Strip tags from answer text and convert back the format to FORMAT_MOODLE. 147 $badanswer->answer = strip_tags($badanswer->answer); 148 $badanswer->answerformat = FORMAT_MOODLE; 149 $DB->update_record('lesson_answers', $badanswer); 150 } 151 $badanswers->close(); 152 153 // Lesson savepoint reached. 154 upgrade_mod_savepoint(true, 2015030301, 'lesson'); 155 } 156 157 if ($oldversion < 2015030400) { 158 159 // Creating new field timelimit in lesson table. 160 $table = new xmldb_table('lesson'); 161 $field = new xmldb_field('timelimit', XMLDB_TYPE_INTEGER, '10', null, XMLDB_NOTNULL, null, '0', 'maxpages'); 162 163 // Conditionally launch add field timelimit. 164 if (!$dbman->field_exists($table, $field)) { 165 $dbman->add_field($table, $field); 166 } 167 168 // Lesson savepoint reached. 169 upgrade_mod_savepoint(true, 2015030400, 'lesson'); 170 } 171 172 if ($oldversion < 2015030401) { 173 174 // Convert maxtime (minutes) to timelimit (seconds). 175 $table = new xmldb_table('lesson'); 176 $oldfield = new xmldb_field('maxtime'); 177 $newfield = new xmldb_field('timelimit'); 178 if ($dbman->field_exists($table, $oldfield) && $dbman->field_exists($table, $newfield)) { 179 $sql = 'UPDATE {lesson} SET timelimit = 60 * maxtime'; 180 $DB->execute($sql); 181 // Drop field maxtime. 182 $dbman->drop_field($table, $oldfield); 183 } 184 185 $oldfield = new xmldb_field('timed'); 186 if ($dbman->field_exists($table, $oldfield) && $dbman->field_exists($table, $newfield)) { 187 // Set timelimit to 0 for non timed lessons. 188 $DB->set_field_select('lesson', 'timelimit', 0, 'timed = 0'); 189 // Drop field timed. 190 $dbman->drop_field($table, $oldfield); 191 } 192 // Lesson savepoint reached. 193 upgrade_mod_savepoint(true, 2015030401, 'lesson'); 194 } 195 196 if ($oldversion < 2015031500) { 197 198 // Define field completiontimespent to be added to lesson. 199 $table = new xmldb_table('lesson'); 200 $field = new xmldb_field('completiontimespent', XMLDB_TYPE_INTEGER, '11', null, null, null, '0', 'completionendreached'); 201 202 // Conditionally launch add field completiontimespent. 203 if (!$dbman->field_exists($table, $field)) { 204 $dbman->add_field($table, $field); 205 } 206 207 // Lesson savepoint reached. 208 upgrade_mod_savepoint(true, 2015031500, 'lesson'); 209 } 210 211 if ($oldversion < 2015032600) { 212 213 // Change practice lesson to allow multiple attempts 214 // so that behaviour is not changed by MDL-18966. 215 $DB->set_field('lesson', 'retake', 1, array('practice' => 1)); 216 217 // Lesson savepoint reached. 218 upgrade_mod_savepoint(true, 2015032600, 'lesson'); 219 } 220 221 if ($oldversion < 2015032700) { 222 // Delete any orphaned lesson_branch record. 223 if ($DB->get_dbfamily() === 'mysql') { 224 $sql = "DELETE {lesson_branch} 225 FROM {lesson_branch} 226 LEFT JOIN {lesson_pages} 227 ON {lesson_branch}.pageid = {lesson_pages}.id 228 WHERE {lesson_pages}.id IS NULL"; 229 } else { 230 $sql = "DELETE FROM {lesson_branch} 231 WHERE NOT EXISTS ( 232 SELECT 'x' FROM {lesson_pages} 233 WHERE {lesson_branch}.pageid = {lesson_pages}.id)"; 234 } 235 236 $DB->execute($sql); 237 238 // Lesson savepoint reached. 239 upgrade_mod_savepoint(true, 2015032700, 'lesson'); 240 } 241 242 if ($oldversion < 2015033100) { 243 244 // Define table lesson_overrides to be created. 245 $table = new xmldb_table('lesson_overrides'); 246 247 // Adding fields to table lesson_overrides. 248 $table->add_field('id', XMLDB_TYPE_INTEGER, '10', null, XMLDB_NOTNULL, XMLDB_SEQUENCE, null); 249 $table->add_field('lessonid', XMLDB_TYPE_INTEGER, '10', null, XMLDB_NOTNULL, null, '0'); 250 $table->add_field('groupid', XMLDB_TYPE_INTEGER, '10', null, null, null, null); 251 $table->add_field('userid', XMLDB_TYPE_INTEGER, '10', null, null, null, null); 252 $table->add_field('available', XMLDB_TYPE_INTEGER, '10', null, null, null, null); 253 $table->add_field('deadline', XMLDB_TYPE_INTEGER, '10', null, null, null, null); 254 $table->add_field('timelimit', XMLDB_TYPE_INTEGER, '10', null, null, null, null); 255 $table->add_field('review', XMLDB_TYPE_INTEGER, '3', null, null, null, null); 256 $table->add_field('maxattempts', XMLDB_TYPE_INTEGER, '3', null, null, null, null); 257 $table->add_field('retake', XMLDB_TYPE_INTEGER, '3', null, null, null, null); 258 $table->add_field('password', XMLDB_TYPE_CHAR, '32', null, null, null, null); 259 260 // Adding keys to table lesson_overrides. 261 $table->add_key('primary', XMLDB_KEY_PRIMARY, array('id')); 262 $table->add_key('lessonid', XMLDB_KEY_FOREIGN, array('lessonid'), 'lesson', array('id')); 263 $table->add_key('groupid', XMLDB_KEY_FOREIGN, array('groupid'), 'groups', array('id')); 264 $table->add_key('userid', XMLDB_KEY_FOREIGN, array('userid'), 'user', array('id')); 265 266 // Conditionally launch create table for lesson_overrides. 267 if (!$dbman->table_exists($table)) { 268 $dbman->create_table($table); 269 } 270 271 // Lesson savepoint reached. 272 upgrade_mod_savepoint(true, 2015033100, 'lesson'); 273 } 274 275 // Moodle v2.9.0 release upgrade line. 276 // Put any upgrade step following this. 277 278 if ($oldversion < 2015071800) { 279 280 // Define table lesson_high_scores to be dropped. 281 $table = new xmldb_table('lesson_high_scores'); 282 283 // Conditionally launch drop table for lesson_high_scores. 284 if ($dbman->table_exists($table)) { 285 $dbman->drop_table($table); 286 } 287 288 // Lesson savepoint reached. 289 upgrade_mod_savepoint(true, 2015071800, 'lesson'); 290 } 291 292 if ($oldversion < 2015071801) { 293 294 // Define field highscores to be dropped from lesson. 295 $table = new xmldb_table('lesson'); 296 $field = new xmldb_field('highscores'); 297 298 // Conditionally launch drop field highscores. 299 if ($dbman->field_exists($table, $field)) { 300 $dbman->drop_field($table, $field); 301 } 302 303 // Lesson savepoint reached. 304 upgrade_mod_savepoint(true, 2015071801, 'lesson'); 305 } 306 307 if ($oldversion < 2015071802) { 308 309 // Define field maxhighscores to be dropped from lesson. 310 $table = new xmldb_table('lesson'); 311 $field = new xmldb_field('maxhighscores'); 312 313 // Conditionally launch drop field maxhighscores. 314 if ($dbman->field_exists($table, $field)) { 315 $dbman->drop_field($table, $field); 316 } 317 318 // Lesson savepoint reached. 319 upgrade_mod_savepoint(true, 2015071802, 'lesson'); 320 } 321 322 if ($oldversion < 2015071803) { 323 unset_config('lesson_maxhighscores'); 324 325 // Lesson savepoint reached. 326 upgrade_mod_savepoint(true, 2015071803, 'lesson'); 327 } 328 329 // Moodle v3.0.0 release upgrade line. 330 // Put any upgrade step following this. 331 332 if ($oldversion < 2016012800) { 333 // Convert lesson settings to use config_plugins instead of $CFG. 334 // Lesson_maxanswers => mod_lesson/maxanswers. 335 if (isset($CFG->lesson_maxanswers)) { 336 set_config('maxanswers', $CFG->lesson_maxanswers, 'mod_lesson'); 337 set_config('maxanswers_adv', '1', 'mod_lesson'); 338 unset_config('lesson_maxanswers'); 339 } 340 341 // Lesson_slideshowwidth => mod_lesson/slideshowwidth. 342 if (isset($CFG->lesson_slideshowwidth)) { 343 set_config('slideshowwidth', $CFG->lesson_slideshowwidth, 'mod_lesson'); 344 unset_config('lesson_slideshowwidth'); 345 } 346 347 // Lesson_slideshowheight => mod_lesson/slideshowheight. 348 if (isset($CFG->lesson_slideshowheight)) { 349 set_config('slideshowheight', $CFG->lesson_slideshowheight, 'mod_lesson'); 350 unset_config('lesson_slideshowheight'); 351 } 352 353 // Lesson_slideshowbgcolor => mod_lesson/slideshowbgcolor. 354 if (isset($CFG->lesson_slideshowbgcolor)) { 355 set_config('slideshowbgcolor', $CFG->lesson_slideshowbgcolor, 'mod_lesson'); 356 unset_config('lesson_slideshowbgcolor'); 357 } 358 359 // Lesson_defaultnextpage => mod_lesson/defaultnextpage. 360 if (isset($CFG->lesson_defaultnextpage)) { 361 set_config('defaultnextpage', $CFG->lesson_defaultnextpage, 'mod_lesson'); 362 set_config('defaultnextpage_adv', '1', 'mod_lesson'); 363 unset_config('lesson_defaultnextpage'); 364 } 365 366 // Lesson_mediawidth => mod_lesson/mediawidth. 367 if (isset($CFG->lesson_mediawidth)) { 368 set_config('mediawidth', $CFG->lesson_mediawidth, 'mod_lesson'); 369 unset_config('lesson_mediawidth'); 370 } 371 372 // Lesson_mediaheight => mod_lesson/mediaheight. 373 if (isset($CFG->lesson_mediaheight)) { 374 set_config('mediaheight', $CFG->lesson_mediaheight, 'mod_lesson'); 375 unset_config('lesson_mediaheight'); 376 } 377 378 // Lesson_mediaclose => mod_lesson/mediaclose. 379 if (isset($CFG->lesson_mediaclose)) { 380 set_config('mediaclose', $CFG->lesson_mediaclose, 'mod_lesson'); 381 unset_config('lesson_mediaclose'); 382 } 383 384 // Lesson savepoint reached. 385 upgrade_mod_savepoint(true, 2016012800, 'lesson'); 386 } 387 // Moodle v3.1.0 release upgrade line. 388 // Put any upgrade step following this. 389 390 return true; 391 }
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 |