From 3f8b9a53f755334ecbcdf8df2b2efa9026ccc877 Mon Sep 17 00:00:00 2001 From: Jun Pataleta Date: Mon, 16 Sep 2024 09:58:46 +0800 Subject: [PATCH] MDL-83153 core: Set `ai_action_register.success` as `INT(1)` --- lib/db/install.xml | 4 ++-- lib/db/upgrade.php | 40 ++++++++++++++++++++++++++++++++++++++++ version.php | 2 +- 3 files changed, 43 insertions(+), 3 deletions(-) diff --git a/lib/db/install.xml b/lib/db/install.xml index bf74cba12ceb0..a0b60ca97c828 100644 --- a/lib/db/install.xml +++ b/lib/db/install.xml @@ -1,5 +1,5 @@ - @@ -4891,7 +4891,7 @@ - + diff --git a/lib/db/upgrade.php b/lib/db/upgrade.php index d29f71da97a19..aece2a3d40b9e 100644 --- a/lib/db/upgrade.php +++ b/lib/db/upgrade.php @@ -1365,5 +1365,45 @@ function xmldb_main_upgrade($oldversion) { upgrade_main_savepoint(true, 2024091000.01); } + if ($oldversion < 2024091600.00) { + + // Temporary rename field success on table ai_action_register to oldsuccess. We'll drop this later. + $table = new xmldb_table('ai_action_register'); + $field = new xmldb_field('success', XMLDB_TYPE_BINARY, null, null, XMLDB_NOTNULL, null, null, 'actionid'); + + // Launch rename field success to oldsuccess. + $dbman->rename_field($table, $field, 'oldsuccess'); + + // Define field success to be added to ai_action_register. This now has the correct type. + $table = new xmldb_table('ai_action_register'); + $field = new xmldb_field('success', XMLDB_TYPE_INTEGER, '1', null, XMLDB_NOTNULL, null, '0', 'actionid'); + + // Conditionally launch add field success. + if (!$dbman->field_exists($table, $field)) { + $dbman->add_field($table, $field); + } + + $actionsrs = $DB->get_recordset('ai_action_register', null, '', 'id, oldsuccess'); + if ($actionsrs->valid()) { + foreach ($actionsrs as $action) { + $DB->set_field('ai_action_register', 'success', (int) $action->oldsuccess, ['id' => $action->id]); + } + } + $actionsrs->close(); + + // Drop the oldsuccess field. + // Define field success to be dropped from ai_action_register. + $table = new xmldb_table('ai_action_register'); + $field = new xmldb_field('oldsuccess'); + + // Conditionally launch drop field oldsuccess. + if ($dbman->field_exists($table, $field)) { + $dbman->drop_field($table, $field); + } + + // Main savepoint reached. + upgrade_main_savepoint(true, 2024091600.00); + } + return true; } diff --git a/version.php b/version.php index eb0760edc74df..bb2c8422f1f09 100644 --- a/version.php +++ b/version.php @@ -29,7 +29,7 @@ defined('MOODLE_INTERNAL') || die(); -$version = 2024091300.00; // YYYYMMDD = weekly release date of this DEV branch. +$version = 2024091600.00; // YYYYMMDD = weekly release date of this DEV branch. // RR = release increments - 00 in DEV branches. // .XX = incremental changes. $release = '4.5dev+ (Build: 20240913)'; // Human-friendly version name