[ Index ]

PHP Cross Reference of Unnamed Project

title

Body

[close]

/mod/feedback/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  // This file keeps track of upgrades to
  18  // the feedback module
  19  //
  20  // Sometimes, changes between versions involve
  21  // alterations to database structures and other
  22  // major things that may break installations.
  23  //
  24  // The upgrade function in this file will attempt
  25  // to perform all the necessary actions to upgrade
  26  // your older installation to the current version.
  27  //
  28  // If there's something it cannot do itself, it
  29  // will tell you what you need to do.
  30  //
  31  // The commands in here will all be database-neutral,
  32  // using the methods of database_manager class
  33  //
  34  // Please do not forget to use upgrade_set_timeout()
  35  // before any action that may take longer time to finish.
  36  
  37  defined('MOODLE_INTERNAL') || die();
  38  
  39  function xmldb_feedback_upgrade($oldversion) {
  40      global $CFG, $DB;
  41      require_once($CFG->dirroot . '/mod/feedback/db/upgradelib.php');
  42  
  43      $dbman = $DB->get_manager(); // Loads ddl manager and xmldb classes.
  44  
  45      // Moodle v2.8.0 release upgrade line.
  46      // Put any upgrade step following this.
  47  
  48      // Moodle v2.9.0 release upgrade line.
  49      // Put any upgrade step following this.
  50  
  51      // Moodle v3.0.0 release upgrade line.
  52      // Put any upgrade step following this.
  53  
  54      if ($oldversion < 2016031600) {
  55          // Remove labels from all 'captcha' and 'label' items.
  56          $DB->execute('UPDATE {feedback_item} SET label = ? WHERE typ = ? OR typ = ?',
  57                  array('', 'captcha', 'label'));
  58  
  59          // Data savepoint reached.
  60          upgrade_mod_savepoint(true, 2016031600, 'feedback');
  61      }
  62  
  63      if ($oldversion < 2016040100) {
  64  
  65          // In order to keep the previous "Analysis" results unchanged,
  66          // set all multiple-answer multiplechoice questions as "Do not analyse empty submits"="Yes"
  67          // because prior to this date this setting did not work.
  68  
  69          $sql = "UPDATE {feedback_item} SET options = " . $DB->sql_concat('?', 'options') .
  70                  " WHERE typ = ? AND presentation LIKE ? AND options NOT LIKE ?";
  71          $params = array('i', 'multichoice', 'c%', '%i%');
  72          $DB->execute($sql, $params);
  73  
  74          // Feedback savepoint reached.
  75          upgrade_mod_savepoint(true, 2016040100, 'feedback');
  76      }
  77  
  78      if ($oldversion < 2016051103) {
  79  
  80          // Define index completed_item (unique) to be added to feedback_value.
  81          $table = new xmldb_table('feedback_value');
  82          $index = new xmldb_index('completed_item', XMLDB_INDEX_UNIQUE, array('completed', 'item', 'course_id'));
  83  
  84          // Conditionally launch add index completed_item.
  85          if (!$dbman->index_exists($table, $index)) {
  86              mod_feedback_upgrade_delete_duplicate_values();
  87              $dbman->add_index($table, $index);
  88          }
  89  
  90          // Feedback savepoint reached.
  91          upgrade_mod_savepoint(true, 2016051103, 'feedback');
  92      }
  93  
  94      if ($oldversion < 2016051104) {
  95  
  96          // Define index completed_item (unique) to be added to feedback_valuetmp.
  97          $table = new xmldb_table('feedback_valuetmp');
  98          $index = new xmldb_index('completed_item', XMLDB_INDEX_UNIQUE, array('completed', 'item', 'course_id'));
  99  
 100          // Conditionally launch add index completed_item.
 101          if (!$dbman->index_exists($table, $index)) {
 102              mod_feedback_upgrade_delete_duplicate_values(true);
 103              $dbman->add_index($table, $index);
 104          }
 105  
 106          // Feedback savepoint reached.
 107          upgrade_mod_savepoint(true, 2016051104, 'feedback');
 108      }
 109  
 110      if ($oldversion < 2016051105) {
 111  
 112          // Define field courseid to be added to feedback_completed.
 113          $table = new xmldb_table('feedback_completed');
 114          $field = new xmldb_field('courseid', XMLDB_TYPE_INTEGER, '10', null, XMLDB_NOTNULL, null, '0', 'anonymous_response');
 115  
 116          // Conditionally launch add field courseid.
 117          if (!$dbman->field_exists($table, $field)) {
 118              $dbman->add_field($table, $field);
 119              // Run upgrade script to fill the new field courseid with the data from feedback_value table.
 120              mod_feedback_upgrade_courseid(false);
 121          }
 122  
 123          // Define field courseid to be added to feedback_completedtmp.
 124          $table = new xmldb_table('feedback_completedtmp');
 125          $field = new xmldb_field('courseid', XMLDB_TYPE_INTEGER, '10', null, XMLDB_NOTNULL, null, '0', 'anonymous_response');
 126  
 127          // Conditionally launch add field courseid.
 128          if (!$dbman->field_exists($table, $field)) {
 129              $dbman->add_field($table, $field);
 130              // Run upgrade script to fill the new field courseid with the data from feedback_valuetmp table.
 131              mod_feedback_upgrade_courseid(true);
 132          }
 133  
 134          // Define table feedback_tracking to be dropped.
 135          $table = new xmldb_table('feedback_tracking');
 136  
 137          // Conditionally launch drop table for feedback_tracking.
 138          if ($dbman->table_exists($table)) {
 139              $dbman->drop_table($table);
 140          }
 141  
 142          // Feedback savepoint reached.
 143          upgrade_mod_savepoint(true, 2016051105, 'feedback');
 144      }
 145  
 146      // Moodle v3.1.0 release upgrade line.
 147      // Put any upgrade step following this.
 148  
 149      return true;
 150  }


Generated: Thu Aug 11 10:00:09 2016 Cross-referenced by PHPXref 0.7.1