diff --git a/Mage/Task/BuiltIn/Releases/RollbackTask.php b/Mage/Task/BuiltIn/Releases/RollbackTask.php
index e5b845d..759c042 100644
--- a/Mage/Task/BuiltIn/Releases/RollbackTask.php
+++ b/Mage/Task/BuiltIn/Releases/RollbackTask.php
@@ -60,6 +60,7 @@ class RollbackTask extends AbstractTask implements IsReleaseAware
} else {
rsort($releases);
+ $deleteCurrent = $this->getConfig()->getParameter('deleteCurrent', false);
$releaseIsAvailable = false;
if ($this->getReleaseId() == '') {
@@ -86,6 +87,13 @@ class RollbackTask extends AbstractTask implements IsReleaseAware
Console::output('Rollback release on ' . $this->getConfig()->getHost() . '');
$rollbackTo = $releasesDirectory . '/' . $releaseId;
+ // Get Current Release
+ if ($deleteCurrent) {
+ $result = $this->runCommandRemote('ls -l ' . $symlink, $output) && $result;
+ $currentRelease = explode('/', $output);
+ $currentRelease = trim(array_pop($currentRelease));
+ }
+
// Tasks
$tasks = 1;
$completedTasks = 0;
@@ -120,8 +128,8 @@ class RollbackTask extends AbstractTask implements IsReleaseAware
$userGroup = '';
$resultFetch = $this->runCommandRemote('ls -ld ' . $rollbackTo . ' | awk \'{print \$3":"\$4}\'', $userGroup);
$command = 'rm -f ' . $symlink
- . ' && '
- . 'ln -sf ' . $rollbackTo . ' ' . $symlink;
+ . ' && '
+ . 'ln -sf ' . $rollbackTo . ' ' . $symlink;
if ($resultFetch) {
$command .= ' && chown -h ' . $userGroup . ' ' . $symlink;
@@ -132,6 +140,11 @@ class RollbackTask extends AbstractTask implements IsReleaseAware
if ($result) {
Console::output('OK', 0);
$completedTasks++;
+
+ // Delete Old Current Release
+ if ($deleteCurrent && $currentRelease) {
+ $this->runCommandRemote('rm -rf ' . $releasesDirectory . '/' . $currentRelease, $output);
+ }
} else {
Console::output('FAIL', 0);
}