Proyectos de Subversion Moodle

Rev

Rev 11 | Mostrar el archivo completo | | | Autoría | Ultima modificación | Ver Log |

Rev 11 Rev 1441
Línea 97... Línea 97...
97
        exit(1);
97
        exit(1);
98
        // Note this savepoint is 100% unreachable, but needed to pass the upgrade checks.
98
        // Note this savepoint is 100% unreachable, but needed to pass the upgrade checks.
99
        upgrade_main_savepoint(true, 2022112802);
99
        upgrade_main_savepoint(true, 2022112802);
100
    }
100
    }
Línea 101... Línea -...
101
 
-
 
102
    // Automatically generated Moodle v4.1.0 release upgrade line.
-
 
103
    // Put any upgrade step following this.
-
 
104
 
-
 
105
    if ($oldversion < 2022120900.01) {
-
 
106
        // Remove any orphaned role assignment records (pointing to non-existing roles).
-
 
107
        $DB->delete_records_select('role_assignments', 'NOT EXISTS (
-
 
108
            SELECT r.id FROM {role} r WHERE r.id = {role_assignments}.roleid
-
 
109
        )');
-
 
110
 
-
 
111
        // Main savepoint reached.
-
 
112
        upgrade_main_savepoint(true, 2022120900.01);
-
 
113
    }
-
 
114
 
-
 
115
    if ($oldversion < 2022121600.01) {
-
 
116
        // Define index blocknameindex (not unique) to be added to block_instances.
-
 
117
        $table = new xmldb_table('block_instances');
-
 
118
        $index = new xmldb_index('blocknameindex', XMLDB_INDEX_NOTUNIQUE, ['blockname']);
-
 
119
 
-
 
120
        // Conditionally launch add index blocknameindex.
-
 
121
        if (!$dbman->index_exists($table, $index)) {
-
 
122
            $dbman->add_index($table, $index);
-
 
123
        }
-
 
124
        // Main savepoint reached.
-
 
125
        upgrade_main_savepoint(true, 2022121600.01);
-
 
126
    }
-
 
127
 
-
 
128
    if ($oldversion < 2023010300.00) {
-
 
129
        // The useexternalyui setting has been removed.
-
 
130
        unset_config('useexternalyui');
-
 
131
 
-
 
132
        // Main savepoint reached.
-
 
133
        upgrade_main_savepoint(true, 2023010300.00);
-
 
134
    }
-
 
135
 
-
 
136
    if ($oldversion < 2023020800.00) {
-
 
137
        // If cachestore_memcached is no longer present, remove it.
-
 
138
        if (!file_exists($CFG->dirroot . '/cache/stores/memcached/version.php')) {
-
 
139
            // Clean config.
-
 
140
            unset_all_config_for_plugin('cachestore_memcached');
-
 
141
        }
-
 
142
 
-
 
143
        // Main savepoint reached.
-
 
144
        upgrade_main_savepoint(true, 2023020800.00);
-
 
145
    }
-
 
146
 
-
 
147
    if ($oldversion < 2023021700.01) {
-
 
148
        // Define field pdfexportfont to be added to course.
-
 
149
        $table = new xmldb_table('course');
-
 
150
        $field = new xmldb_field('pdfexportfont', XMLDB_TYPE_CHAR, '50', null, false, false, null, 'showcompletionconditions');
-
 
151
 
-
 
152
        // Conditionally launch add field pdfexportfont.
-
 
153
        if (!$dbman->field_exists($table, $field)) {
-
 
154
            $dbman->add_field($table, $field);
-
 
155
        }
-
 
156
 
-
 
157
        // Main savepoint reached.
-
 
158
        upgrade_main_savepoint(true, 2023021700.01);
-
 
159
    }
-
 
160
 
-
 
161
    if ($oldversion < 2023022000.00) {
-
 
162
        // Remove grade_report_showquickfeedback, grade_report_enableajax, grade_report_showeyecons,
-
 
163
        // grade_report_showlocks, grade_report_showanalysisicon preferences for every user.
-
 
164
        $DB->delete_records('user_preferences', ['name' => 'grade_report_showquickfeedback']);
-
 
165
        $DB->delete_records('user_preferences', ['name' => 'grade_report_enableajax']);
-
 
166
        $DB->delete_records('user_preferences', ['name' => 'grade_report_showeyecons']);
-
 
167
        $DB->delete_records('user_preferences', ['name' => 'grade_report_showlocks']);
-
 
168
        $DB->delete_records('user_preferences', ['name' => 'grade_report_showanalysisicon']);
-
 
169
 
-
 
170
        // The grade_report_showquickfeedback, grade_report_enableajax, grade_report_showeyecons,
-
 
171
        // grade_report_showlocks, grade_report_showanalysisicon settings have been removed.
-
 
172
        unset_config('grade_report_showquickfeedback');
-
 
173
        unset_config('grade_report_enableajax');
-
 
174
        unset_config('grade_report_showeyecons');
-
 
175
        unset_config('grade_report_showlocks');
-
 
176
        unset_config('grade_report_showanalysisicon');
-
 
177
 
-
 
178
        // Main savepoint reached.
-
 
179
        upgrade_main_savepoint(true, 2023022000.00);
-
 
180
    }
-
 
181
 
-
 
182
    if ($oldversion < 2023030300.01) {
-
 
183
        $sql = "SELECT preset.*
-
 
184
                  FROM {adminpresets} preset
-
 
185
            INNER JOIN {adminpresets_it} it ON preset.id = it.adminpresetid
-
 
186
                 WHERE it.name = :name AND it.value = :value AND preset.iscore > 0";
-
 
187
        // Some settings and plugins have been added/removed to the Starter and Full preset. Add them to the core presets if
-
 
188
        // they haven't been included yet.
-
 
189
        $params = ['name' => get_string('starterpreset', 'core_adminpresets'), 'iscore' => 1];
-
 
190
        $starterpreset = $DB->get_record('adminpresets', $params);
-
 
191
        if (!$starterpreset) {
-
 
192
            // Starter admin preset might have been created using the English name.
-
 
193
            $name = get_string_manager()->get_string('starterpreset', 'core_adminpresets', null, 'en');
-
 
194
            $params['name'] = $name;
-
 
195
            $starterpreset = $DB->get_record('adminpresets', $params);
-
 
196
        }
-
 
197
        if (!$starterpreset) {
-
 
198
            // We tried, but we didn't find starter by name. Let's find a core preset that sets 'usecomments' setting to 0.
-
 
199
            $params = ['name' => 'usecomments', 'value' => '0'];
-
 
200
            $starterpreset = $DB->get_record_sql($sql, $params);
-
 
201
        }
-
 
202
 
-
 
203
        $params = ['name' => get_string('fullpreset', 'core_adminpresets')];
-
 
204
        $fullpreset = $DB->get_record_select('adminpresets', 'name = :name and iscore > 0', $params);
-
 
205
        if (!$fullpreset) {
-
 
206
            // Full admin preset might have been created using the English name.
-
 
207
            $name = get_string_manager()->get_string('fullpreset', 'core_adminpresets', null, 'en');
-
 
208
            $params['name'] = $name;
-
 
209
            $fullpreset = $DB->get_record_select('adminpresets', 'name = :name and iscore > 0', $params);
-
 
210
        }
-
 
211
        if (!$fullpreset) {
-
 
212
            // We tried, but we didn't find full by name. Let's find a core preset that sets 'usecomments' setting to 1.
-
 
213
            $params = ['name' => 'usecomments', 'value' => '1'];
-
 
214
            $fullpreset = $DB->get_record_sql($sql, $params);
-
 
215
        }
-
 
216
 
-
 
217
        $settings = [
-
 
218
            // Settings. Set Activity chooser tabs to "Starred, Recommended, All"(5) for Starter and back it to default(3) for Full.
-
 
219
            [
-
 
220
                'presetid' => $starterpreset->id,
-
 
221
                'plugin' => 'none',
-
 
222
                'name' => 'activitychoosertabmode',
-
 
223
                'value' => '4',
-
 
224
            ],
-
 
225
            [
-
 
226
                'presetid' => $fullpreset->id,
-
 
227
                'plugin' => 'none',
-
 
228
                'name' => 'activitychoosertabmode',
-
 
229
                'value' => '3',
-
 
230
            ],
-
 
231
        ];
-
 
232
        foreach ($settings as $notused => $setting) {
-
 
233
            $params = ['adminpresetid' => $setting['presetid'], 'plugin' => $setting['plugin'], 'name' => $setting['name']];
-
 
234
            if (!$record = $DB->get_record('adminpresets_it', $params)) {
-
 
235
                $record = new \stdClass();
-
 
236
                $record->adminpresetid = $setting['presetid'];
-
 
237
                $record->plugin = $setting['plugin'];
-
 
238
                $record->name = $setting['name'];
-
 
239
                $record->value = $setting['value'];
-
 
240
                $DB->insert_record('adminpresets_it', $record);
-
 
241
            } else {
-
 
242
                $record->value = $setting['value'];
-
 
243
                $DB->update_record('adminpresets_it', $record);
-
 
244
            }
-
 
245
        }
-
 
246
 
-
 
247
        // Main savepoint reached.
-
 
248
        upgrade_main_savepoint(true, 2023030300.01);
-
 
249
    }
-
 
250
 
-
 
251
    if ($oldversion < 2023030300.02) {
-
 
252
        // If cachestore_mongodb is no longer present, remove it.
-
 
253
        if (!file_exists($CFG->dirroot . '/cache/stores/mongodb/version.php')) {
-
 
254
            // Clean config.
-
 
255
            unset_all_config_for_plugin('cachestore_mongodb');
-
 
256
        }
-
 
257
 
-
 
258
        // Main savepoint reached.
-
 
259
        upgrade_main_savepoint(true, 2023030300.02);
-
 
260
    }
-
 
261
 
-
 
262
    if ($oldversion < 2023030300.03) {
-
 
263
        // If editor_tinymce is no longer present, remove it.
-
 
264
        if (!file_exists($CFG->dirroot . '/lib/editor/tinymce/version.php')) {
-
 
265
            // Clean config.
-
 
266
            uninstall_plugin('editor', 'tinymce');
-
 
267
            $DB->delete_records('user_preferences', [
-
 
268
                'name' => 'htmleditor',
-
 
269
                'value' => 'tinymce',
-
 
270
            ]);
-
 
271
 
-
 
272
            if ($editors = get_config('core', 'texteditors')) {
-
 
273
                $editors = array_flip(explode(',', $editors));
-
 
274
                unset($editors['tinymce']);
-
 
275
                set_config('texteditors', implode(',', array_flip($editors)));
-
 
276
            }
-
 
277
        }
-
 
278
        upgrade_main_savepoint(true, 2023030300.03);
-
 
279
    }
