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.
This commit is contained in:
Anupama Sarjoshi 2024-11-06 12:58:21 +00:00
parent d015c4c213
commit 795fa07c3c
2 changed files with 16 additions and 2 deletions

View File

@ -42,7 +42,7 @@ function xmldb_qbank_columnsortorder_upgrade(int $oldversion): bool {
$pluginconfigs = $DB->get_records('config_plugins', ['plugin' => 'qbank_columnsortorder'], 'name');
foreach ($pluginconfigs as $config) {
if ($config->name == 'version') {
if (!in_array($config->name, ['hiddencols', 'enabledcol', 'disabledcol'])) {
continue;
}
$fields = explode(',', $config->value);
@ -77,6 +77,20 @@ function xmldb_qbank_columnsortorder_upgrade(int $oldversion): bool {
upgrade_plugin_savepoint(true, 2024051000, 'qbank', 'columnsortorder');
}
if ($oldversion < 2024100701) {
// When upgrading to version 2024042201, if there were any values for colsize in qbank_columnsortorder plugin,
// they were getting incorrectly updated, resulting in corrupted colsize value,
// e.g., '"width":"30"}-"width":"30"},"width":"180"}-"width":"180"} and thus breaking the question bank page.
$pluginconfig = $DB->get_record('config_plugins', ['plugin' => 'qbank_columnsortorder', 'name' => 'colsize']);
if ($pluginconfig) {
$pattern = '/"width":"[^"]*"}-"width":"[^"]*"}/';
if (preg_match($pattern, $pluginconfig->value)) {
$DB->delete_records('config_plugins', ['plugin' => 'qbank_columnsortorder', 'name' => 'colsize']);
}
}
upgrade_plugin_savepoint(true, 2024100701, 'qbank', 'columnsortorder');
}
// Automatically generated Moodle v4.5.0 release upgrade line.
// Put any upgrade step following this.

View File

@ -26,6 +26,6 @@
defined('MOODLE_INTERNAL') || die();
$plugin->component = 'qbank_columnsortorder';
$plugin->version = 2024100700;
$plugin->version = 2024100701;
$plugin->requires = 2024100100;
$plugin->maturity = MATURITY_STABLE;