Skip to content

Commit

Permalink
removeUnusedColumns should execute only one sql query (#14752)
Browse files Browse the repository at this point in the history
* removeUnusedColumns should execute only one sql query

* Fix when only protected columns exists
  • Loading branch information
blankse committed Mar 27, 2023
1 parent 295f5e8 commit 695f7c9
Showing 1 changed file with 6 additions and 2 deletions.
8 changes: 6 additions & 2 deletions models/DataObject/ClassDefinition/Helper/Dao.php
Expand Up @@ -128,13 +128,17 @@ protected function addModifyColumn($table, $colName, $type, $default, $null)
protected function removeUnusedColumns($table, $columnsToRemove, $protectedColumns)
{
if (is_array($columnsToRemove) && count($columnsToRemove) > 0) {
$dropColumns = [];
foreach ($columnsToRemove as $value) {
//if (!in_array($value, $protectedColumns)) {
if (!in_array(strtolower($value), array_map('strtolower', $protectedColumns))) {
$this->db->executeQuery('ALTER TABLE `' . $table . '` DROP COLUMN `' . $value . '`;');
$dropColumns[] = 'DROP COLUMN `' . $value . '`';
}
}
$this->resetValidTableColumnsCache($table);
if ($dropColumns) {
$this->db->executeQuery('ALTER TABLE `' . $table . '` ' . implode(', ', $dropColumns) . ';');
$this->resetValidTableColumnsCache($table);
}
}
}

Expand Down

0 comments on commit 695f7c9

Please sign in to comment.