-
 
280
 
-
 
281
    if ($oldversion < 2023031000.02) {
-
 
282
        // If editor_tinymce is no longer present, remove it's sub-plugins too.
-
 
283
        if (!file_exists($CFG->dirroot . '/lib/editor/tinymce/version.php')) {
-
 
284
            $DB->delete_records_select(
-
 
285
                'config_plugins',
-
 
286
                $DB->sql_like('plugin', ':plugin'),
-
 
287
                ['plugin' => $DB->sql_like_escape('tinymce_') . '%']
-
 
288
            );
-
 
289
        }
-
 
290
 
-
 
291
        // Main savepoint reached.
-
 
292
        upgrade_main_savepoint(true, 2023031000.02);
-
 
293
    }
-
 
294
 
-
 
295
    if ($oldversion < 2023031400.01) {
-
 
296
        // Define field id to be added to groups.
-
 
297
        $table = new xmldb_table('groups');
-
 
298
        $field = new xmldb_field('visibility', XMLDB_TYPE_INTEGER, '1', null, XMLDB_NOTNULL, null, '0', 'picture');
-
 
299
 
-
 
300
        // Conditionally launch add field visibility.
-
 
301
        if (!$dbman->field_exists($table, $field)) {
-
 
302
            $dbman->add_field($table, $field);
-
 
303
        }
-
 
304
 
-
 
305
        // Define field participation to be added to groups.
-
 
306
        $field = new xmldb_field('participation', XMLDB_TYPE_INTEGER, '1', null, XMLDB_NOTNULL, null, '1', 'visibility');
-
 
307
 
-
 
308
        // Conditionally launch add field participation.
-
 
309
        if (!$dbman->field_exists($table, $field)) {
-
 
310
            $dbman->add_field($table, $field);
-
 
311
        }
-
 
312
 
-
 
313
        // Main savepoint reached.
-
 
314
        upgrade_main_savepoint(true, 2023031400.01);
-
 
315
    }
-
 
316
 
-
 
317
    if ($oldversion < 2023031400.02) {
-
 
318
        // Define table xapi_states to be created.
-
 
319
        $table = new xmldb_table('xapi_states');
-
 
320
 
-
 
321
        // Adding fields to table xapi_states.
-
 
322
        $table->add_field('id', XMLDB_TYPE_INTEGER, '10', null, XMLDB_NOTNULL, XMLDB_SEQUENCE, null);
-
 
323
        $table->add_field('component', XMLDB_TYPE_CHAR, '255', null, XMLDB_NOTNULL, null, null);
-
 
324
        $table->add_field('userid', XMLDB_TYPE_INTEGER, '10', null, null, null, null);
-
 
325
        $table->add_field('itemid', XMLDB_TYPE_INTEGER, '10', null, XMLDB_NOTNULL, null, null);
-
 
326
        $table->add_field('stateid', XMLDB_TYPE_CHAR, '255', null, XMLDB_NOTNULL, null, null);
-
 
327
        $table->add_field('statedata', XMLDB_TYPE_TEXT, null, null, null, null, null);
-
 
328
        $table->add_field('registration', XMLDB_TYPE_CHAR, '255', null, null, null, null);
-
 
329
        $table->add_field('timecreated', XMLDB_TYPE_INTEGER, '10', null, XMLDB_NOTNULL, null, null);
-
 
330
        $table->add_field('timemodified', XMLDB_TYPE_INTEGER, '10', null, null, null, null);
-
 
331
 
-
 
332
        // Adding keys to table xapi_states.
-
 
333
        $table->add_key('primary', XMLDB_KEY_PRIMARY, ['id']);
-
 
334
 
-
 
335
        // Adding indexes to table xapi_states.
-
 
336
        $table->add_index('component-itemid', XMLDB_INDEX_NOTUNIQUE, ['component', 'itemid']);
-
 
337
        $table->add_index('userid', XMLDB_INDEX_NOTUNIQUE, ['userid']);
-
 
338
        $table->add_index('timemodified', XMLDB_INDEX_NOTUNIQUE, ['timemodified']);
-
 
339
 
-
 
340
        // Conditionally launch create table for xapi_states.
-
 
341
        if (!$dbman->table_exists($table)) {
-
 
342
            $dbman->create_table($table);
-
 
343
        }
-
 
344
 
-
 
345
        if (!isset($CFG->xapicleanupperiod)) {
-
 
346
            set_config('xapicleanupperiod', WEEKSECS * 8);
-
 
347
        }
-
 
348
 
-
 
349
        // Main savepoint reached.
-
 
350
        upgrade_main_savepoint(true, 2023031400.02);
-
 
351
    }
-
 
352
 
-
 
353
    if ($oldversion < 2023040600.01) {
-
 
354
        // If logstore_legacy is no longer present, remove it.
-
 
355
        if (!file_exists($CFG->dirroot . '/admin/tool/log/store/legacy/version.php')) {
-
 
356
            uninstall_plugin('logstore', 'legacy');
-
 
357
        }
-
 
358
 
-
 
359
        // Main savepoint reached.
-
 
360
        upgrade_main_savepoint(true, 2023040600.01);
-
 
361
    }
-
 
362
 
-
 
363
    if ($oldversion < 2023041100.00) {
-
 
364
        // Add public key field to user_devices table.
-
 
365
        $table = new xmldb_table('user_devices');
-
 
366
        $field = new xmldb_field('publickey', XMLDB_TYPE_TEXT, null, null, null, null, null, 'uuid');
-
 
367
 
-
 
368
        if (!$dbman->field_exists($table, $field)) {
-
 
369
            $dbman->add_field($table, $field);
-
 
370
        }
-
 
371
 
-
 
372
        // Main savepoint reached.
-
 
373
        upgrade_main_savepoint(true, 2023041100.00);
-
 
374
    }
-
 
375
 
-
 
376
    if ($oldversion < 2023042000.00) {
-
 
377
        // If mod_assignment is no longer present, remove it.
-
 
378
        if (!file_exists($CFG->dirroot . '/mod/assignment/version.php')) {
-
 
379
            // Delete all mod_assignment grade_grades orphaned data.
-
 
380
            $DB->delete_records_select(
-
 
381
                'grade_grades',
-
 
382
                "itemid IN (SELECT id FROM {grade_items} WHERE itemtype = 'mod' AND itemmodule = 'assignment')"
-
 
383
            );
-
 
384
 
-
 
385
            // Delete all mod_assignment grade_grades_history orphaned data.
-
 
386
            $DB->delete_records('grade_grades_history', ['source' => 'mod/assignment']);
-
 
387
 
-
 
388
            // Delete all mod_assignment grade_items orphaned data.
-
 
389
            $DB->delete_records('grade_items', ['itemtype' => 'mod', 'itemmodule' => 'assignment']);
-
 
390
 
-
 
391
            // Delete all mod_assignment grade_items_history orphaned data.
-
 
392
            $DB->delete_records('grade_items_history', ['itemtype' => 'mod', 'itemmodule' => 'assignment']);
-
 
393
 
-
 
394
            // Delete core mod_assignment subplugins.
-
 
395
            uninstall_plugin('assignment', 'offline');
-
 
396
            uninstall_plugin('assignment', 'online');
-
 
397
            uninstall_plugin('assignment', 'upload');
-
 
398
            uninstall_plugin('assignment', 'uploadsingle');
-
 
399
 
-
 
400
            // Delete other mod_assignment subplugins.
-
 
401
            $pluginnamelike = $DB->sql_like('plugin', ':pluginname');
-
 
402
            $subplugins = $DB->get_fieldset_select('config_plugins', 'plugin', "$pluginnamelike AND name = :name", [
-
 
403
                'pluginname' => $DB->sql_like_escape('assignment_') . '%',
-
 
404
                'name' => 'version',
-
 
405
            ]);
-
 
406
            foreach ($subplugins as $subplugin) {
-
 
407
                [$plugin, $subpluginname] = explode('_', $subplugin, 2);
-
 
408
                uninstall_plugin($plugin, $subpluginname);
-
 
409
            }
-
 
410
 
-
 
411
            // Delete mod_assignment.
-
 
412
            uninstall_plugin('mod', 'assignment');
-
 
413
        }
-
 
414
 
-
 
415
        // Main savepoint reached.
-
 
416
        upgrade_main_savepoint(true, 2023042000.00);
-
 
417
    }
-
 
418
 
101
 
419
    // Automatically generated Moodle v4.2.0 release upgrade line.
102
    // Automatically generated Moodle v4.2.0 release upgrade line.
Línea 420... Línea 103...
420
    // Put any upgrade step following this.
103
    // Put any upgrade step following this.
421
 
104
 
Línea 1168... Línea 851...
1168
    }
851
    }
Línea 1169... Línea 852...
1169
 
852
 
1170
    // Automatically generated Moodle v4.4.0 release upgrade line.
853
    // Automatically generated Moodle v4.4.0 release upgrade line.
Línea -... Línea 854...
-
 
854
    // Put any upgrade step following this.
-
 
855
 
-
 
856
    if ($oldversion < 2024070500.01) {
-
 
857
        // Remove the site_contactable config of the hub plugin from config plugin table.
-
 
858
        unset_config('site_contactable', 'hub');
-
 
859
 
-
 
860
        // Main savepoint reached.
-
 
861
        upgrade_main_savepoint(true, 2024070500.01);
-
 
862
    }
-
 
863
 
-
 
