From 1ecc215b3a6603a9d44287b0522363ce82e273cc Mon Sep 17 00:00:00 2001 From: Anupama Sarjoshi Date: Wed, 6 Nov 2024 12:58:21 +0000 Subject: [PATCH] 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. --- question/bank/columnsortorder/db/upgrade.php | 16 +++++++++++++++- question/bank/columnsortorder/version.php | 2 +- 2 files changed, 16 insertions(+), 2 deletions(-) diff --git a/question/bank/columnsortorder/db/upgrade.php b/question/bank/columnsortorder/db/upgrade.php index 2e6032ae68b7..0d20765768a7 100644 --- a/question/bank/columnsortorder/db/upgrade.php +++ b/question/bank/columnsortorder/db/upgrade.php @@ -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. diff --git a/question/bank/columnsortorder/version.php b/question/bank/columnsortorder/version.php index a636e084c655..ab843a78f169 100644 --- a/question/bank/columnsortorder/version.php +++ b/question/bank/columnsortorder/version.php @@ -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;