[2.0] DDC-327 - Always Deep Clone all Schema Assets
This commit is contained in:
parent
49d2dd9bf2
commit
446a2ea7bb
@ -309,4 +309,19 @@ class Schema extends AbstractAsset
|
||||
$sequence->visit($visitor);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Cloning a Schema triggers a deep clone of all related assets.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function __clone()
|
||||
{
|
||||
foreach ($this->_tables AS $k => $table) {
|
||||
$this->_tables[$k] = clone $table;
|
||||
}
|
||||
foreach ($this->_sequences AS $k => $sequence) {
|
||||
$this->_sequences[$k] = clone $sequence;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -620,4 +620,21 @@ class Table extends AbstractAsset
|
||||
$visitor->acceptForeignKey($this, $constraint);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Clone of a Table triggers a deep clone of all affected assets
|
||||
*/
|
||||
public function __clone()
|
||||
{
|
||||
foreach ($this->_columns AS $k => $column) {
|
||||
$this->_columns[$k] = clone $column;
|
||||
}
|
||||
foreach ($this->_indexes AS $k => $index) {
|
||||
$this->_indexes[$k] = clone $index;
|
||||
}
|
||||
foreach ($this->_fkConstraints AS $k => $fk) {
|
||||
$this->_fkConstraints[$k] = clone $fk;
|
||||
$this->_fkConstraints[$k]->setLocalTable($this);
|
||||
}
|
||||
}
|
||||
}
|
@ -212,4 +212,31 @@ class SchemaTest extends \PHPUnit_Framework_TestCase
|
||||
|
||||
$this->assertTrue($table->hasIndex('le_id_idx'));
|
||||
}
|
||||
|
||||
public function testDeepClone()
|
||||
{
|
||||
$schema = new Schema();
|
||||
$sequence = $schema->createSequence('baz');
|
||||
|
||||
$tableA = $schema->createTable('foo');
|
||||
$tableA->createColumn('id', 'integer');
|
||||
|
||||
$tableB = $schema->createTable('bar');
|
||||
$tableB->createColumn('id', 'integer');
|
||||
$tableB->createcolumn('foo_id', 'integer');
|
||||
$tableB->addForeignKeyConstraint($tableA, array('foo_id'), array('id'));
|
||||
|
||||
$schemaNew = clone $schema;
|
||||
|
||||
$this->assertNotSame($sequence, $schemaNew->getSequence('baz'));
|
||||
|
||||
$this->assertNotSame($tableA, $schemaNew->getTable('foo'));
|
||||
$this->assertNotSame($tableA->getColumn('id'), $schemaNew->getTable('foo')->getColumn('id'));
|
||||
|
||||
$this->assertNotSame($tableB, $schemaNew->getTable('bar'));
|
||||
$this->assertNotSame($tableB->getColumn('id'), $schemaNew->getTable('bar')->getColumn('id'));
|
||||
|
||||
$fk = current( $schemaNew->getTable('bar')->getForeignKeys() );
|
||||
$this->assertSame($schemaNew->getTable('bar'), $this->readAttribute($fk, '_localTable'));
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user