864
    if ($oldversion < 2024071900.01) {
-
 
865
        // Define table stored_progress to be created.
-
 
866
        $table = new xmldb_table('stored_progress');
-
 
867
 
-
 
868
        // Adding fields to table stored_progress.
-
 
869
        $table->add_field('id', XMLDB_TYPE_INTEGER, '10', null, XMLDB_NOTNULL, XMLDB_SEQUENCE, null);
-
 
870
        $table->add_field('idnumber', XMLDB_TYPE_CHAR, '255', null, XMLDB_NOTNULL, null, null);
-
 
871
        $table->add_field('timestart', XMLDB_TYPE_INTEGER, '20', null, null, null, null);
-
 
872
        $table->add_field('lastupdate', XMLDB_TYPE_INTEGER, '20', null, null, null, null);
-
 
873
        $table->add_field('percentcompleted', XMLDB_TYPE_NUMBER, '5, 2', null, null, null, '0');
-
 
874
        $table->add_field('message', XMLDB_TYPE_CHAR, '255', null, null, null, null);
-
 
875
        $table->add_field('haserrored', XMLDB_TYPE_INTEGER, '1', null, XMLDB_NOTNULL, null, '0');
-
 
876
 
-
 
877
        // Adding keys to table stored_progress.
-
 
878
        $table->add_key('primary', XMLDB_KEY_PRIMARY, ['id']);
-
 
879
 
-
 
880
        // Adding indexes to table stored_progress.
-
 
881
        $table->add_index('uid_index', XMLDB_INDEX_NOTUNIQUE, ['idnumber']);
-
 
882
 
-
 
883
        // Conditionally launch create table for stored_progress.
-
 
884
        if (!$dbman->table_exists($table)) {
-
 
885
            $dbman->create_table($table);
-
 
886
        }
-
 
887
 
-
 
888
        // Main savepoint reached.
-
 
889
        upgrade_main_savepoint(true, 2024071900.01);
1171
    // Put any upgrade step following this.
890
    }
-
 
891
 
-
 
892
    if ($oldversion < 2024072600.01) {
-
 
893
        // If tool_innodb is no longer present, remove it.
-
 
894
        if (!file_exists($CFG->dirroot . '/admin/tool/innodb/version.php')) {
-
 
895
            // Delete tool_innodb.
-
 
896
            uninstall_plugin('tool', 'innodb');
-
 
897
        }
-
 
898
 
-
 
899
        // Main savepoint reached.
-
 
900
        upgrade_main_savepoint(true, 2024072600.01);
-
 
901
    }
Línea 1172... Línea 902...
1172
 
902
 
1173
    if ($oldversion < 2024042201.09) {
903
    if ($oldversion < 2024080500.00) {
1174
 
904
 
1175
        // Fix missing default admin presets "sensible settings" (those that should be treated as sensitive).
905
        // Fix missing default admin presets "sensible settings" (those that should be treated as sensitive).
Línea 1188... Línea 918...
1188
        }
918
        }
Línea 1189... Línea 919...
1189
 
919
 
Línea 1190... Línea 920...
1190
        set_config('sensiblesettings', $sensiblesettings, 'adminpresets');
920
        set_config('sensiblesettings', $sensiblesettings, 'adminpresets');
-
 
921
 
-
 
922
        // Main savepoint reached.
-
 
923
        upgrade_main_savepoint(true, 2024080500.00);
-
 
924
    }
-
 
925
 
-
 
926
    if ($oldversion < 2024082900.01) {
-
 
927
        // If filter_tidy is no longer present, remove it.
-
 
928
        if (!file_exists($CFG->dirroot . '/filter/tidy/version.php')) {
-
 
929
            // Clean config.
-
 
930
            uninstall_plugin('filter', 'tidy');
-
 
931
        }
-
 
932
 
-
 
933
        upgrade_main_savepoint(true, 2024082900.01);
-
 
934
    }
-
 
935
 
-
 
936
    if ($oldversion < 2024091000.01) {
-
 
937
        // Define table ai_policy_register to be created.
-
 
938
        $table = new xmldb_table('ai_policy_register');
-
 
939
 
-
 
940
        // Adding fields to table ai_policy_register.
-
 
941
        $table->add_field('id', XMLDB_TYPE_INTEGER, '10', null, XMLDB_NOTNULL, XMLDB_SEQUENCE, null);
-
 
942
        $table->add_field('userid', XMLDB_TYPE_INTEGER, '10', null, XMLDB_NOTNULL, null, null);
-
 
943
        $table->add_field('contextid', XMLDB_TYPE_INTEGER, '10', null, XMLDB_NOTNULL, null, null);
-
 
944
        $table->add_field('timeaccepted', XMLDB_TYPE_INTEGER, '10', null, XMLDB_NOTNULL, null, null);
-
 
945
 
-
 
946
        // Adding keys to table ai_policy_register.
-
 
947
        $table->add_key('primary', XMLDB_KEY_PRIMARY, ['id']);
-
 
948
        $table->add_key('userid', XMLDB_KEY_FOREIGN_UNIQUE, ['userid'], 'user', ['id']);
-
 
949
 
-
 
950
        // Conditionally launch create table for ai_policy_register.
-
 
951
        if (!$dbman->table_exists($table)) {
-
 
952
            $dbman->create_table($table);
-
 
953
        }
-
 
954
 
-
 
955
        // Define table ai_action_generate_image to be created.
-
 
956
        $table = new xmldb_table('ai_action_generate_image');
-
 
957
 
-
 
958
        // Adding fields to table ai_action_generate_image.
-
 
959
        $table->add_field('id', XMLDB_TYPE_INTEGER, '10', null, XMLDB_NOTNULL, XMLDB_SEQUENCE, null);
-
 
960
        $table->add_field('prompt', XMLDB_TYPE_TEXT, null, null, null, null, null);
-
 
961
        $table->add_field('numberimages', XMLDB_TYPE_INTEGER, '10', null, XMLDB_NOTNULL, null, null);
-
 
962
        $table->add_field('quality', XMLDB_TYPE_CHAR, '21', null, XMLDB_NOTNULL, null, null);
-
 
963
        $table->add_field('aspectratio', XMLDB_TYPE_CHAR, '20', null, null, null, null);
-
 
964
        $table->add_field('style', XMLDB_TYPE_CHAR, '20', null, null, null, null);
-
 
965
        $table->add_field('sourceurl', XMLDB_TYPE_TEXT, null, null, null, null, null);
-
 
966
        $table->add_field('revisedprompt', XMLDB_TYPE_TEXT, null, null, null, null, null);
-
 
967
 
-
 
968
        // Adding keys to table ai_action_generate_image.
-
 
969
        $table->add_key('primary', XMLDB_KEY_PRIMARY, ['id']);
-
 
970
 
-
 
971
        // Conditionally launch create table for ai_action_generate_image.
-
 
972
        if (!$dbman->table_exists($table)) {
-
 
973
            $dbman->create_table($table);
-
 
974
        }
-
 
975
 
-
 
976
        // Define table ai_action_register to be created.
-
 
977
        $table = new xmldb_table('ai_action_register');
-
 
978
 
-
 
979
        // Adding fields to table ai_action_register.
-
 
980
        $table->add_field('id', XMLDB_TYPE_INTEGER, '10', null, XMLDB_NOTNULL, XMLDB_SEQUENCE, null);
-
 
981
        $table->add_field('actionname', XMLDB_TYPE_CHAR, '100', null, XMLDB_NOTNULL, null, null);
-
 
982
        $table->add_field('actionid', XMLDB_TYPE_INTEGER, '10', null, XMLDB_NOTNULL, null, null);
-
 
983
        $table->add_field('success', XMLDB_TYPE_INTEGER, '1', null, XMLDB_NOTNULL, null, '0');
-
 
984
        $table->add_field('userid', XMLDB_TYPE_INTEGER, '10', null, XMLDB_NOTNULL, null, null);
-
 
985
        $table->add_field('contextid', XMLDB_TYPE_INTEGER, '10', null, XMLDB_NOTNULL, null, null);
-
 
986
        $table->add_field('provider', XMLDB_TYPE_CHAR, '100', null, XMLDB_NOTNULL, null, null);
-
 
987
        $table->add_field('errorcode', XMLDB_TYPE_INTEGER, '4', null, null, null, null);
-
 
988
        $table->add_field('errormessage', XMLDB_TYPE_TEXT, null, null, null, null, null);
-
 
989
        $table->add_field('timecreated', XMLDB_TYPE_INTEGER, '10', null, XMLDB_NOTNULL, null, null);
-
 
990
        $table->add_field('timecompleted', XMLDB_TYPE_INTEGER, '10', null, null, null, null);
-
 
991
 
-
 
992
        // Adding keys to table ai_action_register.
-
 
993
        $table->add_key('primary', XMLDB_KEY_PRIMARY, ['id']);
-
 
994
        $table->add_key('userid', XMLDB_KEY_FOREIGN, ['userid'], 'user', ['id']);
-
 
995
 
-
 
996
        // Adding indexes to table ai_action_register.
-
 
997
        $table->add_index('action', XMLDB_INDEX_UNIQUE, ['actionname', 'actionid']);
-
 
998
        $table->add_index('provider', XMLDB_INDEX_NOTUNIQUE, ['actionname', 'provider']);
-
 
999
 
-
 
1000
        // Conditionally launch create table for ai_action_register.
-
 
1001
        if (!$dbman->table_exists($table)) {
-
 
1002
            $dbman->create_table($table);
-
 
1003
        }
-
 
1004
 
-
 
1005
        // Define table ai_action_generate_text to be created.
-
 
1006
        $table = new xmldb_table('ai_action_generate_text');
-
 
1007
 
-
 
1008
        // Adding fields to table ai_action_generate_text.
-
 
1009
        $table->add_field('id', XMLDB_TYPE_INTEGER, '10', null, XMLDB_NOTNULL, XMLDB_SEQUENCE, null);
-
 
1010
        $table->add_field('prompt', XMLDB_TYPE_TEXT, null, null, null, null, null);
-
 
1011
        $table->add_field('responseid', XMLDB_TYPE_CHAR, '128', null, null, null, null);
-
 
1012
        $table->add_field('fingerprint', XMLDB_TYPE_CHAR, '128', null, null, null, null);
-
 
1013
        $table->add_field('generatedcontent', XMLDB_TYPE_TEXT, null, null, null, null, null);
-
 
1014
        $table->add_field('finishreason', XMLDB_TYPE_CHAR, '128', null, null, null, null);
-
 
1015
        $table->add_field('prompttokens', XMLDB_TYPE_INTEGER, '10', null, null, null, null);
-
 
1016
        $table->add_field('completiontoken', XMLDB_TYPE_INTEGER, '10', null, null, null, null);
-
 
1017
 
-
 
1018
        // Adding keys to table ai_action_generate_text.
-
 
1019
        $table->add_key('primary', XMLDB_KEY_PRIMARY, ['id']);
-
 
1020
 
-
 
1021
        // Conditionally launch create table for ai_action_generate_text.
-
 
1022
        if (!$dbman->table_exists($table)) {
-
 
1023
            $dbman->create_table($table);
-
 
1024
        }
-
 
1025
 
-
 
1026
        // Define table ai_action_summarise_text to be created.
-
 
1027
        $table = new xmldb_table('ai_action_summarise_text');
-
 
1028
 
-
 
1029
        // Adding fields to table ai_action_summarise_text.
-
 
1030
        $table->add_field('id', XMLDB_TYPE_INTEGER, '10', null, XMLDB_NOTNULL, XMLDB_SEQUENCE, null);
-
 
1031
        $table->add_field('prompt', XMLDB_TYPE_TEXT, null, null, null, null, null);
-
 
1032
        $table->add_field('responseid', XMLDB_TYPE_CHAR, '128', null, null, null, null);
-
 
1033
        $table->add_field('fingerprint', XMLDB_TYPE_CHAR, '128', null, null, null, null);
-
 
1034
        $table->add_field('generatedcontent', XMLDB_TYPE_TEXT, null, null, null, null, null);
-
 
1035
        $table->add_field('finishreason', XMLDB_TYPE_CHAR, '128', null, null, null, null);
-
 
1036
        $table->add_field('prompttokens', XMLDB_TYPE_INTEGER, '10', null, null, null, null);
-
 
1037
        $table->add_field('completiontoken', XMLDB_TYPE_INTEGER, '10', null, null, null, null);
-
 
1038
 
-
 
1039
        // Adding keys to table ai_action_summarise_text.
-
 
1040
        $table->add_key('primary', XMLDB_KEY_PRIMARY, ['id']);
-
 
1041
 
-
 
1042
        // Conditionally launch create table for ai_action_summarise_text.
-
 
1043
        if (!$dbman->table_exists($table)) {
-
 
1044
            $dbman->create_table($table);
-
 
1045
        }
-
 
1046
 
-
 
1047
        // Main savepoint reached.
-
 
1048
        upgrade_main_savepoint(true, 2024091000.01);
-
 
1049
    }
