1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/** |
4
|
|
|
* This aims to be a simple controller that only kicks off the rendering on the react |
5
|
|
|
* components. It passes a model to the frontend with URLS to dispatchers that takes |
6
|
|
|
* care of various actions, like git fetching, planning, approvals and so on. |
7
|
|
|
*/ |
8
|
|
|
class EnvironmentOverview extends Dispatcher { |
9
|
|
|
|
10
|
|
|
const ACTION_OVERVIEW = 'overview'; |
11
|
|
|
|
12
|
|
|
/** |
13
|
|
|
* @var array |
14
|
|
|
*/ |
15
|
|
|
private static $action_types = [ |
16
|
|
|
self::ACTION_OVERVIEW |
17
|
|
|
]; |
18
|
|
|
|
19
|
|
View Code Duplication |
public function init() { |
|
|
|
|
20
|
|
|
parent::init(); |
21
|
|
|
$this->project = $this->getCurrentProject(); |
|
|
|
|
22
|
|
|
if(!$this->project) { |
|
|
|
|
23
|
|
|
return $this->project404Response(); |
24
|
|
|
} |
25
|
|
|
// Performs canView permission check by limiting visible projects |
26
|
|
|
$this->environment = $this->getCurrentEnvironment($this->project); |
|
|
|
|
27
|
|
|
} |
28
|
|
|
|
29
|
|
|
/** |
30
|
|
|
* |
31
|
|
|
* @param \SS_HTTPRequest $request |
32
|
|
|
* |
33
|
|
|
* @return \HTMLText|\SS_HTTPResponse |
34
|
|
|
*/ |
35
|
|
|
public function index(\SS_HTTPRequest $request) { |
36
|
|
|
if(!$this->environment) { |
|
|
|
|
37
|
|
|
return $this->environment404Response(); |
38
|
|
|
} |
39
|
|
|
|
40
|
|
|
$this->setCurrentActionType(self::ACTION_OVERVIEW); |
41
|
|
|
|
42
|
|
|
return $this->customise([ |
43
|
|
|
'Environment' => $this->environment |
|
|
|
|
44
|
|
|
])->renderWith(['EnvironmentOverview', 'DNRoot']); |
45
|
|
|
} |
46
|
|
|
|
47
|
|
|
/** |
48
|
|
|
* @return string |
49
|
|
|
*/ |
50
|
|
|
public function Link() { |
51
|
|
|
return $this->environment->Link(); |
|
|
|
|
52
|
|
|
} |
53
|
|
|
|
54
|
|
|
/** |
55
|
|
|
* The model includes the CSRF tokens and the various API |
56
|
|
|
* endpoints that the front end might be interested in. |
57
|
|
|
* |
58
|
|
|
* @param string $name |
59
|
|
|
* |
60
|
|
|
* @return array |
61
|
|
|
*/ |
62
|
|
|
public function getModel($name = '') { |
63
|
|
|
$base = Director::absoluteBaseURL(); |
64
|
|
|
return [ |
65
|
|
|
'dispatchers' => [ |
66
|
|
|
'git' => $base.$this->getCurrentProject()->Link('git'), |
67
|
|
|
'plan' => $base.$this->getCurrentEnvironment()->Link('plan'), |
68
|
|
|
'deploys' => $base.$this->getCurrentEnvironment()->Link('deploys') |
69
|
|
|
], |
70
|
|
|
'api_auth' => [ |
71
|
|
|
'name' => $this->getSecurityToken()->getName(), |
72
|
|
|
'value' => $this->getSecurityToken()->getValue() |
73
|
|
|
] |
74
|
|
|
]; |
75
|
|
|
} |
76
|
|
|
|
77
|
|
|
} |
78
|
|
|
|
Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.
You can also find more detailed suggestions in the “Code” section of your repository.