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
 * Customcert module upgrade code.
19
 *
20
 * @package    mod_customcert
21
 * @copyright  2016 Mark Nelson <markn@moodle.com>
22
 * @license    http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
23
 */
24
 
25
/**
26
 * Customcert module upgrade code.
27
 *
28
 * @param int $oldversion the version we are upgrading from
29
 * @return bool always true
30
 */
31
function xmldb_customcert_upgrade($oldversion) {
32
    global $DB;
33
 
34
    $dbman = $DB->get_manager();
35
 
36
    if ($oldversion < 2016120503) {
37
 
38
        $table = new xmldb_table('customcert_templates');
39
        $field = new xmldb_field('name', XMLDB_TYPE_CHAR, '255', null, XMLDB_NOTNULL, null, null, 'id');
40
        $dbman->change_field_precision($table, $field);
41
 
42
        // Savepoint reached.
43
        upgrade_mod_savepoint(true, 2016120503, 'customcert');
44
    }
45
 
46
    if ($oldversion < 2016120505) {
47
        $table = new xmldb_table('customcert');
48
        $field = new xmldb_field('emailstudents', XMLDB_TYPE_INTEGER, '1', null, XMLDB_NOTNULL, null, '0', 'requiredtime');
49
 
50
        // Conditionally launch add field.
51
        if (!$dbman->field_exists($table, $field)) {
52
            $dbman->add_field($table, $field);
53
        }
54
 
55
        $field = new xmldb_field('emailteachers', XMLDB_TYPE_INTEGER, '1', null, XMLDB_NOTNULL, null, '0', 'emailstudents');
56
 
57
        // Conditionally launch add field.
58
        if (!$dbman->field_exists($table, $field)) {
59
            $dbman->add_field($table, $field);
60
        }
61
 
62
        $field = new xmldb_field('emailothers', XMLDB_TYPE_TEXT, null, null, null, null, null, 'emailteachers');
63
 
64
        // Conditionally launch add field.
65
        if (!$dbman->field_exists($table, $field)) {
66
            $dbman->add_field($table, $field);
67
        }
68
 
69
        $table = new xmldb_table('customcert_issues');
70
        $field = new xmldb_field('emailed', XMLDB_TYPE_INTEGER, '1', null, XMLDB_NOTNULL, null, '0', 'code');
71
 
72
        // Conditionally launch add field.
73
        if (!$dbman->field_exists($table, $field)) {
74
            $dbman->add_field($table, $field);
75
        }
76
 
77
        // Savepoint reached.
78
        upgrade_mod_savepoint(true, 2016120505, 'customcert');
79
    }
80
 
81
    if ($oldversion < 2017050501) {
82
        // Remove any duplicate rows from customcert issue table.
83
        // This SQL fetches the id of those records which have duplicate customcert issues.
84
        // This doesn't return the first issue.
85
        $fromclause = "FROM (
86
                             SELECT min(id) AS minid, userid, customcertid
87
                               FROM {customcert_issues}
88
                           GROUP BY userid, customcertid
89
                            ) minid
90
                       JOIN {customcert_issues} ci
91
                         ON ci.userid = minid.userid
92
                        AND ci.customcertid = minid.customcertid
93
                        AND ci.id > minid.minid";
94
 
95
        // Get the records themselves.
96
        $getduplicatessql = "SELECT ci.id $fromclause ORDER BY minid";
97
        if ($records = $DB->get_records_sql($getduplicatessql)) {
98
            // Delete them.
99
            $ids = implode(',', array_keys($records));
100
            $DB->delete_records_select('customcert_issues', "id IN ($ids)");
101
        }
102
 
103
        // Savepoint reached.
104
        upgrade_mod_savepoint(true, 2017050501, 'customcert');
105
    }
106
 
107
    if ($oldversion < 2017050502) {
108
        // Add column for new 'verifycertificateanyone' setting.
109
        $table = new xmldb_table('customcert');
110
        $field = new xmldb_field('verifyany', XMLDB_TYPE_INTEGER, '1', null, XMLDB_NOTNULL, null, '0',
111
            'requiredtime');
112
 
113
        // Conditionally launch add field.
114
        if (!$dbman->field_exists($table, $field)) {
115
            $dbman->add_field($table, $field);
116
        }
117
 
118
        // Savepoint reached.
119
        upgrade_mod_savepoint(true, 2017050502, 'customcert');
120
    }
121
 
122
    if ($oldversion < 2017050506) {
123
        $table = new xmldb_table('customcert_elements');
124
        $field = new xmldb_field('size');
125
 
126
        // Rename column as it is a reserved word in Oracle.
127
        if ($dbman->field_exists($table, $field)) {
128
            $field->set_attributes(XMLDB_TYPE_INTEGER, '10', null, null, null, null, 'font');
129
            $dbman->rename_field($table, $field, 'fontsize');
130
        }
131
 
132
        // Savepoint reached.
133
        upgrade_mod_savepoint(true, 2017050506, 'customcert');
134
    }
