_releaseId = date('YmdHis');
}
public function run(Mage_Config $config)
{
$this->_config = $config;
// Run Pre-Deployment Tasks
$this->_runNonDeploymentTasks('pre', $config);
// Run Tasks for Deployment
$hosts = $config->getHosts();
if (count($hosts) == 0) {
Mage_Console::output('Warning! No hosts defined, skipping deployment tasks.', 1, 3);
} else {
foreach ($hosts as $host) {
$taskConfig = $config->getConfig($host);
$tasks = 0;
$completedTasks = 0;
Mage_Console::output('Deploying to ' . $host . '');
$tasksToRun = $config->getTasks();
if (isset($taskConfig['deploy']['releases'])) {
if (isset($taskConfig['deploy']['releases']['enabled'])) {
if ($taskConfig['deploy']['releases']['enabled'] == 'true') {
$taskConfig['deploy']['releases']['_id'] = $this->_releaseId;
array_push($tasksToRun, 'deployment/releases');
}
}
}
if (count($tasksToRun) == 0) {
Mage_Console::output('Warning! No Deployment tasks defined.', 2);
Mage_Console::output('Deployment to ' . $host . ' skipped!', 1, 3);
} else {
foreach ($tasksToRun as $taskName) {
$tasks++;
$task = Mage_Task_Factory::get($taskName, $taskConfig);
$task->init();
Mage_Console::output('Running ' . $task->getName() . ' ... ', 2, false);
$result = $task->run();
if ($result == true) {
Mage_Console::output('OK', 0);
$completedTasks++;
} else {
Mage_Console::output('FAIL', 0);
}
}
if ($completedTasks == $tasks) {
$tasksColor = 'green';
} else {
$tasksColor = 'red';
}
Mage_Console::output('Deployment to ' . $host . ' compted: <' . $tasksColor . '>' . $completedTasks . '/' . $tasks . '' . $tasksColor . '> tasks done.', 1, 3);
}
}
}
// Run Post-Deployment Tasks
$this->_runNonDeploymentTasks('post', $config);
}
private function _runNonDeploymentTasks($type, Mage_Config $config)
{
$tasksToRun = $config->getTasks($type);
if (count($tasksToRun) == 0) {
Mage_Console::output('No ' . ucfirst($type) . '-Deployment tasks defined.', 1, 3);
} else {
Mage_Console::output('Starting ' . ucfirst($type) . '-Deployment tasks:');
$taskConfig = $config->getConfig();
$tasks = 0;
$completedTasks = 0;
foreach ($tasksToRun as $taskName) {
$tasks++;
$task = Mage_Task_Factory::get($taskName, $taskConfig);
$task->init();
Mage_Console::output('Running ' . $task->getName() . ' ... ', 2, false);
$result = $task->run();
if ($result == true) {
Mage_Console::output('OK', 0);
$completedTasks++;
} else {
Mage_Console::output('FAIL', 0);
}
}
if ($completedTasks == $tasks) {
$tasksColor = 'green';
} else {
$tasksColor = 'red';
}
Mage_Console::output('Finished ' . ucfirst($type) . '-Deployment tasks: <' . $tasksColor . '>' . $completedTasks . '/' . $tasks . '' . $tasksColor . '> tasks done.', 1, 3);
}
}
}