Skip to content

Commit 29bf315

Browse files
authored
Merge pull request #4337 from mvorisek/from_to_instead_1_2
Rename Comparator::diffTable() params - from/to instead of 1/2
2 parents 908cdc6 + 032b602 commit 29bf315

File tree

1 file changed

+44
-44
lines changed

1 file changed

+44
-44
lines changed

lib/Doctrine/DBAL/Schema/Comparator.php

Lines changed: 44 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -188,48 +188,48 @@ public function diffSequence(Sequence $sequence1, Sequence $sequence2)
188188
}
189189

190190
/**
191-
* Returns the difference between the tables $table1 and $table2.
191+
* Returns the difference between the tables $fromTable and $toTable.
192192
*
193193
* If there are no differences this method returns the boolean false.
194194
*
195195
* @return TableDiff|false
196196
*/
197-
public function diffTable(Table $table1, Table $table2)
197+
public function diffTable(Table $fromTable, Table $toTable)
198198
{
199199
$changes = 0;
200-
$tableDifferences = new TableDiff($table1->getName());
201-
$tableDifferences->fromTable = $table1;
200+
$tableDifferences = new TableDiff($fromTable->getName());
201+
$tableDifferences->fromTable = $fromTable;
202202

203-
$table1Columns = $table1->getColumns();
204-
$table2Columns = $table2->getColumns();
203+
$fromTableColumns = $fromTable->getColumns();
204+
$toTableColumns = $toTable->getColumns();
205205

206-
/* See if all the columns in table 1 exist in table 2 */
207-
foreach ($table2Columns as $columnName => $column) {
208-
if ($table1->hasColumn($columnName)) {
206+
/* See if all the columns in "from" table exist in "to" table */
207+
foreach ($toTableColumns as $columnName => $column) {
208+
if ($fromTable->hasColumn($columnName)) {
209209
continue;
210210
}
211211

212212
$tableDifferences->addedColumns[$columnName] = $column;
213213
$changes++;
214214
}
215215

216-
/* See if there are any removed columns in table 2 */
217-
foreach ($table1Columns as $columnName => $column) {
218-
// See if column is removed in table 2.
219-
if (! $table2->hasColumn($columnName)) {
216+
/* See if there are any removed columns in "to" table */
217+
foreach ($fromTableColumns as $columnName => $column) {
218+
// See if column is removed in "to" table.
219+
if (! $toTable->hasColumn($columnName)) {
220220
$tableDifferences->removedColumns[$columnName] = $column;
221221
$changes++;
222222
continue;
223223
}
224224

225-
// See if column has changed properties in table 2.
226-
$changedProperties = $this->diffColumn($column, $table2->getColumn($columnName));
225+
// See if column has changed properties in "to" table.
226+
$changedProperties = $this->diffColumn($column, $toTable->getColumn($columnName));
227227

228228
if (empty($changedProperties)) {
229229
continue;
230230
}
231231

232-
$columnDiff = new ColumnDiff($column->getName(), $table2->getColumn($columnName), $changedProperties);
232+
$columnDiff = new ColumnDiff($column->getName(), $toTable->getColumn($columnName), $changedProperties);
233233

234234
$columnDiff->fromColumn = $column;
235235
$tableDifferences->changedColumns[$column->getName()] = $columnDiff;
@@ -238,69 +238,69 @@ public function diffTable(Table $table1, Table $table2)
238238

239239
$this->detectColumnRenamings($tableDifferences);
240240

241-
$table1Indexes = $table1->getIndexes();
242-
$table2Indexes = $table2->getIndexes();
241+
$fromTableIndexes = $fromTable->getIndexes();
242+
$toTableIndexes = $toTable->getIndexes();
243243

244-
/* See if all the indexes in table 1 exist in table 2 */
245-
foreach ($table2Indexes as $indexName => $index) {
246-
if (($index->isPrimary() && $table1->hasPrimaryKey()) || $table1->hasIndex($indexName)) {
244+
/* See if all the indexes in "from" table exist in "to" table */
245+
foreach ($toTableIndexes as $indexName => $index) {
246+
if (($index->isPrimary() && $fromTable->hasPrimaryKey()) || $fromTable->hasIndex($indexName)) {
247247
continue;
248248
}
249249

250250
$tableDifferences->addedIndexes[$indexName] = $index;
251251
$changes++;
252252
}
253253

254-
/* See if there are any removed indexes in table 2 */
255-
foreach ($table1Indexes as $indexName => $index) {
256-
// See if index is removed in table 2.
254+
/* See if there are any removed indexes in "to" table */
255+
foreach ($fromTableIndexes as $indexName => $index) {
256+
// See if index is removed in "to" table.
257257
if (
258-
($index->isPrimary() && ! $table2->hasPrimaryKey()) ||
259-
! $index->isPrimary() && ! $table2->hasIndex($indexName)
258+
($index->isPrimary() && ! $toTable->hasPrimaryKey()) ||
259+
! $index->isPrimary() && ! $toTable->hasIndex($indexName)
260260
) {
261261
$tableDifferences->removedIndexes[$indexName] = $index;
262262
$changes++;
263263
continue;
264264
}
265265

266-
// See if index has changed in table 2.
267-
$table2Index = $index->isPrimary() ? $table2->getPrimaryKey() : $table2->getIndex($indexName);
268-
assert($table2Index instanceof Index);
266+
// See if index has changed in "to" table.
267+
$toTableIndex = $index->isPrimary() ? $toTable->getPrimaryKey() : $toTable->getIndex($indexName);
268+
assert($toTableIndex instanceof Index);
269269

270-
if (! $this->diffIndex($index, $table2Index)) {
270+
if (! $this->diffIndex($index, $toTableIndex)) {
271271
continue;
272272
}
273273

274-
$tableDifferences->changedIndexes[$indexName] = $table2Index;
274+
$tableDifferences->changedIndexes[$indexName] = $toTableIndex;
275275
$changes++;
276276
}
277277

278278
$this->detectIndexRenamings($tableDifferences);
279279

280-
$fromFkeys = $table1->getForeignKeys();
281-
$toFkeys = $table2->getForeignKeys();
280+
$fromForeignKeys = $fromTable->getForeignKeys();
281+
$toForeignKeys = $toTable->getForeignKeys();
282282

283-
foreach ($fromFkeys as $key1 => $constraint1) {
284-
foreach ($toFkeys as $key2 => $constraint2) {
285-
if ($this->diffForeignKey($constraint1, $constraint2) === false) {
286-
unset($fromFkeys[$key1], $toFkeys[$key2]);
283+
foreach ($fromForeignKeys as $fromKey => $fromConstraint) {
284+
foreach ($toForeignKeys as $toKey => $toConstraint) {
285+
if ($this->diffForeignKey($fromConstraint, $toConstraint) === false) {
286+
unset($fromForeignKeys[$fromKey], $toForeignKeys[$toKey]);
287287
} else {
288-
if (strtolower($constraint1->getName()) === strtolower($constraint2->getName())) {
289-
$tableDifferences->changedForeignKeys[] = $constraint2;
288+
if (strtolower($fromConstraint->getName()) === strtolower($toConstraint->getName())) {
289+
$tableDifferences->changedForeignKeys[] = $toConstraint;
290290
$changes++;
291-
unset($fromFkeys[$key1], $toFkeys[$key2]);
291+
unset($fromForeignKeys[$fromKey], $toForeignKeys[$toKey]);
292292
}
293293
}
294294
}
295295
}
296296

297-
foreach ($fromFkeys as $constraint1) {
298-
$tableDifferences->removedForeignKeys[] = $constraint1;
297+
foreach ($fromForeignKeys as $fromConstraint) {
298+
$tableDifferences->removedForeignKeys[] = $fromConstraint;
299299
$changes++;
300300
}
301301

302-
foreach ($toFkeys as $constraint2) {
303-
$tableDifferences->addedForeignKeys[] = $constraint2;
302+
foreach ($toForeignKeys as $toConstraint) {
303+
$tableDifferences->addedForeignKeys[] = $toConstraint;
304304
$changes++;
305305
}
306306

0 commit comments

Comments
 (0)