135
 
136
    if ($oldversion < 2018051705) {
137
        $table = new xmldb_table('customcert_elements');
138
        $field = new xmldb_field('element', XMLDB_TYPE_CHAR, '255', null, XMLDB_NOTNULL, null, null, 'name');
139
 
140
        // Alter the 'element' column to be characters, rather than text.
141
        $dbman->change_field_type($table, $field);
142
 
143
        // Savepoint reached.
144
        upgrade_mod_savepoint(true, 2018051705, 'customcert');
145
    }
146
 
147
    if ($oldversion < 2019111803) {
148
        $table = new xmldb_table('customcert');
149
        $index = new xmldb_index('templateid', XMLDB_INDEX_UNIQUE, ['templateid']);
150
        if ($dbman->index_exists($table, $index)) {
151
            $dbman->drop_index($table, $index);
152
        }
153
        $key = new xmldb_key('templateid', XMLDB_KEY_FOREIGN, ['templateid'], 'customcert_templates', ['id']);
154
        $dbman->add_key($table, $key);
155
 
156
        $table = new xmldb_table('customcert_pages');
157
        $index = new xmldb_index('templateid', XMLDB_INDEX_UNIQUE, ['templateid']);
158
        if ($dbman->index_exists($table, $index)) {
159
            $dbman->drop_index($table, $index);
160
        }
161
        $key = new xmldb_key('templateid', XMLDB_KEY_FOREIGN, ['templateid'], 'customcert_templates', ['id']);
162
        $dbman->add_key($table, $key);
163
 
164
        upgrade_mod_savepoint(true, 2019111803, 'customcert');
165
    }
166
 
167
    if ($oldversion < 2020110901) {
168
        $table = new xmldb_table('customcert');
169
        $field = new xmldb_field('deliveryoption', XMLDB_TYPE_CHAR, '255', null, null, null, null, 'verifyany');
170
 
171
        // Conditionally launch add field.
172
        if (!$dbman->field_exists($table, $field)) {
173
            $dbman->add_field($table, $field);
174
        }
175
 
176
        upgrade_mod_savepoint(true, 2020110901, 'customcert');
177
    }
178
 
179
    if ($oldversion < 2021051702) {
180
        $table = new xmldb_table('customcert_elements');
181
        $field = new xmldb_field('alignment', XMLDB_TYPE_CHAR, '1', null, XMLDB_NOTNULL, null, 'L', 'refpoint');
182
 
183
        // Conditionally launch add field.
184
        if (!$dbman->field_exists($table, $field)) {
185
            $dbman->add_field($table, $field);
186
        }
187
 
188
        upgrade_mod_savepoint(true, 2021051702, 'customcert'); // Replace with the actual version number.
189
    }
190
 
191
    if ($oldversion < 2022041903) {
192
        $table = new xmldb_table('customcert');
193
        $field = new xmldb_field('language', XMLDB_TYPE_CHAR, '20', null, null, null, null, 'protection');
194
 
195
        // Conditionally launch add field.
196
        if (!$dbman->field_exists($table, $field)) {
197
            $dbman->add_field($table, $field);
198
        }
199
 
200
        upgrade_mod_savepoint(true, 2022041903, 'customcert'); // Replace with the actual version number.
201
    }
202
 
203
    if ($oldversion < 2023042403) {
204
        // Define index to be added to customcert_issues.
205
        $table = new xmldb_table('customcert_issues');
206
        $index = new xmldb_index('userid-customcertid', XMLDB_INDEX_NOTUNIQUE, ['userid', 'customcertid']);
207
 
208
        // Conditionally launch add index.
209
        if (!$dbman->index_exists($table, $index)) {
210
            $dbman->add_index($table, $index);
211
        }
212
 
213
        upgrade_mod_savepoint(true, 2023042403, 'customcert'); // Replace with the actual version number.
214
    }
215
 
216
    if ($oldversion < 2023042404) {
217
        $table = new xmldb_table('customcert_issues');
218
        $key = new xmldb_key('userid', XMLDB_KEY_FOREIGN, ['userid'], 'user', ['id']);
219
 
220
        $dbman->add_key($table, $key);
221
 
222
        upgrade_mod_savepoint(true, 2023042404, 'customcert');
223
    }
224
 
225
    if ($oldversion < 2023042405) {
226
        // Changing precision of field verifyany on table customcert to (1).
227
        $table = new xmldb_table('customcert');
228
        $field = new xmldb_field('verifyany', XMLDB_TYPE_INTEGER, '1', null, XMLDB_NOTNULL, null, '0',
229
            'requiredtime');
230
 
231
        // Launch change of precision for field verifyany.
232
        $dbman->change_field_precision($table, $field);
233
 
234
        // Customcert savepoint reached.
235
        upgrade_mod_savepoint(true, 2023042405, 'customcert');
236
    }
237
 
238
    return true;
239
}