Skip to content

Commit

Permalink
MDL-82335 qbank_columnsortorder: Fix upgrading issue
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
AnupamaSarjoshi committed Nov 6, 2024
1 parent acff633 commit 1ecc215
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 2 deletions.
16 changes: 15 additions & 1 deletion question/bank/columnsortorder/db/upgrade.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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.

Expand Down
2 changes: 1 addition & 1 deletion question/bank/columnsortorder/version.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;

0 comments on commit 1ecc215

Please sign in to comment.