1 |
efrain |
1 |
<?php
|
|
|
2 |
// This file is part of Moodle - http://moodle.org/
|
|
|
3 |
//
|
|
|
4 |
// Moodle is free software: you can redistribute it and/or modify
|
|
|
5 |
// it under the terms of the GNU General Public License as published by
|
|
|
6 |
// the Free Software Foundation, either version 3 of the License, or
|
|
|
7 |
// (at your option) any later version.
|
|
|
8 |
//
|
|
|
9 |
// Moodle is distributed in the hope that it will be useful,
|
|
|
10 |
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
11 |
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
12 |
// GNU General Public License for more details.
|
|
|
13 |
//
|
|
|
14 |
// You should have received a copy of the GNU General Public License
|
|
|
15 |
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
|
|
|
16 |
|
|
|
17 |
/**
|
|
|
18 |
* Custom sort order upgrade script.
|
|
|
19 |
*
|
|
|
20 |
* @package qbank_columnsortorder
|
|
|
21 |
* @copyright 2024 The Open University
|
|
|
22 |
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
|
|
23 |
*/
|
|
|
24 |
|
|
|
25 |
use core_question\local\bank\column_base;
|
|
|
26 |
|
|
|
27 |
/**
|
|
|
28 |
* Upgrade the plugin.
|
|
|
29 |
*
|
|
|
30 |
* @param int $oldversion the version of this plugin we are upgrading from.
|
|
|
31 |
* @return bool success/failure.
|
|
|
32 |
*/
|
|
|
33 |
function xmldb_qbank_columnsortorder_upgrade(int $oldversion): bool {
|
|
|
34 |
global $DB;
|
|
|
35 |
|
|
|
36 |
if ($oldversion < 2024042201) {
|
|
|
37 |
// Before Moodle 4.3, config_plugins settings for qbank_columnsortorder (disabledcol, enabledcol) had a value like
|
|
|
38 |
// qbank_statistics\columns\facility_index,qbank_statistics\columns\discriminative_efficiency, ...
|
|
|
39 |
// In Moodle 4.3, the values are stored as qbank_statistics\columns\discriminative_efficiency-discriminative_efficiency.
|
|
|
40 |
// So updating the old values to match the new format.
|
|
|
41 |
// Update the columns records for qbank_columnsortorder plugin.
|
|
|
42 |
$pluginconfigs = $DB->get_records('config_plugins', ['plugin' => 'qbank_columnsortorder'], 'name, value');
|
|
|
43 |
|
|
|
44 |
foreach ($pluginconfigs as $config) {
|
|
|
45 |
if ($config->name == 'version') {
|
|
|
46 |
continue;
|
|
|
47 |
}
|
|
|
48 |
$fields = explode(',', $config->value);
|
|
|
49 |
$updatedcols = [];
|
|
|
50 |
foreach ($fields as $columnclass) {
|
|
|
51 |
// Columns config that are already in the correct format, could be ignored.
|
|
|
52 |
if (str_contains($columnclass, column_base::ID_SEPARATOR)) {
|
|
|
53 |
continue;
|
|
|
54 |
}
|
|
|
55 |
|
|
|
56 |
$classbits = explode('\\', $columnclass);
|
|
|
57 |
$columnname = end($classbits);
|
|
|
58 |
|
|
|
59 |
// The custom fields are to be in the format e.g., qbank_customfields\custom_field_column-test.
|
|
|
60 |
if (str_contains($columnclass, 'custom_field_column')) {
|
|
|
61 |
array_pop($classbits);
|
|
|
62 |
}
|
|
|
63 |
|
|
|
64 |
$updatedcols[] = implode('\\', $classbits) . column_base::ID_SEPARATOR . $columnname;
|
|
|
65 |
}
|
|
|
66 |
$updatedconfig = implode(',', $updatedcols);
|
|
|
67 |
set_config($config->name, $updatedconfig, 'qbank_columnsortorder');
|
|
|
68 |
}
|
|
|
69 |
|
|
|
70 |
// Custom sort order savepoint reached.
|
|
|
71 |
upgrade_plugin_savepoint(true, 2024042201, 'qbank', 'columnsortorder');
|
|
|
72 |
}
|
|
|
73 |
|
|
|
74 |
if ($oldversion < 2024042202) {
|
|
|
75 |
// Remove plugin entry created by previously incorrect 2024042201 savepoint.
|
|
|
76 |
$DB->delete_records('config_plugins', ['plugin' => 'qbank_qbank_columnsortorder']);
|
|
|
77 |
upgrade_plugin_savepoint(true, 2024042202, 'qbank', 'columnsortorder');
|
|
|
78 |
}
|
|
|
79 |
|
|
|
80 |
return true;
|
|
|
81 |
}
|