|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
/** |
|
4
|
|
|
* This dispatcher takes care of updating and returning information about this |
|
5
|
|
|
* projects git repository |
|
6
|
|
|
*/ |
|
7
|
|
|
class DeployDispatcher extends Dispatcher { |
|
8
|
|
|
|
|
9
|
|
|
const ACTION_DEPLOY = 'deploy'; |
|
10
|
|
|
|
|
11
|
|
|
/** |
|
12
|
|
|
* @var array |
|
13
|
|
|
*/ |
|
14
|
|
|
private static $action_types = [ |
|
15
|
|
|
self::ACTION_DEPLOY |
|
16
|
|
|
]; |
|
17
|
|
|
|
|
18
|
|
|
/** |
|
19
|
|
|
* @var array |
|
20
|
|
|
*/ |
|
21
|
|
|
public static $allowed_actions = [ |
|
22
|
|
|
'history' |
|
23
|
|
|
]; |
|
24
|
|
|
|
|
25
|
|
|
/** |
|
26
|
|
|
* @var \DNProject |
|
27
|
|
|
*/ |
|
28
|
|
|
protected $project = null; |
|
29
|
|
|
|
|
30
|
|
|
/** |
|
31
|
|
|
* @var \DNEnvironment |
|
32
|
|
|
*/ |
|
33
|
|
|
protected $environment = null; |
|
34
|
|
|
|
|
35
|
|
|
public function init() { |
|
36
|
|
|
parent::init(); |
|
37
|
|
|
|
|
38
|
|
|
$this->project = $this->getCurrentProject(); |
|
39
|
|
|
|
|
40
|
|
|
if(!$this->project) { |
|
41
|
|
|
return $this->project404Response(); |
|
42
|
|
|
} |
|
43
|
|
|
} |
|
44
|
|
|
|
|
45
|
|
|
/** |
|
46
|
|
|
* |
|
47
|
|
|
* @param \SS_HTTPRequest $request |
|
48
|
|
|
* |
|
49
|
|
|
* @return \HTMLText|\SS_HTTPResponse |
|
50
|
|
|
*/ |
|
51
|
|
|
public function index(\SS_HTTPRequest $request) { |
|
52
|
|
|
return $this->redirect(\Controller::join_links($this->Link(), 'history'), 302); |
|
53
|
|
|
} |
|
54
|
|
|
|
|
55
|
|
|
/** |
|
56
|
|
|
* @return SS_HTTPResponse |
|
57
|
|
|
*/ |
|
58
|
|
|
public function history(SS_HTTPRequest $request) { |
|
59
|
|
|
$data = []; |
|
60
|
|
|
foreach($this->DeployHistory() as $deployment) { |
|
|
|
|
|
|
61
|
|
|
$data[] = [ |
|
62
|
|
|
'CreatedDate' => $deployment->Created, |
|
63
|
|
|
'Branch' => $deployment->Branch, |
|
64
|
|
|
'Tags' => $deployment->getTags()->toArray(), |
|
65
|
|
|
'Changes' => $deployment->getDeploymentStrategy()->getChanges(), |
|
66
|
|
|
'CommitMessage' => $deployment->getCommitMessage(), |
|
67
|
|
|
'Deployer' => $deployment->Deployer()->getName(), |
|
68
|
|
|
'Approver' => $deployment->Approver()->getName(), |
|
69
|
|
|
'State' => $deployment->State, |
|
70
|
|
|
]; |
|
71
|
|
|
} |
|
72
|
|
|
return $this->getAPIResponse(['history' => $data], 200); |
|
73
|
|
|
} |
|
74
|
|
|
|
|
75
|
|
|
/** |
|
76
|
|
|
* @return string |
|
77
|
|
|
*/ |
|
78
|
|
|
public function Link() { |
|
79
|
|
|
return \Controller::join_links($this->project->Link(), self::ACTION_DEPLOY); |
|
80
|
|
|
} |
|
81
|
|
|
|
|
82
|
|
|
/** |
|
83
|
|
|
* @param string $name |
|
84
|
|
|
* |
|
85
|
|
|
* @return array |
|
86
|
|
|
*/ |
|
87
|
|
|
public function getModel($name = '') { |
|
88
|
|
|
return []; |
|
89
|
|
|
} |
|
90
|
|
|
|
|
91
|
|
|
} |
|
92
|
|
|
|
There are different options of fixing this problem.
If you want to be on the safe side, you can add an additional type-check:
If you are sure that the expression is traversable, you might want to add a doc comment cast to improve IDE auto-completion and static analysis:
Mark the issue as a false-positive: Just hover the remove button, in the top-right corner of this issue for more options.