Rollback awareness.

Tasks are aware if they are in rollbacks; they will be invoked only if
they implement the new interface RollbackAware.
This commit is contained in:
Andrs Montaez
2012-01-03 23:25:42 -02:00
parent 01cbd0e447
commit 9cf720c602
9 changed files with 70 additions and 23 deletions
+17 -13
View File
@@ -72,24 +72,28 @@ class Mage_Task_BuiltIn_Releases_Rollback
} else {
foreach ($tasksToRun as $taskName) {
$tasks++;
$task = Mage_Task_Factory::get($taskName, $this->_config);
$task->init();
Mage_Console::output('Running <purple>' . $task->getName() . '</purple> ... ', 2, false);
$result = $task->run();
if ($result == true) {
Mage_Console::output('<green>OK</green>', 0);
$completedTasks++;
} else {
Mage_Console::output('<red>FAIL</red>', 0);
$task = Mage_Task_Factory::get($taskName, $this->_config, true);
$task->init();
Mage_Console::output('Running <purple>' . $task->getName() . '</purple> ... ', 2, false);
if ($task instanceOf Mage_Task_Releases_RollbackAware) {
$tasks++;
$result = $task->run();
if ($result == true) {
Mage_Console::output('<green>OK</green>', 0);
$completedTasks++;
} else {
Mage_Console::output('<red>FAIL</red>', 0);
}
} else {
Mage_Console::output('<yellow>SKIPPED</yellow>', 0);
}
}
}
// Changing Release
Mage_Console::output('Releasing to <dark_gray>' . $releaseId . '</dark_gray> ... ', 2, false);
Mage_Console::output('Running <purple>Rollback Release [id=' . $releaseId . ']</purple> ... ', 2, false);
$userGroup = '';
$resultFetch = $this->_runRemoteCommand('ls -ld ' . $rollbackTo . ' | awk \'{print \$3\":\"\$4}\'', $userGroup);
+4 -3
View File
@@ -5,21 +5,22 @@ class Mage_Task_Factory
*
*
* @param string $taskName
* @param boolean $inRollback
* @return Mage_Task_TaskAbstract
*/
public static function get($taskName, Mage_Config $taskConfig)
public static function get($taskName, Mage_Config $taskConfig, $inRollback = false)
{
$instance = null;
if (strpos($taskName, '/') === false) {
Mage_Autoload::loadUserTask($taskName);
$className = 'Task_' . ucfirst($taskName);
$instance = new $className($taskConfig);
$instance = new $className($taskConfig, $inRollback);
} else {
$taskName = str_replace(' ', '_', ucwords(str_replace('/', ' ', $taskName)));
$className = 'Mage_Task_BuiltIn_' . $taskName;
$instance = new $className($taskConfig);
$instance = new $className($taskConfig, $inRollback);
}
assert($instance instanceOf Mage_Task_TaskAbstract);
-6
View File
@@ -57,10 +57,4 @@ class Mage_Task_Releases
}
}
}
private function _listReleases()
{
}
}
+4
View File
@@ -0,0 +1,4 @@
<?php
interface Mage_Task_Releases_RollbackAware
{
}
+8 -1
View File
@@ -2,14 +2,21 @@
abstract class Mage_Task_TaskAbstract
{
protected $_config = null;
protected $_inRollback = false;
public abstract function getName();
public abstract function run();
public final function __construct(Mage_Config $config)
public final function __construct(Mage_Config $config, $inRollback = false)
{
$this->_config = $config;
$this->_inRollback = $inRollback;
}
public function inRollback()
{
return $this->_inRollback;
}
public function init()