-
 
1050
 
-
 
1051
    if ($oldversion < 2024091700.01) {
-
 
1052
        // Convert the ai_action_register.success column to an integer, if necessary.
-
 
1053
        upgrade_change_binary_column_to_int('ai_action_register', 'success', XMLDB_NOTNULL, 'actionid');
-
 
1054
 
-
 
1055
        // Main savepoint reached.
-
 
1056
        upgrade_main_savepoint(true, 2024091700.01);
-
 
1057
    }
-
 
1058
 
-
 
1059
    if ($oldversion < 2024092000.01) {
-
 
1060
 
-
 
1061
        // Define table sms_messages to be created.
-
 
1062
        $table = new xmldb_table('sms_messages');
-
 
1063
 
-
 
1064
        // Adding fields to table sms_messages.
-
 
1065
        $table->add_field('id', XMLDB_TYPE_INTEGER, '10', null, XMLDB_NOTNULL, XMLDB_SEQUENCE, null);
-
 
1066
        $table->add_field('recipientnumber', XMLDB_TYPE_CHAR, '30', null, XMLDB_NOTNULL, null, null);
-
 
1067
        $table->add_field('content', XMLDB_TYPE_TEXT, null, null, null, null, null);
-
 
1068
        $table->add_field('component', XMLDB_TYPE_CHAR, '100', null, XMLDB_NOTNULL, null, null);
-
 
1069
        $table->add_field('messagetype', XMLDB_TYPE_CHAR, '100', null, XMLDB_NOTNULL, null, null);
-
 
1070
        $table->add_field('recipientuserid', XMLDB_TYPE_INTEGER, '10', null, null, null, null);
-
 
1071
        $table->add_field('issensitive', XMLDB_TYPE_INTEGER, '2', null, XMLDB_NOTNULL, null, '0');
-
 
1072
        $table->add_field('gatewayid', XMLDB_TYPE_INTEGER, '10', null, null, null, null);
-
 
1073
        $table->add_field('status', XMLDB_TYPE_CHAR, '100', null, null, null, null);
-
 
1074
        $table->add_field('timecreated', XMLDB_TYPE_INTEGER, '10', null, XMLDB_NOTNULL, null, null);
-
 
1075
 
-
 
1076
        // Adding keys to table sms_messages.
-
 
1077
        $table->add_key('primary', XMLDB_KEY_PRIMARY, ['id']);
-
 
1078
        $table->add_key('gateway', XMLDB_KEY_FOREIGN, ['gatewayid'], 'sms_gateways', ['id']);
-
 
1079
 
-
 
1080
        // Conditionally launch create table for sms_messages.
-
 
1081
        if (!$dbman->table_exists($table)) {
-
 
1082
            $dbman->create_table($table);
-
 
1083
        }
-
 
1084
 
-
 
1085
        // Define table sms_gateways to be created.
-
 
1086
        $table = new xmldb_table('sms_gateways');
-
 
1087
 
-
 
1088
        // Adding fields to table sms_gateways.
-
 
1089
        $table->add_field('id', XMLDB_TYPE_INTEGER, '10', null, XMLDB_NOTNULL, XMLDB_SEQUENCE, null);
-
 
1090
        $table->add_field('name', XMLDB_TYPE_CHAR, '255', null, XMLDB_NOTNULL, null, null);
-
 
1091
        $table->add_field('gateway', XMLDB_TYPE_CHAR, '255', null, XMLDB_NOTNULL, null, null);
-
 
1092
        $table->add_field('enabled', XMLDB_TYPE_INTEGER, '2', null, XMLDB_NOTNULL, null, '1');
-
 
1093
        $table->add_field('config', XMLDB_TYPE_TEXT, null, null, XMLDB_NOTNULL, null, null);
-
 
1094
 
-
 
1095
        // Adding keys to table sms_gateways.
-
 
1096
        $table->add_key('primary', XMLDB_KEY_PRIMARY, ['id']);
-
 
1097
 
-
 
1098
        // Conditionally launch create table for sms_gateways.
-
 
1099
        if (!$dbman->table_exists($table)) {
-
 
1100
            $dbman->create_table($table);
-
 
1101
        }
-
 
1102
 
-
 
1103
        // Main savepoint reached.
-
 
1104
        upgrade_main_savepoint(true, 2024092000.01);
-
 
1105
    }
-
 
1106
 
-
 
1107
    if ($oldversion < 2024092600.00) {
-
 
1108
        // If h5plib_v126 is no longer present, remove it.
-
 
1109
        if (!file_exists($CFG->dirroot . '/h5p/h5plib/v126/version.php')) {
-
 
1110
            // Clean config.
-
 
1111
            uninstall_plugin('h5plib', 'v126');
-
 
1112
        }
-
 
1113
 
-
 
1114
        // If h5plib_v127 is present, set it as the default one.
-
 
1115
        if (file_exists($CFG->dirroot . '/h5p/h5plib/v127/version.php')) {
-
 
1116
            set_config('h5plibraryhandler', 'h5plib_v127');
-
 
1117
        }
-
 
1118
        // Main savepoint reached.
-
 
1119
        upgrade_main_savepoint(true, 2024092600.00);
-
 
1120
    }
-
 
1121
 
-
 
1122
    if ($oldversion < 2024100100.02) {
-
 
1123
        upgrade_store_relative_url_sitehomepage();
-
 
1124
 
-
 
1125
        // Main savepoint reached.
-
 
1126
        upgrade_main_savepoint(true, 2024100100.02);
-
 
1127
    }
-
 
1128
 
-
 
1129
    // Automatically generated Moodle v4.5.0 release upgrade line.
-
 
1130
    // Put any upgrade step following this.
-
 
1131
 
-
 
1132
    if ($oldversion < 2024110400.00) {
-
 
1133
 
-
 
1134
        // Define field model to be added to ai_action_register.
-
 
1135
        $table = new xmldb_table('ai_action_register');
-
 
1136
        $field = new xmldb_field('model', XMLDB_TYPE_CHAR, '50', null, null, null, null, null);
-
 
1137
 
-
 
1138
        // Conditionally launch add field model.
-
 
1139
        if (!$dbman->field_exists($table, $field)) {
-
 
1140
            $dbman->add_field($table, $field);
-
 
1141
        }
-
 
1142
 
-
 
1143
        // Main savepoint reached.
-
 
1144
        upgrade_main_savepoint(true, 2024110400.00);
-
 
1145
    }
-
 
1146
    if ($oldversion < 2024110800.00) {
-
 
1147
        // Delete settings that were removed from code.
-
 
1148
        $settings = ['backup_general_questionbank', 'backup_import_questionbank', 'backup_auto_questionbank'];
-
 
1149
        array_walk($settings, static fn($setting) => unset_config($setting, 'backup'));
-
 
1150
 
-
 
1151
        // Main savepoint reached.
-
 
1152
        upgrade_main_savepoint(true, 2024110800.00);
-
 
1153
    }
-
 
1154
 
-
 
1155
    if ($oldversion < 2024110800.02) {
-
 
1156
        // Changing type of field value on table user_preferences to text.
-
 
1157
        $table = new xmldb_table('user_preferences');
-
 
1158
        $field = new xmldb_field('value', XMLDB_TYPE_TEXT, null, null, XMLDB_NOTNULL, null, null, 'name');
-
 
1159
 
-
 
1160
        // Launch change of type for field value.
-
 
1161
        $dbman->change_field_type($table, $field);
-
 
1162
 
-
 
1163
        // Main savepoint reached.
-
 
1164
        upgrade_main_savepoint(true, 2024110800.02);
-
 
1165
    }
-
 
1166
 
-
 
1167
    if ($oldversion < 2024111500.00) {
-
 
1168
 
-
 
1169
        // Changing precision of field fullname on table course to (1333).
-
 
1170
        $table = new xmldb_table('course');
-
 
1171
        $field = new xmldb_field('fullname', XMLDB_TYPE_CHAR, '1333', null, XMLDB_NOTNULL, null, null, 'sortorder');
-
 
1172
 
-
 
1173
        // Launch change of precision for field fullname.
-
 
1174
        $dbman->change_field_precision($table, $field);
-
 
1175
 
-
 
1176
        // Main savepoint reached.
-
 
1177
        upgrade_main_savepoint(true, 2024111500.00);
-
 
1178
    }
