Proyectos de Subversion Moodle

Rev

| Ultima modificación | Ver Log |

Rev Autor Línea Nro. Línea
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.1.0 release upgrade line.
34
    // Put any upgrade step following this.
35
 
36
    if ($oldversion < 2022120500) {
37
        // Define field displaynumber to be added to quiz_slots.
38
        $table = new xmldb_table('quiz_slots');
39
        $field = new xmldb_field('displaynumber', XMLDB_TYPE_CHAR, '16', null, null, null, null, 'page');
40
 
41
        // Conditionally launch add field displaynumber.
42
        if (!$dbman->field_exists($table, $field)) {
43
            $dbman->add_field($table, $field);
44
        }
45
 
46
        // Quiz savepoint reached.
47
        upgrade_mod_savepoint(true, 2022120500, 'quiz');
48
    }
49
 
50
    // Automatically generated Moodle v4.2.0 release upgrade line.
51
    // Put any upgrade step following this.
52
 
53
    if ($oldversion < 2023042401) {
54
        // Define field reviewmaxmarks to be added to quiz.
55
        $table = new xmldb_table('quiz');
56
        $field = new xmldb_field('reviewmaxmarks', XMLDB_TYPE_INTEGER, '6', null, XMLDB_NOTNULL, null, '0', 'reviewcorrectness');
57
 
58
        // Conditionally launch add field reviewmaxmarks.
59
        if (!$dbman->field_exists($table, $field)) {
60
            $dbman->add_field($table, $field);
61
        }
62
 
63
        // Quiz savepoint reached.
64
        upgrade_mod_savepoint(true, 2023042401, 'quiz');
65
    }
66
 
67
    // Automatically generated Moodle v4.3.0 release upgrade line.
68
    // Put any upgrade step following this.
69
 
70
    if ($oldversion < 2023112300) {
71
 
72
        // Set the value for all existing rows to match the previous behaviour,
73
        // but only where users have not already set another value.
74
        $DB->set_field('quiz', 'reviewmaxmarks', 0x11110, ['reviewmaxmarks' => 0]);
75
 
76
        // Quiz savepoint reached.
77
        upgrade_mod_savepoint(true, 2023112300, 'quiz');
78
    }
79
 
80
    if ($oldversion < 2023112400) {
81
 
82
        // Define table quiz_grade_items to be created.
83
        $table = new xmldb_table('quiz_grade_items');
84
 
85
        // Adding fields to table quiz_grade_items.
86
        $table->add_field('id', XMLDB_TYPE_INTEGER, '10', null, XMLDB_NOTNULL, XMLDB_SEQUENCE, null);
87
        $table->add_field('quizid', XMLDB_TYPE_INTEGER, '10', null, XMLDB_NOTNULL, null, null);
88
        $table->add_field('sortorder', XMLDB_TYPE_INTEGER, '10', null, XMLDB_NOTNULL, null, null);
89
        $table->add_field('name', XMLDB_TYPE_CHAR, '255', null, XMLDB_NOTNULL, null, null);
90
 
91
        // Adding keys to table quiz_grade_items.
92
        $table->add_key('primary', XMLDB_KEY_PRIMARY, ['id']);
93
        $table->add_key('quizid', XMLDB_KEY_FOREIGN, ['quizid'], 'quiz', ['id']);
94
 
95
        // Adding indexes to table quiz_grade_items.
96
        $table->add_index('quizid-sortorder', XMLDB_INDEX_UNIQUE, ['quizid', 'sortorder']);
97
 
98
        // Conditionally launch create table for quiz_grade_items.
99
        if (!$dbman->table_exists($table)) {
100
            $dbman->create_table($table);
101
        }
102
 
103
        // Quiz savepoint reached.
104
        upgrade_mod_savepoint(true, 2023112400, 'quiz');
105
    }
106
 
107
    if ($oldversion < 2023112401) {
108
 
109
        // Define field quizgradeitemid to be added to quiz_slots.
110
        $table = new xmldb_table('quiz_slots');
111
        $field = new xmldb_field('quizgradeitemid', XMLDB_TYPE_INTEGER, '10', null, null, null, null, 'maxmark');
112
 
113
        // Conditionally launch add field quizgradeitemid.
114
        if (!$dbman->field_exists($table, $field)) {
115
            $dbman->add_field($table, $field);
116
        }
117
 
118
        // Quiz savepoint reached.
119
        upgrade_mod_savepoint(true, 2023112401, 'quiz');
120
    }
121
 
122
    if ($oldversion < 2023112402) {
123
 
124
        // Define key quizgradeitemid (foreign) to be added to quiz_slots.
125
        $table = new xmldb_table('quiz_slots');
126
        $key = new xmldb_key('quizgradeitemid', XMLDB_KEY_FOREIGN, ['quizgradeitemid'], 'quiz_grade_items', ['id']);
127
 
128
        // Launch add key quizgradeitemid.
129
        $dbman->add_key($table, $key);
130
 
131
        // Quiz savepoint reached.
132
        upgrade_mod_savepoint(true, 2023112402, 'quiz');
133
    }
134
 
135
    // Automatically generated Moodle v4.4.0 release upgrade line.
136
    // Put any upgrade step following this.
137
 
138
    return true;
139
}