From 0f174685534b1b86fd2c8c9a4ce3e894a3917afa Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andr=C3=A9s=20Monta=C3=B1ez?= Date: Thu, 19 Dec 2013 15:37:26 -0200 Subject: [PATCH] Cleanup for SensioLabs Insights. --- Mage/Command/BuiltIn/ReleasesCommand.php | 4 ++-- Mage/Command/Factory.php | 1 + Mage/Console.php | 15 +++++++++------ Mage/Mailer.php | 2 +- Mage/Task/BuiltIn/Deployment/ReleaseTask.php | 16 ++++++++++------ .../BuiltIn/Deployment/Strategy/RsyncTask.php | 4 ++-- .../BuiltIn/Deployment/Strategy/TarGzTask.php | 4 ++-- Mage/Task/BuiltIn/Releases/RollbackTask.php | 9 ++++++--- Mage/Task/Factory.php | 1 + 9 files changed, 34 insertions(+), 22 deletions(-) diff --git a/Mage/Command/BuiltIn/ReleasesCommand.php b/Mage/Command/BuiltIn/ReleasesCommand.php index d47c99a..552569c 100644 --- a/Mage/Command/BuiltIn/ReleasesCommand.php +++ b/Mage/Command/BuiltIn/ReleasesCommand.php @@ -24,8 +24,6 @@ use Exception; */ class ReleasesCommand extends AbstractCommand implements RequiresEnvironment { - private $release = null; - /** * List the Releases, Rollback to a Release * @see \Mage\Command\AbstractCommand::run() @@ -66,5 +64,7 @@ class ReleasesCommand extends AbstractCommand implements RequiresEnvironment } } } + + return $result; } } \ No newline at end of file diff --git a/Mage/Command/Factory.php b/Mage/Command/Factory.php index 7e6b322..56b350a 100644 --- a/Mage/Command/Factory.php +++ b/Mage/Command/Factory.php @@ -10,6 +10,7 @@ namespace Mage\Command; +use Mage\Command\AbstractCommand; use Mage\Config; use Mage\Autoload; diff --git a/Mage/Console.php b/Mage/Console.php index 1e5f6d6..7436de3 100644 --- a/Mage/Console.php +++ b/Mage/Console.php @@ -10,6 +10,11 @@ namespace Mage; +use Mage\Config; +use Mage\Command\Factory; +use Mage\Command\RequiresEnvironment; +use Mage\Console\Colors; + use Exception; use RecursiveDirectoryIterator; @@ -78,7 +83,6 @@ class Console // Load Config $config = self::$config = new Config; $config->load($arguments); - $configLoadedOk = true; } catch (Exception $exception) { $configError = $exception->getMessage(); @@ -108,9 +112,9 @@ class Console } else { // Run Command and check for Command Requirements try { - $command = Command\Factory::get($commandName, $config); + $command = Factory::get($commandName, $config); - if ($command instanceOf Command\RequiresEnvironment) { + if ($command instanceOf RequiresEnvironment) { if ($config->getEnvironment() == false) { throw new Exception('You must specify an environment for this command.'); } @@ -149,7 +153,7 @@ class Console . str_repeat(PHP_EOL, $newLine); $output = str_repeat("\t", $tabs) - . Console\Colors::color($message, self::$config) + . Colors::color($message, self::$config) . str_repeat(PHP_EOL, $newLine); echo $output; @@ -187,9 +191,8 @@ class Console * Log a message to the logfile. * * @param string $message - * @param boolean $continuation */ - public static function log($message, $continuation = false) + public static function log($message) { if (self::$logEnabled) { if (self::$log == null) { diff --git a/Mage/Mailer.php b/Mage/Mailer.php index 6fdcfe7..48b9fa2 100644 --- a/Mage/Mailer.php +++ b/Mage/Mailer.php @@ -87,6 +87,6 @@ class Mailer . '--Mage-mixed-' . $boundary . '--' . self::EOL ; - $mail_sent = @mail($this->address, $subject, $message, $headers); + @mail($this->address, $subject, $message, $headers); } } \ No newline at end of file diff --git a/Mage/Task/BuiltIn/Deployment/ReleaseTask.php b/Mage/Task/BuiltIn/Deployment/ReleaseTask.php index c09ba3a..512416b 100644 --- a/Mage/Task/BuiltIn/Deployment/ReleaseTask.php +++ b/Mage/Task/BuiltIn/Deployment/ReleaseTask.php @@ -49,17 +49,21 @@ class ReleaseTask extends AbstractTask implements IsReleaseAware, SkipOnOverride $currentCopy = $releasesDirectory . '/' . $this->getConfig()->getReleaseId(); // Fetch the user and group from base directory; defaults usergroup to 33:33 - $userGroup = '33:33'; + $userGroup = ''; $resultFetch = $this->runCommandRemote('ls -ld . | awk \'{print \$3":"\$4}\'', $userGroup); // Remove symlink if exists; create new symlink and change owners $command = 'rm -f ' . $symlink . ' ; ' - . 'ln -sf ' . $currentCopy . ' ' . $symlink - . ' && ' - . 'chown -h ' . $userGroup . ' ' . $symlink - . ' && ' - . 'chown -R ' . $userGroup . ' ' . $currentCopy; + . 'ln -sf ' . $currentCopy . ' ' . $symlink; + + if ($resultFetch && $userGroup != '') { + $command .= ' && ' + . 'chown -h ' . $userGroup . ' ' . $symlink + . ' && ' + . 'chown -R ' . $userGroup . ' ' . $currentCopy; + } + $result = $this->runCommandRemote($command); // Set Directory Releases to same owner diff --git a/Mage/Task/BuiltIn/Deployment/Strategy/RsyncTask.php b/Mage/Task/BuiltIn/Deployment/Strategy/RsyncTask.php index 4d670a5..1024149 100644 --- a/Mage/Task/BuiltIn/Deployment/Strategy/RsyncTask.php +++ b/Mage/Task/BuiltIn/Deployment/Strategy/RsyncTask.php @@ -50,7 +50,7 @@ class RsyncTask extends AbstractTask implements IsReleaseAware if ($overrideRelease == true) { $releaseToOverride = false; $resultFetch = $this->runCommandRemote('ls -ld current | cut -d"/" -f2', $releaseToOverride); - if (is_numeric($releaseToOverride)) { + if ($resultFetch && is_numeric($releaseToOverride)) { $this->getConfig()->setReleaseId($releaseToOverride); } } @@ -101,7 +101,7 @@ class RsyncTask extends AbstractTask implements IsReleaseAware $countReleasesFetch = $this->runCommandRemote('ls -1 ' . $releasesDirectory, $releasesList); $releasesList = trim($releasesList); - if ($releasesList != '') { + if ($countReleasesFetch && $releasesList != '') { $releasesList = explode(PHP_EOL, $releasesList); if (count($releasesList) > $maxReleases) { $releasesToDelete = array_diff($releasesList, array($this->getConfig()->getReleaseId())); diff --git a/Mage/Task/BuiltIn/Deployment/Strategy/TarGzTask.php b/Mage/Task/BuiltIn/Deployment/Strategy/TarGzTask.php index c4b38c3..034dbdc 100644 --- a/Mage/Task/BuiltIn/Deployment/Strategy/TarGzTask.php +++ b/Mage/Task/BuiltIn/Deployment/Strategy/TarGzTask.php @@ -50,7 +50,7 @@ class TarGzTask extends AbstractTask implements IsReleaseAware if ($overrideRelease == true) { $releaseToOverride = false; $resultFetch = $this->runCommandRemote('ls -ld current | cut -d"/" -f2', $releaseToOverride); - if (is_numeric($releaseToOverride)) { + if ($resultFetch && is_numeric($releaseToOverride)) { $this->getConfig()->setReleaseId($releaseToOverride); } } @@ -136,7 +136,7 @@ class TarGzTask extends AbstractTask implements IsReleaseAware $countReleasesFetch = $this->runCommandRemote('ls -1 ' . $releasesDirectory, $releasesList); $releasesList = trim($releasesList); - if ($releasesList != '') { + if ($countReleasesFetch && $releasesList != '') { $releasesList = explode(PHP_EOL, $releasesList); if (count($releasesList) > $maxReleases) { $releasesToDelete = array_diff($releasesList, array($this->getConfig()->getReleaseId())); diff --git a/Mage/Task/BuiltIn/Releases/RollbackTask.php b/Mage/Task/BuiltIn/Releases/RollbackTask.php index e130d2e..0c33bf8 100644 --- a/Mage/Task/BuiltIn/Releases/RollbackTask.php +++ b/Mage/Task/BuiltIn/Releases/RollbackTask.php @@ -138,9 +138,12 @@ class RollbackTask extends AbstractTask implements IsReleaseAware $resultFetch = $this->runCommandRemote('ls -ld ' . $rollbackTo . ' | awk \'{print \$3":"\$4}\'', $userGroup); $command = 'rm -f ' . $symlink . ' && ' - . 'ln -sf ' . $rollbackTo . ' ' . $symlink - . ' && ' - . 'chown -h ' . $userGroup . ' ' . $symlink; + . 'ln -sf ' . $rollbackTo . ' ' . $symlink; + + if ($resultFetch) { + $command .= ' && chown -h ' . $userGroup . ' ' . $symlink; + } + $result = $this->runCommandRemote($command); if ($result) { diff --git a/Mage/Task/Factory.php b/Mage/Task/Factory.php index eff0fb0..6a0b0eb 100644 --- a/Mage/Task/Factory.php +++ b/Mage/Task/Factory.php @@ -13,6 +13,7 @@ namespace Mage\Task; use Mage\Config; use Mage\Autoload; use Mage\Task\ErrorWithMessageException; +use Mage\Task\AbstractTask; use Exception;