Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
D
doctrine-dbal
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Tomáš Trávníček
doctrine-dbal
Commits
446a2ea7
Commit
446a2ea7
authored
Feb 13, 2010
by
beberlei
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
[2.0] DDC-327 - Always Deep Clone all Schema Assets
parent
49d2dd9b
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
59 additions
and
0 deletions
+59
-0
Schema.php
lib/Doctrine/DBAL/Schema/Schema.php
+15
-0
Table.php
lib/Doctrine/DBAL/Schema/Table.php
+17
-0
SchemaTest.php
tests/Doctrine/Tests/DBAL/Schema/SchemaTest.php
+27
-0
No files found.
lib/Doctrine/DBAL/Schema/Schema.php
View file @
446a2ea7
...
...
@@ -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
;
}
}
}
lib/Doctrine/DBAL/Schema/Table.php
View file @
446a2ea7
...
...
@@ -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
);
}
}
}
\ No newline at end of file
tests/Doctrine/Tests/DBAL/Schema/SchemaTest.php
View file @
446a2ea7
...
...
@@ -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'
));
}
}
\ No newline at end of file
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment