[ Index ]

PHP Cross Reference of moodle-2.8

title

Body

[close]

/mod/book/db/ -> upgrade.php (source)

   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   * Book module upgrade code
  18   *
  19   * @package    mod_book
  20   * @copyright  2009-2011 Petr Skoda {@link http://skodak.org}
  21   * @license    http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
  22   */
  23  
  24  defined('MOODLE_INTERNAL') || die;
  25  
  26  /**
  27   * Book module upgrade task
  28   *
  29   * @param int $oldversion the version we are upgrading from
  30   * @return bool always true
  31   */
  32  function xmldb_book_upgrade($oldversion) {
  33      global $CFG, $DB;
  34  
  35      $dbman = $DB->get_manager();
  36  
  37      // Moodle v2.2.0 release upgrade line
  38      // Put any upgrade step following this
  39  
  40      // Moodle v2.3.0 release upgrade line
  41      // Put any upgrade step following this
  42  
  43      // Note: The next steps (up to 2012090408 included, are a "replay" of old upgrade steps,
  44      // because some sites updated to Moodle 2.3 didn't have the latest contrib mod_book
  45      // installed, so some required changes were missing.
  46      //
  47      // All the steps are run conditionally so sites upgraded from latest contrib mod_book or
  48      // new (2.3 and upwards) sites won't get affected.
  49      //
  50      // Warn: It will be safe to delete these steps once Moodle 2.5 (not 2.4!) is declared as minimum
  51      // requirement (environment.xml) in some future Moodle 2.x version. Never, never, before!
  52      //
  53      // See MDL-35297 and commit msg for more information.
  54  
  55      if ($oldversion < 2012090401) {
  56          // Rename field summary on table book to intro
  57          $table = new xmldb_table('book');
  58          $field = new xmldb_field('summary', XMLDB_TYPE_TEXT, null, null, null, null, null, 'name');
  59  
  60          // Launch rename field summary
  61          if ($dbman->field_exists($table, $field)) {
  62              $dbman->rename_field($table, $field, 'intro');
  63          }
  64  
  65          // book savepoint reached
  66          upgrade_mod_savepoint(true, 2012090401, 'book');
  67      }
  68  
  69      if ($oldversion < 2012090402) {
  70          // Define field introformat to be added to book
  71          $table = new xmldb_table('book');
  72          $field = new xmldb_field('introformat', XMLDB_TYPE_INTEGER, '4', null, XMLDB_NOTNULL, null, '0', 'intro');
  73  
  74          // Launch add field introformat
  75          if (!$dbman->field_exists($table, $field)) {
  76              $dbman->add_field($table, $field);
  77              // Conditionally migrate to html format in intro
  78              // Si está activo el htmleditor!!!!!
  79              if ($CFG->texteditors !== 'textarea') {
  80                  $rs = $DB->get_recordset('book', array('introformat'=>FORMAT_MOODLE), '', 'id,intro,introformat');
  81                  foreach ($rs as $b) {
  82                      $b->intro       = text_to_html($b->intro, false, false, true);
  83                      $b->introformat = FORMAT_HTML;
  84                      $DB->update_record('book', $b);
  85                      upgrade_set_timeout();
  86                  }
  87                  unset($b);
  88                  $rs->close();
  89              }
  90          }
  91  
  92          // book savepoint reached
  93          upgrade_mod_savepoint(true, 2012090402, 'book');
  94      }
  95  
  96      if ($oldversion < 2012090403) {
  97          // Define field introformat to be added to book
  98          $table = new xmldb_table('book_chapters');
  99          $field = new xmldb_field('contentformat', XMLDB_TYPE_INTEGER, '4', null, XMLDB_NOTNULL, null, '0', 'content');
 100  
 101          // Launch add field introformat
 102          if (!$dbman->field_exists($table, $field)) {
 103              $dbman->add_field($table, $field);
 104  
 105              $DB->set_field('book_chapters', 'contentformat', FORMAT_HTML, array());
 106          }
 107  
 108          // book savepoint reached
 109          upgrade_mod_savepoint(true, 2012090403, 'book');
 110      }
 111  
 112      if ($oldversion < 2012090404) {
 113          require_once("$CFG->dirroot/mod/book/db/upgradelib.php");
 114  
 115          $sqlfrom = "FROM {book} b
 116                      JOIN {modules} m ON m.name = 'book'
 117                      JOIN {course_modules} cm ON (cm.module = m.id AND cm.instance = b.id)";
 118  
 119          $count = $DB->count_records_sql("SELECT COUNT('x') $sqlfrom");
 120  
 121          if ($rs = $DB->get_recordset_sql("SELECT b.id, b.course, cm.id AS cmid $sqlfrom ORDER BY b.course, b.id")) {
 122  
 123              $pbar = new progress_bar('migratebookfiles', 500, true);
 124  
 125              $i = 0;
 126              foreach ($rs as $book) {
 127                  $i++;
 128                  upgrade_set_timeout(360); // set up timeout, may also abort execution
 129                  $pbar->update($i, $count, "Migrating book files - $i/$count.");
 130  
 131                  $context = context_module::instance($book->cmid);
 132  
 133                  mod_book_migrate_moddata_dir_to_legacy($book, $context, '/');
 134  
 135                  // remove dirs if empty
 136                  @rmdir("$CFG->dataroot/$book->course/$CFG->moddata/book/$book->id/");
 137                  @rmdir("$CFG->dataroot/$book->course/$CFG->moddata/book/");
 138                  @rmdir("$CFG->dataroot/$book->course/$CFG->moddata/");
 139                  @rmdir("$CFG->dataroot/$book->course/");
 140              }
 141              $rs->close();
 142          }
 143  
 144          // book savepoint reached
 145          upgrade_mod_savepoint(true, 2012090404, 'book');
 146      }
 147  
 148      if ($oldversion < 2012090405) {
 149          // Define field disableprinting to be dropped from book
 150          $table = new xmldb_table('book');
 151          $field = new xmldb_field('disableprinting');
 152  
 153          // Conditionally launch drop field disableprinting
 154          if ($dbman->field_exists($table, $field)) {
 155              $dbman->drop_field($table, $field);
 156          }
 157  
 158          // book savepoint reached
 159          upgrade_mod_savepoint(true, 2012090405, 'book');
 160      }
 161  
 162      if ($oldversion < 2012090406) {
 163          unset_config('book_tocwidth');
 164  
 165          // book savepoint reached
 166          upgrade_mod_savepoint(true, 2012090406, 'book');
 167      }
 168  
 169      if ($oldversion < 2012090407) {
 170          require_once("$CFG->dirroot/mod/book/db/upgradelib.php");
 171  
 172          mod_book_migrate_all_areas();
 173  
 174          upgrade_mod_savepoint(true, 2012090407, 'book');
 175      }
 176  
 177      if ($oldversion < 2012090408) {
 178  
 179          // Define field revision to be added to book
 180          $table = new xmldb_table('book');
 181          $field = new xmldb_field('revision', XMLDB_TYPE_INTEGER, '10', null, XMLDB_NOTNULL, null, '0', 'customtitles');
 182  
 183          // Conditionally launch add field revision
 184          if (!$dbman->field_exists($table, $field)) {
 185              $dbman->add_field($table, $field);
 186          }
 187  
 188          // book savepoint reached
 189          upgrade_mod_savepoint(true, 2012090408, 'book');
 190      }
 191      // End of MDL-35297 "replayed" steps.
 192  
 193      // Moodle v2.4.0 release upgrade line
 194      // Put any upgrade step following this
 195  
 196  
 197      // Moodle v2.5.0 release upgrade line.
 198      // Put any upgrade step following this.
 199  
 200  
 201      // Moodle v2.6.0 release upgrade line.
 202      // Put any upgrade step following this.
 203  
 204      // Moodle v2.7.0 release upgrade line.
 205      // Put any upgrade step following this.
 206  
 207      // Moodle v2.8.0 release upgrade line.
 208      // Put any upgrade step following this.
 209  
 210      return true;
 211  }


Generated: Fri Nov 28 20:29:05 2014 Cross-referenced by PHPXref 0.7.1