MDL-87158 tool_xmldb: make generated code to rename field idempotent.

Consistent with similar DDL structure change code generated by this tool,
and allows for upgrade steps to be replayed without errors.
This commit is contained in:
Paul Holden
2026-01-28 17:04:44 +00:00
parent b3cd83bd48
commit 374226dca0
2 changed files with 11 additions and 2 deletions
@@ -0,0 +1,7 @@
issueNumber: MDL-87158
notes:
tool_xmldb:
- message: >-
Generated `rename_field(...)` upgrade step code now checks for field
existence, to ensure it can be executed multiple times
type: changed
@@ -416,8 +416,10 @@ class view_table_php extends XMLDBAction {
// Launch the proper DDL
$result .= XMLDB_LINEFEED;
$result .= ' // Launch rename field ' . $field->getName() . '.' . XMLDB_LINEFEED;
$result .= ' $dbman->rename_field($table, $field, ' . "'" . 'NEWNAMEGOESHERE' . "'" . ');' . XMLDB_LINEFEED;
$result .= ' // Conditionally launch rename field ' . $field->getName() . '.' . XMLDB_LINEFEED;
$result .= ' if ($dbman->field_exists($table, $field)) {' . XMLDB_LINEFEED;
$result .= ' $dbman->rename_field($table, $field, ' . "'" . 'NEWNAMEGOESHERE' . "'" . ');' . XMLDB_LINEFEED;
$result .= ' }' . XMLDB_LINEFEED;
// Add the proper upgrade_xxxx_savepoint call
$result .= $this->upgrade_savepoint_php ($structure);