-
 
1179
 
-
 
1180
    if ($oldversion < 2024111500.01) {
-
 
1181
 
-
 
1182
        // Changing precision of field fullname on table course_request to (1333).
-
 
1183
        $table = new xmldb_table('course_request');
-
 
1184
        $field = new xmldb_field('fullname', XMLDB_TYPE_CHAR, '1333', null, XMLDB_NOTNULL, null, null, 'id');
-
 
1185
 
-
 
1186
        // Launch change of precision for field fullname.
-
 
1187
        $dbman->change_field_precision($table, $field);
-
 
1188
 
-
 
1189
        // Main savepoint reached.
-
 
1190
        upgrade_main_savepoint(true, 2024111500.01);
-
 
1191
    }
-
 
1192
 
-
 
1193
    // Now we want to change the precision of course_request.shortname.
-
 
1194
    // To do this, we need to first drop the index, then re-create it.
-
 
1195
    if ($oldversion < 2024111500.02) {
-
 
1196
 
-
 
1197
        // Define index shortname (not unique) to be dropped form course_request.
-
 
1198
        $table = new xmldb_table('course_request');
-
 
1199
        $index = new xmldb_index('shortname', XMLDB_INDEX_NOTUNIQUE, ['shortname']);
-
 
1200
 
-
 
1201
        // Conditionally launch drop index shortname.
-
 
1202
        if ($dbman->index_exists($table, $index)) {
-
 
1203
            $dbman->drop_index($table, $index);
-
 
1204
        }
-
 
1205
 
-
 
1206
        // Main savepoint reached.
-
 
1207
        upgrade_main_savepoint(true, 2024111500.02);
-
 
1208
    }
-
 
1209
 
-
 
1210
    if ($oldversion < 2024111500.03) {
-
 
1211
 
-
 
1212
        // Changing precision of field shortname on table course_request to (255).
-
 
1213
        $table = new xmldb_table('course_request');
-
 
1214
        $field = new xmldb_field('shortname', XMLDB_TYPE_CHAR, '255', null, XMLDB_NOTNULL, null, null, 'fullname');
-
 
1215
 
-
 
1216
        // Launch change of precision for field shortname.
-
 
1217
        $dbman->change_field_precision($table, $field);
-
 
1218
 
-
 
1219
        // Main savepoint reached.
-
 
1220
        upgrade_main_savepoint(true, 2024111500.03);
-
 
1221
    }
-
 
1222
 
-
 
1223
    if ($oldversion < 2024111500.04) {
-
 
1224
 
-
 
1225
        // Define index shortname (not unique) to be added to course_request.
-
 
1226
        $table = new xmldb_table('course_request');
-
 
1227
        $index = new xmldb_index('shortname', XMLDB_INDEX_NOTUNIQUE, ['shortname']);
-
 
1228
 
-
 
1229
        // Conditionally launch add index shortname.
-
 
1230
        if (!$dbman->index_exists($table, $index)) {
-
 
1231
            $dbman->add_index($table, $index);
-
 
1232
        }
-
 
1233
 
-
 
1234
        // Main savepoint reached.
-
 
1235
        upgrade_main_savepoint(true, 2024111500.04);
-
 
1236
    }
-
 
1237
 
-
 
1238
    if ($oldversion < 2024112900.01) {
-
 
1239
 
-
 
1240
        // Define table reportbuilder_user_filter to be created.
-
 
1241
        $table = new xmldb_table('reportbuilder_user_filter');
-
 
1242
 
-
 
1243
        // Adding fields to table reportbuilder_user_filter.
-
 
1244
        $table->add_field('id', XMLDB_TYPE_INTEGER, '10', null, XMLDB_NOTNULL, XMLDB_SEQUENCE, null);
-
 
1245
        $table->add_field('reportid', XMLDB_TYPE_INTEGER, '10', null, XMLDB_NOTNULL, null, '0');
-
 
1246
        $table->add_field('filterdata', XMLDB_TYPE_TEXT, null, null, XMLDB_NOTNULL, null, null);
-
 
1247
        $table->add_field('usercreated', XMLDB_TYPE_INTEGER, '10', null, XMLDB_NOTNULL, null, '0');
-
 
1248
        $table->add_field('usermodified', XMLDB_TYPE_INTEGER, '10', null, XMLDB_NOTNULL, null, '0');
-
 
1249
        $table->add_field('timecreated', XMLDB_TYPE_INTEGER, '10', null, XMLDB_NOTNULL, null, '0');
-
 
1250
        $table->add_field('timemodified', XMLDB_TYPE_INTEGER, '10', null, XMLDB_NOTNULL, null, '0');
-
 
1251
 
-
 
1252
        // Adding keys to table reportbuilder_user_filter.
-
 
1253
        $table->add_key('primary', XMLDB_KEY_PRIMARY, ['id']);
-
 
1254
        $table->add_key('reportid', XMLDB_KEY_FOREIGN, ['reportid'], 'reportbuilder_report', ['id']);
-
 
1255
        $table->add_key('usercreated', XMLDB_KEY_FOREIGN, ['usercreated'], 'user', ['id']);
-
 
1256
        $table->add_key('usermodified', XMLDB_KEY_FOREIGN, ['usermodified'], 'user', ['id']);
-
 
1257
 
-
 
1258
        // Adding indexes to table reportbuilder_user_filter.
-
 
1259
        $table->add_index('report-user', XMLDB_INDEX_UNIQUE, ['reportid', 'usercreated']);
-
 
1260
 
-
 
1261
        // Conditionally launch create table for reportbuilder_user_filter.
-
 
1262
        if (!$dbman->table_exists($table)) {
-
 
1263
            $dbman->create_table($table);
-
 
1264
        }
-
 
1265
 
-
 
1266
        // Main savepoint reached.
-
 
1267
        upgrade_main_savepoint(true, 2024112900.01);
-
 
1268
    }
-
 
1269
 
-
 
1270
    if ($oldversion < 2024112900.02) {
-
 
1271
 
-
 
1272
        // Structure to collect current user filter preferences.
-
 
1273
        $userfilterdata = [];
-
 
1274
 
-
 
1275
        $select = $DB->sql_like('name', '?');
-
 
1276
        $params = [$DB->sql_like_escape('reportbuilder-report-') . '%'];
-
 
1277
 
-
 
1278
        $preferences = $DB->get_records_select('user_preferences', $select, $params, 'userid, name');
-
 
1279
        foreach ($preferences as $preference) {
-
 
1280
            preg_match('/^reportbuilder-report-(?<reportid>\d+)-/', $preference->name, $matches);
-
 
1281
            $userfilterdata[$preference->userid][$matches['reportid']][] = $preference->value;
-
 
1282
        }
-
 
1283
 
-
 
1284
        // Migrate user filter preferences to new schema (combining previously chunked values due to size limitation).
-
 
1285
        foreach ($userfilterdata as $userid => $reportfilterdata) {
-
 
1286
            foreach ($reportfilterdata as $reportid => $filterdata) {
-
 
1287
                $DB->insert_record('reportbuilder_user_filter', (object) [
-
 
1288
                    'reportid' => $reportid,
-
 
1289
                    'filterdata' => implode('', $filterdata),
-
 
1290
                    'usercreated' => $userid,
-
 
1291
                    'usermodified' => $userid,
-
 
1292
                    'timecreated' => time(),
-
 
1293
                    'timemodified' => time(),
-
 
1294
                ]);
-
 
1295
            }
-
 
1296
        }
-
 
1297
 
-
 
1298
        // Clean up old user filter preferences.
-
 
1299
        $DB->delete_records_select('user_preferences', $select, $params);
-
 
1300
 
-
 
1301
        // Main savepoint reached.
-
 
1302
        upgrade_main_savepoint(true, 2024112900.02);
-
 
1303
    }
-
 
1304
 
-
 
1305
    // Moodle 5.0 Upgrade.
-
 
1306
    if ($oldversion < 2024121800.00) {
-
 
1307
        $smsgateways = $DB->get_records('sms_gateways');
-
 
1308
        foreach ($smsgateways as $gateway) {
-
 
1309
            $newconfig = json_decode($gateway->config);
-
 
1310
            // Continue only if either the `returnurl` OR the `saveandreturn` property exists.
-
 
1311
            if (property_exists($newconfig, "returnurl") || property_exists($newconfig, "saveandreturn")) {
-
 
1312
                // Remove unnecessary data in the config.
-
 
1313
                unset($newconfig->returnurl, $newconfig->saveandreturn);
-
 
1314
 
-
 
1315
                // Update the record with the new config.
-
 
1316
                $gateway->config = json_encode($newconfig);
-
 
1317
                $DB->update_record('sms_gateways', $gateway);
-
 
1318
            }
-
 
1319
        }
-
 
1320
 
-
 
1321
        // Main savepoint reached.
-
 
1322
        upgrade_main_savepoint(true, 2024121800.00);
-
 
1323
    }
-
 
1324
 
-
 
1325
    if ($oldversion < 2024121900.01) {
-
 
1326
        // Enable mod_subsection unless 'keepsubsectiondisabled' is set.
-
 
1327
        if ((empty($CFG->keepsubsectiondisabled) || !$CFG->keepsubsectiondisabled)
-
 
1328
                && $DB->get_record('modules', ['name' => 'subsection'])) {
-
 
1329
            $manager = \core_plugin_manager::resolve_plugininfo_class('mod');
-
 
1330
            $manager::enable_plugin('subsection', 1);
-
 
1331
        }
-
 
1332
 
-
 
1333
        // Main savepoint reached.
-
 
1334
        upgrade_main_savepoint(true, 2024121900.01);
-
 
1335
    }
-
 
1336
 
-
 
