@@ -110,8 +110,12 @@ |
||
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, |
@@ -110,8 +110,8 @@ discard block |
||
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 |
||
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 |
||
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 |
||
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 |
||
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 |
||
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 | } |
@@ -31,7 +31,7 @@ |
||
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']); |
@@ -205,12 +205,16 @@ |
||
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( |
@@ -116,7 +116,7 @@ discard block |
||
116 | 116 | } |
117 | 117 | |
118 | 118 | public function LogLink() { |
119 | - return $this->Link() . '/log'; |
|
119 | + return $this->Link().'/log'; |
|
120 | 120 | } |
121 | 121 | |
122 | 122 | public function canView($member = null) { |
@@ -162,7 +162,7 @@ discard block |
||
162 | 162 | * @return \Gitonomy\Git\Repository|null |
163 | 163 | */ |
164 | 164 | public function getRepository() { |
165 | - if(!$this->SHA) { |
|
165 | + if (!$this->SHA) { |
|
166 | 166 | return null; |
167 | 167 | } |
168 | 168 | return $this->Environment()->Project()->getRepository(); |
@@ -175,10 +175,10 @@ discard block |
||
175 | 175 | */ |
176 | 176 | public function getCommit() { |
177 | 177 | $repo = $this->getRepository(); |
178 | - if($repo) { |
|
178 | + if ($repo) { |
|
179 | 179 | try { |
180 | 180 | return $this->Environment()->getCommit($this->SHA); |
181 | - } catch(Gitonomy\Git\Exception\ReferenceNotFoundException $ex) { |
|
181 | + } catch (Gitonomy\Git\Exception\ReferenceNotFoundException $ex) { |
|
182 | 182 | return null; |
183 | 183 | } |
184 | 184 | } |
@@ -203,7 +203,7 @@ discard block |
||
203 | 203 | if (!$interface) { |
204 | 204 | return null; |
205 | 205 | } |
206 | - return $interface->CommitURL . '/' . $this->SHA; |
|
206 | + return $interface->CommitURL.'/'.$this->SHA; |
|
207 | 207 | } |
208 | 208 | |
209 | 209 | /** |
@@ -213,10 +213,10 @@ discard block |
||
213 | 213 | */ |
214 | 214 | public function getCommitMessage() { |
215 | 215 | $commit = $this->getCommit(); |
216 | - if($commit) { |
|
216 | + if ($commit) { |
|
217 | 217 | try { |
218 | 218 | return Convert::raw2xml($this->Environment()->getCommitMessage($commit)); |
219 | - } catch(Gitonomy\Git\Exception\ReferenceNotFoundException $e) { |
|
219 | + } catch (Gitonomy\Git\Exception\ReferenceNotFoundException $e) { |
|
220 | 220 | return null; |
221 | 221 | } |
222 | 222 | } |
@@ -230,10 +230,10 @@ discard block |
||
230 | 230 | */ |
231 | 231 | public function getCommitSubjectMessage() { |
232 | 232 | $commit = $this->getCommit(); |
233 | - if($commit) { |
|
233 | + if ($commit) { |
|
234 | 234 | try { |
235 | 235 | return Convert::raw2xml($this->Environment()->getCommitSubjectMessage($commit)); |
236 | - } catch(Gitonomy\Git\Exception\ReferenceNotFoundException $e) { |
|
236 | + } catch (Gitonomy\Git\Exception\ReferenceNotFoundException $e) { |
|
237 | 237 | return null; |
238 | 238 | } |
239 | 239 | } |
@@ -247,13 +247,13 @@ discard block |
||
247 | 247 | */ |
248 | 248 | public function getTags() { |
249 | 249 | $commit = $this->Environment()->getCommit($this->SHA); |
250 | - if(!$commit) { |
|
250 | + if (!$commit) { |
|
251 | 251 | return new ArrayList([]); |
252 | 252 | } |
253 | 253 | $tags = $this->Environment()->getCommitTags($commit); |
254 | 254 | $returnTags = []; |
255 | 255 | if (!empty($tags)) { |
256 | - foreach($tags as $tag) { |
|
256 | + foreach ($tags as $tag) { |
|
257 | 257 | $field = Varchar::create('Tag', '255'); |
258 | 258 | $field->setValue($tag->getName()); |
259 | 259 | $returnTags[] = $field; |
@@ -270,12 +270,12 @@ discard block |
||
270 | 270 | */ |
271 | 271 | public function getFullDeployMessages() { |
272 | 272 | $strategy = $this->getDeploymentStrategy(); |
273 | - if ($strategy->getActionCode()!=='full') return null; |
|
273 | + if ($strategy->getActionCode() !== 'full') return null; |
|
274 | 274 | |
275 | 275 | $changes = $strategy->getChangesModificationNeeded(); |
276 | 276 | $messages = []; |
277 | 277 | foreach ($changes as $change => $details) { |
278 | - if ($change==='Code version') continue; |
|
278 | + if ($change === 'Code version') continue; |
|
279 | 279 | |
280 | 280 | $messages[] = [ |
281 | 281 | 'Flag' => sprintf( |
@@ -303,7 +303,7 @@ discard block |
||
303 | 303 | */ |
304 | 304 | public function getTag() { |
305 | 305 | $tags = $this->getTags(); |
306 | - if($tags->count() > 0) { |
|
306 | + if ($tags->count() > 0) { |
|
307 | 307 | return $tags->last(); |
308 | 308 | } |
309 | 309 | return null; |
@@ -328,7 +328,7 @@ discard block |
||
328 | 328 | public function getChanges() { |
329 | 329 | $list = new ArrayList(); |
330 | 330 | $strategy = $this->getDeploymentStrategy(); |
331 | - foreach($strategy->getChanges() as $name => $change) { |
|
331 | + foreach ($strategy->getChanges() as $name => $change) { |
|
332 | 332 | $changed = (isset($change['from']) && isset($change['to'])) ? $change['from'] != $change['to'] : null; |
333 | 333 | $description = isset($change['description']) ? $change['description'] : ''; |
334 | 334 | $compareUrl = null; |
@@ -378,11 +378,11 @@ discard block |
||
378 | 378 | // Make sure we use the SHA as it was written into this DNDeployment. |
379 | 379 | $args['sha'] = $this->SHA; |
380 | 380 | |
381 | - if(!$this->DeployerID) { |
|
381 | + if (!$this->DeployerID) { |
|
382 | 382 | $this->DeployerID = Member::currentUserID(); |
383 | 383 | } |
384 | 384 | |
385 | - if($this->DeployerID) { |
|
385 | + if ($this->DeployerID) { |
|
386 | 386 | $deployer = $this->Deployer(); |
387 | 387 | $message = sprintf( |
388 | 388 | 'Deploy to %s initiated by %s (%s), with IP address %s', |
@@ -58,7 +58,9 @@ |
||
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) { |
@@ -10,7 +10,7 @@ |
||
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 | }); |
@@ -133,7 +133,7 @@ discard block |
||
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 |
||
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, |
@@ -50,14 +50,14 @@ |
||
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 | } |
@@ -30,8 +30,8 @@ discard block |
||
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 |
||
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 |
||
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 | }); |
@@ -48,25 +48,25 @@ discard block |
||
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 |
||
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 |
||
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 | } |