@@ -96,7 +96,7 @@ |
||
| 96 | 96 | // It gives a chance to perform a dry-run, and reject the transition, for example |
| 97 | 97 | // in case the user is unauthorised. |
| 98 | 98 | 'finite.test_transition', |
| 99 | - function (Finite\Event\TransitionEvent $e) use ($project) { |
|
| 99 | + function(Finite\Event\TransitionEvent $e) use ($project) { |
|
| 100 | 100 | $code = null; |
| 101 | 101 | |
| 102 | 102 | switch ($e->getTransition()->getName()) { |
@@ -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 | } |
@@ -41,7 +41,7 @@ discard block |
||
| 41 | 41 | |
| 42 | 42 | $file = sprintf('%s/%s.deploy-history.txt', DEPLOYNAUT_LOG_PATH, $environment->getFullName()); |
| 43 | 43 | $CLI_file = escapeshellarg($file); |
| 44 | - $CLI_line = escapeshellarg(date('Y-m-d H:i:s') . " => $sha"); |
|
| 44 | + $CLI_line = escapeshellarg(date('Y-m-d H:i:s')." => $sha"); |
|
| 45 | 45 | |
| 46 | 46 | // Put maintenance page up |
| 47 | 47 | $this->enableMaintenance($environment, $log, $project); |
@@ -54,7 +54,7 @@ discard block |
||
| 54 | 54 | $log->write("Well, that was a waste of time"); |
| 55 | 55 | |
| 56 | 56 | // Once the deployment has run it's necessary to update the maintenance page status |
| 57 | - if(!empty($options['leaveMaintenancePage'])) { |
|
| 57 | + if (!empty($options['leaveMaintenancePage'])) { |
|
| 58 | 58 | $this->enableMaintenance($environment, $log, $project); |
| 59 | 59 | } else { |
| 60 | 60 | // Remove maintenance page if we want it to |
@@ -70,7 +70,7 @@ |
||
| 70 | 70 | * @return string |
| 71 | 71 | */ |
| 72 | 72 | public function get($keyname) { |
| 73 | - if(array_key_exists($keyname, $this->data)) { |
|
| 73 | + if (array_key_exists($keyname, $this->data)) { |
|
| 74 | 74 | return $this->data[$keyname]; |
| 75 | 75 | } |
| 76 | 76 | return ''; |
@@ -59,7 +59,7 @@ discard block |
||
| 59 | 59 | */ |
| 60 | 60 | protected function getAPIResponse($output) { |
| 61 | 61 | $response = $this->getResponse(); |
| 62 | - if($this->respondWithText()) { |
|
| 62 | + if ($this->respondWithText()) { |
|
| 63 | 63 | $body = print_r($output, true); |
| 64 | 64 | $response->addHeader('Content-Type', 'text/plain'); |
| 65 | 65 | } else { |
@@ -74,10 +74,10 @@ discard block |
||
| 74 | 74 | * @return boolean |
| 75 | 75 | */ |
| 76 | 76 | protected function respondWithJSON() { |
| 77 | - if($this->getRequest()->getExtension() == 'json') { |
|
| 77 | + if ($this->getRequest()->getExtension() == 'json') { |
|
| 78 | 78 | return true; |
| 79 | 79 | } |
| 80 | - if(strpos($this->getRequest()->getHeader('Accept'), 'application/json') !== false) { |
|
| 80 | + if (strpos($this->getRequest()->getHeader('Accept'), 'application/json') !== false) { |
|
| 81 | 81 | return true; |
| 82 | 82 | } |
| 83 | 83 | return false; |
@@ -87,10 +87,10 @@ discard block |
||
| 87 | 87 | * @return boolean |
| 88 | 88 | */ |
| 89 | 89 | protected function respondWithText() { |
| 90 | - if($this->getRequest()->getExtension() == 'txt') { |
|
| 90 | + if ($this->getRequest()->getExtension() == 'txt') { |
|
| 91 | 91 | return true; |
| 92 | 92 | } |
| 93 | - if(strpos($this->getRequest()->getHeader('Accept'), 'text/plain') !== false) { |
|
| 93 | + if (strpos($this->getRequest()->getHeader('Accept'), 'text/plain') !== false) { |
|
| 94 | 94 | return true; |
| 95 | 95 | } |
| 96 | 96 | return false; |
@@ -15,11 +15,11 @@ discard block |
||
| 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 |
||
| 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 |
||
| 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 |
||
| 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 |
||
| 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 | |
@@ -15,10 +15,10 @@ discard block |
||
| 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 |
||
| 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 |
||
| 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 |
||
| 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 |
||
| 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 |
||
| 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 |
||
| 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 |
||
| 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 |
||
| 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( |