From 64547a253b3def10dd494705c7c710661644a367 Mon Sep 17 00:00:00 2001 From: "Paul L. McNeely" Date: Thu, 16 Feb 2017 14:38:30 -0600 Subject: [PATCH] Added Setup, cleanup, transaction_setup, transaction_cleanup, pretransaction_up/down, postcommit_up/down. --- lib/Task/Db/Migrate.php | 43 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 43 insertions(+) diff --git a/lib/Task/Db/Migrate.php b/lib/Task/Db/Migrate.php index c7da42a6..8a75126b 100644 --- a/lib/Task/Db/Migrate.php +++ b/lib/Task/Db/Migrate.php @@ -247,12 +247,55 @@ private function run_migrations($migrations, $target_method, $destination) $obj = new $klass($this->_adapter); $start = $this->start_timer(); try { + /* + * Run up or down, before transaction start + * This allows commands to run on both up and down to be set in one place. + */ + if(method_exists($obj, "setup")) { + $obj->setup(); + } + + /* + * Run up or down, before transaction + * This allows for commands that can't run in transactions + */ + $method = "pretransaction_" . $target_method; + if(method_exists($obj, $method)) { + $result = $obj->$method(); + } + //start transaction $this->_adapter->start_transaction(); + + //Run up or down, after transaction start + if(method_exists($obj, "transaction_setup")) { + $obj->transaction_setup(); + } $result = $obj->$target_method(); //successfully ran migration, update our version and commit $this->_migrator_util->resolve_current_version($file['version'], $target_method); + + //Run up or down, before transaction commit + if(method_exists($obj, "transaction_cleanup")) { + $obj->transaction_cleanup(); + } + $this->_adapter->commit_transaction(); + + //Run up or down, after commit + $method = "postcommit_" . $target_method; + if(method_exists($obj, $method)) { + $result = $obj->$method(); + } + + /* + * Run up or down, after transaction end + * This allows commands to run on both up and down to be set in one place. + */ + if(method_exists($obj, "cleanup")) { + $obj->cleanup(); + } + } catch (Ruckusing_Exception $e) { $this->_adapter->rollback_transaction(); //wrap the caught exception in our own