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 the Zoom plugin for 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
 * This file keeps track of upgrades to the zoom module
19
 *
20
 * Sometimes, changes between versions involve alterations to database
21
 * structures and other major things that may break installations. The upgrade
22
 * function in this file will attempt to perform all the necessary actions to
23
 * upgrade your older installation to the current version. If there's something
24
 * it cannot do itself, it will tell you what you need to do.  The commands in
25
 * here will all be database-neutral, using the functions defined in DLL libraries.
26
 *
27
 * @package    mod_zoom
28
 * @copyright  2015 UC Regents
29
 * @license    http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
30
 */
31
 
32
/**
33
 * Execute zoom upgrade from the given old version
34
 *
35
 * @param int $oldversion
36
 * @return bool
37
 */
38
function xmldb_zoom_upgrade($oldversion) {
39
    global $DB;
40
 
41
    $dbman = $DB->get_manager(); // Loads ddl manager and xmldb classes.
42
    $table = new xmldb_table('zoom');
43
 
44
    if ($oldversion < 2015071000) {
45
        // Add updated_at.
46
        $field = new xmldb_field('updated_at', XMLDB_TYPE_CHAR, '20', null, null, null, null, 'created_at');
47
        if (!$dbman->field_exists($table, $field)) {
48
            $dbman->add_field($table, $field);
49
        }
50
 
51
        // Add ended_at.
52
        $field = new xmldb_field('ended_at', XMLDB_TYPE_CHAR, '20', null, null, null, null, 'updated_at');
53
        if (!$dbman->field_exists($table, $field)) {
54
            $dbman->add_field($table, $field);
55
        }
56
 
57
        upgrade_mod_savepoint(true, 2015071000, 'zoom');
58
    }
59
 
60
    if ($oldversion < 2015071500) {
61
        // Rename option_no_video_host to option_host_video; change default to 1; invert values.
62
        $field = new xmldb_field('option_no_video_host', XMLDB_TYPE_INTEGER, '1', null, null, null, '1', 'option_start_type');
63
        // Invert option_no_video_host.
64
        $DB->set_field('UPDATE {zoom} SET option_no_video_host = 1 - option_no_video_host');
65
        $dbman->change_field_default($table, $field);
66
        $dbman->rename_field($table, $field, 'option_host_video');
67
 
68
        // Rename option_no_video_participants to option_participants_video; change default to 1; invert values.
69
        $field = new xmldb_field(
70
            'option_no_video_participants',
71
            XMLDB_TYPE_INTEGER,
72
            '1',
73
            null,
74
            null,
75
            null,
76
            '1',
77
            'option_host_video'
78
        );
79
        // Invert option_no_video_participants.
80
        $DB->set_field('UPDATE {zoom} SET option_no_video_participants = 1 - option_no_video_participants');
81
        $dbman->change_field_default($table, $field);
82
        $dbman->rename_field($table, $field, 'option_participants_video');
83
 
84
        // Change start_time to int (timestamp).
85
        $field = new xmldb_field('start_time', XMLDB_TYPE_INTEGER, '12', null, null, null, null, 'name');
86
        $starttimes = $DB->get_recordset('zoom');
87
        foreach ($starttimes as $time) {
88
            $time->start_time = strtotime($time->start_time);
89
            $DB->update_record('zoom', $time);
90
        }
91
 
92
        $starttimes->close();
93
        $dbman->change_field_type($table, $field);
94
 
95
        // Change precision/length of duration to 6 digits.
96
        $field = new xmldb_field('duration', XMLDB_TYPE_INTEGER, '6', null, null, null, null, 'type');
97
        $dbman->change_field_precision($table, $field);
98
        $DB->set_field('UPDATE {zoom} SET duration = duration*60');
99
 
100
        upgrade_mod_savepoint(true, 2015071500, 'zoom');
101
    }
102
 
103
    if ($oldversion < 2015071600) {
104
        // Add intro.
105
        $field = new xmldb_field('intro', XMLDB_TYPE_TEXT, null, null, null, null, null, 'course');
106
        if (!$dbman->field_exists($table, $field)) {
107
            $dbman->add_field($table, $field);
108
        }
109
 
110
        // Add introformat.
111
        $field = new xmldb_field('introformat', XMLDB_TYPE_INTEGER, '4', null, null, null, null, 'intro');
112
        if (!$dbman->field_exists($table, $field)) {
113
            $dbman->add_field($table, $field);
114
        }
115
 
116
        upgrade_mod_savepoint(true, 2015071600, 'zoom');
117
    }
118
 
119
    if ($oldversion < 2015072000) {
120
        // Drop updated_at.
121
        $field = new xmldb_field('updated_at');
122
        if ($dbman->field_exists($table, $field)) {
123
            $dbman->drop_field($table, $field);
124
        }
125
 
126
        // Drop ended_at.
127
        $field = new xmldb_field('ended_at');
128
        if ($dbman->field_exists($table, $field)) {
129
            $dbman->drop_field($table, $field);
130
        }
131
 
132
        // Add timemodified.
133
        $field = new xmldb_field('timemodified', XMLDB_TYPE_INTEGER, '12', null, null, null, null, 'start_time');
134
        if (!$dbman->field_exists($table, $field)) {
135
            $dbman->add_field($table, $field);
136
        }
137
 
138
        // Add grade.
139
        $field = new xmldb_field('grade', XMLDB_TYPE_INTEGER, '10', null, null, null, null, 'introformat');
140
        if (!$dbman->field_exists($table, $field)) {
141
            $dbman->add_field($table, $field);
142
        }
143
 
144
        // Zoom savepoint reached.
145
        upgrade_mod_savepoint(true, 2015072000, 'zoom');
146
    }
147
 
148
    if ($oldversion < 2016040100) {
149
        // Add webinar.
150
        $field = new xmldb_field('webinar', XMLDB_TYPE_INTEGER, '1', null, null, null, '0', 'type');
151
        if (!$dbman->field_exists($table, $field)) {
152
            $dbman->add_field($table, $field);
153
        }
154
 
155
        // Change type to recurring.
156
        $field = new xmldb_field('type', XMLDB_TYPE_INTEGER, '1', null, null, null, '0', 'timemodified');
157
        $dbman->change_field_notnull($table, $field);
158
        $dbman->change_field_default($table, $field);
159
        // Meeting is recurring if type is 3.
160
        $DB->set_field_select('zoom', 'type', 0, 'type <> 3');
161
        $DB->set_field('zoom', 'type', 1, ['type' => 3]);
162
        $dbman->rename_field($table, $field, 'recurring');
163
 
164
        // Zoom savepoint reached.
165
        upgrade_mod_savepoint(true, 2016040100, 'zoom');
166
    }
167
 
168
    if ($oldversion < 2018091200) {
169
        // Removed apiurl option from settings.
170
        set_config('apiurl', null, 'mod_zoom');
171
 
172
        // Set the starting number of API calls.
173
        set_config('calls_left', 2000, 'mod_zoom');
174
 
175
        // Set the time at which to start looking for meeting reports.
176
        set_config('last_call_made_at', time() - (60 * 60 * 12), 'mod_zoom');
177
 
178
        // Start zoom table modifications.
179
        $table = new xmldb_table('zoom');
180
 
181
        // Define field status to be dropped from zoom.
182
        $field = new xmldb_field('status');
183
 
184
        // Conditionally launch drop field status.
185
        if ($dbman->field_exists($table, $field)) {
186
            $dbman->drop_field($table, $field);
187
        }
188
 
189
        // Define field exists_on_zoom to be added to zoom.
190
        $field = new xmldb_field('exists_on_zoom', XMLDB_TYPE_INTEGER, '1', null, XMLDB_NOTNULL, null, '1', 'option_audio');
191
 
192
        // Conditionally launch add field exists_on_zoom.
193
        if (!$dbman->field_exists($table, $field)) {
194
            $dbman->add_field($table, $field);
195
        }
196
 
197
        // Define field uuid to be dropped from zoom.
198
        $field = new xmldb_field('uuid');
199
 
200
        // Conditionally launch drop field uuid.
201
        if ($dbman->field_exists($table, $field)) {
202
            $dbman->drop_field($table, $field);
203
        }
204
 
205
        // Define table zoom_meeting_details to be created.
206
        $table = new xmldb_table('zoom_meeting_details');
207
 
208
        // Adding fields to table zoom_meeting_details.
209
        $table->add_field('id', XMLDB_TYPE_INTEGER, '10', null, XMLDB_NOTNULL, XMLDB_SEQUENCE, null);
210
        $table->add_field('uuid', XMLDB_TYPE_CHAR, '30', null, XMLDB_NOTNULL, null, null);
211
        $table->add_field('meeting_id', XMLDB_TYPE_INTEGER, '11', null, XMLDB_NOTNULL, null, null);
212
        $table->add_field('end_time', XMLDB_TYPE_INTEGER, '12', null, XMLDB_NOTNULL, null, null);
213
        $table->add_field('duration', XMLDB_TYPE_INTEGER, '12', null, XMLDB_NOTNULL, null, null);
214
        $table->add_field('start_time', XMLDB_TYPE_INTEGER, '12', null, null, null, null);
215
        $table->add_field('topic', XMLDB_TYPE_CHAR, '300', null, XMLDB_NOTNULL, null, null);
216
        $table->add_field('total_minutes', XMLDB_TYPE_INTEGER, '12', null, null, null, '0');
217
        $table->add_field('participants_count', XMLDB_TYPE_INTEGER, '4', null, null, null, '0');
218
        $table->add_field('zoomid', XMLDB_TYPE_INTEGER, '10', null, XMLDB_NOTNULL, null, null);
219
 
220
        // Adding keys to table zoom_meeting_details.
221
        $table->add_key('uuid_unique', XMLDB_KEY_UNIQUE, ['uuid']);
222
        $table->add_key('id_primary', XMLDB_KEY_PRIMARY, ['id']);
223
        $table->add_key('zoomid_foreign', XMLDB_KEY_FOREIGN, ['zoomid'], 'zoom', ['id']);
224
        $table->add_key('meeting_unique', XMLDB_KEY_UNIQUE, ['meeting_id', 'uuid']);
225
 
226
        // Conditionally launch create table for zoom_meeting_details.
227
        if (!$dbman->table_exists($table)) {
228
            $dbman->create_table($table);
229
        }
230
 
231
        // Define table zoom_meeting_participants to be created.
232
        $table = new xmldb_table('zoom_meeting_participants');
233
 
234
        // Adding fields to table zoom_meeting_participants.
235
        $table->add_field('id', XMLDB_TYPE_INTEGER, '10', null, XMLDB_NOTNULL, XMLDB_SEQUENCE, null);
236
        $table->add_field('zoomuserid', XMLDB_TYPE_INTEGER, '11', null, XMLDB_NOTNULL, null, null);
237
        $table->add_field('uuid', XMLDB_TYPE_CHAR, '30', null, null, null, null);
238
        $table->add_field('user_email', XMLDB_TYPE_TEXT, null, null, null, null, null);
239
        $table->add_field('join_time', XMLDB_TYPE_INTEGER, '12', null, XMLDB_NOTNULL, null, null);
240
        $table->add_field('leave_time', XMLDB_TYPE_INTEGER, '12', null, XMLDB_NOTNULL, null, null);
241
        $table->add_field('duration', XMLDB_TYPE_INTEGER, '12', null, XMLDB_NOTNULL, null, null);
242
        $table->add_field('attentiveness_score', XMLDB_TYPE_CHAR, '7', null, XMLDB_NOTNULL, null, null);
243
        $table->add_field('userid', XMLDB_TYPE_CHAR, '255', null, null, null, null);
244
        $table->add_field('name', XMLDB_TYPE_CHAR, '255', null, XMLDB_NOTNULL, null, null);
245
        $table->add_field('detailsid', XMLDB_TYPE_INTEGER, '10', null, XMLDB_NOTNULL, null, null, 'name');
246
 
247
        // Adding keys to table zoom_meeting_participants.
248
        $table->add_key('id_primary', XMLDB_KEY_PRIMARY, ['id']);
249
        $table->add_key('user_by_meeting_key', XMLDB_KEY_UNIQUE, ['detailsid', 'zoomuserid']);
250
        $table->add_key('detailsid_foreign', XMLDB_KEY_FOREIGN, ['detailsid'], 'zoom_meeting_details', ['id']);
251
 
252
        // Adding indexes to table zoom_meeting_participants.
253
        $table->add_index('userid', XMLDB_INDEX_NOTUNIQUE, ['userid']);
254
 
255
        // Conditionally launch create table for zoom_meeting_participants.
256
        if (!$dbman->table_exists($table)) {
257
            $dbman->create_table($table);
258
        }
259
 
260
        upgrade_mod_savepoint(true, 2018091200, 'zoom');
261
    }
262
 
263
    if ($oldversion < 2018091400) {
264
        // Define field alternative_hosts to be added to zoom.
265
        $table = new xmldb_table('zoom');
266
        $field = new xmldb_field('alternative_hosts', XMLDB_TYPE_CHAR, '255', null, null, null, null, 'exists_on_zoom');
267
 
268
        // Conditionally launch add field alternative_hosts.
269
        if (!$dbman->field_exists($table, $field)) {
270
            $dbman->add_field($table, $field);
271
        }
272
 
273
        // Zoom savepoint reached.
274
        upgrade_mod_savepoint(true, 2018091400, 'zoom');
275
    }
276
 
277
    if ($oldversion < 2018092201) {
278
        // Changing type of field userid on table zoom_meeting_participants to int.
279
        $table = new xmldb_table('zoom_meeting_participants');
280
 
281
        $index = new xmldb_index('userid', XMLDB_INDEX_NOTUNIQUE, ['userid']);
282
 
283
        // Conditionally launch drop index userid.
284
        if ($dbman->index_exists($table, $index)) {
285
            $dbman->drop_index($table, $index);
286
        }
287
 
288
        $field = new xmldb_field('userid', XMLDB_TYPE_INTEGER, '10', null, null, null, null, 'id');
289
 
290
        // Launch change of type for field userid.
291
        $dbman->change_field_type($table, $field);
292
 
293
        $index = new xmldb_index('userid', XMLDB_INDEX_NOTUNIQUE, ['userid']);
294
 
295
        // Conditionally launch add index userid.
296
        if (!$dbman->index_exists($table, $index)) {
297
            $dbman->add_index($table, $index);
298
        }
299
 
300
        // Zoom savepoint reached.
301
        upgrade_mod_savepoint(true, 2018092201, 'zoom');
302
    }
303
 
304
    if ($oldversion < 2019061800) {
305
        // Make sure start_time is not null to match install.xml.
306
        $table = new xmldb_table('zoom_meeting_details');
307
        $field = new xmldb_field('start_time', XMLDB_TYPE_INTEGER, '12', null, XMLDB_NOTNULL, null, null);
308
        if ($dbman->field_exists($table, $field)) {
309
            $dbman->change_field_notnull($table, $field);
310
        }
311
 
312
        // Zoom savepoint reached.
313
        upgrade_mod_savepoint(true, 2019061800, 'zoom');
314
    }
315
 
316
    if ($oldversion < 2019091200) {
317
        // Change field alternative_hosts from type char(255) to text.
318
        $table = new xmldb_table('zoom');
319
        $field = new xmldb_field('alternative_hosts', XMLDB_TYPE_TEXT, null, null, null, null, null, 'exists_on_zoom');
320
        $dbman->change_field_type($table, $field);
321
 
322
        // Zoom savepoint reached.
323
        upgrade_mod_savepoint(true, 2019091200, 'zoom');
324
    }
325
 
326
    if ($oldversion < 2020042600) {
327
        // Change field zoom_meeting_participants from type int(11) to char(35),
328
        // because sometimes zoomuserid is concatenated with a timestamp.
329
        // See https://devforum.zoom.us/t/meeting-participant-user-id-value/7886/2.
330
        $table = new xmldb_table('zoom_meeting_participants');
331
 
332
        // First drop key, not needed anymore.
333
        $key = new xmldb_key('user_by_meeting_key', XMLDB_KEY_UNIQUE, ['detailsid', 'zoomuserid']);
334
        $dbman->drop_key($table, $key);
335
 
336
        // Change of type for field zoomuserid to char(35).
337
        $field = new xmldb_field('zoomuserid', XMLDB_TYPE_CHAR, '35', null, XMLDB_NOTNULL, null, null, 'userid');
338
        $dbman->change_field_type($table, $field);
339
 
340
        // Zoom savepoint reached.
341
        upgrade_mod_savepoint(true, 2020042600, 'zoom');
342
    }
343
 
344
    if ($oldversion < 2020042700) {
345
        // Define field attentiveness_score to be dropped from zoom_meeting_participants.
346
        $table = new xmldb_table('zoom_meeting_participants');
347
        $field = new xmldb_field('attentiveness_score');
348
 
349
        // Conditionally launch drop field attentiveness_score.
350
        if ($dbman->field_exists($table, $field)) {
351
            $dbman->drop_field($table, $field);
352
        }
353
 
354
        // Zoom savepoint reached.
355
        upgrade_mod_savepoint(true, 2020042700, 'zoom');
356
    }
357
 
358
    if ($oldversion < 2020051800) {
359
        // Define field option_mute_upon_entry to be added to zoom.
360
        $table = new xmldb_table('zoom');
361
        $field = new xmldb_field('option_mute_upon_entry', XMLDB_TYPE_INTEGER, '1', null, null, null, '1', 'option_audio');
362
 
363
        // Conditionally launch add field option_mute_upon_entry.
364
        if (!$dbman->field_exists($table, $field)) {
365
            $dbman->add_field($table, $field);
366
        }
367
 
368
        // Define field option_waiting_room to be added to zoom.
369
        $table = new xmldb_table('zoom');
370
        $field = new xmldb_field('option_waiting_room', XMLDB_TYPE_INTEGER, '1', null, null, null, '1', 'option_mute_upon_entry');
371
 
372
        // Conditionally launch add field option_waiting_room.
373
        if (!$dbman->field_exists($table, $field)) {
374
            $dbman->add_field($table, $field);
375
        }
376
 
377
        // Define field authenticated_users to be added to zoom.
378
        $table = new xmldb_table('zoom');
379
        $field = new xmldb_field(
380
            'option_authenticated_users',
381
            XMLDB_TYPE_INTEGER,
382
            '1',
383
            null,
384
            null,
385
            null,
386
            '0',
387
            'option_waiting_room'
388
        );
389
 
390
        // Conditionally launch add field authenticated_users.
391
        if (!$dbman->field_exists($table, $field)) {
392
            $dbman->add_field($table, $field);
393
        }
394
 
395
        // Changing the default of field option_host_video on table zoom to 0.
396
        $table = new xmldb_table('zoom');
397
        $field = new xmldb_field('option_host_video', XMLDB_TYPE_INTEGER, '1', null, null, null, '0', 'option_start_type');
398
 
399
        // Launch change of default for field option_host_video.
400
        $dbman->change_field_default($table, $field);
401
 
402
        // Changing the default of field option_participants_video on table zoom to 0.
403
        $table = new xmldb_table('zoom');
404
        $field = new xmldb_field('option_participants_video', XMLDB_TYPE_INTEGER, '1', null, null, null, '0', 'option_host_video');
405
 
406
        // Launch change of default for field option_participants_video.
407
        $dbman->change_field_default($table, $field);
408
 
409
        // Zoom savepoint reached.
410
        upgrade_mod_savepoint(true, 2020051800, 'zoom');
411
    }
412
 
413
    if ($oldversion < 2020052100) {
414
        // Increase meeting_id since Zoom increased the size from 10 to 11.
415
 
416
        // First need to drop index.
417
        $table = new xmldb_table('zoom');
418
        $index = new xmldb_index('meeting_id_idx', XMLDB_INDEX_NOTUNIQUE, ['meeting_id']);
419
        if ($dbman->index_exists($table, $index)) {
420
            $dbman->drop_index($table, $index);
421
        }
422
 
423
        // Increase size to 15 for future proofing.
424
        $field = new xmldb_field('meeting_id', XMLDB_TYPE_INTEGER, '15', null, XMLDB_NOTNULL, null, null, 'grade');
425
        $dbman->change_field_precision($table, $field);
426
 
427
        // Add index back.
428
        $dbman->add_index($table, $index);
429
 
430
        // First need to drop key.
431
        $table = new xmldb_table('zoom_meeting_details');
432
        $key = new xmldb_key('meeting_unique', XMLDB_KEY_UNIQUE, ['meeting_id', 'uuid']);
433
        $dbman->drop_key($table, $key);
434
 
435
        // Increase size to 15 for future proofing.
436
        $field = new xmldb_field('meeting_id', XMLDB_TYPE_INTEGER, '15', null, XMLDB_NOTNULL, null, null, 'uuid');
437
        $dbman->change_field_precision($table, $field);
438
 
439
        // Add key back.
440
        $dbman->add_key($table, $key);
441
 
442
        // Zoom savepoint reached.
443
        upgrade_mod_savepoint(true, 2020052100, 'zoom');
444
    }
445
 
446
    if ($oldversion < 2020100800) {
447
        // Changing the default of field option_host_video on table zoom to 0.
448
        $table = new xmldb_table('zoom');
449
        $field = new xmldb_field('option_host_video', XMLDB_TYPE_INTEGER, '1', null, null, null, '0', 'option_start_type');
450
 
451
        // Launch change of default for field option_host_video.
452
        $dbman->change_field_default($table, $field);
453
 
454
        // Changing the default of field option_participants_video on table zoom to 0.
455
        $table = new xmldb_table('zoom');
456
        $field = new xmldb_field('option_participants_video', XMLDB_TYPE_INTEGER, '1', null, null, null, '0', 'option_host_video');
457
 
458
        // Launch change of default for field option_participants_video.
459
        $dbman->change_field_default($table, $field);
460
 
461
        // Changing the default of field option_mute_upon_entry on table zoom to 1.
462
        $table = new xmldb_table('zoom');
463
        $field = new xmldb_field('option_mute_upon_entry', XMLDB_TYPE_INTEGER, '1', null, null, null, '1', 'option_audio');
464
 
465
        // Launch change of default for field option_participants_video.
466
        $dbman->change_field_default($table, $field);
467
 
468
        // Zoom savepoint reached.
469
        upgrade_mod_savepoint(true, 2020100800, 'zoom');
470
    }
471
 
472
    if ($oldversion < 2020120800) {
473
        // Delete config no longer used.
474
        set_config('calls_left', null, 'mod_zoom');
475
        upgrade_mod_savepoint(true, 2020120800, 'zoom');
476
    }
477
 
478
    if ($oldversion < 2021012902) {
479
        // Define field option_encryption_type to be added to zoom.
480
        $table = new xmldb_table('zoom');
481
        $field = new xmldb_field(
482
            'option_encryption_type',
483
            XMLDB_TYPE_CHAR,
484
            '20',
485
            null,
486
            null,
487
            null,
488
            'enhanced_encryption',
489
            'option_authenticated_users'
490
        );
491
 
492
        // Conditionally launch add field option_encryption_type.
493
        if (!$dbman->field_exists($table, $field)) {
494
            $dbman->add_field($table, $field);
495
        }
496
 
497
        // Zoom savepoint reached.
498
        upgrade_mod_savepoint(true, 2021012902, 'zoom');
499
    }
500
 
501
    if ($oldversion < 2021012903) {
502
        // Quite all settings in settings.php had the 'mod_zoom' prefix while it should have had a 'zoom' prefix.
503
        // After the prefix has been modified in settings.php, the existing settings in DB have to be modified as well.
504
 
505
        // Get the existing settings with the old prefix from the DB,
506
        // but don't get the 'version' setting as this one has to have the 'mod_zoom' prefix.
507
        $oldsettingsql = 'SELECT name
508
                          FROM {config_plugins}
509
                          WHERE plugin = :plugin AND name != :name';
510
        $oldsettingparams = ['plugin' => 'mod_zoom', 'name' => 'version'];
511
        $oldsettingkeys = $DB->get_fieldset_sql($oldsettingsql, $oldsettingparams);
512
 
513
        // Change the prefix of each setting.
514
        foreach ($oldsettingkeys as $oldsettingkey) {
515
            // Get the value of the existing setting with the old prefix.
516
            $oldsettingvalue = get_config('mod_zoom', $oldsettingkey);
517
            // Set the value of the setting with the new prefix.
518
            set_config($oldsettingkey, $oldsettingvalue, 'zoom');
519
            // Drop the setting with the old prefix.
520
            set_config($oldsettingkey, null, 'mod_zoom');
521
        }
522
 
523
        // Zoom savepoint reached.
524
        upgrade_mod_savepoint(true, 2021012903, 'zoom');
525
    }
526
 
527
    if ($oldversion < 2021030300) {
528
        // Define index uuid (not unique) to be added to zoom_meeting_participants.
529
        $table = new xmldb_table('zoom_meeting_participants');
530
        $index = new xmldb_index('uuid', XMLDB_INDEX_NOTUNIQUE, ['uuid']);
531
 
532
        // Conditionally launch add index uuid.
533
        if (!$dbman->index_exists($table, $index)) {
534
            $dbman->add_index($table, $index);
535
        }
536
 
537
        // Zoom savepoint reached.
538
        upgrade_mod_savepoint(true, 2021030300, 'zoom');
539
    }
540
 
541
    if ($oldversion < 2021081900) {
542
        $table = new xmldb_table('zoom');
543
 
544
        // Define and conditionally add field recurrence_type.
545
        $field = new xmldb_field('recurrence_type', XMLDB_TYPE_INTEGER, '1', null, null, null, null, 'recurring');
546
        if (!$dbman->field_exists($table, $field)) {
547
            $dbman->add_field($table, $field);
548
        }
549
 
550
        // Define and conditionally add field repeat_interval.
551
        $field = new xmldb_field('repeat_interval', XMLDB_TYPE_INTEGER, '2', null, null, null, null, 'recurrence_type');
552
        if (!$dbman->field_exists($table, $field)) {
553
            $dbman->add_field($table, $field);
554
        }
555
 
556
        // Define and conditionally add field weekly_days.
557
        $field = new xmldb_field('weekly_days', XMLDB_TYPE_CHAR, '14', null, null, null, null, 'repeat_interval');
558
        if (!$dbman->field_exists($table, $field)) {
559
            $dbman->add_field($table, $field);
560
        }
561
 
562
        // Define and conditionally add field monthly_day.
563
        $field = new xmldb_field('monthly_day', XMLDB_TYPE_INTEGER, '2', null, null, null, null, 'weekly_days');
564
        if (!$dbman->field_exists($table, $field)) {
565
            $dbman->add_field($table, $field);
566
        }
567
 
568
        // Define and conditionally add field monthly_week.
569
        $field = new xmldb_field('monthly_week', XMLDB_TYPE_INTEGER, '2', null, null, null, null, 'monthly_day');
570
        if (!$dbman->field_exists($table, $field)) {
571
            $dbman->add_field($table, $field);
572
        }
573
 
574
        // Define and conditionally add field monthly_week_day.
575
        $field = new xmldb_field('monthly_week_day', XMLDB_TYPE_INTEGER, '1', null, null, null, null, 'monthly_week');
576
        if (!$dbman->field_exists($table, $field)) {
577
            $dbman->add_field($table, $field);
578
        }
579
 
580
        // Define and conditionally add field monthly_repeat_option.
581
        $field = new xmldb_field('monthly_repeat_option', XMLDB_TYPE_INTEGER, '1', null, null, null, null, 'monthly_week_day');
582
        if (!$dbman->field_exists($table, $field)) {
583
            $dbman->add_field($table, $field);
584
        }
585
 
586
        // Define and conditionally add field end_times.
587
        $field = new xmldb_field('end_times', XMLDB_TYPE_INTEGER, '1', null, null, null, null, 'monthly_week_day');
588
        if (!$dbman->field_exists($table, $field)) {
589
            $dbman->add_field($table, $field);
590
        }
591
 
592
        // Define and conditionally add field end_date_time.
593
        $field = new xmldb_field('end_date_time', XMLDB_TYPE_INTEGER, '12', null, null, null, null, 'end_times');
594
        if (!$dbman->field_exists($table, $field)) {
595
            $dbman->add_field($table, $field);
596
        }
597
 
598
        // Define and conditionally add field end_date_option.
599
        $field = new xmldb_field('end_date_option', XMLDB_TYPE_INTEGER, '1', null, null, null, null, 'end_date_time');
600
        if (!$dbman->field_exists($table, $field)) {
601
            $dbman->add_field($table, $field);
602
        }
603
 
604
        // For a time these defaults were not being updated but needed to be. This should catch them up.
605
 
606
        // Changing the default of field option_host_video on table zoom to 0.
607
        $table = new xmldb_table('zoom');
608
        $field = new xmldb_field('option_host_video', XMLDB_TYPE_INTEGER, '1', null, null, null, '0', 'option_start_type');
609
 
610
        // Launch change of default for field option_host_video.
611
        $dbman->change_field_default($table, $field);
612
 
613
        // Changing the default of field option_participants_video on table zoom to 0.
614
        $table = new xmldb_table('zoom');
615
        $field = new xmldb_field('option_participants_video', XMLDB_TYPE_INTEGER, '1', null, null, null, '0', 'option_host_video');
616
 
617
        // Launch change of default for field option_participants_video.
618
        $dbman->change_field_default($table, $field);
619
 
620
        // Changing the default of field option_mute_upon_entry on table zoom to 1.
621
        $table = new xmldb_table('zoom');
622
        $field = new xmldb_field('option_mute_upon_entry', XMLDB_TYPE_INTEGER, '1', null, null, null, '1', 'option_audio');
623
 
624
        // Launch change of default for field option_participants_video.
625
        $dbman->change_field_default($table, $field);
626
 
627
        // Zoom savepoint reached.
628
        upgrade_mod_savepoint(true, 2021081900, 'zoom');
629
    }
630
 
631
    if ($oldversion < 2021111100) {
632
        // Define table zoom_meeting_tracking_fields to be created.
633
        $table = new xmldb_table('zoom_meeting_tracking_fields');
634
 
635
        // Adding fields to table zoom_meeting_tracking_fields.
636
        $table->add_field('id', XMLDB_TYPE_INTEGER, '10', null, XMLDB_NOTNULL, XMLDB_SEQUENCE, null);
637
        $table->add_field('meeting_id', XMLDB_TYPE_INTEGER, '10', null, XMLDB_NOTNULL, null, null);
638
        $table->add_field('tracking_field', XMLDB_TYPE_CHAR, '255', null, XMLDB_NOTNULL, null, null);
639
        $table->add_field('value', XMLDB_TYPE_TEXT, null, null, null, null, null);
640
 
641
        // Adding keys to table zoom_meeting_tracking_fields.
642
        $table->add_key('id_primary', XMLDB_KEY_PRIMARY, ['id']);
643
 
644
        // Adding indexes to table zoom_meeting_tracking_fields.
645
        $table->add_index('meeting_id', XMLDB_INDEX_NOTUNIQUE, ['meeting_id']);
646
        $table->add_index('tracking_field', XMLDB_INDEX_NOTUNIQUE, ['tracking_field']);
647
 
648
        // Conditionally launch create table for zoom_meeting_tracking_fields.
649
        if (!$dbman->table_exists($table)) {
650
            $dbman->create_table($table);
651
        }
652
 
653
        // Zoom savepoint reached.
654
        upgrade_mod_savepoint(true, 2021111100, 'zoom');
655
    }
656
 
657
    if ($oldversion < 2021111800) {
658
        // Define table zoom_meeting_recordings to be created.
659
        $table = new xmldb_table('zoom_meeting_recordings');
660
 
661
        // Adding fields to table zoom_meeting_recordings.
662
        $table->add_field('id', XMLDB_TYPE_INTEGER, '10', null, XMLDB_NOTNULL, XMLDB_SEQUENCE, null);
663
        $table->add_field('zoomid', XMLDB_TYPE_INTEGER, '10', null, XMLDB_NOTNULL, null, null);
664
        $table->add_field('meetinguuid', XMLDB_TYPE_CHAR, '30', null, XMLDB_NOTNULL, null, null);
665
        $table->add_field('zoomrecordingid', XMLDB_TYPE_CHAR, '36', null, XMLDB_NOTNULL, null, null);
666
        $table->add_field('name', XMLDB_TYPE_CHAR, '300', null, XMLDB_NOTNULL, null, null);
667
        $table->add_field('externalurl', XMLDB_TYPE_TEXT, null, null, XMLDB_NOTNULL, null, null);
668
        $table->add_field('passcode', XMLDB_TYPE_CHAR, '30', null, null, null, null);
669
        $table->add_field('recordingtype', XMLDB_TYPE_CHAR, '30', null, XMLDB_NOTNULL, null, null);
670
        $table->add_field('recordingstart', XMLDB_TYPE_INTEGER, '12', null, XMLDB_NOTNULL, null, null);
671
        $table->add_field('showrecording', XMLDB_TYPE_INTEGER, '1', null, XMLDB_NOTNULL, null, '0');
672
        $table->add_field('timecreated', XMLDB_TYPE_INTEGER, '12', null, null, null, null);
673
        $table->add_field('timemodified', XMLDB_TYPE_INTEGER, '12', null, null, null, null);
674
 
675
        // Adding keys to table zoom_meeting_recordings.
676
        $table->add_key('id_primary', XMLDB_KEY_PRIMARY, ['id']);
677
        $table->add_key('zoomid_foreign', XMLDB_KEY_FOREIGN, ['zoomid'], 'zoom', ['id']);
678
 
679
        // Conditionally launch create table for zoom_meeting_recordings.
680
        if (!$dbman->table_exists($table)) {
681
            $dbman->create_table($table);
682
        }
683
 
684
        // Define table zoom_meeting_recordings_view to be created.
685
        $table = new xmldb_table('zoom_meeting_recordings_view');
686
 
687
        // Adding fields to table zoom_meeting_recordings_view.
688
        $table->add_field('id', XMLDB_TYPE_INTEGER, '10', null, XMLDB_NOTNULL, XMLDB_SEQUENCE, null);
689
        $table->add_field('recordingsid', XMLDB_TYPE_INTEGER, '10', null, XMLDB_NOTNULL, null, null);
690
        $table->add_field('userid', XMLDB_TYPE_INTEGER, '10', null, XMLDB_NOTNULL, null, null);
691
        $table->add_field('viewed', XMLDB_TYPE_INTEGER, '1', null, XMLDB_NOTNULL, null, '0');
692
        $table->add_field('timemodified', XMLDB_TYPE_INTEGER, '12', null, null, null, null);
693
 
694
        // Adding keys to table zoom_meeting_recordings_view.
695
        $table->add_key('id_primary', XMLDB_KEY_PRIMARY, ['id']);
696
        $table->add_key('recordingsid_foreign', XMLDB_KEY_FOREIGN, ['recordingsid'], 'zoom_meeting_recordings', ['id']);
697
 
698
        // Adding indexes to table zoom_meeting_recordings_view.
699
        $table->add_index('userid', XMLDB_INDEX_NOTUNIQUE, ['userid']);
700
 
701
        // Conditionally launch create table for zoom_meeting_recordings_view.
702
        if (!$dbman->table_exists($table)) {
703
            $dbman->create_table($table);
704
        }
705
 
706
        // Add new field for recordings_visible_default.
707
        $table = new xmldb_table('zoom');
708
        // Define field recordings_visible_default to be added to zoom.
709
        $field = new xmldb_field(
710
            'recordings_visible_default',
711
            XMLDB_TYPE_INTEGER,
712
            '1',
713
            null,
714
            XMLDB_NOTNULL,
715
            null,
716
            '1',
717
            'alternative_hosts'
718
        );
719
 
720
        // Conditionally launch add field recordings_visible_default.
721
        if (!$dbman->field_exists($table, $field)) {
722
            $dbman->add_field($table, $field);
723
        }
724
 
725
        // Zoom savepoint reached.
726
        upgrade_mod_savepoint(true, 2021111800, 'zoom');
727
    }
728
 
729
    if ($oldversion < 2021112900) {
730
        // Define table zoom_meeting_details to be created.
731
        $table = new xmldb_table('zoom_meeting_details');
732
        // Conditionally launch add key uuid_unique.
733
        if (!$table->getKey('uuid_unique')) {
734
            $key = new xmldb_key('uuid_unique', XMLDB_KEY_UNIQUE, ['uuid']);
735
            $dbman->add_key($table, $key);
736
        }
737
 
738
        // Launch drop key meeting_unique.
739
        $key = new xmldb_key('meeting_unique', XMLDB_KEY_UNIQUE, ['meeting_id', 'uuid']);
740
        $dbman->drop_key($table, $key);
741
 
742
        // Zoom savepoint reached.
743
        upgrade_mod_savepoint(true, 2021112900, 'zoom');
744
    }
745
 
746
    if ($oldversion < 2022022400) {
747
        // Change the recordings_visible_default field in the zoom table.
748
        $table = new xmldb_table('zoom');
749
        $field = new xmldb_field(
750
            'recordings_visible_default',
751
            XMLDB_TYPE_INTEGER,
752
            '1',
753
            null,
754
            XMLDB_NOTNULL,
755
            null,
756
            '1',
757
            'alternative_hosts'
758
        );
759
        $dbman->change_field_default($table, $field);
760
 
761
        // Change the showrecording field in the zoom table.
762
        $table = new xmldb_table('zoom_meeting_recordings');
763
        $field = new xmldb_field('showrecording', XMLDB_TYPE_INTEGER, '1', null, XMLDB_NOTNULL, null, '0');
764
        $dbman->change_field_default($table, $field);
765
 
766
        // Zoom savepoint reached.
767
        upgrade_mod_savepoint(true, 2022022400, 'zoom');
768
    }
769
 
770
    if ($oldversion < 2022031600) {
771
        $table = new xmldb_table('zoom');
772
 
773
        // Define and conditionally add field show_schedule.
774
        $field = new xmldb_field(
775
            'show_schedule',
776
            XMLDB_TYPE_INTEGER,
777
            '1',
778
            null,
779
            XMLDB_NOTNULL,
780
            null,
781
            '1',
782
            'recordings_visible_default'
783
        );
784
        if (!$dbman->field_exists($table, $field)) {
785
            $dbman->add_field($table, $field);
786
        }
787
 
788
        // Define and conditionally add field show_security.
789
        $field = new xmldb_field('show_security', XMLDB_TYPE_INTEGER, '1', null, XMLDB_NOTNULL, null, '1', 'show_schedule');
790
        if (!$dbman->field_exists($table, $field)) {
791
            $dbman->add_field($table, $field);
792
        }
793
 
794
        // Define and conditionally add field show_media.
795
        $field = new xmldb_field('show_media', XMLDB_TYPE_INTEGER, '1', null, XMLDB_NOTNULL, null, '1', 'show_security');
796
        if (!$dbman->field_exists($table, $field)) {
797
            $dbman->add_field($table, $field);
798
        }
799
 
800
        // Zoom savepoint reached.
801
        upgrade_mod_savepoint(true, 2022031600, 'zoom');
802
    }
803
 
804
    if ($oldversion < 2022071500) {
805
        // Define table zoom_meeting_breakout_rooms to be created.
806
        $table = new xmldb_table('zoom_meeting_breakout_rooms');
807
 
808
        // Adding fields to table zoom_meeting_breakout_rooms.
809
        $table->add_field('id', XMLDB_TYPE_INTEGER, '10', null, XMLDB_NOTNULL, XMLDB_SEQUENCE, null);
810
        $table->add_field('name', XMLDB_TYPE_CHAR, '32', null, null, null, null);
811
        $table->add_field('zoomid', XMLDB_TYPE_INTEGER, '10', null, XMLDB_NOTNULL, null, null);
812
 
813
        // Adding keys to table zoom_meeting_breakout_rooms.
814
        $table->add_key('primary', XMLDB_KEY_PRIMARY, ['id']);
815
        $table->add_key('fk_zoomid', XMLDB_KEY_FOREIGN, ['zoomid'], 'zoom', ['id']);
816
 
817
        // Conditionally launch create table for customfield_category.
818
        if (!$dbman->table_exists($table)) {
819
            $dbman->create_table($table);
820
        }
821
 
822
        // Define table zoom_rooms_participants to be created.
823
        $table = new xmldb_table('zoom_breakout_participants');
824
 
825
        // Adding fields to table zoom_rooms_participants.
826
        $table->add_field('id', XMLDB_TYPE_INTEGER, '10', null, XMLDB_NOTNULL, XMLDB_SEQUENCE, null);
827
        $table->add_field('userid', XMLDB_TYPE_INTEGER, '10', null, XMLDB_NOTNULL, null, null);
828
        $table->add_field('breakoutroomid', XMLDB_TYPE_INTEGER, '10', null, XMLDB_NOTNULL, null, null);
829
 
830
        // Adding keys to table zoom_rooms_participants.
831
        $table->add_key('primary', XMLDB_KEY_PRIMARY, ['id']);
832
        $table->add_key('fk_breakoutroomid', XMLDB_KEY_FOREIGN, ['breakoutroomid'], 'zoom_meeting_breakout_rooms', ['id']);
833
 
834
        // Conditionally launch create table for customfield_category.
835
        if (!$dbman->table_exists($table)) {
836
            $dbman->create_table($table);
837
        }
838
 
839
        // Define table zoom_rooms_groups to be created.
840
        $table = new xmldb_table('zoom_breakout_groups');
841
 
842
        // Adding fields to table zoom_rooms_groups.
843
        $table->add_field('id', XMLDB_TYPE_INTEGER, '10', null, XMLDB_NOTNULL, XMLDB_SEQUENCE, null);
844
        $table->add_field('groupid', XMLDB_TYPE_INTEGER, '10', null, XMLDB_NOTNULL, null, null);
845
        $table->add_field('breakoutroomid', XMLDB_TYPE_INTEGER, '10', null, XMLDB_NOTNULL, null, null);
846
 
847
        // Adding keys to table zoom_rooms_groups.
848
        $table->add_key('primary', XMLDB_KEY_PRIMARY, ['id']);
849
        $table->add_key('fk_breakoutroomid', XMLDB_KEY_FOREIGN, ['breakoutroomid'], 'zoom_meeting_breakout_rooms', ['id']);
850
 
851
        // Conditionally launch create table for customfield_category.
852
        if (!$dbman->table_exists($table)) {
853
            $dbman->create_table($table);
854
        }
855
 
856
        // Zoom savepoint reached.
857
        upgrade_mod_savepoint(true, 2022071500, 'zoom');
858
    }
859
 
860
    if ($oldversion < 2022082500) {
861
        $table = new xmldb_table('zoom');
862
 
863
        // Define and conditionally add field option_auto_recording.
864
        $field = new xmldb_field('option_auto_recording', XMLDB_TYPE_CHAR, '5', null, null, null, null, 'show_media');
865
        if (!$dbman->field_exists($table, $field)) {
866
            $dbman->add_field($table, $field);
867
        }
868
 
869
        // Zoom savepoint reached.
870
        upgrade_mod_savepoint(true, 2022082500, 'zoom');
871
    }
872
 
873
    if ($oldversion < 2022102700) {
874
        $table = new xmldb_table('zoom');
875
 
876
        // Define and conditionally add field registration.
877
        $field = new xmldb_field('registration', XMLDB_TYPE_INTEGER, '1', null, XMLDB_NOTNULL, null, '2', 'option_auto_recording');
878
        if (!$dbman->field_exists($table, $field)) {
879
            $dbman->add_field($table, $field);
880
        }
881
 
882
        // Zoom savepoint reached.
883
        upgrade_mod_savepoint(true, 2022102700, 'zoom');
884
    }
885
 
886
    if ($oldversion < 2023080202) {
887
        // Issue #432: Inconsistency between the DB and schema, this is to verify everything matches.
888
        // Verify show_schedule, show_security, and show_media are all set to NOTNULL.
889
        // Verify option_auto_record is set to NOTNULL and defaults to "none".
890
        $table = new xmldb_table('zoom');
891
 
892
        // Launch change of nullability for show schedule.
893
        $field = new xmldb_field(
894
            'show_schedule',
895
            XMLDB_TYPE_INTEGER,
896
            '1',
897
            null,
898
            XMLDB_NOTNULL,
899
            null,
900
            '1',
901
            'recordings_visible_default'
902
        );
903
        $dbman->change_field_notnull($table, $field);
904
 
905
        $field = new xmldb_field('show_security', XMLDB_TYPE_INTEGER, '1', null, XMLDB_NOTNULL, null, '1', 'show_schedule');
906
        $dbman->change_field_notnull($table, $field);
907
 
908
        $field = new xmldb_field('show_media', XMLDB_TYPE_INTEGER, '1', null, XMLDB_NOTNULL, null, '1', 'show_security');
909
        $dbman->change_field_notnull($table, $field);
910
 
911
        $field = new xmldb_field('option_auto_recording', XMLDB_TYPE_CHAR, '5', null, null, null, null, 'show_media');
912
        $dbman->change_field_type($table, $field);
913
 
914
        // Zoom savepoint reached.
915
        upgrade_mod_savepoint(true, 2023080202, 'zoom');
916
    }
917
 
918
    if ($oldversion < 2023111600) {
919
        // Issue #326: Drop start_url from database.
920
 
921
        // Start zoom table modifications.
922
        $table = new xmldb_table('zoom');
923
 
924
        // Define field status to be dropped from zoom.
925
        $field = new xmldb_field('start_url');
926
 
927
        // Conditionally launch drop field status.
928
        if ($dbman->field_exists($table, $field)) {
929
            $dbman->drop_field($table, $field);
930
        }
931
 
932
        // Zoom savepoint reached.
933
        upgrade_mod_savepoint(true, 2023111600, 'zoom');
934
    }
935
 
936
    if ($oldversion < 2024012500) {
937
        // Version 5.1.0 incorrectly upgraded the zoom table's registration field. It should not be null and should default to 2.
938
        $table = new xmldb_table('zoom');
939
        $field = new xmldb_field('registration', XMLDB_TYPE_INTEGER, '1', null, XMLDB_NOTNULL, null, '2', 'option_auto_recording');
940
 
941
        // Set any null values to the new default: 2.
942
        $DB->set_field_select('zoom', 'registration', '2', 'registration IS NULL');
943
 
944
        // Launch change of nullability for field registration.
945
        $dbman->change_field_notnull($table, $field);
946
 
947
        // Launch change of default for field registration.
948
        $dbman->change_field_default($table, $field);
949
 
950
        // Zoom savepoint reached.
951
        upgrade_mod_savepoint(true, 2024012500, 'zoom');
952
    }
953
 
954
    if ($oldversion < 2024030100) {
955
        // Define field grading_method to be added to zoom.
956
        $table = new xmldb_table('zoom');
957
        $field = new xmldb_field('grading_method', XMLDB_TYPE_CHAR, '10', null, null, null, null, 'grade');
958
 
959
        // Conditionally launch add field grading_method.
960
        if (!$dbman->field_exists($table, $field)) {
961
            $dbman->add_field($table, $field);
962
        }
963
 
964
        // Zoom savepoint reached.
965
        upgrade_mod_savepoint(true, 2024030100, 'zoom');
966
    }
967
 
968
    if ($oldversion < 2024041900) {
969
        // Update existing recording names to default for translatable recordingtype strings.
970
        $meetings = $DB->get_records('zoom');
971
 
972
        foreach ($meetings as $meeting) {
973
            $DB->set_field_select('zoom_meeting_recordings', 'name', $meeting->name, 'zoomid = ?', [$meeting->id]);
974
        }
975
 
976
        // Zoom savepoint reached.
977
        upgrade_mod_savepoint(true, 2024041900, 'zoom');
978
    }
979
 
980
    return true;
981
}