From 5d39e46d9e957600b381da2082d7d817d6228449 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andr=C3=A9s=20Monta=C3=B1ez?= Date: Sat, 11 Oct 2014 14:36:22 -0200 Subject: [PATCH] Code should not be duplicated --- Mage/Task/BuiltIn/Deployment/ReleaseTask.php | 2 +- .../Strategy/GitRemoteCacheTask.php | 35 ++----------------- 2 files changed, 3 insertions(+), 34 deletions(-) diff --git a/Mage/Task/BuiltIn/Deployment/ReleaseTask.php b/Mage/Task/BuiltIn/Deployment/ReleaseTask.php index bf42643..e44c5d8 100644 --- a/Mage/Task/BuiltIn/Deployment/ReleaseTask.php +++ b/Mage/Task/BuiltIn/Deployment/ReleaseTask.php @@ -133,7 +133,7 @@ class ReleaseTask extends AbstractTask implements IsReleaseAware, SkipOnOverride $directoryToDelete = $releasesDirectory . '/' . $releaseIdToDelete; if ($directoryToDelete != '/') { $command = 'rm -rf ' . $directoryToDelete; - $this->runCommandRemote($command); + $result = $result && $this->runCommandRemote($command); } } } diff --git a/Mage/Task/BuiltIn/Deployment/Strategy/GitRemoteCacheTask.php b/Mage/Task/BuiltIn/Deployment/Strategy/GitRemoteCacheTask.php index 43296c3..fd0869f 100644 --- a/Mage/Task/BuiltIn/Deployment/Strategy/GitRemoteCacheTask.php +++ b/Mage/Task/BuiltIn/Deployment/Strategy/GitRemoteCacheTask.php @@ -97,39 +97,8 @@ class GitRemoteCacheTask extends AbstractTask implements IsReleaseAware $command = 'cd ' . $remoteCacheFolder . ' && /usr/bin/env git archive ' . $branch . ' | tar -x -C ' . $deployToDirectory . ' ' . $excludeCmd; $result = $this->runCommandRemote($command) && $result; - // Count Releases - if ($this->getConfig()->release('enabled', false) == true) { - $releasesDirectory = $this->getConfig()->release('directory', 'releases'); - $symlink = $this->getConfig()->release('symlink', 'current'); - - if (substr($symlink, 0, 1) == '/') { - $releasesDirectory = rtrim($this->getConfig()->deployment('to'), '/') . '/' . $releasesDirectory; - } - - $maxReleases = $this->getConfig()->release('max', false); - if (($maxReleases !== false) && ($maxReleases > 0)) { - $releasesList = ''; - $countReleasesFetch = $this->runCommandRemote('ls -1 ' . $releasesDirectory, $releasesList); - $releasesList = trim($releasesList); - - if ($countReleasesFetch && $releasesList != '') { - $releasesList = explode(PHP_EOL, $releasesList); - if (count($releasesList) > $maxReleases) { - $releasesToDelete = array_diff($releasesList, array($this->getConfig()->getReleaseId())); - sort($releasesToDelete); - $releasesToDeleteCount = count($releasesToDelete) - $maxReleases; - $releasesToDelete = array_slice($releasesToDelete, 0, $releasesToDeleteCount + 1); - - foreach ($releasesToDelete as $releaseIdToDelete) { - $directoryToDelete = $releasesDirectory . '/' . $releaseIdToDelete; - if ($directoryToDelete != '/') { - $command = 'rm -rf ' . $directoryToDelete; - $result = $result && $this->runCommandRemote($command); - } - } - } - } - } + if ($result) { + $this->cleanUpReleases(); } return $result;