From: Matthias Schmidt Date: Fri, 27 Sep 2019 15:19:20 +0000 (+0200) Subject: Always split database changes into single requests X-Git-Tag: 5.2.0_Beta_2~29^2 X-Git-Url: https://git.stricted.de/?a=commitdiff_plain;h=d94411309c775ee53d4cdd0f84c9fab98bf9ea3a;p=GitHub%2FWoltLab%2FWCF.git Always split database changes into single requests --- diff --git a/wcfsetup/install/files/lib/system/database/table/DatabaseTableChangeProcessor.class.php b/wcfsetup/install/files/lib/system/database/table/DatabaseTableChangeProcessor.class.php index 6b8d37c3b5..0e07b14c32 100644 --- a/wcfsetup/install/files/lib/system/database/table/DatabaseTableChangeProcessor.class.php +++ b/wcfsetup/install/files/lib/system/database/table/DatabaseTableChangeProcessor.class.php @@ -102,12 +102,6 @@ class DatabaseTableChangeProcessor { */ protected $foreignKeysToDrop = []; - /** - * is `true` if only one change will be handled per request - * @var bool - */ - protected $oneChangePerRequest = true; - /** * package that wants to apply the changes * @var Package @@ -150,9 +144,8 @@ class DatabaseTableChangeProcessor { * @param Package $package * @param DatabaseTable[] $tables * @param DatabaseEditor $dbEditor - * @param bool $oneChangePerRequest */ - public function __construct(Package $package, array $tables, DatabaseEditor $dbEditor, $oneChangePerRequest = true) { + public function __construct(Package $package, array $tables, DatabaseEditor $dbEditor) { $this->package = $package; $tableNames = []; @@ -166,7 +159,6 @@ class DatabaseTableChangeProcessor { $this->tables = $tables; $this->dbEditor = $dbEditor; - $this->oneChangePerRequest = $oneChangePerRequest; $this->existingTableNames = $dbEditor->getTableNames(); @@ -373,10 +365,8 @@ class DatabaseTableChangeProcessor { if (in_array($tableName, $this->existingTableNames)) { $this->tablesToDrop[] = $table; - if ($this->oneChangePerRequest) { - $this->splitNodeMessage .= "Dropped table '{$tableName}'."; - break; - } + $this->splitNodeMessage .= "Dropped table '{$tableName}'."; + break; } else if (isset($this->tablePackageIDs[$tableName])) { $this->deleteTableLog($table); @@ -385,10 +375,8 @@ class DatabaseTableChangeProcessor { else if (!in_array($tableName, $this->existingTableNames)) { $this->tablesToCreate[] = $table; - if ($this->oneChangePerRequest) { - $this->splitNodeMessage .= "Created table '{$tableName}'."; - break; - } + $this->splitNodeMessage .= "Created table '{$tableName}'."; + break; } else { // calculate difference between tables @@ -423,7 +411,7 @@ class DatabaseTableChangeProcessor { // all column-related changes are executed in one query thus break // here and not within the previous loop - if ($this->oneChangePerRequest && (!empty($this->columnsToAdd) || !empty($this->columnsToAlter) || !empty($this->columnsToDrop))) { + if (!empty($this->columnsToAdd) || !empty($this->columnsToAlter) || !empty($this->columnsToDrop)) { $this->splitNodeMessage .= "Altered columns of table '{$tableName}'."; break; } @@ -445,10 +433,8 @@ class DatabaseTableChangeProcessor { } $this->foreignKeysToDrop[$tableName][] = $foreignKey; - if ($this->oneChangePerRequest) { - $this->splitNodeMessage .= "Dropped foreign key '{$tableName}." . implode(',', $foreignKey->getColumns()) . "'."; - break 2; - } + $this->splitNodeMessage .= "Dropped foreign key '{$tableName}." . implode(',', $foreignKey->getColumns()) . "'."; + break 2; } else if (isset($this->foreignKeyPackageIDs[$tableName][$foreignKey->getName()])) { $this->deleteForeignKeyLog($tableName, $foreignKey); @@ -460,10 +446,8 @@ class DatabaseTableChangeProcessor { } $this->foreignKeysToAdd[$tableName][] = $foreignKey; - if ($this->oneChangePerRequest) { - $this->splitNodeMessage .= "Added foreign key '{$tableName}." . implode(',', $foreignKey->getColumns()) . "'."; - break 2; - } + $this->splitNodeMessage .= "Added foreign key '{$tableName}." . implode(',', $foreignKey->getColumns()) . "'."; + break 2; } } @@ -484,10 +468,8 @@ class DatabaseTableChangeProcessor { } $this->indicesToDrop[$tableName][] = $index; - if ($this->oneChangePerRequest) { - $this->splitNodeMessage .= "Dropped index '{$tableName}." . implode(',', $index->getColumns()) . "'."; - break 2; - } + $this->splitNodeMessage .= "Dropped index '{$tableName}." . implode(',', $index->getColumns()) . "'."; + break 2; } else if (isset($this->indexPackageIDs[$tableName][$index->getName()])) { $this->deleteIndexLog($tableName, $index); @@ -499,10 +481,8 @@ class DatabaseTableChangeProcessor { } $this->indicesToAdd[$tableName][] = $index; - if ($this->oneChangePerRequest) { - $this->splitNodeMessage .= "Added index '{$tableName}." . implode(',', $index->getColumns()) . "'."; - break 2; - } + $this->splitNodeMessage .= "Added index '{$tableName}." . implode(',', $index->getColumns()) . "'."; + break 2; } } }