| 1 | 
           efrain | 
           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 | 
            * Upgrade script for the quiz module.
  | 
        
        
            | 
            | 
           19 | 
            *
  | 
        
        
            | 
            | 
           20 | 
            * @package    mod_quiz
  | 
        
        
            | 
            | 
           21 | 
            * @copyright  2006 Eloy Lafuente (stronk7)
  | 
        
        
            | 
            | 
           22 | 
            * @license    http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
  | 
        
        
            | 
            | 
           23 | 
            */
  | 
        
        
            | 
            | 
           24 | 
              | 
        
        
            | 
            | 
           25 | 
           /**
  | 
        
        
            | 
            | 
           26 | 
            * Quiz module upgrade function.
  | 
        
        
            | 
            | 
           27 | 
            * @param string $oldversion the version we are upgrading from.
  | 
        
        
            | 
            | 
           28 | 
            */
  | 
        
        
            | 
            | 
           29 | 
           function xmldb_quiz_upgrade($oldversion) {
  | 
        
        
            | 
            | 
           30 | 
               global $CFG, $DB;
  | 
        
        
            | 
            | 
           31 | 
               $dbman = $DB->get_manager();
  | 
        
        
            | 
            | 
           32 | 
              | 
        
        
            | 
            | 
           33 | 
               // Automatically generated Moodle v4.2.0 release upgrade line.
  | 
        
        
            | 
            | 
           34 | 
               // Put any upgrade step following this.
  | 
        
        
            | 
            | 
           35 | 
              | 
        
        
            | 
            | 
           36 | 
               if ($oldversion < 2023042401) {
  | 
        
        
            | 
            | 
           37 | 
                   // Define field reviewmaxmarks to be added to quiz.
  | 
        
        
            | 
            | 
           38 | 
                   $table = new xmldb_table('quiz');
  | 
        
        
            | 
            | 
           39 | 
                   $field = new xmldb_field('reviewmaxmarks', XMLDB_TYPE_INTEGER, '6', null, XMLDB_NOTNULL, null, '0', 'reviewcorrectness');
  | 
        
        
            | 
            | 
           40 | 
              | 
        
        
            | 
            | 
           41 | 
                   // Conditionally launch add field reviewmaxmarks.
  | 
        
        
            | 
            | 
           42 | 
                   if (!$dbman->field_exists($table, $field)) {
  | 
        
        
            | 
            | 
           43 | 
                       $dbman->add_field($table, $field);
  | 
        
        
            | 
            | 
           44 | 
                   }
  | 
        
        
            | 
            | 
           45 | 
              | 
        
        
            | 
            | 
           46 | 
                   // Quiz savepoint reached.
  | 
        
        
            | 
            | 
           47 | 
                   upgrade_mod_savepoint(true, 2023042401, 'quiz');
  | 
        
        
            | 
            | 
           48 | 
               }
  | 
        
        
            | 
            | 
           49 | 
              | 
        
        
            | 
            | 
           50 | 
               // Automatically generated Moodle v4.3.0 release upgrade line.
  | 
        
        
            | 
            | 
           51 | 
               // Put any upgrade step following this.
  | 
        
        
            | 
            | 
           52 | 
              | 
        
        
            | 
            | 
           53 | 
               if ($oldversion < 2023112300) {
  | 
        
        
            | 
            | 
           54 | 
              | 
        
        
            | 
            | 
           55 | 
                   // Set the value for all existing rows to match the previous behaviour,
  | 
        
        
            | 
            | 
           56 | 
                   // but only where users have not already set another value.
  | 
        
        
            | 
            | 
           57 | 
                   $DB->set_field('quiz', 'reviewmaxmarks', 0x11110, ['reviewmaxmarks' => 0]);
  | 
        
        
            | 
            | 
           58 | 
              | 
        
        
            | 
            | 
           59 | 
                   // Quiz savepoint reached.
  | 
        
        
            | 
            | 
           60 | 
                   upgrade_mod_savepoint(true, 2023112300, 'quiz');
  | 
        
        
            | 
            | 
           61 | 
               }
  | 
        
        
            | 
            | 
           62 | 
              | 
        
        
            | 
            | 
           63 | 
               if ($oldversion < 2023112400) {
  | 
        
        
            | 
            | 
           64 | 
              | 
        
        
            | 
            | 
           65 | 
                   // Define table quiz_grade_items to be created.
  | 
        
        
            | 
            | 
           66 | 
                   $table = new xmldb_table('quiz_grade_items');
  | 
        
        
            | 
            | 
           67 | 
              | 
        
        
            | 
            | 
           68 | 
                   // Adding fields to table quiz_grade_items.
  | 
        
        
            | 
            | 
           69 | 
                   $table->add_field('id', XMLDB_TYPE_INTEGER, '10', null, XMLDB_NOTNULL, XMLDB_SEQUENCE, null);
  | 
        
        
            | 
            | 
           70 | 
                   $table->add_field('quizid', XMLDB_TYPE_INTEGER, '10', null, XMLDB_NOTNULL, null, null);
  | 
        
        
            | 
            | 
           71 | 
                   $table->add_field('sortorder', XMLDB_TYPE_INTEGER, '10', null, XMLDB_NOTNULL, null, null);
  | 
        
        
            | 
            | 
           72 | 
                   $table->add_field('name', XMLDB_TYPE_CHAR, '255', null, XMLDB_NOTNULL, null, null);
  | 
        
        
            | 
            | 
           73 | 
              | 
        
        
            | 
            | 
           74 | 
                   // Adding keys to table quiz_grade_items.
  | 
        
        
            | 
            | 
           75 | 
                   $table->add_key('primary', XMLDB_KEY_PRIMARY, ['id']);
  | 
        
        
            | 
            | 
           76 | 
                   $table->add_key('quizid', XMLDB_KEY_FOREIGN, ['quizid'], 'quiz', ['id']);
  | 
        
        
            | 
            | 
           77 | 
              | 
        
        
            | 
            | 
           78 | 
                   // Adding indexes to table quiz_grade_items.
  | 
        
        
            | 
            | 
           79 | 
                   $table->add_index('quizid-sortorder', XMLDB_INDEX_UNIQUE, ['quizid', 'sortorder']);
  | 
        
        
            | 
            | 
           80 | 
              | 
        
        
            | 
            | 
           81 | 
                   // Conditionally launch create table for quiz_grade_items.
  | 
        
        
            | 
            | 
           82 | 
                   if (!$dbman->table_exists($table)) {
  | 
        
        
            | 
            | 
           83 | 
                       $dbman->create_table($table);
  | 
        
        
            | 
            | 
           84 | 
                   }
  | 
        
        
            | 
            | 
           85 | 
              | 
        
        
            | 
            | 
           86 | 
                   // Quiz savepoint reached.
  | 
        
        
            | 
            | 
           87 | 
                   upgrade_mod_savepoint(true, 2023112400, 'quiz');
  | 
        
        
            | 
            | 
           88 | 
               }
  | 
        
        
            | 
            | 
           89 | 
              | 
        
        
            | 
            | 
           90 | 
               if ($oldversion < 2023112401) {
  | 
        
        
            | 
            | 
           91 | 
              | 
        
        
            | 
            | 
           92 | 
                   // Define field quizgradeitemid to be added to quiz_slots.
  | 
        
        
            | 
            | 
           93 | 
                   $table = new xmldb_table('quiz_slots');
  | 
        
        
            | 
            | 
           94 | 
                   $field = new xmldb_field('quizgradeitemid', XMLDB_TYPE_INTEGER, '10', null, null, null, null, 'maxmark');
  | 
        
        
            | 
            | 
           95 | 
              | 
        
        
            | 
            | 
           96 | 
                   // Conditionally launch add field quizgradeitemid.
  | 
        
        
            | 
            | 
           97 | 
                   if (!$dbman->field_exists($table, $field)) {
  | 
        
        
            | 
            | 
           98 | 
                       $dbman->add_field($table, $field);
  | 
        
        
            | 
            | 
           99 | 
                   }
  | 
        
        
            | 
            | 
           100 | 
              | 
        
        
            | 
            | 
           101 | 
                   // Quiz savepoint reached.
  | 
        
        
            | 
            | 
           102 | 
                   upgrade_mod_savepoint(true, 2023112401, 'quiz');
  | 
        
        
            | 
            | 
           103 | 
               }
  | 
        
        
            | 
            | 
           104 | 
              | 
        
        
            | 
            | 
           105 | 
               if ($oldversion < 2023112402) {
  | 
        
        
            | 
            | 
           106 | 
              | 
        
        
            | 
            | 
           107 | 
                   // Define key quizgradeitemid (foreign) to be added to quiz_slots.
  | 
        
        
            | 
            | 
           108 | 
                   $table = new xmldb_table('quiz_slots');
  | 
        
        
            | 
            | 
           109 | 
                   $key = new xmldb_key('quizgradeitemid', XMLDB_KEY_FOREIGN, ['quizgradeitemid'], 'quiz_grade_items', ['id']);
  | 
        
        
            | 
            | 
           110 | 
              | 
        
        
            | 
            | 
           111 | 
                   // Launch add key quizgradeitemid.
  | 
        
        
            | 
            | 
           112 | 
                   $dbman->add_key($table, $key);
  | 
        
        
            | 
            | 
           113 | 
              | 
        
        
            | 
            | 
           114 | 
                   // Quiz savepoint reached.
  | 
        
        
            | 
            | 
           115 | 
                   upgrade_mod_savepoint(true, 2023112402, 'quiz');
  | 
        
        
            | 
            | 
           116 | 
               }
  | 
        
        
            | 
            | 
           117 | 
              | 
        
        
            | 
            | 
           118 | 
               // Automatically generated Moodle v4.4.0 release upgrade line.
  | 
        
        
            | 
            | 
           119 | 
               // Put any upgrade step following this.
  | 
        
        
            | 
            | 
           120 | 
              | 
        
        
           | 1441 | 
           ariadna | 
           121 | 
               // Automatically generated Moodle v4.5.0 release upgrade line.
  | 
        
        
            | 
            | 
           122 | 
               // Put any upgrade step following this.
  | 
        
        
            | 
            | 
           123 | 
               if ($oldversion < 2025011300) {
  | 
        
        
            | 
            | 
           124 | 
                   // Define field precreateattempts to be added to quiz.
  | 
        
        
            | 
            | 
           125 | 
                   $table = new xmldb_table('quiz');
  | 
        
        
            | 
            | 
           126 | 
                   $field = new xmldb_field('precreateattempts', XMLDB_TYPE_INTEGER, '1', null, null, null, null, 'allowofflineattempts');
  | 
        
        
            | 
            | 
           127 | 
              | 
        
        
            | 
            | 
           128 | 
                   // Conditionally launch add field precreateattempts.
  | 
        
        
            | 
            | 
           129 | 
                   if (!$dbman->field_exists($table, $field)) {
  | 
        
        
            | 
            | 
           130 | 
                       $dbman->add_field($table, $field);
  | 
        
        
            | 
            | 
           131 | 
                   }
  | 
        
        
            | 
            | 
           132 | 
              | 
        
        
            | 
            | 
           133 | 
                   upgrade_mod_savepoint(true, 2025011300, 'quiz');
  | 
        
        
            | 
            | 
           134 | 
               }
  | 
        
        
            | 
            | 
           135 | 
              | 
        
        
            | 
            | 
           136 | 
               // Automatically generated Moodle v5.0.0 release upgrade line.
  | 
        
        
            | 
            | 
           137 | 
               // Put any upgrade step following this.
  | 
        
        
            | 
            | 
           138 | 
              | 
        
        
           | 1 | 
           efrain | 
           139 | 
               return true;
  | 
        
        
            | 
            | 
           140 | 
           }
  |