diff --git a/lib/Doctrine/DBAL/Schema/Comparator.php b/lib/Doctrine/DBAL/Schema/Comparator.php index 20f5ea7b1a9..7e24b3e8c01 100644 --- a/lib/Doctrine/DBAL/Schema/Comparator.php +++ b/lib/Doctrine/DBAL/Schema/Comparator.php @@ -188,24 +188,24 @@ public function diffSequence(Sequence $sequence1, Sequence $sequence2) } /** - * Returns the difference between the tables $table1 and $table2. + * Returns the difference between the tables $fromTable and $toTable. * * If there are no differences this method returns the boolean false. * * @return TableDiff|false */ - public function diffTable(Table $table1, Table $table2) + public function diffTable(Table $fromTable, Table $toTable) { $changes = 0; - $tableDifferences = new TableDiff($table1->getName()); - $tableDifferences->fromTable = $table1; + $tableDifferences = new TableDiff($fromTable->getName()); + $tableDifferences->fromTable = $fromTable; - $table1Columns = $table1->getColumns(); - $table2Columns = $table2->getColumns(); + $fromTableColumns = $fromTable->getColumns(); + $toTableColumns = $toTable->getColumns(); - /* See if all the columns in table 1 exist in table 2 */ - foreach ($table2Columns as $columnName => $column) { - if ($table1->hasColumn($columnName)) { + /* See if all the columns in "from" table exist in "to" table */ + foreach ($toTableColumns as $columnName => $column) { + if ($fromTable->hasColumn($columnName)) { continue; } @@ -213,23 +213,23 @@ public function diffTable(Table $table1, Table $table2) $changes++; } - /* See if there are any removed columns in table 2 */ - foreach ($table1Columns as $columnName => $column) { - // See if column is removed in table 2. - if (! $table2->hasColumn($columnName)) { + /* See if there are any removed columns in "to" table */ + foreach ($fromTableColumns as $columnName => $column) { + // See if column is removed in "to" table. + if (! $toTable->hasColumn($columnName)) { $tableDifferences->removedColumns[$columnName] = $column; $changes++; continue; } - // See if column has changed properties in table 2. - $changedProperties = $this->diffColumn($column, $table2->getColumn($columnName)); + // See if column has changed properties in "to" table. + $changedProperties = $this->diffColumn($column, $toTable->getColumn($columnName)); if (empty($changedProperties)) { continue; } - $columnDiff = new ColumnDiff($column->getName(), $table2->getColumn($columnName), $changedProperties); + $columnDiff = new ColumnDiff($column->getName(), $toTable->getColumn($columnName), $changedProperties); $columnDiff->fromColumn = $column; $tableDifferences->changedColumns[$column->getName()] = $columnDiff; @@ -238,12 +238,12 @@ public function diffTable(Table $table1, Table $table2) $this->detectColumnRenamings($tableDifferences); - $table1Indexes = $table1->getIndexes(); - $table2Indexes = $table2->getIndexes(); + $fromTableIndexes = $fromTable->getIndexes(); + $toTableIndexes = $toTable->getIndexes(); - /* See if all the indexes in table 1 exist in table 2 */ - foreach ($table2Indexes as $indexName => $index) { - if (($index->isPrimary() && $table1->hasPrimaryKey()) || $table1->hasIndex($indexName)) { + /* See if all the indexes in "from" table exist in "to" table */ + foreach ($toTableIndexes as $indexName => $index) { + if (($index->isPrimary() && $fromTable->hasPrimaryKey()) || $fromTable->hasIndex($indexName)) { continue; } @@ -251,56 +251,56 @@ public function diffTable(Table $table1, Table $table2) $changes++; } - /* See if there are any removed indexes in table 2 */ - foreach ($table1Indexes as $indexName => $index) { - // See if index is removed in table 2. + /* See if there are any removed indexes in "to" table */ + foreach ($fromTableIndexes as $indexName => $index) { + // See if index is removed in "to" table. if ( - ($index->isPrimary() && ! $table2->hasPrimaryKey()) || - ! $index->isPrimary() && ! $table2->hasIndex($indexName) + ($index->isPrimary() && ! $toTable->hasPrimaryKey()) || + ! $index->isPrimary() && ! $toTable->hasIndex($indexName) ) { $tableDifferences->removedIndexes[$indexName] = $index; $changes++; continue; } - // See if index has changed in table 2. - $table2Index = $index->isPrimary() ? $table2->getPrimaryKey() : $table2->getIndex($indexName); - assert($table2Index instanceof Index); + // See if index has changed in "to" table. + $toTableIndex = $index->isPrimary() ? $toTable->getPrimaryKey() : $toTable->getIndex($indexName); + assert($toTableIndex instanceof Index); - if (! $this->diffIndex($index, $table2Index)) { + if (! $this->diffIndex($index, $toTableIndex)) { continue; } - $tableDifferences->changedIndexes[$indexName] = $table2Index; + $tableDifferences->changedIndexes[$indexName] = $toTableIndex; $changes++; } $this->detectIndexRenamings($tableDifferences); - $fromFkeys = $table1->getForeignKeys(); - $toFkeys = $table2->getForeignKeys(); + $fromForeignKeys = $fromTable->getForeignKeys(); + $toForeignKeys = $toTable->getForeignKeys(); - foreach ($fromFkeys as $key1 => $constraint1) { - foreach ($toFkeys as $key2 => $constraint2) { - if ($this->diffForeignKey($constraint1, $constraint2) === false) { - unset($fromFkeys[$key1], $toFkeys[$key2]); + foreach ($fromForeignKeys as $fromKey => $fromConstraint) { + foreach ($toForeignKeys as $toKey => $toConstraint) { + if ($this->diffForeignKey($fromConstraint, $toConstraint) === false) { + unset($fromForeignKeys[$fromKey], $toForeignKeys[$toKey]); } else { - if (strtolower($constraint1->getName()) === strtolower($constraint2->getName())) { - $tableDifferences->changedForeignKeys[] = $constraint2; + if (strtolower($fromConstraint->getName()) === strtolower($toConstraint->getName())) { + $tableDifferences->changedForeignKeys[] = $toConstraint; $changes++; - unset($fromFkeys[$key1], $toFkeys[$key2]); + unset($fromForeignKeys[$fromKey], $toForeignKeys[$toKey]); } } } } - foreach ($fromFkeys as $constraint1) { - $tableDifferences->removedForeignKeys[] = $constraint1; + foreach ($fromForeignKeys as $fromConstraint) { + $tableDifferences->removedForeignKeys[] = $fromConstraint; $changes++; } - foreach ($toFkeys as $constraint2) { - $tableDifferences->addedForeignKeys[] = $constraint2; + foreach ($toForeignKeys as $toConstraint) { + $tableDifferences->addedForeignKeys[] = $toConstraint; $changes++; }