This repository has been archived by the owner on Sep 5, 2020. It is now read-only.
/
Rollback.php
82 lines (69 loc) · 2.27 KB
/
Rollback.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
<?php
/*
* This file is part of Rocketeer
*
* (c) Maxime Fabre <ehtnam6@gmail.com>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace Rocketeer\Tasks;
use Rocketeer\Abstracts\AbstractTask;
/**
* Rollback to the previous release, or to a specific one.
*
* @author Maxime Fabre <ehtnam6@gmail.com>
*/
class Rollback extends AbstractTask
{
/**
* The console command description.
*
* @type string
*/
protected $description = 'Rollback to the previous release, or to a specific one';
/**
* Run the task.
*
* @return string|null
*/
public function execute()
{
$releases = $this->releasesManager->getReleases();
// Get previous release
$rollbackRelease = $this->getRollbackRelease();
if (!$rollbackRelease) {
return $this->explainer->error('Rocketeer could not rollback as no releases have yet been deployed');
}
// If no release specified, display the available ones
if ($this->command->option('list')) {
$this->displayReleases();
// Get actual release name from date
$rollbackRelease = $this->command->askWith('Which one do you want to go back to ?', 0);
$rollbackRelease = $releases[$rollbackRelease];
}
// Check if release actually exists
if (!in_array($rollbackRelease, $releases, true)) {
return $this->explainer->error('Unable to find release:'.$rollbackRelease);
}
// Rollback release
$this->updateSymlink($rollbackRelease);
return $this->explainer->success('Rolling back to release '.$rollbackRelease);
}
////////////////////////////////////////////////////////////////////
/////////////////////////////// HELPERS ////////////////////////////
////////////////////////////////////////////////////////////////////
/**
* Get the release to rollback to.
*
* @return int|null
*/
protected function getRollbackRelease()
{
$release = $this->command->argument('release');
if (!$release) {
$release = $this->releasesManager->getPreviousRelease();
}
return (string) $release;
}
}