Completed
Pull Request — master (#832)
by Stig
03:45
created
code/backends/DeploymentStrategy.php 2 patches
Braces   +6 added lines, -2 removed lines patch added patch discarded remove patch
@@ -110,8 +110,12 @@
 block discarded – undo
110 110
 		// Normalise "empty" values into dashes so comparisons are done properly.
111 111
 		// This means there is no diference between an empty string and a null
112 112
 		// but "0" is considered to be non-empty.
113
-		if(empty($from) && !strlen($from)) $from = '-';
114
-		if(empty($to) && !strlen($to)) $to = '-';
113
+		if(empty($from) && !strlen($from)) {
114
+			$from = '-';
115
+		}
116
+		if(empty($to) && !strlen($to)) {
117
+			$to = '-';
118
+		}
115 119
 
116 120
 		return $this->changes[$title] = array(
117 121
 			'from' => $from,
Please login to merge, or discard this patch.
Spacing   +8 added lines, -8 removed lines patch added patch discarded remove patch
@@ -110,8 +110,8 @@  discard block
 block discarded – undo
110 110
 		// Normalise "empty" values into dashes so comparisons are done properly.
111 111
 		// This means there is no diference between an empty string and a null
112 112
 		// but "0" is considered to be non-empty.
113
-		if(empty($from) && !strlen($from)) $from = '-';
114
-		if(empty($to) && !strlen($to)) $to = '-';
113
+		if (empty($from) && !strlen($from)) $from = '-';
114
+		if (empty($to) && !strlen($to)) $to = '-';
115 115
 
116 116
 		return $this->changes[$title] = array(
117 117
 			'from' => $from,
@@ -170,7 +170,7 @@  discard block
 block discarded – undo
170 170
 	 */
171 171
 	public function getChange($key) {
172 172
 		$changes = $this->getChanges();
173
-		if(array_key_exists($key, $changes)) {
173
+		if (array_key_exists($key, $changes)) {
174 174
 			return new ArrayData($changes[$key]);
175 175
 		}
176 176
 		return null;
@@ -189,7 +189,7 @@  discard block
 block discarded – undo
189 189
 	 * @return string|null
190 190
 	 */
191 191
 	public function getOption($option) {
192
-		if(!empty($this->options[$option])) {
192
+		if (!empty($this->options[$option])) {
193 193
 			return $this->options[$option];
194 194
 		}
195 195
 	}
@@ -230,7 +230,7 @@  discard block
 block discarded – undo
230 230
 			DeploymentStrategy::WARNING_CODE => 1,
231 231
 			DeploymentStrategy::ERROR_CODE => 2
232 232
 		];
233
-		if($map[$current] < $map[$code]) {
233
+		if ($map[$current] < $map[$code]) {
234 234
 			$this->setValidationCode($code);
235 235
 		}
236 236
 	}
@@ -259,7 +259,7 @@  discard block
 block discarded – undo
259 259
 		);
260 260
 
261 261
 		$output = array();
262
-		foreach($fields as $field) {
262
+		foreach ($fields as $field) {
263 263
 			$output[$field] = $this->$field;
264 264
 		}
265 265
 		return $output;
@@ -300,8 +300,8 @@  discard block
 block discarded – undo
300 300
 			'messages'
301 301
 		);
302 302
 
303
-		foreach($fields as $field) {
304
-			if(!empty($data[$field])) {
303
+		foreach ($fields as $field) {
304
+			if (!empty($data[$field])) {
305 305
 				$this->$field = $data[$field];
306 306
 			}
307 307
 		}
Please login to merge, or discard this patch.
code/jobs/PingJob.php 1 patch
Spacing   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -31,7 +31,7 @@
 block discarded – undo
31 31
 	 * Do the actual job by calling the appropiate backend
32 32
 	 */
33 33
 	public function perform() {
34
-		echo "[-] PingJob starting" . PHP_EOL;
34
+		echo "[-] PingJob starting".PHP_EOL;
35 35
 		$log = new DeploynautLogFile($this->args['logfile']);
36 36
 
37 37
 		$ping = DNPing::get()->byID($this->args['pingID']);
Please login to merge, or discard this patch.
code/model/jobs/DNDeployment.php 2 patches
Braces   +6 added lines, -2 removed lines patch added patch discarded remove patch
@@ -205,12 +205,16 @@
 block discarded – undo
205 205
 	 */
206 206
 	public function getFullDeployMessages() {
207 207
 		$strategy = $this->getDeploymentStrategy();
208
-		if ($strategy->getActionCode()!=='full') return null;
208
+		if ($strategy->getActionCode()!=='full') {
209
+			return null;
210
+		}
209 211
 
210 212
 		$changes = $strategy->getChangesModificationNeeded();
211 213
 		$messages = [];
212 214
 		foreach ($changes as $change => $details) {
213
-			if ($change==='Code version') continue;
215
+			if ($change==='Code version') {
216
+				continue;
217
+			}
214 218
 
215 219
 			$messages[] = [
216 220
 				'Flag' => sprintf(
Please login to merge, or discard this patch.
Spacing   +15 added lines, -15 removed lines patch added patch discarded remove patch
@@ -111,7 +111,7 @@  discard block
 block discarded – undo
111 111
 	}
112 112
 
113 113
 	public function LogLink() {
114
-		return $this->Link() . '/log';
114
+		return $this->Link().'/log';
115 115
 	}
116 116
 
117 117
 	public function canView($member = null) {
@@ -157,7 +157,7 @@  discard block
 block discarded – undo
157 157
 	 * @return \Gitonomy\Git\Repository|null
158 158
 	 */
159 159
 	public function getRepository() {
160
-		if(!$this->SHA) {
160
+		if (!$this->SHA) {
161 161
 			return null;
162 162
 		}
163 163
 		return $this->Environment()->Project()->getRepository();
@@ -170,10 +170,10 @@  discard block
 block discarded – undo
170 170
 	 */
171 171
 	public function getCommit() {
172 172
 		$repo = $this->getRepository();
173
-		if($repo) {
173
+		if ($repo) {
174 174
 			try {
175 175
 				return $this->Environment()->getCommit($this->SHA);
176
-			} catch(Gitonomy\Git\Exception\ReferenceNotFoundException $ex) {
176
+			} catch (Gitonomy\Git\Exception\ReferenceNotFoundException $ex) {
177 177
 				return null;
178 178
 			}
179 179
 		}
@@ -198,7 +198,7 @@  discard block
 block discarded – undo
198 198
 		if (!$interface) {
199 199
 			return null;
200 200
 		}
201
-		return $interface->CommitURL . '/' . $this->SHA;
201
+		return $interface->CommitURL.'/'.$this->SHA;
202 202
 	}
203 203
 
204 204
 	/**
@@ -208,10 +208,10 @@  discard block
 block discarded – undo
208 208
 	 */
209 209
 	public function getCommitMessage() {
210 210
 		$commit = $this->getCommit();
211
-		if($commit) {
211
+		if ($commit) {
212 212
 			try {
213 213
 				return Convert::raw2xml($this->Environment()->getCommitMessage($commit));
214
-			} catch(Gitonomy\Git\Exception\ReferenceNotFoundException $e) {
214
+			} catch (Gitonomy\Git\Exception\ReferenceNotFoundException $e) {
215 215
 				return null;
216 216
 			}
217 217
 		}
@@ -225,13 +225,13 @@  discard block
 block discarded – undo
225 225
 	 */
226 226
 	public function getTags() {
227 227
 		$commit = $this->Environment()->getCommit($this->SHA);
228
-		if(!$commit) {
228
+		if (!$commit) {
229 229
 			return new ArrayList([]);
230 230
 		}
231 231
 		$tags = $this->Environment()->getCommitTags($commit);
232 232
 		$returnTags = [];
233 233
 		if (!empty($tags)) {
234
-			foreach($tags as $tag) {
234
+			foreach ($tags as $tag) {
235 235
 				$field = Varchar::create('Tag', '255');
236 236
 				$field->setValue($tag->getName());
237 237
 				$returnTags[] = $field;
@@ -248,12 +248,12 @@  discard block
 block discarded – undo
248 248
 	 */
249 249
 	public function getFullDeployMessages() {
250 250
 		$strategy = $this->getDeploymentStrategy();
251
-		if ($strategy->getActionCode()!=='full') return null;
251
+		if ($strategy->getActionCode() !== 'full') return null;
252 252
 
253 253
 		$changes = $strategy->getChangesModificationNeeded();
254 254
 		$messages = [];
255 255
 		foreach ($changes as $change => $details) {
256
-			if ($change==='Code version') continue;
256
+			if ($change === 'Code version') continue;
257 257
 
258 258
 			$messages[] = [
259 259
 				'Flag' => sprintf(
@@ -281,7 +281,7 @@  discard block
 block discarded – undo
281 281
 	 */
282 282
 	public function getTag() {
283 283
 		$tags = $this->getTags();
284
-		if($tags->count() > 0) {
284
+		if ($tags->count() > 0) {
285 285
 			return $tags->last();
286 286
 		}
287 287
 		return null;
@@ -306,7 +306,7 @@  discard block
 block discarded – undo
306 306
 	public function getChanges() {
307 307
 		$list = new ArrayList();
308 308
 		$strategy = $this->getDeploymentStrategy();
309
-		foreach($strategy->getChanges() as $name => $change) {
309
+		foreach ($strategy->getChanges() as $name => $change) {
310 310
 			$changed = (isset($change['from']) && isset($change['to'])) ? $change['from'] != $change['to'] : null;
311 311
 			$description = isset($change['description']) ? $change['description'] : '';
312 312
 			$compareUrl = null;
@@ -356,11 +356,11 @@  discard block
 block discarded – undo
356 356
 		// Make sure we use the SHA as it was written into this DNDeployment.
357 357
 		$args['sha'] = $this->SHA;
358 358
 
359
-		if(!$this->DeployerID) {
359
+		if (!$this->DeployerID) {
360 360
 			$this->DeployerID = Member::currentUserID();
361 361
 		}
362 362
 
363
-		if($this->DeployerID) {
363
+		if ($this->DeployerID) {
364 364
 			$deployer = $this->Deployer();
365 365
 			$message = sprintf(
366 366
 				'Deploy to %s initiated by %s (%s), with IP address %s',
Please login to merge, or discard this patch.
code/model/StateMachineFactory.php 1 patch
Braces   +3 added lines, -1 removed lines patch added patch discarded remove patch
@@ -58,7 +58,9 @@
 block discarded – undo
58 58
 
59 59
 	protected function addHandlers($machine) {
60 60
 		$class = get_class($machine->getObject());
61
-		if (empty($this->config()->handlers[$class])) return;
61
+		if (empty($this->config()->handlers[$class])) {
62
+			return;
63
+		}
62 64
 
63 65
 		$transitions = $this->config()->handlers[$class];
64 66
 		foreach ($transitions as $transName => $handlers) {
Please login to merge, or discard this patch.
_config.php 1 patch
Spacing   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -10,7 +10,7 @@
 block discarded – undo
10 10
 // This will ensure jobs can correctly clean themselves up on any type of failure
11 11
 Resque_Event::listen('onFailure', function(Exception $exception, Resque_job $job) {
12 12
 	$inst = $job->getInstance();
13
-	if($inst instanceof DeploynautJobInterface) {
13
+	if ($inst instanceof DeploynautJobInterface) {
14 14
 		$inst->onFailure($exception);
15 15
 	}
16 16
 });
Please login to merge, or discard this patch.
code/control/GitDispatcher.php 1 patch
Spacing   +2 added lines, -2 removed lines patch added patch discarded remove patch
@@ -133,7 +133,7 @@  discard block
 block discarded – undo
133 133
 	protected function getUpdateStatus($ID) {
134 134
 		$ping = DNGitFetch::get()->byID($ID);
135 135
 		if (!$ping) {
136
-			return $this->getAPIResponse(['message' => 'GIT update (' . $ID . ') not found'], 404);
136
+			return $this->getAPIResponse(['message' => 'GIT update ('.$ID.') not found'], 404);
137 137
 		}
138 138
 		$output = [
139 139
 			'id' => $ID,
@@ -154,7 +154,7 @@  discard block
 block discarded – undo
154 154
 		$fetch->write();
155 155
 		$fetch->start();
156 156
 
157
-		$location = Director::absoluteBaseURL() . $this->Link() . '/update/' . $fetch->ID;
157
+		$location = Director::absoluteBaseURL().$this->Link().'/update/'.$fetch->ID;
158 158
 		$output = [
159 159
 			'message' => 'git fetch has been queued',
160 160
 			'id' => $fetch->ID,
Please login to merge, or discard this patch.
code/backends/PackageGenerator.php 1 patch
Spacing   +4 added lines, -4 removed lines patch added patch discarded remove patch
@@ -50,14 +50,14 @@
 block discarded – undo
50 50
 	 */
51 51
 	public function getPackageFilename($identifier, $sha, $repositoryDir, DeploynautLogFile $log) {
52 52
 		// Fetch through the cache
53
-		if($this->cache) {
54
-			$identifier .= '-' . get_class($this) . '-' . $this->getIdentifier();
53
+		if ($this->cache) {
54
+			$identifier .= '-'.get_class($this).'-'.$this->getIdentifier();
55 55
  			return $this->cache->getPackageFilename($this, $identifier, $sha, $repositoryDir, $log);
56 56
 
57 57
  		// Default, cacheless implementation
58 58
  		} else {
59
- 			$filename = TEMP_FOLDER . '/' . $sha . '.tar.gz';
60
- 			if($this->generatePackage($sha, $repositoryDir, $filename, $log)) {
59
+ 			$filename = TEMP_FOLDER.'/'.$sha.'.tar.gz';
60
+ 			if ($this->generatePackage($sha, $repositoryDir, $filename, $log)) {
61 61
  				return $filename;
62 62
  			}
63 63
  		}
Please login to merge, or discard this patch.
code/backends/SimplePackageGenerator.php 1 patch
Spacing   +7 added lines, -7 removed lines patch added patch discarded remove patch
@@ -30,8 +30,8 @@  discard block
 block discarded – undo
30 30
 	 * Generate the package
31 31
 	 */
32 32
 	public function generatePackage($sha, $baseDir, $outputFilename, DeploynautLogFile $log) {
33
-		$tempPath = TEMP_FOLDER . "/" . str_replace(".tar.gz", "", basename($outputFilename));
34
-		if(!file_exists($tempPath)) {
33
+		$tempPath = TEMP_FOLDER."/".str_replace(".tar.gz", "", basename($outputFilename));
34
+		if (!file_exists($tempPath)) {
35 35
 			mkdir($tempPath);
36 36
 		}
37 37
 
@@ -42,22 +42,22 @@  discard block
 block discarded – undo
42 42
 		// Execute these in sequence until there's a failure
43 43
 		$processes = array(
44 44
 			// Export the relevant SHA into a temp folder
45
-			new AbortableProcess("git archive $sha | tar -x -C " . $escapedTempPath, $baseDir),
45
+			new AbortableProcess("git archive $sha | tar -x -C ".$escapedTempPath, $baseDir),
46 46
 			// Run build script
47 47
 			new AbortableProcess($this->buildScript, $tempPath, null, null, 3600),
48 48
 			// Compress the result
49
-			new AbortableProcess("tar -czf " . $escapedOutputFile . " " . $escapedTempDir, dirname($tempPath)),
49
+			new AbortableProcess("tar -czf ".$escapedOutputFile." ".$escapedTempDir, dirname($tempPath)),
50 50
 		);
51 51
 
52 52
 		// Call at the end, regardless of success or failure
53 53
 		$cleanup = array(
54 54
 			// Delete the temporary staging folder
55
-			new AbortableProcess("rm -rf " . $escapedTempPath),
55
+			new AbortableProcess("rm -rf ".$escapedTempPath),
56 56
 		);
57 57
 
58 58
 		try {
59 59
 			$this->executeProcesses($processes, $log);
60
-		} catch(Exception $e) {
60
+		} catch (Exception $e) {
61 61
 			// Execute cleanup on failure
62 62
 			$this->executeProcesses($cleanup, $log);
63 63
 			throw $e;
@@ -75,7 +75,7 @@  discard block
 block discarded – undo
75 75
 	 * @param DeploynautLogFile $log The log to send output to
76 76
 	 */
77 77
 	protected function executeProcesses($processes, DeploynautLogFile $log) {
78
-		foreach($processes as $process) {
78
+		foreach ($processes as $process) {
79 79
 			$process->mustRun(function($type, $buffer) use($log) {
80 80
 				$log->write($buffer);
81 81
 			});
Please login to merge, or discard this patch.
code/backends/SizeRestrictedPackageCache.php 1 patch
Spacing   +13 added lines, -13 removed lines patch added patch discarded remove patch
@@ -48,25 +48,25 @@  discard block
 block discarded – undo
48 48
 		$repositoryDir,
49 49
 		DeploynautLogFile $log
50 50
 	) {
51
-		if(!$this->baseDir) {
51
+		if (!$this->baseDir) {
52 52
 			throw new \LogicException("Can't use PackageCache without setting BaseDir");
53 53
 		}
54 54
 
55
-		$buildPath = $this->baseDir . '/' . $this->sanitiseDirName($identifier);
55
+		$buildPath = $this->baseDir.'/'.$this->sanitiseDirName($identifier);
56 56
 		$filename = "$buildPath/$sha.tar.gz";
57 57
 
58
-		if(!file_exists($this->baseDir)) {
59
-			if(!mkdir($this->baseDir)) {
58
+		if (!file_exists($this->baseDir)) {
59
+			if (!mkdir($this->baseDir)) {
60 60
 				throw new \LogicException("Can't create base dir {$this->baseDir}");
61 61
 			}
62 62
 		}
63
-		if(!file_exists($buildPath)) {
64
-			if(!mkdir($buildPath)) {
63
+		if (!file_exists($buildPath)) {
64
+			if (!mkdir($buildPath)) {
65 65
 				throw new \LogicException("Can't create build path $buildPath");
66 66
 			}
67 67
 		}
68 68
 
69
-		if(file_exists($filename)) {
69
+		if (file_exists($filename)) {
70 70
 			$log->write("Using previously generated package $filename");
71 71
 			// This will ensure that our cache garbage collection will remove least-recently-accessed,
72 72
 			// rather than oldest.
@@ -74,11 +74,11 @@  discard block
 block discarded – undo
74 74
 			return $filename;
75 75
 
76 76
 		} else {
77
-			if($this->cacheSize) {
77
+			if ($this->cacheSize) {
78 78
 				$this->reduceDirSizeTo($buildPath, $this->cacheSize - 1, $log);
79 79
 			}
80 80
 
81
-			if($generator->generatePackage($sha, $repositoryDir, $filename, $log)) {
81
+			if ($generator->generatePackage($sha, $repositoryDir, $filename, $log)) {
82 82
 				return $filename;
83 83
 			}
84 84
 		}
@@ -103,14 +103,14 @@  discard block
 block discarded – undo
103 103
 	 * @param DeploynautLogFile $log The log to send removal status messages to
104 104
 	 */
105 105
 	protected function reduceDirSizeTo($dir, $count, DeploynautLogFile $log) {
106
-		$files = glob($dir . '/*.tar.gz');
107
-		if(sizeof($files) > $count) {
106
+		$files = glob($dir.'/*.tar.gz');
107
+		if (sizeof($files) > $count) {
108 108
 			usort($files, function($a, $b) {
109 109
 				return filemtime($a) > filemtime($b);
110 110
 			});
111 111
 
112
-			for($i = 0; $i < sizeof($files) - $count; $i++) {
113
-				$log->write("Removing " . $files[$i] . " from package cache");
112
+			for ($i = 0; $i < sizeof($files) - $count; $i++) {
113
+				$log->write("Removing ".$files[$i]." from package cache");
114 114
 				unlink($files[$i]);
115 115
 			}
116 116
 		}
Please login to merge, or discard this patch.