magallanes/Mage/Command/BuiltIn/ReleasesCommand.php

97 lines
2.9 KiB
PHP
Raw Normal View History

2012-01-01 16:36:41 +01:00
<?php
2013-11-05 17:12:09 +01:00
/*
* This file is part of the Magallanes package.
*
* (c) Andrés Montañez <andres@andresmontanez.com>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace Mage\Command\BuiltIn;
use Mage\Command\AbstractCommand;
use Mage\Command\RequiresEnvironment;
use Mage\Task\Factory;
use Mage\Console;
/**
* Command for Managing the Releases
*
* @author Andrés Montañez <andres@andresmontanez.com>
*/
class ReleasesCommand extends AbstractCommand implements RequiresEnvironment
2012-01-01 16:36:41 +01:00
{
/**
* List the Releases, Rollback to a Release
* @see \Mage\Command\AbstractCommand::run()
*/
public function run()
2012-01-01 16:36:41 +01:00
{
2014-11-01 22:19:05 +01:00
$exitCode = 100;
$subCommand = $this->getConfig()->getArgument(1);
2012-01-01 16:36:41 +01:00
// Run Tasks for Deployment
$hosts = $this->getConfig()->getHosts();
2012-01-01 16:36:41 +01:00
if (count($hosts) == 0) {
Console::output(
2014-11-01 22:31:04 +01:00
'<light_purple>Warning!</light_purple> <bold>No hosts defined, unable to get releases.</bold>',
1, 3
);
2014-11-01 22:19:05 +01:00
return 101;
}
2014-08-07 02:43:29 +02:00
$result = true;
2014-11-01 22:09:25 +01:00
foreach ($hosts as $hostKey => $host) {
// Check if Host has specific configuration
$hostConfig = null;
if (is_array($host)) {
$hostConfig = $host;
$host = $hostKey;
}
// Set Host and Host Specific Config
$this->getConfig()->setHost($host);
2014-11-01 22:09:25 +01:00
$this->getConfig()->setHostConfig($hostConfig);
switch ($subCommand) {
2014-08-06 19:01:39 +02:00
case 'list':
$task = Factory::get('releases/list', $this->getConfig());
$task->init();
2014-08-07 02:43:29 +02:00
$result = $task->run() && $result;
2014-08-06 19:01:39 +02:00
break;
2014-08-06 19:01:39 +02:00
case 'rollback':
if (!is_numeric($this->getConfig()->getParameter('release', ''))) {
Console::output('<red>Missing required releaseid.</red>', 1, 2);
2014-11-01 22:19:05 +01:00
return 102;
2014-08-06 19:01:39 +02:00
}
2014-08-06 19:01:39 +02:00
$lockFile = getcwd() . '/.mage/' . $this->getConfig()->getEnvironment() . '.lock';
if (file_exists($lockFile)) {
Console::output('<red>This environment is locked!</red>', 1, 2);
echo file_get_contents($lockFile);
2014-11-01 22:19:05 +01:00
return 103;
2014-08-06 19:01:39 +02:00
}
2014-08-06 19:01:39 +02:00
$releaseId = $this->getConfig()->getParameter('release', '');
2014-08-06 19:17:26 +02:00
$this->getConfig()->setReleaseId($releaseId);
2014-08-06 19:01:39 +02:00
$task = Factory::get('releases/rollback', $this->getConfig());
$task->init();
2014-08-07 02:43:29 +02:00
$result = $task->run() && $result;
2014-08-06 19:01:39 +02:00
break;
2012-01-01 16:36:41 +01:00
}
}
2013-12-19 18:37:26 +01:00
2014-08-07 02:43:29 +02:00
if ($result) {
$exitCode = 0;
}
return $exitCode;
2012-01-01 16:36:41 +01:00
}
}