Skip to content
Permalink
Browse files

Drop fixtures inside a key disabled transaction.

Dropping tables with foreign keys is complicated, by putting it in
a transaction and disabling keys we can have a much simpler time of
removing fixtures using foreign keys.
  • Loading branch information...
markstory committed Sep 5, 2014
1 parent 3e143d9 commit c0a5a1e06f36f3aaaadecd472c11eca903665495
Showing with 12 additions and 8 deletions.
  1. +12 −8 src/TestSuite/Fixture/FixtureManager.php
@@ -278,7 +278,7 @@ public function unload($test) {
$db = ConnectionManager::get($connection, false);
$db->transactional(function($db) use ($fixtures, $connection) {
$db->disableForeignKeys();
foreach ($fixtures as $f) {
foreach ($fixtures as $fixture) {
if (!empty($fixture->created) && in_array($connection, $fixture->created)) {
$fixture->truncate($db);
}
@@ -322,14 +322,18 @@ public function loadSingle($name, $db = null, $dropTables = true) {
* @return void
*/
public function shutDown() {
foreach ($this->_loaded as $fixture) {
if (!empty($fixture->created)) {
foreach ($fixture->created as $ds) {
$db = ConnectionManager::get($ds);
$fixture->drop($db);
$dbs = $this->_fixtureConnections(array_keys($this->_loaded));
foreach ($dbs as $connection => $fixtures) {
$db = ConnectionManager::get($connection, false);
$db->transactional(function($db) use ($fixtures, $connection) {
$db->disableForeignKeys();
foreach ($fixtures as $fixture) {
if (!empty($fixture->created) && in_array($connection, $fixture->created)) {
$fixture->drop($db);
}
}
$fixture->created = [];
}
$db->enableForeignKeys();
});
}
}

0 comments on commit c0a5a1e

Please sign in to comment.
You can’t perform that action at this time.