Skip to content

Commit

Permalink
fixup! MDL-83153 core: WIP
Browse files Browse the repository at this point in the history
  • Loading branch information
junpataleta committed Sep 18, 2024
1 parent d1bcfa4 commit 6d50bac
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 5 deletions.
6 changes: 4 additions & 2 deletions lib/db/upgradelib.php
Original file line number Diff line number Diff line change
Expand Up @@ -1880,8 +1880,10 @@ 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)]);

// Drop the old field.
$oldfield = new xmldb_field($tmpfieldname);
Expand Down
7 changes: 4 additions & 3 deletions lib/tests/upgradelib_test.php
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down

0 comments on commit 6d50bac

Please sign in to comment.