Search moodle.org's
Developer Documentation

See Release Notes

  • Bug fixes for general core bugs in 3.10.x will end 8 November 2021 (12 months).
  • Bug fixes for security issues in 3.10.x will end 9 May 2022 (18 months).
  • PHP version: minimum PHP 7.2.0 Note: minimum PHP version has increased since Moodle 3.8. PHP 7.3.x and 7.4.x are supported too.

Differences Between: [Versions 310 and 311] [Versions 310 and 400] [Versions 310 and 401] [Versions 310 and 402] [Versions 310 and 403] [Versions 39 and 310]

   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   * Keeps track of upgrades to the workshop module
  19   *
  20   * @package    mod_workshop
  21   * @category   upgrade
  22   * @copyright  2009 David Mudrak <david.mudrak@gmail.com>
  23   * @license    http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
  24   */
  25  
  26  defined('MOODLE_INTERNAL') || die();
  27  
  28  /**
  29   * Performs upgrade of the database structure and data
  30   *
  31   * Workshop supports upgrades from version 1.9.0 and higher only. During 1.9 > 2.0 upgrade,
  32   * there are significant database changes.
  33   *
  34   * @param int $oldversion the version we are upgrading from
  35   * @return bool result
  36   */
  37  function xmldb_workshop_upgrade($oldversion) {
  38      global $DB;
  39  
  40      $dbman = $DB->get_manager();
  41  
  42      // Automatically generated Moodle v3.5.0 release upgrade line.
  43      // Put any upgrade step following this.
  44  
  45      if ($oldversion < 2018062600) {
  46  
  47          // Define field submissiontypetext to be added to workshop.
  48          $table = new xmldb_table('workshop');
  49          $field = new xmldb_field('submissiontypetext', XMLDB_TYPE_INTEGER, '1', null, XMLDB_NOTNULL, null, '1', 'gradedecimals');
  50  
  51          // Conditionally launch add field submissiontypetext.
  52          if (!$dbman->field_exists($table, $field)) {
  53              $dbman->add_field($table, $field);
  54          }
  55  
  56          $field = new xmldb_field('submissiontypefile', XMLDB_TYPE_INTEGER, '1', null, XMLDB_NOTNULL, null, '1',
  57                  'submissiontypetext');
  58  
  59          // Conditionally launch add field submissiontypefile.
  60          if (!$dbman->field_exists($table, $field)) {
  61              $dbman->add_field($table, $field);
  62          }
  63  
  64          // Convert existing workshops with attachments disabled to use the new settings.
  65          $workshops = $DB->get_records('workshop', ['nattachments' => 0]);
  66          foreach ($workshops as $workshop) {
  67              $update = (object) [
  68                  'id' => $workshop->id,
  69                  'submissiontypefile' => 0,
  70                  'submissiontypetext' => 2,
  71                  'nattachments' => 1
  72              ];
  73              $DB->update_record('workshop', $update);
  74          }
  75  
  76          // Changing the default of field nattachments on table workshop to 1.
  77          $field = new xmldb_field('nattachments', XMLDB_TYPE_INTEGER, '3', null, null, null, '1', 'submissiontypefile');
  78  
  79          // Launch change of default for field nattachments.
  80          $dbman->change_field_default($table, $field);
  81  
  82          // Workshop savepoint reached.
  83          upgrade_mod_savepoint(true, 2018062600, 'workshop');
  84      }
  85  
  86      // Automatically generated Moodle v3.6.0 release upgrade line.
  87      // Put any upgrade step following this.
  88  
  89      // Automatically generated Moodle v3.7.0 release upgrade line.
  90      // Put any upgrade step following this.
  91  
  92      // Automatically generated Moodle v3.8.0 release upgrade line.
  93      // Put any upgrade step following this.
  94  
  95      // Automatically generated Moodle v3.9.0 release upgrade line.
  96      // Put any upgrade step following this.
  97  
  98      // Automatically generated Moodle v3.10.0 release upgrade line.
  99      // Put any upgrade step following this.
 100  
 101      if ($oldversion < 2020110901) {
 102  
 103          // Changing nullability of field grade on table workshop_grades to null.
 104          $table = new xmldb_table('workshop_grades');
 105          $field = new xmldb_field('grade', XMLDB_TYPE_NUMBER, '10, 5', null, null, null, null, 'dimensionid');
 106  
 107          // Launch change of nullability for field grade.
 108          $dbman->change_field_notnull($table, $field);
 109  
 110          // Main savepoint reached.
 111          upgrade_mod_savepoint(true, 2020110901, 'workshop');
 112      }
 113  
 114      return true;
 115  }