Skip to content

Commit 21fc25e

Browse files
MDL-82335 qbank_columnsortorder: Fix upgrading issue
When upgraded to Moodle 4.4 or higher, for qbank_columnsortorder the colsize values in the config_plugins were getting incorrectly set, resulting in errors accessing the question bank. Changes done to fix this code and to remove the corrupted colsize value from config_plugins table.
1 parent 99b5729 commit 21fc25e

File tree

2 files changed

+16
-2
lines changed

2 files changed

+16
-2
lines changed

question/bank/columnsortorder/db/upgrade.php

+15-1
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ function xmldb_qbank_columnsortorder_upgrade(int $oldversion): bool {
4242
$pluginconfigs = $DB->get_records('config_plugins', ['plugin' => 'qbank_columnsortorder'], 'name');
4343

4444
foreach ($pluginconfigs as $config) {
45-
if ($config->name == 'version') {
45+
if (!in_array($config->name, ['hiddencols', 'enabledcol', 'disabledcol'])) {
4646
continue;
4747
}
4848
$fields = explode(',', $config->value);
@@ -77,5 +77,19 @@ function xmldb_qbank_columnsortorder_upgrade(int $oldversion): bool {
7777
upgrade_plugin_savepoint(true, 2024042202, 'qbank', 'columnsortorder');
7878
}
7979

80+
if ($oldversion < 2024042203) {
81+
// When upgrading to version 2024042201, if there were any values for colsize in qbank_columnsortorder plugin,
82+
// they were getting incorrectly updated, resulting in corrupted colsize value,
83+
// e.g., '"width":"30"}-"width":"30"},"width":"180"}-"width":"180"} and thus breaking the question bank page.
84+
$pluginconfig = $DB->get_record('config_plugins', ['plugin' => 'qbank_columnsortorder', 'name' => 'colsize']);
85+
if ($pluginconfig) {
86+
$pattern = '/"width":"[^"]*"}-"width":"[^"]*"}/';
87+
if (preg_match($pattern, $pluginconfig->value)) {
88+
$DB->delete_records('config_plugins', ['plugin' => 'qbank_columnsortorder', 'name' => 'colsize']);
89+
}
90+
}
91+
upgrade_plugin_savepoint(true, 2024042203, 'qbank', 'columnsortorder');
92+
}
93+
8094
return true;
8195
}

question/bank/columnsortorder/version.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,6 @@
2626
defined('MOODLE_INTERNAL') || die();
2727

2828
$plugin->component = 'qbank_columnsortorder';
29-
$plugin->version = 2024042202;
29+
$plugin->version = 2024042203;
3030
$plugin->requires = 2024041600;
3131
$plugin->maturity = MATURITY_STABLE;

0 commit comments

Comments
 (0)