1337
    if ($oldversion < 2025011700.02) {
-
 
1338
        // Define table ai_providers to be created.
-
 
1339
        $table = new xmldb_table('ai_providers');
-
 
1340
 
-
 
1341
        // Adding fields to table ai_providers.
-
 
1342
        $table->add_field('id', XMLDB_TYPE_INTEGER, '10', null, XMLDB_NOTNULL, XMLDB_SEQUENCE, null);
-
 
1343
        $table->add_field('name', XMLDB_TYPE_CHAR, '255', null, XMLDB_NOTNULL, null, null);
-
 
1344
        $table->add_field('provider', XMLDB_TYPE_CHAR, '255', null, XMLDB_NOTNULL, null, null);
-
 
1345
        $table->add_field('enabled', XMLDB_TYPE_INTEGER, '1', null, XMLDB_NOTNULL, null, '1');
-
 
1346
        $table->add_field('config', XMLDB_TYPE_TEXT, null, null, XMLDB_NOTNULL, null, null);
-
 
1347
        $table->add_field('actionconfig', XMLDB_TYPE_TEXT, null, null, null, null, null);
-
 
1348
 
-
 
1349
        // Adding keys to table ai_provider.
-
 
1350
        $table->add_key('primary', XMLDB_KEY_PRIMARY, ['id']);
-
 
1351
 
-
 
1352
        // Adding indexes to table ai_provider.
-
 
1353
        $table->add_index('provider', XMLDB_INDEX_NOTUNIQUE, ['provider']);
-
 
1354
 
-
 
1355
        // Conditionally launch create table for ai_provider.
-
 
1356
        if (!$dbman->table_exists($table)) {
-
 
1357
            $dbman->create_table($table);
-
 
1358
        }
-
 
1359
 
-
 
1360
        // Now the instance table exists, migrate the existing providers.
-
 
1361
        upgrade_convert_ai_providers_to_instances();
-
 
1362
 
-
 
1363
        // Main savepoint reached.
-
 
1364
        upgrade_main_savepoint(true, 2025011700.02);
-
 
1365
    }
-
 
1366
 
-
 
1367
    if ($oldversion < 2025012400.01) {
-
 
1368
        // Remove the default value for the apiversion field.
-
 
1369
        $table = new xmldb_table('badge_external_backpack');
-
 
1370
        $apiversionfield = new xmldb_field('apiversion', XMLDB_TYPE_CHAR, '12', null, XMLDB_NOTNULL, null, null);
-
 
1371
        $dbman->change_field_default($table, $apiversionfield);
-
 
1372
 
-
 
1373
        // Main savepoint reached.
-
 
1374
        upgrade_main_savepoint(true, 2025012400.01);
-
 
1375
    }
-
 
1376
 
-
 
1377
    if ($oldversion < 2025013100.01) {
-
 
1378
        // Remove imageauthorname, imageauthoremail and imageauthorurl fields for badges.
-
 
1379
        $table = new xmldb_table('badge');
-
 
1380
        $fields = [
-
 
1381
            'imageauthorname',
-
 
1382
            'imageauthoremail',
-
 
1383
            'imageauthorurl',
-
 
1384
        ];
-
 
1385
 
-
 
1386
        foreach ($fields as $field) {
-
 
1387
            $field = new xmldb_field($field);
-
 
1388
            if ($dbman->field_exists($table, $field)) {
-
 
1389
                $dbman->drop_field($table, $field);
-
 
1390
            }
-
 
1391
        }
-
 
1392
 
-
 
1393
        // Main savepoint reached.
-
 
1394
        upgrade_main_savepoint(true, 2025013100.01);
-
 
1395
    }
-
 
1396
 
-
 
1397
    if ($oldversion < 2025022100.01) {
-
 
1398
        // Define table ai_action_explain_text to be created.
-
 
1399
        $table = new xmldb_table('ai_action_explain_text');
-
 
1400
 
-
 
1401
        // Adding fields to table ai_action_explain_text.
-
 
1402
        $table->add_field('id', XMLDB_TYPE_INTEGER, '10', null, XMLDB_NOTNULL, XMLDB_SEQUENCE, null);
-
 
1403
        $table->add_field('prompt', XMLDB_TYPE_TEXT, null, null, null, null, null);
-
 
1404
        $table->add_field('responseid', XMLDB_TYPE_CHAR, '128', null, null, null, null);
-
 
1405
        $table->add_field('fingerprint', XMLDB_TYPE_CHAR, '128', null, null, null, null);
-
 
1406
        $table->add_field('generatedcontent', XMLDB_TYPE_TEXT, null, null, null, null, null);
-
 
1407
        $table->add_field('finishreason', XMLDB_TYPE_CHAR, '128', null, null, null, null);
-
 
1408
        $table->add_field('prompttokens', XMLDB_TYPE_INTEGER, '10', null, null, null, null);
-
 
1409
        $table->add_field('completiontoken', XMLDB_TYPE_INTEGER, '10', null, null, null, null);
-
 
1410
 
-
 
1411
        // Adding keys to table ai_action_explain_text.
-
 
1412
        $table->add_key('primary', XMLDB_KEY_PRIMARY, ['id']);
-
 
1413
 
-
 
1414
        // Conditionally launch create table for ai_action_explain_text.
-
 
1415
        if (!$dbman->table_exists($table)) {
-
 
1416
            $dbman->create_table($table);
-
 
1417
        }
-
 
1418
 
-
 
1419
        // Add explain action config to the AI providers.
-
 
1420
        upgrade_add_explain_action_to_ai_providers();
-
 
1421
 
-
 
1422
        // Main savepoint reached.
-
 
1423
        upgrade_main_savepoint(true, 2025022100.01);
-
 
1424
    }
-
 
1425
 
-
 
1426
    if ($oldversion < 2025022100.02) {
-
 
1427
        // Due to a code restriction on the upgrade, invoking any core functions is not permitted.
-
 
1428
        // Thus, to acquire the list of provider plugins,
-
 
1429
        // we should extract them from the `config_plugins` database table.
-
 
1430
        $condition = $DB->sql_like('plugin', ':pattern');
-
 
1431
        $params = ['pattern' => 'aiprovider_%', 'name' => 'version'];
-
 
1432
        $sql = "SELECT plugin FROM {config_plugins} WHERE {$condition} AND name = :name";
-
 
1433
        $providers = $DB->get_fieldset_sql($sql, $params);
-
 
1434
        foreach ($providers as $provider) {
-
 
1435
            // Replace the provider's language string with the provider component's name.
-
 
1436
            if (get_string_manager()->string_exists('pluginname', $provider)) {
-
 
1437
                $providername = get_string('pluginname', $provider);
-
 
1438
                $sql = 'UPDATE {ai_action_register}
-
 
1439
                        SET provider = :provider
-
 
1440
                        WHERE LOWER(provider) = :providername';
-
 
1441
                $DB->execute($sql, ['provider' => $provider, 'providername' => strtolower($providername)]);
-
 
1442
            }
-
 
1443
        }
-
 
1444
 
-
 
1445
        // Main savepoint reached.
-
 
1446
        upgrade_main_savepoint(true, 2025022100.02);
-
 
1447
    }
-
 
1448
 
-
 
1449
    // Uninstall auth_cas and remove dependencies.
-
 
1450
    if ($oldversion < 2025030500.00) {
-
 
1451
        if (!file_exists($CFG->dirroot . "/auth/cas/version.php")) {
-
 
1452
            uninstall_plugin('auth', 'cas');
-
 
1453
 
-
 
1454
            // Remove the sensiblesettings config for auth_cas.
-
 
1455
            $sensiblesettingsraw = explode(',', get_config('adminpresets', 'sensiblesettings'));
-
 
1456
            $sensiblesettings = array_map('trim', $sensiblesettingsraw);
-
 
1457
 
-
 
1458
            if (($key = array_search('bind_pw@@auth_cas', $sensiblesettings)) !== false) {
-
 
1459
                unset($sensiblesettings[$key]);
-
 
1460
            }
-
 
1461
            $sensiblesettings = implode(', ', $sensiblesettings);
-
 
1462
            set_config('sensiblesettings', $sensiblesettings, 'adminpresets');
-
 
1463
        }
-
 
1464
 
-
 
1465
        // Main savepoint reached.
-
 
1466
        upgrade_main_savepoint(true, 2025030500.00);
-
 
1467
    }
-
 
1468
 
-
 
1469
    if ($oldversion < 2025030500.01) {
-
 
1470
        // If atto is no longer present, remove it.
-
 
1471
        if (!file_exists("{$CFG->dirroot}/lib/editor/atto/version.php")) {
-
 
1472
            // Remove each of the subplugins first. These are no longer on disk so the standard `uninstall_plugin` approach
-
 
1473
            // on atto itself will not remove them.
-
 
1474
            $plugins = array_keys(core_plugin_manager::instance()->get_plugins_of_type('atto'));
-
 
1475
 
-
 
1476
            // Now remove each.
-
 
1477
            foreach ($plugins as $pluginname) {
-
 
1478
                uninstall_plugin('atto', $pluginname);
-
 
1479
            }
-
 
1480
 
-
 
1481
            // Finally uninstall the actual plugin.
-
 
1482
            uninstall_plugin('editor', 'atto');
-
 
1483
        }
-
 
1484
 
-
 
1485
        upgrade_main_savepoint(true, 2025030500.01);
-
 
1486
    }
-
 
1487
 
-
 
1488
    // Remove portfolio_mahara.
-
 
1489
    if ($oldversion < 2025030600.02) {
-
 
1490
        if (!file_exists($CFG->dirroot . "/portfolio/mahara/version.php")) {
-
 
1491
            uninstall_plugin('portfolio', 'mahara');
-
 
1492
        }
-
 
1493
        // Main savepoint reached.
-
 
1494
        upgrade_main_savepoint(true, 2025030600.02);
-
 
1495
    }
-
 
1496
 
-
 
1497
    // Remove enrol_mnet.
-
 
1498
    if ($oldversion < 2025030600.03) {
-
 
1499
        if (!file_exists($CFG->dirroot . "/enrol/mnet/version.php")) {
-
 
1500
            uninstall_plugin('enrol', 'mnet');
-
 
1501
        }
-
 
1502
        // Main savepoint reached.
-
 
1503
        upgrade_main_savepoint(true, 2025030600.03);
-
 
1504
    }
-
 
1505
 
-
 
1506
    // Remove block_mnet_hosts.
-
 
1507
    if ($oldversion < 2025030600.04) {
-
 
1508
        if (!file_exists($CFG->dirroot . "/blocks/mnet_hosts/version.php")) {
-
 
1509
            uninstall_plugin('block', 'mnet_hosts');
-
 
1510
 
-
 
1511
            // Delete all the admin preset plugin states concerning mnet_hosts in adminpresets_plug table.
-
 
1512
            $DB->delete_records('adminpresets_plug', ['name' => 'mnet_hosts']);
-
 
1513
        }
-
 
1514
 
-
 
1515
        // Main savepoint reached.
-
 
1516
        upgrade_main_savepoint(true, 2025030600.04);
-
 
1517
    }
