Completed
Pull Request — master (#643)
by Stig
07:47
created
code/api/nouns/APIProject.php 1 patch
Spacing   +8 added lines, -8 removed lines patch added patch discarded remove patch
@@ -15,11 +15,11 @@  discard block
 block discarded – undo
15 15
 	 * @return SS_HTTPResponse
16 16
 	 */
17 17
 	public function index(SS_HTTPRequest $request) {
18
-		if(!$this->record->canView($this->getMember())) {
18
+		if (!$this->record->canView($this->getMember())) {
19 19
 			return $this->message('You are not authorized to this environment', 403);
20 20
 		}
21 21
 
22
-		switch($request->httpMethod()) {
22
+		switch ($request->httpMethod()) {
23 23
 			case 'GET':
24 24
 				$response = array(
25 25
 					"name" => $this->record->Name,
@@ -29,7 +29,7 @@  discard block
 block discarded – undo
29 29
 					"disk-quota-mb" => $this->record->DiskQuotaMB,
30 30
 					"environments" => array(),
31 31
 				);
32
-				foreach($this->record->DNEnvironmentList() as $environment) {
32
+				foreach ($this->record->DNEnvironmentList() as $environment) {
33 33
 					$response['environments'][] = array(
34 34
 						'name' => $environment->Name,
35 35
 						'href' => Director::absoluteURL($this->record->APILink($environment->Name)),
@@ -47,10 +47,10 @@  discard block
 block discarded – undo
47 47
 	 * @return SS_HTTPResponse
48 48
 	 */
49 49
 	public function fetch(SS_HTTPRequest $request) {
50
-		if(!$this->record->canView($this->getMember())) {
50
+		if (!$this->record->canView($this->getMember())) {
51 51
 			return $this->message('You are not authorized to do that on this environment', 403);
52 52
 		}
53
-		switch($request->httpMethod()) {
53
+		switch ($request->httpMethod()) {
54 54
 			case 'GET':
55 55
 				return $this->getFetch($this->getRequest()->param('ID'));
56 56
 			case 'POST':
@@ -66,7 +66,7 @@  discard block
 block discarded – undo
66 66
 	 */
67 67
 	protected function getFetch($ID) {
68 68
 		$ping = DNGitFetch::get()->byID($ID);
69
-		if(!$ping) {
69
+		if (!$ping) {
70 70
 			return $this->message('Fetch not found', 404);
71 71
 		}
72 72
 		$output = array(
@@ -87,9 +87,9 @@  discard block
 block discarded – undo
87 87
 		$fetch->write();
88 88
 		$fetch->start();
89 89
 
90
-		$location = Director::absoluteBaseURL() . $this->Link() . '/fetch/' . $fetch->ID;
90
+		$location = Director::absoluteBaseURL().$this->Link().'/fetch/'.$fetch->ID;
91 91
 		$output = array(
92
-			'message' => 'Fetch queued as job ' . $fetch->ResqueToken,
92
+			'message' => 'Fetch queued as job '.$fetch->ResqueToken,
93 93
 			'href' => $location,
94 94
 		);
95 95
 
Please login to merge, or discard this patch.
code/api/nouns/APIEnvironment.php 1 patch
Spacing   +16 added lines, -16 removed lines patch added patch discarded remove patch
@@ -15,10 +15,10 @@  discard block
 block discarded – undo
15 15
 	 * @return SS_HTTPResponse
16 16
 	 */
17 17
 	public function index(SS_HTTPRequest $request) {
18
-		if(!$this->record->canView($this->getMember())) {
18
+		if (!$this->record->canView($this->getMember())) {
19 19
 			return $this->message('You are not authorized to view this environment', 403);
20 20
 		}
21
-		switch($request->httpMethod()) {
21
+		switch ($request->httpMethod()) {
22 22
 			case 'GET':
23 23
 				$href = Director::absoluteURL($this->record->Project()->APILink($this->record->Name));
24 24
 				return $this->getAPIResponse(array(
@@ -51,10 +51,10 @@  discard block
 block discarded – undo
51 51
 	 * @return SS_HTTPResponse
52 52
 	 */
53 53
 	public function ping(SS_HTTPRequest $request) {
54
-		if(!$this->record->canView($this->getMember())) {
54
+		if (!$this->record->canView($this->getMember())) {
55 55
 			return $this->message('You are not authorized to do that on this environment', 403);
56 56
 		}
57
-		switch($request->httpMethod()) {
57
+		switch ($request->httpMethod()) {
58 58
 			case 'GET':
59 59
 				return $this->getPing($this->getRequest()->param('ID'));
60 60
 			case 'POST':
@@ -71,10 +71,10 @@  discard block
 block discarded – undo
71 71
 	 * @return SS_HTTPResponse
72 72
 	 */
73 73
 	public function deploy(SS_HTTPRequest $request) {
74
-		if(!$this->record->canView($this->getMember())) {
74
+		if (!$this->record->canView($this->getMember())) {
75 75
 			return $this->message('You are not authorized to do that on this environment', 403);
76 76
 		}
77
-		switch($request->httpMethod()) {
77
+		switch ($request->httpMethod()) {
78 78
 			case 'GET':
79 79
 				return $this->getDeploy($this->getRequest()->param('ID'));
80 80
 			case 'POST':
@@ -106,7 +106,7 @@  discard block
 block discarded – undo
106 106
 	 * @return SS_HTTPResponse
107 107
 	 */
108 108
 	protected function createPing() {
109
-		if(!$this->record->canDeploy($this->getMember())) {
109
+		if (!$this->record->canDeploy($this->getMember())) {
110 110
 			return $this->message('You are not authorized to do that on this environment', 403);
111 111
 		}
112 112
 		$ping = DNPing::create();
@@ -114,9 +114,9 @@  discard block
 block discarded – undo
114 114
 		$ping->write();
115 115
 		$ping->start();
116 116
 
117
-		$location = Director::absoluteBaseURL() . $this->Link() . '/ping/' . $ping->ID;
117
+		$location = Director::absoluteBaseURL().$this->Link().'/ping/'.$ping->ID;
118 118
 		$output = array(
119
-			'message' => 'Ping queued as job ' . $ping->ResqueToken,
119
+			'message' => 'Ping queued as job '.$ping->ResqueToken,
120 120
 			'href' => $location,
121 121
 		);
122 122
 
@@ -132,7 +132,7 @@  discard block
 block discarded – undo
132 132
 	 */
133 133
 	protected function getPing($ID) {
134 134
 		$ping = DNPing::get()->byID($ID);
135
-		if(!$ping) {
135
+		if (!$ping) {
136 136
 			return $this->message('Ping not found', 404);
137 137
 		}
138 138
 		$output = array(
@@ -149,17 +149,17 @@  discard block
 block discarded – undo
149 149
 	 * @return SS_HTTPResponse
150 150
 	 */
151 151
 	protected function createDeploy() {
152
-		if(!$this->record->canDeploy($this->getMember())) {
152
+		if (!$this->record->canDeploy($this->getMember())) {
153 153
 			return $this->message('You are not authorized to do that on this environment', 403);
154 154
 		}
155 155
 
156 156
 		$reqBody = $this->getRequestBody();
157 157
 
158
-		if($reqBody === null) {
158
+		if ($reqBody === null) {
159 159
 			return $this->message('the request body did not contain a valid JSON object.', 400);
160 160
 		}
161 161
 
162
-		if(empty($reqBody['release'])) {
162
+		if (empty($reqBody['release'])) {
163 163
 			return $this->message('deploy requires a {"release": "sha1"} in the body of the request.', 400);
164 164
 		}
165 165
 
@@ -168,9 +168,9 @@  discard block
 block discarded – undo
168 168
 		));
169 169
 		$deploy = $strategy->createDeployment();
170 170
 		$deploy->start();
171
-		$location = Director::absoluteBaseURL() . $this->Link() . '/deploy/' . $deploy->ID;
171
+		$location = Director::absoluteBaseURL().$this->Link().'/deploy/'.$deploy->ID;
172 172
 		$output = array(
173
-			'message' => 'Deploy queued as job ' . $deploy->ResqueToken,
173
+			'message' => 'Deploy queued as job '.$deploy->ResqueToken,
174 174
 			'href' => $location,
175 175
 		);
176 176
 		$response = $this->getAPIResponse($output);
@@ -187,7 +187,7 @@  discard block
 block discarded – undo
187 187
 	 */
188 188
 	protected function getDeploy($id) {
189 189
 		$deploy = DNDeployment::get()->byID($id);
190
-		if(!$deploy) {
190
+		if (!$deploy) {
191 191
 			return $this->message('Deploy not found', 404);
192 192
 		}
193 193
 		$output = array(
Please login to merge, or discard this patch.
code/api/DeploynautAPI.php 1 patch
Spacing   +8 added lines, -8 removed lines patch added patch discarded remove patch
@@ -51,12 +51,12 @@  discard block
 block discarded – undo
51 51
 			'projects' => array(),
52 52
 		);
53 53
 
54
-		if($request->httpMethod() != 'GET') {
54
+		if ($request->httpMethod() != 'GET') {
55 55
 			return $this->message('API not found', 404);
56 56
 		}
57 57
 
58
-		foreach(DNProject::get() as $item) {
59
-			if($item->canView($this->getMember())) {
58
+		foreach (DNProject::get() as $item) {
59
+			if ($item->canView($this->getMember())) {
60 60
 				$response['projects'][] = array(
61 61
 					"name" => $item->Name,
62 62
 					"href" => Director::absoluteURL($item->APILink("")),
@@ -75,7 +75,7 @@  discard block
 block discarded – undo
75 75
 	 */
76 76
 	public function project(SS_HTTPRequest $request) {
77 77
 		$project = $this->getProject();
78
-		if(!$project) {
78
+		if (!$project) {
79 79
 			return $this->project404Response();
80 80
 		}
81 81
 		return new APIProject($this, $project);
@@ -89,12 +89,12 @@  discard block
 block discarded – undo
89 89
 	 */
90 90
 	public function environment(SS_HTTPRequest $request) {
91 91
 		$project = $this->getProject();
92
-		if(!$project) {
92
+		if (!$project) {
93 93
 			return $this->project404Response();
94 94
 		}
95 95
 
96 96
 		$environment = $this->getEnvironment();
97
-		if(!$environment) {
97
+		if (!$environment) {
98 98
 			return $this->environment404Response();
99 99
 		}
100 100
 		return new APIEnvironment($this, $environment);
@@ -105,7 +105,7 @@  discard block
 block discarded – undo
105 105
 	 */
106 106
 	protected function project404Response() {
107 107
 		$projectName = Convert::raw2xml($this->getRequest()->latestParam('Project'));
108
-		return new SS_HTTPResponse('Project "' . $projectName . '" not found.', 404);
108
+		return new SS_HTTPResponse('Project "'.$projectName.'" not found.', 404);
109 109
 	}
110 110
 
111 111
 	/**
@@ -113,7 +113,7 @@  discard block
 block discarded – undo
113 113
 	 */
114 114
 	protected function environment404Response() {
115 115
 		$envName = Convert::raw2xml($this->getRequest()->latestParam('Environment'));
116
-		return new SS_HTTPResponse('Environment "' . $envName . '" not found.', 404);
116
+		return new SS_HTTPResponse('Environment "'.$envName.'" not found.', 404);
117 117
 	}
118 118
 
119 119
 	/**
Please login to merge, or discard this patch.
code/tasks/MigrateDeploymentStatusTask.php 1 patch
Spacing   +2 added lines, -2 removed lines patch added patch discarded remove patch
@@ -4,8 +4,8 @@
 block discarded – undo
4 4
 
5 5
 	public function run($request) {
6 6
 		$log = function($message) {
7
-			$message = sprintf('[%s] ', date('Y-m-d H:i:s')) . $message;
8
-			echo $message . PHP_EOL;
7
+			$message = sprintf('[%s] ', date('Y-m-d H:i:s')).$message;
8
+			echo $message.PHP_EOL;
9 9
 		};
10 10
 
11 11
 		if (!Director::is_cli()) {
Please login to merge, or discard this patch.
code/jobs/DataTransferJob.php 1 patch
Spacing   +7 added lines, -7 removed lines patch added patch discarded remove patch
@@ -20,13 +20,13 @@  discard block
 block discarded – undo
20 20
 	}
21 21
 
22 22
 	public function perform() {
23
-		echo "[-] DataTransferJob starting" . PHP_EOL;
23
+		echo "[-] DataTransferJob starting".PHP_EOL;
24 24
 		$log = new DeploynautLogFile($this->args['logfile']);
25 25
 		$dataTransfer = DNDataTransfer::get()->byID($this->args['dataTransferID']);
26 26
 		$environment = $dataTransfer->Environment();
27 27
 		$backupDataTransfer = null;
28 28
 
29
-		if(
29
+		if (
30 30
 			!empty($this->args['backupBeforePush'])
31 31
 			&& $this->args['backupBeforePush'] !== 'false'
32 32
 			&& $dataTransfer->Direction == 'push'
@@ -54,7 +54,7 @@  discard block
 block discarded – undo
54 54
 					'Created:GreaterThan' => strtotime('-30 minutes')
55 55
 				))
56 56
 				->exclude('ID', $dataTransfer->ID);
57
-			if($runningTransfers->count()) {
57
+			if ($runningTransfers->count()) {
58 58
 				$runningTransfer = $runningTransfers->first();
59 59
 				$message = sprintf(
60 60
 					'Error: another transfer is in progress (started at %s by %s)',
@@ -67,13 +67,13 @@  discard block
 block discarded – undo
67 67
 
68 68
 			$this->performBackup($backupDataTransfer, $log);
69 69
 			$environment->Backend()->dataTransfer($dataTransfer, $log);
70
-		} catch(Exception $e) {
71
-			echo "[-] DataTransferJob failed" . PHP_EOL;
70
+		} catch (Exception $e) {
71
+			echo "[-] DataTransferJob failed".PHP_EOL;
72 72
 			throw $e;
73 73
 		}
74 74
 
75 75
 		$this->updateStatus('Finished');
76
-		echo "[-] DataTransferJob finished" . PHP_EOL;
76
+		echo "[-] DataTransferJob finished".PHP_EOL;
77 77
 	}
78 78
 
79 79
 	protected function performBackup($backupDataTransfer, DeploynautLogFile $log) {
@@ -88,7 +88,7 @@  discard block
 block discarded – undo
88 88
 			DB::connect($databaseConfig);
89 89
 			$backupDataTransfer->Status = 'Finished';
90 90
 			$backupDataTransfer->write();
91
-		} catch(Exception $e) {
91
+		} catch (Exception $e) {
92 92
 			global $databaseConfig;
93 93
 			DB::connect($databaseConfig);
94 94
 			$backupDataTransfer->Status = 'Failed';
Please login to merge, or discard this patch.
code/jobs/CreateEnvJob.php 1 patch
Spacing   +5 added lines, -5 removed lines patch added patch discarded remove patch
@@ -19,23 +19,23 @@
 block discarded – undo
19 19
 	 *
20 20
 	 */
21 21
 	public function perform() {
22
-		echo "[-] CreateEnvJob starting" . PHP_EOL;
22
+		echo "[-] CreateEnvJob starting".PHP_EOL;
23 23
 		// This is a bit icky, but there is no easy way of capturing a failed deploy by using the PHP Resque
24 24
 		try {
25 25
 			$envCreate = DNCreateEnvironment::get()->byId($this->args['createID']);
26
-			if(!($envCreate && $envCreate->exists())) {
26
+			if (!($envCreate && $envCreate->exists())) {
27 27
 				throw new RuntimeException(sprintf('Could not find create environment record %s', $args['createID']));
28 28
 			}
29 29
 
30 30
 			// This will throw and exception if it fails.
31 31
 			$envCreate->createEnvironment();
32 32
 
33
-		} catch(Exception $e) {
34
-			echo "[-] CreateEnvJob failed" . PHP_EOL;
33
+		} catch (Exception $e) {
34
+			echo "[-] CreateEnvJob failed".PHP_EOL;
35 35
 			throw $e;
36 36
 		}
37 37
 		$this->updateStatus('Finished');
38
-		echo "[-] CreateEnvJob finished" . PHP_EOL;
38
+		echo "[-] CreateEnvJob finished".PHP_EOL;
39 39
 	}
40 40
 
41 41
 	/**
Please login to merge, or discard this patch.
code/jobs/FetchJob.php 1 patch
Spacing   +14 added lines, -14 removed lines patch added patch discarded remove patch
@@ -33,12 +33,12 @@  discard block
 block discarded – undo
33 33
 	public function perform() {
34 34
 		set_time_limit(0);
35 35
 
36
-		if(!empty($this->args['logfile'])) {
36
+		if (!empty($this->args['logfile'])) {
37 37
 			$this->log = new DeploynautLogFile($this->args['logfile']);
38 38
 		}
39 39
 
40 40
 		$this->project = DNProject::get()->byId($this->args['projectID']);
41
-		if(!($this->project && $this->project->exists())) {
41
+		if (!($this->project && $this->project->exists())) {
42 42
 			throw new RuntimeException(sprintf('Project ID %s not found', $this->args['projectID']));
43 43
 		}
44 44
 
@@ -47,7 +47,7 @@  discard block
 block discarded – undo
47 47
 		// Disallow concurrent git fetches on the same project.
48 48
 		// Only consider fetches started in the last 30 minutes (older jobs probably got stuck)
49 49
 		try {
50
-			if(!empty($this->args['fetchID'])) {
50
+			if (!empty($this->args['fetchID'])) {
51 51
 				$runningFetches = DNGitFetch::get()
52 52
 					->filter(array(
53 53
 						'ProjectID' => $this->project->ID,
@@ -56,14 +56,14 @@  discard block
 block discarded – undo
56 56
 					))
57 57
 					->exclude('ID', $this->args['fetchID']);
58 58
 
59
-				if($runningFetches->count()) {
59
+				if ($runningFetches->count()) {
60 60
 					$runningFetch = $runningFetches->first();
61 61
 					$message = sprintf(
62 62
 						'Another fetch is in progress (started at %s by %s)',
63 63
 						$runningFetch->dbObject('Created')->Nice(),
64 64
 						$runningFetch->Deployer()->Title
65 65
 					);
66
-					if($this->log) {
66
+					if ($this->log) {
67 67
 						$this->log->write($message);
68 68
 					}
69 69
 					throw new RuntimeException($message);
@@ -72,13 +72,13 @@  discard block
 block discarded – undo
72 72
 
73 73
 			// Decide whether we need to just update what we already have
74 74
 			// or initiate a clone if no local repo exists.
75
-			if($this->project->repoExists() && empty($this->args['forceClone'])) {
75
+			if ($this->project->repoExists() && empty($this->args['forceClone'])) {
76 76
 				$this->fetchRepo();
77 77
 			} else {
78 78
 				$this->cloneRepo();
79 79
 			}
80
-		} catch(Exception $e) {
81
-			if($this->log) {
80
+		} catch (Exception $e) {
81
+			if ($this->log) {
82 82
 				$this->log->write($e->getMessage());
83 83
 			}
84 84
 			throw $e;
@@ -95,7 +95,7 @@  discard block
 block discarded – undo
95 95
 	}
96 96
 
97 97
 	protected function cloneRepo() {
98
-		if(file_exists($this->project->getLocalCVSPath())) {
98
+		if (file_exists($this->project->getLocalCVSPath())) {
99 99
 			$this->runCommand(sprintf(
100 100
 				'rm -rf %s',
101 101
 				escapeshellarg($this->project->getLocalCVSPath())
@@ -117,17 +117,17 @@  discard block
 block discarded – undo
117 117
 	 * @throws RuntimeException
118 118
 	 */
119 119
 	protected function runCommand($command, $workingDir = null) {
120
-		if(!empty($this->user)) {
120
+		if (!empty($this->user)) {
121 121
 			$command = sprintf('sudo -u %s %s', $this->user, $command);
122 122
 		}
123
-		if($this->log) {
123
+		if ($this->log) {
124 124
 			$this->log->write(sprintf('Running command: %s', $command));
125 125
 		}
126 126
 		$process = new AbortableProcess($command, $workingDir);
127 127
 		$process->setEnv($this->project->getProcessEnv());
128 128
 		$process->setTimeout(1800);
129 129
 		$process->run();
130
-		if(!$process->isSuccessful()) {
130
+		if (!$process->isSuccessful()) {
131 131
 			throw new RuntimeException($process->getErrorOutput());
132 132
 		}
133 133
 	}
@@ -140,9 +140,9 @@  discard block
 block discarded – undo
140 140
 		global $databaseConfig;
141 141
 		DB::connect($databaseConfig);
142 142
 
143
-		if(!empty($this->args['fetchID'])) {
143
+		if (!empty($this->args['fetchID'])) {
144 144
 			$fetch = DNGitFetch::get()->byID($this->args['fetchID']);
145
-			if($fetch && $fetch->exists()) {
145
+			if ($fetch && $fetch->exists()) {
146 146
 				$fetch->Status = $status;
147 147
 				$fetch->write();
148 148
 			}
Please login to merge, or discard this patch.
code/form/TabbedSelectionGroup.php 1 patch
Spacing   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -9,7 +9,7 @@
 block discarded – undo
9 9
 		$items = CompositeField::FieldList()->toArray();
10 10
 		$fields = new ArrayList();
11 11
 
12
-		foreach($items as $item) {
12
+		foreach ($items as $item) {
13 13
 			$extra = array(
14 14
 				'Selected' => $this->value == $item->getValue(),
15 15
 			);
Please login to merge, or discard this patch.
code/form/DataArchiveFileField.php 1 patch
Spacing   +7 added lines, -7 removed lines patch added patch discarded remove patch
@@ -15,11 +15,11 @@  discard block
 block discarded – undo
15 15
 	 * @return bool|DataArchiveFileField
16 16
 	 */
17 17
 	public function saveInto(DataObjectInterface $record) {
18
-		if(!isset($_FILES[$this->name])) {
18
+		if (!isset($_FILES[$this->name])) {
19 19
 			return false;
20 20
 		}
21 21
 
22
-		if(!($record instanceof DNDataArchive)) {
22
+		if (!($record instanceof DNDataArchive)) {
23 23
 			throw new LogicException('Saving into wrong type, expected DNDataArchive');
24 24
 		}
25 25
 
@@ -27,7 +27,7 @@  discard block
 block discarded – undo
27 27
 
28 28
 		/** @var DNDataTransfer $dataTransfer */
29 29
 		$dataTransfer = $dataArchive->DataTransfers()->First();
30
-		if(!$dataTransfer) {
30
+		if (!$dataTransfer) {
31 31
 			throw new LogicException('No transfer found');
32 32
 		}
33 33
 
@@ -36,16 +36,16 @@  discard block
 block discarded – undo
36 36
 		// Hack: loadIntoFile assumes paths relative to assets,
37 37
 		//  otherwise it creates the whole structure *within* that folder
38 38
 		$absolutePath = $dataArchive->generateFilepath($dataTransfer);
39
-		$relativePath = preg_replace('#^' . preg_quote(ASSETS_PATH) . '/#', '', $absolutePath);
39
+		$relativePath = preg_replace('#^'.preg_quote(ASSETS_PATH).'/#', '', $absolutePath);
40 40
 		$this->upload->loadIntoFile($_FILES[$this->name], $file, $relativePath);
41
-		if($this->upload->isError()) {
41
+		if ($this->upload->isError()) {
42 42
 			return false;
43 43
 		}
44 44
 
45 45
 		$file = $this->upload->getFile();
46
-		if($this->relationAutoSetting) {
46
+		if ($this->relationAutoSetting) {
47 47
 			// save to record
48
-			$record->{$this->name . 'ID'} = $file->ID;
48
+			$record->{$this->name.'ID'} = $file->ID;
49 49
 		}
50 50
 
51 51
 		return $this;
Please login to merge, or discard this patch.