From 374226dca03670cb16ed393d76cca2cb9450f9f8 Mon Sep 17 00:00:00 2001 From: Paul Holden Date: Mon, 29 Dec 2025 15:40:27 +0000 Subject: [PATCH] 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. --- .upgradenotes/MDL-87158-2025122915442188.yml | 7 +++++++ .../xmldb/actions/view_table_php/view_table_php.class.php | 6 ++++-- 2 files changed, 11 insertions(+), 2 deletions(-) create mode 100644 .upgradenotes/MDL-87158-2025122915442188.yml diff --git a/.upgradenotes/MDL-87158-2025122915442188.yml b/.upgradenotes/MDL-87158-2025122915442188.yml new file mode 100644 index 00000000000..77587fc0008 --- /dev/null +++ b/.upgradenotes/MDL-87158-2025122915442188.yml @@ -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 diff --git a/public/admin/tool/xmldb/actions/view_table_php/view_table_php.class.php b/public/admin/tool/xmldb/actions/view_table_php/view_table_php.class.php index 492ce5aef30..035c3d3da1e 100644 --- a/public/admin/tool/xmldb/actions/view_table_php/view_table_php.class.php +++ b/public/admin/tool/xmldb/actions/view_table_php/view_table_php.class.php @@ -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);