-
 
1518
 
-
 
1519
    // Remove auth_mnet.
-
 
1520
    if ($oldversion < 2025030600.05) {
-
 
1521
        if (!file_exists($CFG->dirroot . "/auth/mnet/version.php")) {
-
 
1522
            uninstall_plugin('auth', 'mnet');
-
 
1523
        }
-
 
1524
        // Main savepoint reached.
-
 
1525
        upgrade_main_savepoint(true, 2025030600.05);
-
 
1526
    }
-
 
1527
 
-
 
1528
    if ($oldversion < 2025030600.06) {
-
 
1529
        // If mlbackend_php is no longer present, remove it.
-
 
1530
        if (!file_exists($CFG->dirroot . '/lib/mlbackend/php/version.php')) {
-
 
1531
            // Clean config.
-
 
1532
            uninstall_plugin('mlbackend', 'php');
-
 
1533
 
-
 
1534
            // Change the processor if mlbackend_php is set.
-
 
1535
            if (get_config('analytics', 'predictionsprocessor') === '\mlbackend_php\processor') {
-
 
1536
                set_config('predictionsprocessor', '\mlbackend_python\processor', 'analytics');
-
 
1537
                // We can't be sure mlbackend_python is set up correctly, so we disable analytics.
-
 
1538
                set_config('enableanalytics', false);
-
 
1539
            }
-
 
1540
 
-
 
1541
            // Cleanup any references to mlbackend_php.
-
 
1542
            $select = $DB->sql_like('predictionsprocessor', ':predictionsprocessor', false);
-
 
1543
            $params = ['predictionsprocessor' => '%' . $DB->sql_like_escape('mlbackend_php') . '%'];
-
 
1544
            $DB->set_field_select(
-
 
1545
                table: 'analytics_models',
-
 
1546
                newfield: 'predictionsprocessor',
-
 
1547
                newvalue: null,
-
 
1548
                select: $select,
-
 
1549
                params: $params,
-
 
1550
            );
-
 
1551
        }
-
 
1552
 
-
 
1553
        // Main savepoint reached.
-
 
1554
        upgrade_main_savepoint(true, 2025030600.06);
-
 
1555
    }
-
 
1556
 
-
 
1557
    if ($oldversion < 2025030600.07) {
-
 
1558
        $providers = $DB->get_records('ai_providers', ['enabled' => 1]);
-
 
1559
        // Formatting the value.
-
 
1560
        $value = ','. implode(',', array_column($providers, 'id'));
-
 
1561
        // Create the order config setting.
-
 
1562
        set_config('provider_order', $value, 'core_ai');
-
 
1563
 
-
 
1564
        // Main savepoint reached.
-
 
1565
        upgrade_main_savepoint(true, 2025030600.07);
-
 
1566
    }
-
 
1567
 
-
 
1568
    // Remove mnetservice_enrol.
-
 
1569
    if ($oldversion < 2025030600.08) {
-
 
1570
        if (!file_exists($CFG->dirroot . "/mnet/service/enrol/version.php")) {
-
 
1571
            uninstall_plugin('mnetservice', 'enrol');
-
 
1572
        }
-
 
1573
        // Main savepoint reached.
-
 
1574
        upgrade_main_savepoint(true, 2025030600.08);
-
 
1575
    }
-
 
1576
 
-
 
1577
    if ($oldversion < 2025031800.00) {
-
 
1578
        // Add index for querying delegated sections.
-
 
1579
        $table = new xmldb_table('course_sections');
-
 
1580
        $index = new xmldb_index('component_itemid', XMLDB_INDEX_NOTUNIQUE, ['component', 'itemid']);
-
 
1581
 
-
 
1582
        if (!$dbman->index_exists($table, $index)) {
-
 
1583
            $dbman->add_index($table, $index);
-
 
1584
        }
-
 
1585
        // Main savepoint reached.
-
 
1586
        upgrade_main_savepoint(true, 2025031800.00);
-
 
1587
    }
-
 
1588
 
-
 
1589
    if ($oldversion < 2025031800.03) {
-
 
1590
 
-
 
1591
        // Define field penalty to be added to grade_grades.
-
 
1592
        $table = new xmldb_table('grade_grades');
-
 
1593
        $field = new xmldb_field('deductedmark', XMLDB_TYPE_NUMBER, '10, 5', null,
-
 
1594
            XMLDB_NOTNULL, null, '0', 'aggregationweight');
-
 
1595
 
-
 
1596
        // Conditionally launch add field penalty.
-
 
1597
        if (!$dbman->field_exists($table, $field)) {
-
 
1598
            $dbman->add_field($table, $field);
-
 
1599
        }
-
 
1600
 
-
 
1601
        // Main savepoint reached.
-
 
1602
        upgrade_main_savepoint(true, 2025031800.03);
-
 
1603
    }
-
 
1604
 
-
 
1605
    if ($oldversion < 2025031800.04) {
-
 
1606
 
-
 
1607
        // Define field overriddenmark to be added to grade_grades.
-
 
1608
        $table = new xmldb_table('grade_grades');
-
 
1609
        $field = new xmldb_field('overriddenmark', XMLDB_TYPE_NUMBER, '10, 5', null,
-
 
1610
            XMLDB_NOTNULL, null, '0', 'deductedmark');
-
 
1611
 
-
 
1612
        // Conditionally launch add field penalty.
-
 
1613
        if (!$dbman->field_exists($table, $field)) {
-
 
1614
            $dbman->add_field($table, $field);
-
 
1615
        }
-
 
1616
 
-
 
1617
        // Main savepoint reached.
-
 
1618
        upgrade_main_savepoint(true, 2025031800.04);
-
 
1619
    }
-
 
1620
 
-
 
1621
    if ($oldversion < 2025032800.01) {
-
 
1622
        // Upgrade webp mime type for existing webp files.
-
 
1623
        upgrade_create_async_mimetype_upgrade_task('image/webp', ['webp']);
-
 
1624
 
-
 
1625
        // Main savepoint reached.
-
 
1626
        upgrade_main_savepoint(true, 2025032800.01);
-
 
1627
    }
-
 
1628
 
-
 
1629
    // Remove chat and survey and respective analytics indicators.
-
 
1630
    if ($oldversion < 2025040100.01) {
-
 
1631
        $indicatorstoremove = [];
-
 
1632
        $sqllikes = [];
-
 
1633
        $sqlparams = [];
-
 
1634
 
-
 
1635
        if (!file_exists($CFG->dirroot . "/mod/survey/version.php")) {
-
 
1636
            uninstall_plugin('mod', 'survey');
-
 
1637
            $DB->delete_records('adminpresets_plug', ['plugin' => 'mod', 'name' => 'survey']);
-
 
1638
            $indicatorstoremove['survey'] = [
-
 
1639
                '\mod_survey\analytics\indicator\cognitive_depth',
-
 
1640
                '\mod_survey\analytics\indicator\social_breadth',
-
 
1641
            ];
-
 
1642
            $sqlparams['surveypluginname'] = '%' . $DB->sql_like_escape('mod_survey') . '%';
-
 
1643
            $sqllikes['survey'] = $DB->sql_like('indicators', ':surveypluginname');
-
 
1644
        }
-
 
1645
        if (!file_exists($CFG->dirroot . "/mod/chat/version.php")) {
-
 
1646
            uninstall_plugin('mod', 'chat');
-
 
1647
            $DB->delete_records('adminpresets_plug', ['plugin' => 'mod', 'name' => 'chat']);
-
 
1648
            $indicatorstoremove['chat'] = [
-
 
1649
                '\mod_chat\analytics\indicator\cognitive_depth',
-
 
1650
                '\mod_chat\analytics\indicator\social_breadth',
-
 
1651
            ];
-
 
1652
            $sqlparams['chatpluginname'] = '%' . $DB->sql_like_escape('mod_chat') . '%';
-
 
1653
            $sqllikes['chat'] = $DB->sql_like('indicators', ':chatpluginname');
-
 
1654
        }
-
 
1655
 
-
 
1656
        foreach ($indicatorstoremove as $module => $indicators) {
-
 
1657
            $models = $DB->get_recordset_select('analytics_models', $sqllikes[$module], $sqlparams);
-
 
1658
            foreach ($models as $model) {
-
 
1659
                $currentindicators = json_decode($model->indicators, true);
-
 
1660
                if (!empty($indicators) && !empty($currentindicators)) {
-
 
1661
                    $newindicators = array_values(array_diff($currentindicators, $indicators));
-
 
1662
                    $model->indicators = json_encode($newindicators);
-
 
1663
                    $DB->update_record('analytics_models', $model);
-
 
1664
                }
-
 
1665
            }
-
 
1666
            $models->close();
-
 
1667
        }
-
 
1668
        // Main savepoint reached.
-
 
1669
        upgrade_main_savepoint(true, 2025040100.01);
-
 
1670
    }
-
 
1671
 
-
 
1672
    // Remove overriddenmark field from grade_grades.
-
 
1673
    if ($oldversion < 2025040700.00) {
-
 
1674
        $table = new xmldb_table('grade_grades');
-
 
1675
        $field = new xmldb_field('overriddenmark');
-
 
1676
        if ($dbman->field_exists($table, $field)) {
-
 
1677
            $dbman->drop_field($table, $field);
-
 
1678
        }
-
 
1679
 
-
 
1680
        // Main savepoint reached.
-
 
1681
        upgrade_main_savepoint(true, 2025040700.00);
-
 
1682
    }
-
 
1683
 
-
 
1684
    // Automatically generated Moodle v5.0.0 release upgrade line.
-
 
1685
    // Put any upgrade step following this.
-
 
1686
 
-
 
1687
    if ($oldversion < 2025041400.09) {
-
 
1688
 
-
 
1689
        // Define field systememail to be added to oauth2_issuer.
-
 
1690
        $table = new xmldb_table('oauth2_issuer');
-
 
1691
        $field = new xmldb_field('systememail', XMLDB_TYPE_CHAR, '100', null, null, null, null, 'loginpagename');
-
 
1692
 
-
 
1693
        // Conditionally launch add field systememail.
-
 
1694
        if (!$dbman->field_exists($table, $field)) {
-
 
1695
            $dbman->add_field($table, $field);
-
 
1696
        }
-
 
1697
 
-
 
1698
        // Main savepoint reached.
-
 
1699
        upgrade_main_savepoint(true, 2025041400.09);
-
 
1700
    }
