From 5650e0198cc7b161e21e2aee48a5007e6d32d7ac Mon Sep 17 00:00:00 2001 From: Jun Pataleta Date: Wed, 18 Sep 2024 09:04:14 +0800 Subject: [PATCH] fixup! MDL-83153 core: WIP --- lib/db/upgradelib.php | 8 +++++--- lib/tests/upgradelib_test.php | 7 ++++--- 2 files changed, 9 insertions(+), 6 deletions(-) diff --git a/lib/db/upgradelib.php b/lib/db/upgradelib.php index 293889365211..4cdaa1fb0970 100644 --- a/lib/db/upgradelib.php +++ b/lib/db/upgradelib.php @@ -1880,9 +1880,11 @@ function upgrade_change_binary_column_to_int( // Copy the values from the old field to the new field. $sql = 'UPDATE {' . $tablename . '} SET ' . $fieldname . ' = 1 - WHERE ' . $DB->sql_compare_text($tmpfieldname) . ' = :truefieldvalue'; - $DB->execute($sql, ['truefieldvalue' => 1]); - + WHERE ' . $DB->sql_compare_text($tmpfieldname) . ' = ?'; + print_object($sql); + print_object($DB->sql_compare_text('1')); + $DB->execute($sql, [$DB->sql_compare_text(1)]); + print_object($DB->get_records($tablename)); // Drop the old field. $oldfield = new xmldb_field($tmpfieldname); $dbman->drop_field($table, $oldfield); diff --git a/lib/tests/upgradelib_test.php b/lib/tests/upgradelib_test.php index c9c3d0086c03..ad4a9929aa01 100644 --- a/lib/tests/upgradelib_test.php +++ b/lib/tests/upgradelib_test.php @@ -1724,12 +1724,13 @@ public function test_upgrade_change_binary_column_to_int( $field = $columns[$fieldname]; $this->assertFalse($field->binary); + // Verify that the renamed old field has now been removed. + $this->assertArrayNotHasKey("tmp$fieldname", $columns); + // Confirm that the values for the converted column ar ethe same. $records = $DB->get_fieldset($tmptablename, 'id', [$fieldname => 1]); + print_object($records); $this->assertEqualsCanonicalizing($ones, $records); - - // Verify that the renamed old field has now been removed. - $this->assertArrayNotHasKey("tmp$fieldname", $columns); } // Cleanup.