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);