-
 
1701
 
-
 
1702
    if ($oldversion < 2025041401.08) {
-
 
1703
        // Get all OpenAI providers.
-
 
1704
        $records = $DB->get_records('ai_providers', ['provider' => 'aiprovider_openai\provider']);
-
 
1705
 
-
 
1706
        foreach ($records as $record) {
-
 
1707
            $actionconfig = json_decode($record->actionconfig, true, 512);
-
 
1708
            $originalactionconfig = $actionconfig;
-
 
1709
 
-
 
1710
            foreach ($actionconfig as $actionkey => $action) {
-
 
1711
                $model = $action['settings']['model'];
-
 
1712
                if ($model === 'gpt-4o' || $model === 'o1') {
-
 
1713
                    // Rename setting max_tokens to max_completion_tokens.
-
 
1714
                    if (isset($action['settings']['max_tokens'])) {
-
 
1715
                        $actionconfig[$actionkey]['settings']['max_completion_tokens'] = intval($action['settings']['max_tokens']);
-
 
1716
                        unset($actionconfig[$actionkey]['settings']['max_tokens']);
-
 
1717
                    }
-
 
1718
                }
-
 
1719
                // Cast settings for 'gpt-4o' model.
-
 
1720
                if ($model === 'gpt-4o') {
-
 
1721
                    if (isset($action['settings']['top_p'])) {
-
 
1722
                        $actionconfig[$actionkey]['settings']['top_p'] = floatval($action['settings']['top_p']);
-
 
1723
                    }
-
 
1724
                    if (isset($action['settings']['presence_penalty'])) {
-
 
1725
                        $actionconfig[$actionkey]['settings']['presence_penalty'] =
-
 
1726
                            floatval($action['settings']['presence_penalty']);
-
 
1727
                    }
-
 
1728
                    if (isset($action['settings']['frequency_penalty'])) {
-
 
1729
                        $actionconfig[$actionkey]['settings']['frequency_penalty'] =
-
 
1730
                            floatval($action['settings']['frequency_penalty']);
-
 
1731
                    }
-
 
1732
                }
-
 
1733
                // Remove settings from 'o1' model.
-
 
1734
                if ($model === 'o1') {
-
 
1735
                    if (isset($action['settings']['top_p'])) {
-
 
1736
                        unset($actionconfig[$actionkey]['settings']['top_p']);
-
 
1737
                    }
-
 
1738
                    if (isset($action['settings']['presence_penalty'])) {
-
 
1739
                        unset($actionconfig[$actionkey]['settings']['presence_penalty']);
-
 
1740
                    }
-
 
1741
                    if (isset($action['settings']['frequency_penalty'])) {
-
 
1742
                        unset($actionconfig[$actionkey]['settings']['frequency_penalty']);
-
 
1743
                    }
-
 
1744
                }
-
 
1745
            }
-
 
1746
 
-
 
1747
            if ($originalactionconfig !== $actionconfig) {
-
 
1748
                $updatedrecord = new stdClass();
-
 
1749
                $updatedrecord->id = $record->id;
-
 
1750
                $updatedrecord->actionconfig = json_encode($actionconfig);
-
 
1751
                $DB->update_record('ai_providers', $updatedrecord);
-
 
1752
            }
-
 
1753
        }
1191
 
1754
 
-
 
1755
        // Main savepoint reached.
-
 
1756
        upgrade_main_savepoint(true, 2025041401.08);
-
 
1757
    }
-
 
1758
 
-
 
1759
    if ($oldversion < 2025041401.10) {
-
 
1760
        // A [name => url] map of new OIDC endpoints to be updated/created.
-
 
1761
        $endpointuris = [
-
 
1762
            'discovery_endpoint' => 'https://login.microsoftonline.com/common/v2.0/.well-known/openid-configuration',
-
 
1763
            'token_endpoint' => 'https://login.microsoftonline.com/common/oauth2/v2.0/token',
-
 
1764
            'userinfo_endpoint' => 'https://graph.microsoft.com/oidc/userinfo',
-
 
1765
            'authorization_endpoint' => 'https://login.microsoftonline.com/common/oauth2/v2.0/authorize',
-
 
1766
            'device_authorization_endpoint' => 'https://login.microsoftonline.com/common/oauth2/v2.0/devicecode',
-
 
1767
            'end_session_endpoint' => 'https://login.microsoftonline.com/common/oauth2/v2.0/logout',
-
 
1768
            'kerberos_endpoint' => 'https://login.microsoftonline.com/common/kerberos',
-
 
1769
        ];
-
 
1770
        // A [name] map of endpoints to be deleted.
-
 
1771
        $deletedendpointuris = [
-
 
1772
            'userpicture_endpoint',
-
 
1773
        ];
-
 
1774
        // A [internalfield => externalfield] map of new OIDC-based user field mappings to be updated/created.
-
 
1775
        $userfieldmappings = [
-
 
1776
            'idnumber' => 'sub',
-
 
1777
            'firstname' => 'givenname',
-
 
1778
            'lastname' => 'familyname',
-
 
1779
            'email' => 'email',
-
 
1780
            'lang' => 'locale',
-
 
1781
        ];
-
 
1782
        $admin = get_admin();
-
 
1783
        $adminid = $admin ? $admin->id : '0';
-
 
1784
        $microsoftservices = $DB->get_records('oauth2_issuer', ['servicetype' => 'microsoft']);
-
 
1785
        foreach ($microsoftservices as $microsoftservice) {
-
 
1786
            $time = time();
-
 
1787
            if (strpos($microsoftservice->baseurl, 'common') !== false) {
-
 
1788
                // Multi-tenant endpoint, proceed with upgrade.
-
 
1789
                // Insert/update the new endpoints.
-
 
1790
                foreach ($endpointuris as $endpointname => $endpointuri) {
-
 
1791
                    $endpoint = ['issuerid' => $microsoftservice->id, 'name' => $endpointname];
-
 
1792
                    $endpointid = $DB->get_field('oauth2_endpoint', 'id', $endpoint);
-
 
1793
                    if ($endpointid) {
-
 
1794
                        $endpoint = array_merge($endpoint, [
-
 
1795
                            'id' => $endpointid,
-
 
1796
                            'url' => $endpointuri,
-
 
1797
                            'timemodified' => $time,
-
 
1798
                            'usermodified' => $adminid,
-
 
1799
                        ]);
-
 
1800
                        $DB->update_record('oauth2_endpoint', $endpoint);
-
 
1801
                    } else {
-
 
1802
                        $endpoint = array_merge($endpoint, [
-
 
1803
                            'url' => $endpointuri,
-
 
1804
                            'timecreated' => $time,
-
 
1805
                            'timemodified' => $time,
-
 
1806
                            'usermodified' => $adminid,
-
 
1807
                        ]);
-
 
1808
                        $DB->insert_record('oauth2_endpoint', $endpoint);
-
 
1809
                    }
-
 
1810
                }
-
 
1811
                // Delete the old endpoints.
-
 
1812
                foreach ($deletedendpointuris as $endpointname) {
-
 
1813
                    $endpoint = ['issuerid' => $microsoftservice->id, 'name' => $endpointname];
-
 
1814
                    $DB->delete_records('oauth2_endpoint', $endpoint);
-
 
1815
                }
-
 
1816
                // Insert/update new user field mappings.
-
 
1817
                foreach ($userfieldmappings as $internalfieldname => $externalfieldname) {
-
 
1818
                    $fieldmap = ['issuerid' => $microsoftservice->id, 'internalfield' => $internalfieldname];
-
 
1819
                    $fieldmapid = $DB->get_field('oauth2_user_field_mapping', 'id', $fieldmap);
-
 
1820
                    if ($fieldmapid) {
-
 
1821
                        $fieldmap = array_merge($fieldmap, [
-
 
1822
                            'id' => $fieldmapid,
-
 
1823
                            'externalfield' => $externalfieldname,
-
 
1824
                            'timemodified' => $time,
-
 
1825
                            'usermodified' => $adminid,
-
 
1826
                        ]);
-
 
1827
                        $DB->update_record('oauth2_user_field_mapping', $fieldmap);
-
 
1828
                    } else {
-
 
1829
                        $fieldmap = array_merge($fieldmap, [
-
 
1830
                            'externalfield' => $externalfieldname,
-
 
1831
                            'timecreated' => $time,
-
 
1832
                            'timemodified' => $time,
-
 
1833
                            'usermodified' => $adminid,
-
 
1834
                        ]);
-
 
1835
                        $DB->insert_record('oauth2_user_field_mapping', $fieldmap);
-
 
1836
                    }
-
 
1837
                }
-
 
1838
                // Update the baseurl for the issuer.
-
 
1839
                $microsoftservice->baseurl = 'https://login.microsoftonline.com/common/v2.0';
-
 
1840
                $microsoftservice->timemodified = $time;
-
 
1841
                $microsoftservice->usermodified = $adminid;
-
 
1842
                $DB->update_record('oauth2_issuer', $microsoftservice);
-
 
1843
            } else {
-
 
1844
                // Single-tenant endpoint, add discovery_endpoint if it doesn't exist.
-
 
1845
                $url = $microsoftservice->baseurl;
-
 
1846
                $url .= (substr($url, -1) === '/') ? '' : '/';
-
 
1847
                $url .= '.well-known/openid-configuration';
-
 
1848
                $endpoint = ['issuerid' => $microsoftservice->id, 'name' => 'discovery_endpoint'];
-
 
1849
                $endpointid = $DB->get_field('oauth2_endpoint', 'id', $endpoint);
-
 
1850
                if (!$endpointid) {
-
 
1851
                    $endpoint = array_merge($endpoint, [
-
 
1852
                        'url' => $url,
-
 
1853
                        'timecreated' => $time,
-
 
1854
                        'timemodified' => $time,
-
 
1855
                        'usermodified' => $adminid,
-
 
1856
                    ]);
-
 
1857
                    $DB->insert_record('oauth2_endpoint', $endpoint);
-
 
1858
                }
-
 
1859
            }
-
 
1860
        }
1192
        // Main savepoint reached.
1861
        // Main savepoint reached.
Línea 1193... Línea 1862...
1193
        upgrade_main_savepoint(true, 2024042201.09);
1862
        upgrade_main_savepoint(true, 2025041401.10);
1194
    }
1863
    }