@@ -9,19 +9,19 @@ discard block |
||
| 9 | 9 | $remove = true; |
| 10 | 10 | $dryRun = true; |
| 11 | 11 | |
| 12 | - if($request && $request->requestVar('remove') !== null) { |
|
| 13 | - $remove = (bool)$request->requestVar('remove'); |
|
| 12 | + if ($request && $request->requestVar('remove') !== null) { |
|
| 13 | + $remove = (bool) $request->requestVar('remove'); |
|
| 14 | 14 | } |
| 15 | 15 | |
| 16 | - if($request && $request->requestVar('dryrun') !== null) { |
|
| 17 | - $dryRun = (bool)$request->requestVar('dryrun'); |
|
| 16 | + if ($request && $request->requestVar('dryrun') !== null) { |
|
| 17 | + $dryRun = (bool) $request->requestVar('dryrun'); |
|
| 18 | 18 | } |
| 19 | 19 | |
| 20 | - if($dryRun) { |
|
| 20 | + if ($dryRun) { |
|
| 21 | 21 | echo "Running in dry run mode, no changes commited, "; |
| 22 | - echo "the output shows a prediction on what will happen." . PHP_EOL; |
|
| 23 | - echo "To skip dryrun, run the task like this:" . PHP_EOL; |
|
| 24 | - echo "./framework/sake dev/tasks/SyncProjectsAndEnvironments dryrun=0" . PHP_EOL . PHP_EOL; |
|
| 22 | + echo "the output shows a prediction on what will happen.".PHP_EOL; |
|
| 23 | + echo "To skip dryrun, run the task like this:".PHP_EOL; |
|
| 24 | + echo "./framework/sake dev/tasks/SyncProjectsAndEnvironments dryrun=0".PHP_EOL.PHP_EOL; |
|
| 25 | 25 | sleep(3); |
| 26 | 26 | } |
| 27 | 27 | |
@@ -30,7 +30,7 @@ discard block |
||
| 30 | 30 | |
| 31 | 31 | // Sync projects |
| 32 | 32 | $projects = DNProject::get(); |
| 33 | - if($remove) { |
|
| 33 | + if ($remove) { |
|
| 34 | 34 | $this->echoHeader('Removing obsolete projects'); |
| 35 | 35 | $this->removeObsoleteProjects($projectPaths, $dryRun); |
| 36 | 36 | } |
@@ -38,7 +38,7 @@ discard block |
||
| 38 | 38 | $this->syncProjectPaths($projectPaths, $dryRun); |
| 39 | 39 | |
| 40 | 40 | $this->echoHeader('Syncing environment files'); |
| 41 | - foreach($projects as $project) { |
|
| 41 | + foreach ($projects as $project) { |
|
| 42 | 42 | $this->echoHeader($project->Name); |
| 43 | 43 | // Sync environments for each project |
| 44 | 44 | $environmentPaths = $data->getEnvironmentPaths($project->Name); |
@@ -62,13 +62,13 @@ discard block |
||
| 62 | 62 | }, $paths); |
| 63 | 63 | |
| 64 | 64 | $removeList = $list->filter('Filename:not', $basePaths); |
| 65 | - if($removeList->count() === 0) { |
|
| 65 | + if ($removeList->count() === 0) { |
|
| 66 | 66 | return; |
| 67 | 67 | } |
| 68 | 68 | |
| 69 | - foreach($removeList as $remove) { |
|
| 70 | - $this->message('Removing "' . basename($remove->Name) . '" from db'); |
|
| 71 | - if(!$dryRun) { |
|
| 69 | + foreach ($removeList as $remove) { |
|
| 70 | + $this->message('Removing "'.basename($remove->Name).'" from db'); |
|
| 71 | + if (!$dryRun) { |
|
| 72 | 72 | $removeList->remove($remove); |
| 73 | 73 | } |
| 74 | 74 | } |
@@ -83,13 +83,13 @@ discard block |
||
| 83 | 83 | */ |
| 84 | 84 | protected function removeObsoleteProjects($paths, $dryrun = false) { |
| 85 | 85 | $removeList = DNProject::get()->filter('Name:not', $paths); |
| 86 | - if($removeList->count() == 0) { |
|
| 86 | + if ($removeList->count() == 0) { |
|
| 87 | 87 | return; |
| 88 | 88 | } |
| 89 | 89 | |
| 90 | - foreach($removeList as $remove) { |
|
| 91 | - $this->message($remove->Name . ' ' . $remove->Path); |
|
| 92 | - if(!$dryrun) { |
|
| 90 | + foreach ($removeList as $remove) { |
|
| 91 | + $this->message($remove->Name.' '.$remove->Path); |
|
| 92 | + if (!$dryrun) { |
|
| 93 | 93 | $removeList->remove($remove); |
| 94 | 94 | } |
| 95 | 95 | } |
@@ -106,22 +106,22 @@ discard block |
||
| 106 | 106 | $list = $project->Environments(); |
| 107 | 107 | |
| 108 | 108 | // Normalise paths in DB |
| 109 | - foreach($list as $item) { |
|
| 109 | + foreach ($list as $item) { |
|
| 110 | 110 | $real = realpath($item->Filename); |
| 111 | - if($real && $real != $item->Filename) { |
|
| 111 | + if ($real && $real != $item->Filename) { |
|
| 112 | 112 | $item->Filename = $real; |
| 113 | 113 | $item->write(); |
| 114 | 114 | } |
| 115 | 115 | } |
| 116 | 116 | |
| 117 | - foreach($paths as $path) { |
|
| 117 | + foreach ($paths as $path) { |
|
| 118 | 118 | $path = basename($path); |
| 119 | - if($list->filter('Filename', $path)->count()) { |
|
| 119 | + if ($list->filter('Filename', $path)->count()) { |
|
| 120 | 120 | continue; |
| 121 | 121 | } |
| 122 | 122 | |
| 123 | - $this->message('Adding "' . basename($path) . '" to db'); |
|
| 124 | - if(!$dryRun) { |
|
| 123 | + $this->message('Adding "'.basename($path).'" to db'); |
|
| 124 | + if (!$dryRun) { |
|
| 125 | 125 | $environment = DNEnvironment::create_from_path($path); |
| 126 | 126 | $environment->ProjectID = $project->ID; |
| 127 | 127 | $environment->write(); |
@@ -136,10 +136,10 @@ discard block |
||
| 136 | 136 | * @param boolean $dryRun |
| 137 | 137 | */ |
| 138 | 138 | public function syncProjectPaths($paths, $dryRun = false) { |
| 139 | - foreach($paths as $path) { |
|
| 140 | - if(!DNProject::get()->filter('Name', $path)->count()) { |
|
| 139 | + foreach ($paths as $path) { |
|
| 140 | + if (!DNProject::get()->filter('Name', $path)->count()) { |
|
| 141 | 141 | $this->message($path); |
| 142 | - if(!$dryRun) { |
|
| 142 | + if (!$dryRun) { |
|
| 143 | 143 | DNProject::create_from_path($path)->write(); |
| 144 | 144 | } |
| 145 | 145 | } |
@@ -150,20 +150,20 @@ discard block |
||
| 150 | 150 | * @param string $text |
| 151 | 151 | */ |
| 152 | 152 | protected function message($text) { |
| 153 | - if(PHP_SAPI !== 'cli') { |
|
| 154 | - $text = '<p>' . $text . '</p>' . PHP_EOL; |
|
| 153 | + if (PHP_SAPI !== 'cli') { |
|
| 154 | + $text = '<p>'.$text.'</p>'.PHP_EOL; |
|
| 155 | 155 | } |
| 156 | - echo ' - ' . $text . PHP_EOL; |
|
| 156 | + echo ' - '.$text.PHP_EOL; |
|
| 157 | 157 | } |
| 158 | 158 | |
| 159 | 159 | /** |
| 160 | 160 | * @param string $text |
| 161 | 161 | */ |
| 162 | 162 | protected function echoHeader($text) { |
| 163 | - if(PHP_SAPI !== 'cli') { |
|
| 164 | - echo '<h2>' . $text . '</h2>' . PHP_EOL; |
|
| 163 | + if (PHP_SAPI !== 'cli') { |
|
| 164 | + echo '<h2>'.$text.'</h2>'.PHP_EOL; |
|
| 165 | 165 | } else { |
| 166 | - echo '# ' . $text . PHP_EOL; |
|
| 166 | + echo '# '.$text.PHP_EOL; |
|
| 167 | 167 | } |
| 168 | 168 | } |
| 169 | 169 | } |
@@ -50,19 +50,19 @@ discard block |
||
| 50 | 50 | * @return string |
| 51 | 51 | */ |
| 52 | 52 | public function Name() { |
| 53 | - return (string)htmlentities($this->branch->getName()); |
|
| 53 | + return (string) htmlentities($this->branch->getName()); |
|
| 54 | 54 | } |
| 55 | 55 | |
| 56 | 56 | public function Link() { |
| 57 | 57 | // Use a get-var for branch so that it can handle unsafe chars better |
| 58 | - return Controller::join_links($this->project->Link(), 'branch?name=' . urlencode($this->Name())); |
|
| 58 | + return Controller::join_links($this->project->Link(), 'branch?name='.urlencode($this->Name())); |
|
| 59 | 59 | } |
| 60 | 60 | |
| 61 | 61 | /** |
| 62 | 62 | * @return string |
| 63 | 63 | */ |
| 64 | 64 | public function SHA() { |
| 65 | - return (string)htmlentities($this->branch->getCommit()->getHash()); |
|
| 65 | + return (string) htmlentities($this->branch->getCommit()->getHash()); |
|
| 66 | 66 | } |
| 67 | 67 | |
| 68 | 68 | /** |
@@ -78,12 +78,12 @@ discard block |
||
| 78 | 78 | */ |
| 79 | 79 | public function LastUpdated() { |
| 80 | 80 | |
| 81 | - if($this->_lastUpdatedCache) { |
|
| 81 | + if ($this->_lastUpdatedCache) { |
|
| 82 | 82 | return $this->_lastUpdatedCache; |
| 83 | 83 | } |
| 84 | 84 | try { |
| 85 | 85 | $created = $this->branch->getCommit()->getCommitterDate(); |
| 86 | - } catch(Exception $e) { |
|
| 86 | + } catch (Exception $e) { |
|
| 87 | 87 | //occasionally parsing will fail this is a fallback to make it still work |
| 88 | 88 | return new SS_Datetime(); |
| 89 | 89 | } |
@@ -103,7 +103,7 @@ discard block |
||
| 103 | 103 | * @return string |
| 104 | 104 | */ |
| 105 | 105 | public function IsOpenByDefault() { |
| 106 | - if($this->Name() == 'master') { |
|
| 106 | + if ($this->Name() == 'master') { |
|
| 107 | 107 | return " open"; |
| 108 | 108 | } else { |
| 109 | 109 | return ""; |
@@ -160,7 +160,7 @@ discard block |
||
| 160 | 160 | $cache = self::get_git_cache(); |
| 161 | 161 | // we only need to clear the tag cache since everything else is cached by SHA, that is for commit and |
| 162 | 162 | // commit message. |
| 163 | - $cache->clean(Zend_Cache::CLEANING_MODE_MATCHING_TAG, ['gitonomy', 'tags', 'project_' . $this->ID]); |
|
| 163 | + $cache->clean(Zend_Cache::CLEANING_MODE_MATCHING_TAG, ['gitonomy', 'tags', 'project_'.$this->ID]); |
|
| 164 | 164 | } |
| 165 | 165 | |
| 166 | 166 | /** |
@@ -331,7 +331,7 @@ discard block |
||
| 331 | 331 | return true; |
| 332 | 332 | } |
| 333 | 333 | |
| 334 | - return (bool) $this->Environments()->filterByCallback(function ($env) use ($member) { |
|
| 334 | + return (bool) $this->Environments()->filterByCallback(function($env) use ($member) { |
|
| 335 | 335 | return $env->canRestore($member); |
| 336 | 336 | })->Count(); |
| 337 | 337 | } |
@@ -352,7 +352,7 @@ discard block |
||
| 352 | 352 | return true; |
| 353 | 353 | } |
| 354 | 354 | |
| 355 | - return (bool) $this->Environments()->filterByCallback(function ($env) use ($member) { |
|
| 355 | + return (bool) $this->Environments()->filterByCallback(function($env) use ($member) { |
|
| 356 | 356 | return $env->canBackup($member); |
| 357 | 357 | })->Count(); |
| 358 | 358 | } |
@@ -373,7 +373,7 @@ discard block |
||
| 373 | 373 | return true; |
| 374 | 374 | } |
| 375 | 375 | |
| 376 | - return (bool) $this->Environments()->filterByCallback(function ($env) use ($member) { |
|
| 376 | + return (bool) $this->Environments()->filterByCallback(function($env) use ($member) { |
|
| 377 | 377 | return $env->canUploadArchive($member); |
| 378 | 378 | })->Count(); |
| 379 | 379 | } |
@@ -394,7 +394,7 @@ discard block |
||
| 394 | 394 | return true; |
| 395 | 395 | } |
| 396 | 396 | |
| 397 | - return (bool) $this->Environments()->filterByCallback(function ($env) use ($member) { |
|
| 397 | + return (bool) $this->Environments()->filterByCallback(function($env) use ($member) { |
|
| 398 | 398 | return $env->canDownloadArchive($member); |
| 399 | 399 | })->Count(); |
| 400 | 400 | } |
@@ -453,7 +453,7 @@ discard block |
||
| 453 | 453 | // Key-pair is available, use it. |
| 454 | 454 | $processEnv = [ |
| 455 | 455 | 'IDENT_KEY' => $this->getPrivateKeyPath(), |
| 456 | - 'GIT_SSH' => BASE_PATH . "/deploynaut/git-deploy.sh" |
|
| 456 | + 'GIT_SSH' => BASE_PATH."/deploynaut/git-deploy.sh" |
|
| 457 | 457 | ]; |
| 458 | 458 | } else { |
| 459 | 459 | $processEnv = []; |
@@ -541,7 +541,7 @@ discard block |
||
| 541 | 541 | |
| 542 | 542 | $currentMember = self::$_current_member_cache; |
| 543 | 543 | return $this->Environments() |
| 544 | - ->filterByCallBack(function ($item) use ($currentMember) { |
|
| 544 | + ->filterByCallBack(function($item) use ($currentMember) { |
|
| 545 | 545 | return $item->canView($currentMember); |
| 546 | 546 | }); |
| 547 | 547 | } |
@@ -560,14 +560,14 @@ discard block |
||
| 560 | 560 | * @return false|DNDeployment |
| 561 | 561 | */ |
| 562 | 562 | public function currentBuilds() { |
| 563 | - if (!isset(self::$relation_cache['currentBuilds.' . $this->ID])) { |
|
| 563 | + if (!isset(self::$relation_cache['currentBuilds.'.$this->ID])) { |
|
| 564 | 564 | $currentBuilds = []; |
| 565 | 565 | foreach ($this->Environments() as $env) { |
| 566 | 566 | $currentBuilds[$env->Name] = $env->CurrentBuild(); |
| 567 | 567 | } |
| 568 | - self::$relation_cache['currentBuilds.' . $this->ID] = $currentBuilds; |
|
| 568 | + self::$relation_cache['currentBuilds.'.$this->ID] = $currentBuilds; |
|
| 569 | 569 | } |
| 570 | - return self::$relation_cache['currentBuilds.' . $this->ID]; |
|
| 570 | + return self::$relation_cache['currentBuilds.'.$this->ID]; |
|
| 571 | 571 | } |
| 572 | 572 | |
| 573 | 573 | /** |
@@ -808,7 +808,7 @@ discard block |
||
| 808 | 808 | */ |
| 809 | 809 | public function getPublicKeyPath() { |
| 810 | 810 | if ($privateKey = $this->getPrivateKeyPath()) { |
| 811 | - return $privateKey . '.pub'; |
|
| 811 | + return $privateKey.'.pub'; |
|
| 812 | 812 | } |
| 813 | 813 | return null; |
| 814 | 814 | } |
@@ -823,7 +823,7 @@ discard block |
||
| 823 | 823 | if (!empty($keyDir)) { |
| 824 | 824 | $filter = FileNameFilter::create(); |
| 825 | 825 | $name = $filter->filter($this->Name); |
| 826 | - return $keyDir . '/' . $name; |
|
| 826 | + return $keyDir.'/'.$name; |
|
| 827 | 827 | } |
| 828 | 828 | return null; |
| 829 | 829 | } |
@@ -842,7 +842,7 @@ discard block |
||
| 842 | 842 | $filter = FileNameFilter::create(); |
| 843 | 843 | $name = $filter->filter($this->Name); |
| 844 | 844 | |
| 845 | - return $this->DNData()->getKeyDir() . '/' . $name; |
|
| 845 | + return $this->DNData()->getKeyDir().'/'.$name; |
|
| 846 | 846 | } |
| 847 | 847 | |
| 848 | 848 | /** |
@@ -868,7 +868,7 @@ discard block |
||
| 868 | 868 | /* Look for each whitelisted hostname */ |
| 869 | 869 | foreach ($interfaces as $host => $interface) { |
| 870 | 870 | /* See if the CVS Path is for this hostname, followed by some junk (maybe a port), then the path */ |
| 871 | - if (preg_match('{^[^.]*' . $host . '(.*?)([/a-zA-Z].+)}', $this->CVSPath, $match)) { |
|
| 871 | + if (preg_match('{^[^.]*'.$host.'(.*?)([/a-zA-Z].+)}', $this->CVSPath, $match)) { |
|
| 872 | 872 | |
| 873 | 873 | $path = $match[2]; |
| 874 | 874 | |
@@ -879,10 +879,10 @@ discard block |
||
| 879 | 879 | $components = explode('.', $host); |
| 880 | 880 | |
| 881 | 881 | foreach ($regex as $pattern => $replacement) { |
| 882 | - $path = preg_replace('/' . $pattern . '/', $replacement, $path); |
|
| 882 | + $path = preg_replace('/'.$pattern.'/', $replacement, $path); |
|
| 883 | 883 | } |
| 884 | 884 | |
| 885 | - $uxurl = Controller::join_links($scheme . '://', $host, $path); |
|
| 885 | + $uxurl = Controller::join_links($scheme.'://', $host, $path); |
|
| 886 | 886 | |
| 887 | 887 | if (array_key_exists('commit', $interface) && $interface['commit'] == false) { |
| 888 | 888 | $commiturl = false; |
@@ -1009,7 +1009,7 @@ discard block |
||
| 1009 | 1009 | // {@see DataObject::extendedCan()} |
| 1010 | 1010 | $isDone = $this->extend('isProjectReady'); |
| 1011 | 1011 | if ($isDone && is_array($isDone)) { |
| 1012 | - $isDone = array_filter($isDone, function ($val) { |
|
| 1012 | + $isDone = array_filter($isDone, function($val) { |
|
| 1013 | 1013 | return !is_null($val); |
| 1014 | 1014 | }); |
| 1015 | 1015 | |
@@ -1094,11 +1094,11 @@ discard block |
||
| 1094 | 1094 | return false; |
| 1095 | 1095 | } |
| 1096 | 1096 | |
| 1097 | - $cachekey = $this->ID . '_commit_' . $sha; |
|
| 1097 | + $cachekey = $this->ID.'_commit_'.$sha; |
|
| 1098 | 1098 | $cache = self::get_git_cache(); |
| 1099 | 1099 | if (!($result = $cache->load($cachekey))) { |
| 1100 | 1100 | $result = $repo->getCommit($sha); |
| 1101 | - $cache->save($result, $cachekey, ['gitonomy', 'commit', 'project_' . $this->ID]); |
|
| 1101 | + $cache->save($result, $cachekey, ['gitonomy', 'commit', 'project_'.$this->ID]); |
|
| 1102 | 1102 | } |
| 1103 | 1103 | return $result; |
| 1104 | 1104 | } |
@@ -1108,11 +1108,11 @@ discard block |
||
| 1108 | 1108 | * @return string |
| 1109 | 1109 | */ |
| 1110 | 1110 | public function getCommitMessage(\Gitonomy\Git\Commit $commit) { |
| 1111 | - $cachekey = $this->ID . '_message_' . $commit->getRevision(); |
|
| 1111 | + $cachekey = $this->ID.'_message_'.$commit->getRevision(); |
|
| 1112 | 1112 | $cache = self::get_git_cache(); |
| 1113 | 1113 | if (!($result = $cache->load($cachekey))) { |
| 1114 | 1114 | $result = $commit->getMessage(); |
| 1115 | - $cache->save($result, $cachekey, ['gitonomy', 'message', 'project_' . $this->ID]); |
|
| 1115 | + $cache->save($result, $cachekey, ['gitonomy', 'message', 'project_'.$this->ID]); |
|
| 1116 | 1116 | } |
| 1117 | 1117 | return $result; |
| 1118 | 1118 | } |
@@ -1122,14 +1122,14 @@ discard block |
||
| 1122 | 1122 | * @return mixed |
| 1123 | 1123 | */ |
| 1124 | 1124 | public function getCommitTags(\Gitonomy\Git\Commit $commit) { |
| 1125 | - $cachekey = $this->ID . '_tags_' . $commit->getRevision(); |
|
| 1125 | + $cachekey = $this->ID.'_tags_'.$commit->getRevision(); |
|
| 1126 | 1126 | $cache = self::get_git_cache(); |
| 1127 | 1127 | $result = $cache->load($cachekey); |
| 1128 | 1128 | // we check against false, because in many cases the tag list is an empty array |
| 1129 | 1129 | if ($result === false) { |
| 1130 | 1130 | $repo = $this->getRepository(); |
| 1131 | 1131 | $result = $tags = $repo->getReferences()->resolveTags($commit->getRevision()); |
| 1132 | - $cache->save($result, $cachekey, ['gitonomy', 'tags', 'project_' . $this->ID]); |
|
| 1132 | + $cache->save($result, $cachekey, ['gitonomy', 'tags', 'project_'.$this->ID]); |
|
| 1133 | 1133 | } |
| 1134 | 1134 | return $result; |
| 1135 | 1135 | } |
@@ -6,8 +6,8 @@ |
||
| 6 | 6 | */ |
| 7 | 7 | class SS_Datetimezone extends SS_Datetime { |
| 8 | 8 | /** |
| 9 | - * Returns the date in the raw SQL-format specific to a given timezone passed from the Member class, e.g. “2006-01-18 16:32:04” |
|
| 10 | - */ |
|
| 9 | + * Returns the date in the raw SQL-format specific to a given timezone passed from the Member class, e.g. “2006-01-18 16:32:04” |
|
| 10 | + */ |
|
| 11 | 11 | public function Nice() { |
| 12 | 12 | //instantiate new DateTime object based off received timestamp in the default timezone |
| 13 | 13 | $timestamp = new DateTime($this->value, new DateTimeZone(date_default_timezone_get())); |
@@ -9,7 +9,7 @@ |
||
| 9 | 9 | * Returns the date in the raw SQL-format specific to a given timezone passed from the Member class, e.g. “2006-01-18 16:32:04” |
| 10 | 10 | */ |
| 11 | 11 | public function Format($format) { |
| 12 | - if($this->value){ |
|
| 12 | + if($this->value) { |
|
| 13 | 13 | $date = new DateTime($this->value); |
| 14 | 14 | //if the current user has set a timezone that is not the default then use that |
| 15 | 15 | $member = Member::currentUser(); |
@@ -15,7 +15,7 @@ discard block |
||
| 15 | 15 | * Returns the date in the raw SQL-format specific to a given timezone passed from the Member class, e.g. “2006-01-18 16:32:04” |
| 16 | 16 | */ |
| 17 | 17 | public function Format($format) { |
| 18 | - if($this->value){ |
|
| 18 | + if ($this->value) { |
|
| 19 | 19 | $date = new DateTime($this->value); |
| 20 | 20 | //if the current user has set a timezone that is not the default then use that |
| 21 | 21 | $member = $this->getCurrentCachedUser(); |
@@ -34,10 +34,10 @@ discard block |
||
| 34 | 34 | */ |
| 35 | 35 | protected function getCurrentCachedUser() { |
| 36 | 36 | $memberID = \Member::currentUserID(); |
| 37 | - if(!$memberID) { |
|
| 37 | + if (!$memberID) { |
|
| 38 | 38 | return null; |
| 39 | 39 | } |
| 40 | - if(!isset(self::$_cache_members[$memberID])) { |
|
| 40 | + if (!isset(self::$_cache_members[$memberID])) { |
|
| 41 | 41 | self::$_cache_members[$memberID] = Member::get()->byId($memberID); |
| 42 | 42 | } |
| 43 | 43 | return self::$_cache_members[$memberID]; |
@@ -14,7 +14,7 @@ |
||
| 14 | 14 | return array_combine($timezones, $timezones); |
| 15 | 15 | } |
| 16 | 16 | |
| 17 | - public function updateCMSFields(FieldList $fields) { |
|
| 17 | + public function updateCMSFields(FieldList $fields) { |
|
| 18 | 18 | $fields->removeFieldFromTab('Root', 'Timezone'); |
| 19 | 19 | $field = DropdownField::create( |
| 20 | 20 | 'Timezone', |
@@ -25,7 +25,7 @@ discard block |
||
| 25 | 25 | |
| 26 | 26 | $currentBuild = $environment->CurrentBuild(); |
| 27 | 27 | $currentSha = $currentBuild ? $currentBuild->SHA : '-'; |
| 28 | - if($currentSha !== $options['sha']) { |
|
| 28 | + if ($currentSha !== $options['sha']) { |
|
| 29 | 29 | $strategy->setChange('Code version', $currentSha, $options['sha']); |
| 30 | 30 | } |
| 31 | 31 | $strategy->setActionTitle('Confirm deployment'); |
@@ -66,7 +66,7 @@ discard block |
||
| 66 | 66 | |
| 67 | 67 | // Use a package generator if specified, otherwise run a direct deploy, which is the default behaviour |
| 68 | 68 | // if build_filename isn't specified |
| 69 | - if($this->packageGenerator) { |
|
| 69 | + if ($this->packageGenerator) { |
|
| 70 | 70 | $log->write(sprintf('Using package generator "%s"', get_class($this->packageGenerator))); |
| 71 | 71 | |
| 72 | 72 | try { |
@@ -76,7 +76,7 @@ discard block |
||
| 76 | 76 | throw $e; |
| 77 | 77 | } |
| 78 | 78 | |
| 79 | - if(empty($args['build_filename'])) { |
|
| 79 | + if (empty($args['build_filename'])) { |
|
| 80 | 80 | throw new RuntimeException('Failed to generate package.'); |
| 81 | 81 | } |
| 82 | 82 | } |
@@ -94,7 +94,7 @@ discard block |
||
| 94 | 94 | $log->write($buffer); |
| 95 | 95 | }); |
| 96 | 96 | |
| 97 | - if(!$command->isSuccessful()) { |
|
| 97 | + if (!$command->isSuccessful()) { |
|
| 98 | 98 | $self->extend('cleanupFailure', $environment, $sha, $log, $project); |
| 99 | 99 | $log->write('Warning: Cleanup failed, but fine to continue. Needs manual cleanup sometime.'); |
| 100 | 100 | } |
@@ -105,7 +105,7 @@ discard block |
||
| 105 | 105 | $this->enableMaintenance($environment, $log, $project); |
| 106 | 106 | |
| 107 | 107 | $rolledBack = null; |
| 108 | - if(!$command->isSuccessful() || !$this->smokeTest($environment, $log)) { |
|
| 108 | + if (!$command->isSuccessful() || !$this->smokeTest($environment, $log)) { |
|
| 109 | 109 | $cleanupFn(); |
| 110 | 110 | $this->extend('deployFailure', $environment, $sha, $log, $project); |
| 111 | 111 | |
@@ -171,7 +171,7 @@ discard block |
||
| 171 | 171 | $command->run(function($type, $buffer) use($log) { |
| 172 | 172 | $log->write($buffer); |
| 173 | 173 | }); |
| 174 | - if(!$command->isSuccessful()) { |
|
| 174 | + if (!$command->isSuccessful()) { |
|
| 175 | 175 | $this->extend('maintenanceEnableFailure', $environment, $log); |
| 176 | 176 | throw new RuntimeException($command->getErrorOutput()); |
| 177 | 177 | } |
@@ -187,7 +187,7 @@ discard block |
||
| 187 | 187 | $command->run(function($type, $buffer) use($log) { |
| 188 | 188 | $log->write($buffer); |
| 189 | 189 | }); |
| 190 | - if(!$command->isSuccessful()) { |
|
| 190 | + if (!$command->isSuccessful()) { |
|
| 191 | 191 | $this->extend('maintenanceDisableFailure', $environment, $log); |
| 192 | 192 | throw new RuntimeException($command->getErrorOutput()); |
| 193 | 193 | } |
@@ -209,25 +209,25 @@ discard block |
||
| 209 | 209 | * @inheritdoc |
| 210 | 210 | */ |
| 211 | 211 | public function dataTransfer(DNDataTransfer $dataTransfer, DeploynautLogFile $log) { |
| 212 | - if($dataTransfer->Direction == 'get') { |
|
| 212 | + if ($dataTransfer->Direction == 'get') { |
|
| 213 | 213 | $this->dataTransferBackup($dataTransfer, $log); |
| 214 | 214 | } else { |
| 215 | 215 | $environment = $dataTransfer->Environment(); |
| 216 | 216 | $project = $environment->Project(); |
| 217 | - $workingDir = TEMP_FOLDER . DIRECTORY_SEPARATOR . 'deploynaut-transfer-' . $dataTransfer->ID; |
|
| 217 | + $workingDir = TEMP_FOLDER.DIRECTORY_SEPARATOR.'deploynaut-transfer-'.$dataTransfer->ID; |
|
| 218 | 218 | $archive = $dataTransfer->DataArchive(); |
| 219 | 219 | |
| 220 | 220 | // extract the sspak contents, we'll need these so capistrano can restore that content |
| 221 | 221 | try { |
| 222 | 222 | $archive->extractArchive($workingDir); |
| 223 | - } catch(Exception $e) { |
|
| 223 | + } catch (Exception $e) { |
|
| 224 | 224 | $log->write($e->getMessage()); |
| 225 | 225 | throw new RuntimeException($e->getMessage()); |
| 226 | 226 | } |
| 227 | 227 | |
| 228 | 228 | // validate the contents match the requested transfer mode |
| 229 | 229 | $result = $archive->validateArchiveContents($dataTransfer->Mode); |
| 230 | - if(!$result->valid()) { |
|
| 230 | + if (!$result->valid()) { |
|
| 231 | 231 | // do some cleaning, get rid of the extracted archive lying around |
| 232 | 232 | $process = new AbortableProcess(sprintf('rm -rf %s', escapeshellarg($workingDir))); |
| 233 | 233 | $process->setTimeout(120); |
@@ -257,41 +257,41 @@ discard block |
||
| 257 | 257 | $name = $environment->getFullName(); |
| 258 | 258 | $env = $environment->Project()->getProcessEnv(); |
| 259 | 259 | |
| 260 | - if(!$args) { |
|
| 260 | + if (!$args) { |
|
| 261 | 261 | $args = array(); |
| 262 | 262 | } |
| 263 | - $args['history_path'] = realpath(DEPLOYNAUT_LOG_PATH . '/'); |
|
| 263 | + $args['history_path'] = realpath(DEPLOYNAUT_LOG_PATH.'/'); |
|
| 264 | 264 | $args['environment_id'] = $environment->ID; |
| 265 | 265 | |
| 266 | 266 | // Inject env string directly into the command. |
| 267 | 267 | // Capistrano doesn't like the $process->setEnv($env) we'd normally do below. |
| 268 | 268 | $envString = ''; |
| 269 | - if(!empty($env)) { |
|
| 269 | + if (!empty($env)) { |
|
| 270 | 270 | $envString .= 'env '; |
| 271 | - foreach($env as $key => $value) { |
|
| 271 | + foreach ($env as $key => $value) { |
|
| 272 | 272 | $envString .= "$key=\"$value\" "; |
| 273 | 273 | } |
| 274 | 274 | } |
| 275 | 275 | |
| 276 | 276 | $data = DNData::inst(); |
| 277 | 277 | // Generate a capfile from a template |
| 278 | - $capTemplate = file_get_contents(BASE_PATH . '/deploynaut/Capfile.template'); |
|
| 278 | + $capTemplate = file_get_contents(BASE_PATH.'/deploynaut/Capfile.template'); |
|
| 279 | 279 | $cap = str_replace( |
| 280 | 280 | array('<config root>', '<ssh key>', '<base path>'), |
| 281 | 281 | array($data->getEnvironmentDir(), DEPLOYNAUT_SSH_KEY, BASE_PATH), |
| 282 | 282 | $capTemplate |
| 283 | 283 | ); |
| 284 | 284 | |
| 285 | - if(defined('DEPLOYNAUT_CAPFILE')) { |
|
| 285 | + if (defined('DEPLOYNAUT_CAPFILE')) { |
|
| 286 | 286 | $capFile = DEPLOYNAUT_CAPFILE; |
| 287 | 287 | } else { |
| 288 | - $capFile = ASSETS_PATH . '/Capfile'; |
|
| 288 | + $capFile = ASSETS_PATH.'/Capfile'; |
|
| 289 | 289 | } |
| 290 | 290 | file_put_contents($capFile, $cap); |
| 291 | 291 | |
| 292 | - $command = "{$envString}cap -f " . escapeshellarg($capFile) . " -vv $name $action ROLES=$roles"; |
|
| 293 | - foreach($args as $argName => $argVal) { |
|
| 294 | - $command .= ' -s ' . escapeshellarg($argName) . '=' . escapeshellarg($argVal); |
|
| 292 | + $command = "{$envString}cap -f ".escapeshellarg($capFile)." -vv $name $action ROLES=$roles"; |
|
| 293 | + foreach ($args as $argName => $argVal) { |
|
| 294 | + $command .= ' -s '.escapeshellarg($argName).'='.escapeshellarg($argVal); |
|
| 295 | 295 | } |
| 296 | 296 | |
| 297 | 297 | $log->write(sprintf('Running command: %s', $command)); |
@@ -325,16 +325,16 @@ discard block |
||
| 325 | 325 | $filepathBase = $dataArchive->generateFilepath($dataTransfer); |
| 326 | 326 | mkdir($filepathBase, 0700, true); |
| 327 | 327 | |
| 328 | - $databasePath = $filepathBase . DIRECTORY_SEPARATOR . 'database.sql.gz'; |
|
| 328 | + $databasePath = $filepathBase.DIRECTORY_SEPARATOR.'database.sql.gz'; |
|
| 329 | 329 | |
| 330 | 330 | // Backup database |
| 331 | - if(in_array($dataTransfer->Mode, array('all', 'db'))) { |
|
| 331 | + if (in_array($dataTransfer->Mode, array('all', 'db'))) { |
|
| 332 | 332 | $log->write(sprintf('Backup of database from "%s" started', $name)); |
| 333 | 333 | $command = $this->getCommand('data:getdb', 'db', $environment, array('data_path' => $databasePath), $log); |
| 334 | 334 | $command->run(function($type, $buffer) use($log) { |
| 335 | 335 | $log->write($buffer); |
| 336 | 336 | }); |
| 337 | - if(!$command->isSuccessful()) { |
|
| 337 | + if (!$command->isSuccessful()) { |
|
| 338 | 338 | $this->extend('dataTransferFailure', $environment, $log); |
| 339 | 339 | throw new RuntimeException($command->getErrorOutput()); |
| 340 | 340 | } |
@@ -342,13 +342,13 @@ discard block |
||
| 342 | 342 | } |
| 343 | 343 | |
| 344 | 344 | // Backup assets |
| 345 | - if(in_array($dataTransfer->Mode, array('all', 'assets'))) { |
|
| 345 | + if (in_array($dataTransfer->Mode, array('all', 'assets'))) { |
|
| 346 | 346 | $log->write(sprintf('Backup of assets from "%s" started', $name)); |
| 347 | 347 | $command = $this->getCommand('data:getassets', 'web', $environment, array('data_path' => $filepathBase), $log); |
| 348 | 348 | $command->run(function($type, $buffer) use($log) { |
| 349 | 349 | $log->write($buffer); |
| 350 | 350 | }); |
| 351 | - if(!$command->isSuccessful()) { |
|
| 351 | + if (!$command->isSuccessful()) { |
|
| 352 | 352 | $this->extend('dataTransferFailure', $environment, $log); |
| 353 | 353 | throw new RuntimeException($command->getErrorOutput()); |
| 354 | 354 | } |
@@ -363,12 +363,12 @@ discard block |
||
| 363 | 363 | $log->write('Creating sspak...'); |
| 364 | 364 | |
| 365 | 365 | $sspakFilename = sprintf('%s.sspak', $dataArchive->generateFilename($dataTransfer)); |
| 366 | - $sspakFilepath = $filepathBase . DIRECTORY_SEPARATOR . $sspakFilename; |
|
| 366 | + $sspakFilepath = $filepathBase.DIRECTORY_SEPARATOR.$sspakFilename; |
|
| 367 | 367 | |
| 368 | 368 | try { |
| 369 | 369 | $dataArchive->attachFile($sspakFilepath, $dataTransfer); |
| 370 | 370 | $dataArchive->setArchiveFromFiles($filepathBase); |
| 371 | - } catch(Exception $e) { |
|
| 371 | + } catch (Exception $e) { |
|
| 372 | 372 | $log->write($e->getMessage()); |
| 373 | 373 | throw new RuntimeException($e->getMessage()); |
| 374 | 374 | } |
@@ -379,7 +379,7 @@ discard block |
||
| 379 | 379 | $process = new AbortableProcess(sprintf('rm -rf %s/assets && rm -f %s', escapeshellarg($filepathBase), escapeshellarg($databasePath))); |
| 380 | 380 | $process->setTimeout(120); |
| 381 | 381 | $process->run(); |
| 382 | - if(!$process->isSuccessful()) { |
|
| 382 | + if (!$process->isSuccessful()) { |
|
| 383 | 383 | $log->write('Could not delete temporary files'); |
| 384 | 384 | throw new RuntimeException($process->getErrorOutput()); |
| 385 | 385 | } |
@@ -398,7 +398,7 @@ discard block |
||
| 398 | 398 | $command->run(function($type, $buffer) use($log) { |
| 399 | 399 | $log->write($buffer); |
| 400 | 400 | }); |
| 401 | - if(!$command->isSuccessful()) { |
|
| 401 | + if (!$command->isSuccessful()) { |
|
| 402 | 402 | $log->write(sprintf('Rebuild of "%s" failed: %s', $name, $command->getErrorOutput())); |
| 403 | 403 | throw new RuntimeException($command->getErrorOutput()); |
| 404 | 404 | } |
@@ -428,14 +428,14 @@ discard block |
||
| 428 | 428 | }; |
| 429 | 429 | |
| 430 | 430 | // Restore database into target environment |
| 431 | - if(in_array($dataTransfer->Mode, array('all', 'db'))) { |
|
| 431 | + if (in_array($dataTransfer->Mode, array('all', 'db'))) { |
|
| 432 | 432 | $log->write(sprintf('Restore of database to "%s" started', $name)); |
| 433 | - $args = array('data_path' => $workingDir . DIRECTORY_SEPARATOR . 'database.sql'); |
|
| 433 | + $args = array('data_path' => $workingDir.DIRECTORY_SEPARATOR.'database.sql'); |
|
| 434 | 434 | $command = $this->getCommand('data:pushdb', 'db', $environment, $args, $log); |
| 435 | 435 | $command->run(function($type, $buffer) use($log) { |
| 436 | 436 | $log->write($buffer); |
| 437 | 437 | }); |
| 438 | - if(!$command->isSuccessful()) { |
|
| 438 | + if (!$command->isSuccessful()) { |
|
| 439 | 439 | $cleanupFn(); |
| 440 | 440 | $log->write(sprintf('Restore of database to "%s" failed: %s', $name, $command->getErrorOutput())); |
| 441 | 441 | $this->extend('dataTransferFailure', $environment, $log); |
@@ -445,14 +445,14 @@ discard block |
||
| 445 | 445 | } |
| 446 | 446 | |
| 447 | 447 | // Restore assets into target environment |
| 448 | - if(in_array($dataTransfer->Mode, array('all', 'assets'))) { |
|
| 448 | + if (in_array($dataTransfer->Mode, array('all', 'assets'))) { |
|
| 449 | 449 | $log->write(sprintf('Restore of assets to "%s" started', $name)); |
| 450 | - $args = array('data_path' => $workingDir . DIRECTORY_SEPARATOR . 'assets'); |
|
| 450 | + $args = array('data_path' => $workingDir.DIRECTORY_SEPARATOR.'assets'); |
|
| 451 | 451 | $command = $this->getCommand('data:pushassets', 'web', $environment, $args, $log); |
| 452 | 452 | $command->run(function($type, $buffer) use($log) { |
| 453 | 453 | $log->write($buffer); |
| 454 | 454 | }); |
| 455 | - if(!$command->isSuccessful()) { |
|
| 455 | + if (!$command->isSuccessful()) { |
|
| 456 | 456 | $cleanupFn(); |
| 457 | 457 | $log->write(sprintf('Restore of assets to "%s" failed: %s', $name, $command->getErrorOutput())); |
| 458 | 458 | $this->extend('dataTransferFailure', $environment, $log); |
@@ -477,7 +477,7 @@ discard block |
||
| 477 | 477 | $timeout = 600; |
| 478 | 478 | $tick = 60; |
| 479 | 479 | |
| 480 | - if(!$url) { |
|
| 480 | + if (!$url) { |
|
| 481 | 481 | $log->write('Skipping site accessible check: no URL found.'); |
| 482 | 482 | return true; |
| 483 | 483 | } |
@@ -508,7 +508,7 @@ discard block |
||
| 508 | 508 | // query the site every second. Note that if the URL doesn't respond, |
| 509 | 509 | // curl_exec will take 5 seconds to timeout (see CURLOPT_CONNECTTIMEOUT and CURLOPT_TIMEOUT above) |
| 510 | 510 | do { |
| 511 | - if(time() > $start + $timeout) { |
|
| 511 | + if (time() > $start + $timeout) { |
|
| 512 | 512 | $log->write(sprintf(' * Failed: check for %s timed out after %smin', $url, $timeout / 60)); |
| 513 | 513 | return false; |
| 514 | 514 | } |
@@ -517,13 +517,13 @@ discard block |
||
| 517 | 517 | |
| 518 | 518 | // check the HTTP response code for HTTP protocols |
| 519 | 519 | $status = curl_getinfo($ch, CURLINFO_HTTP_CODE); |
| 520 | - if($status && !in_array($status, [500, 501, 502, 503, 504])) { |
|
| 520 | + if ($status && !in_array($status, [500, 501, 502, 503, 504])) { |
|
| 521 | 521 | $success = true; |
| 522 | 522 | } |
| 523 | 523 | |
| 524 | 524 | // check for any curl errors, mostly for checking the response state of non-HTTP protocols, |
| 525 | 525 | // but applies to checks of any protocol |
| 526 | - if($response && !curl_errno($ch)) { |
|
| 526 | + if ($response && !curl_errno($ch)) { |
|
| 527 | 527 | $success = true; |
| 528 | 528 | } |
| 529 | 529 | |
@@ -551,7 +551,7 @@ discard block |
||
| 551 | 551 | } |
| 552 | 552 | |
| 553 | 553 | sleep(1); |
| 554 | - } while(!$success); |
|
| 554 | + } while (!$success); |
|
| 555 | 555 | |
| 556 | 556 | curl_close($ch); |
| 557 | 557 | $log->write(' * Success: site is accessible!'); |
@@ -19,27 +19,27 @@ |
||
| 19 | 19 | * |
| 20 | 20 | */ |
| 21 | 21 | public function perform() { |
| 22 | - echo "[-] CreateEnvJob starting" . PHP_EOL; |
|
| 22 | + echo "[-] CreateEnvJob starting".PHP_EOL; |
|
| 23 | 23 | |
| 24 | 24 | $log = new DeploynautLogFile($this->args['logfile']); |
| 25 | 25 | $envCreate = DNCreateEnvironment::get()->byId($this->args['createID']); |
| 26 | 26 | |
| 27 | 27 | // This is a bit icky, but there is no easy way of capturing a failed deploy by using the PHP Resque |
| 28 | 28 | try { |
| 29 | - if(!($envCreate && $envCreate->exists())) { |
|
| 29 | + if (!($envCreate && $envCreate->exists())) { |
|
| 30 | 30 | throw new RuntimeException(sprintf('Could not find create environment record %s', $args['createID'])); |
| 31 | 31 | } |
| 32 | 32 | |
| 33 | 33 | // This will throw and exception if it fails. |
| 34 | 34 | $envCreate->createEnvironment(); |
| 35 | 35 | |
| 36 | - } catch(Exception $e) { |
|
| 36 | + } catch (Exception $e) { |
|
| 37 | 37 | $log->write($e->getMessage()); |
| 38 | - echo "[-] CreateEnvJob failed" . PHP_EOL; |
|
| 38 | + echo "[-] CreateEnvJob failed".PHP_EOL; |
|
| 39 | 39 | throw $e; |
| 40 | 40 | } |
| 41 | 41 | $this->updateStatus('Finished'); |
| 42 | - echo "[-] CreateEnvJob finished" . PHP_EOL; |
|
| 42 | + echo "[-] CreateEnvJob finished".PHP_EOL; |
|
| 43 | 43 | } |
| 44 | 44 | |
| 45 | 45 | /** |
@@ -121,7 +121,7 @@ discard block |
||
| 121 | 121 | } |
| 122 | 122 | |
| 123 | 123 | public function onBeforeWrite() { |
| 124 | - if(!$this->AuthorID) { |
|
| 124 | + if (!$this->AuthorID) { |
|
| 125 | 125 | $this->AuthorID = Member::currentUserID(); |
| 126 | 126 | } |
| 127 | 127 | |
@@ -179,7 +179,7 @@ discard block |
||
| 179 | 179 | * @return string The human-readable size of this archive file |
| 180 | 180 | */ |
| 181 | 181 | public function FileSize() { |
| 182 | - if($this->ArchiveFile()->exists()) { |
|
| 182 | + if ($this->ArchiveFile()->exists()) { |
|
| 183 | 183 | return $this->ArchiveFile()->getSize(); |
| 184 | 184 | } else { |
| 185 | 185 | return "N/A"; |
@@ -187,7 +187,7 @@ discard block |
||
| 187 | 187 | } |
| 188 | 188 | |
| 189 | 189 | public function getModeNice() { |
| 190 | - if($this->Mode == 'all') { |
|
| 190 | + if ($this->Mode == 'all') { |
|
| 191 | 191 | return 'database and assets'; |
| 192 | 192 | } else { |
| 193 | 193 | return $this->Mode; |
@@ -223,12 +223,12 @@ discard block |
||
| 223 | 223 | */ |
| 224 | 224 | public function canRestore($member = null) { |
| 225 | 225 | $memberID = $member ? $member->ID : Member::currentUserID(); |
| 226 | - if(!$memberID) { |
|
| 226 | + if (!$memberID) { |
|
| 227 | 227 | return false; |
| 228 | 228 | } |
| 229 | 229 | |
| 230 | - $key = $memberID . '-' . $this->EnvironmentID; |
|
| 231 | - if(!isset(self::$_cache_can_restore[$key])) { |
|
| 230 | + $key = $memberID.'-'.$this->EnvironmentID; |
|
| 231 | + if (!isset(self::$_cache_can_restore[$key])) { |
|
| 232 | 232 | self::$_cache_can_restore[$key] = $this->Environment()->canUploadArchive($member); |
| 233 | 233 | } |
| 234 | 234 | |
@@ -244,12 +244,12 @@ discard block |
||
| 244 | 244 | */ |
| 245 | 245 | public function canDownload($member = null) { |
| 246 | 246 | $memberID = $member ? $member->ID : Member::currentUserID(); |
| 247 | - if(!$memberID) { |
|
| 247 | + if (!$memberID) { |
|
| 248 | 248 | return false; |
| 249 | 249 | } |
| 250 | 250 | |
| 251 | - $key = $memberID . '-' . $this->EnvironmentID; |
|
| 252 | - if(!isset(self::$_cache_can_download[$key])) { |
|
| 251 | + $key = $memberID.'-'.$this->EnvironmentID; |
|
| 252 | + if (!isset(self::$_cache_can_download[$key])) { |
|
| 253 | 253 | self::$_cache_can_download[$key] = $this->Environment()->canDownloadArchive($member); |
| 254 | 254 | } |
| 255 | 255 | return self::$_cache_can_download[$key]; |
@@ -274,27 +274,27 @@ discard block |
||
| 274 | 274 | * @return boolean true if $member can upload archives linked to this environment, false if they can't. |
| 275 | 275 | */ |
| 276 | 276 | public function canMoveTo($targetEnv, $member = null) { |
| 277 | - if($this->Environment()->Project()->ID != $targetEnv->Project()->ID) { |
|
| 277 | + if ($this->Environment()->Project()->ID != $targetEnv->Project()->ID) { |
|
| 278 | 278 | // We don't permit moving snapshots between projects at this stage. |
| 279 | 279 | return false; |
| 280 | 280 | } |
| 281 | 281 | |
| 282 | - if(!$member) { |
|
| 282 | + if (!$member) { |
|
| 283 | 283 | $member = Member::currentUser(); |
| 284 | 284 | } |
| 285 | 285 | |
| 286 | 286 | // Must be logged in to check permissions |
| 287 | - if(!$member) { |
|
| 287 | + if (!$member) { |
|
| 288 | 288 | return false; |
| 289 | 289 | } |
| 290 | 290 | |
| 291 | 291 | // Admin can always move. |
| 292 | - if(Permission::checkMember($member, 'ADMIN')) { |
|
| 292 | + if (Permission::checkMember($member, 'ADMIN')) { |
|
| 293 | 293 | return true; |
| 294 | 294 | } |
| 295 | 295 | |
| 296 | 296 | // Checks if the user can actually access the archive. |
| 297 | - if(!$this->canDownload($member)) { |
|
| 297 | + if (!$this->canDownload($member)) { |
|
| 298 | 298 | return false; |
| 299 | 299 | } |
| 300 | 300 | |
@@ -403,7 +403,7 @@ discard block |
||
| 403 | 403 | * @return bool |
| 404 | 404 | */ |
| 405 | 405 | public function extractArchive($workingDir = null) { |
| 406 | - if(!is_dir($workingDir)) { |
|
| 406 | + if (!is_dir($workingDir)) { |
|
| 407 | 407 | mkdir($workingDir, 0700, true); |
| 408 | 408 | } |
| 409 | 409 | |
@@ -422,28 +422,28 @@ discard block |
||
| 422 | 422 | )); |
| 423 | 423 | $process->setTimeout(3600); |
| 424 | 424 | $process->run(); |
| 425 | - if(!$process->isSuccessful()) { |
|
| 425 | + if (!$process->isSuccessful()) { |
|
| 426 | 426 | $cleanupFn(); |
| 427 | 427 | throw new RuntimeException(sprintf('Could not extract the sspak file: %s', $process->getErrorOutput())); |
| 428 | 428 | } |
| 429 | 429 | |
| 430 | 430 | // Extract database.sql.gz to <workingdir>/database.sql |
| 431 | - if(file_exists($workingDir . DIRECTORY_SEPARATOR . 'database.sql.gz')) { |
|
| 431 | + if (file_exists($workingDir.DIRECTORY_SEPARATOR.'database.sql.gz')) { |
|
| 432 | 432 | $process = new AbortableProcess('gunzip database.sql.gz', $workingDir); |
| 433 | 433 | $process->setTimeout(3600); |
| 434 | 434 | $process->run(); |
| 435 | - if(!$process->isSuccessful()) { |
|
| 435 | + if (!$process->isSuccessful()) { |
|
| 436 | 436 | $cleanupFn(); |
| 437 | 437 | throw new RuntimeException(sprintf('Could not extract the db archive: %s', $process->getErrorOutput())); |
| 438 | 438 | } |
| 439 | 439 | } |
| 440 | 440 | |
| 441 | 441 | // Extract assets.tar.gz to <workingdir>/assets/ |
| 442 | - if(file_exists($workingDir . DIRECTORY_SEPARATOR . 'assets.tar.gz')) { |
|
| 442 | + if (file_exists($workingDir.DIRECTORY_SEPARATOR.'assets.tar.gz')) { |
|
| 443 | 443 | $process = new AbortableProcess('tar xzf assets.tar.gz', $workingDir); |
| 444 | 444 | $process->setTimeout(3600); |
| 445 | 445 | $process->run(); |
| 446 | - if(!$process->isSuccessful()) { |
|
| 446 | + if (!$process->isSuccessful()) { |
|
| 447 | 447 | $cleanupFn(); |
| 448 | 448 | throw new RuntimeException(sprintf('Could not extract the assets archive: %s', $process->getErrorOutput())); |
| 449 | 449 | } |
@@ -467,7 +467,7 @@ discard block |
||
| 467 | 467 | |
| 468 | 468 | $file = $this->ArchiveFile()->FullPath; |
| 469 | 469 | |
| 470 | - if(!is_readable($file)) { |
|
| 470 | + if (!is_readable($file)) { |
|
| 471 | 471 | $result->error(sprintf('SSPak file "%s" cannot be read.', $file)); |
| 472 | 472 | return $result; |
| 473 | 473 | } |
@@ -475,19 +475,19 @@ discard block |
||
| 475 | 475 | $process = new AbortableProcess(sprintf('tar -tf %s', escapeshellarg($file))); |
| 476 | 476 | $process->setTimeout(120); |
| 477 | 477 | $process->run(); |
| 478 | - if(!$process->isSuccessful()) { |
|
| 478 | + if (!$process->isSuccessful()) { |
|
| 479 | 479 | throw new RuntimeException(sprintf('Could not list files in archive: %s', $process->getErrorOutput())); |
| 480 | 480 | } |
| 481 | 481 | |
| 482 | 482 | $output = explode(PHP_EOL, $process->getOutput()); |
| 483 | 483 | $files = array_filter($output); |
| 484 | 484 | |
| 485 | - if(in_array($mode, array('all', 'db')) && !in_array('database.sql.gz', $files)) { |
|
| 485 | + if (in_array($mode, array('all', 'db')) && !in_array('database.sql.gz', $files)) { |
|
| 486 | 486 | $result->error('The snapshot is missing the database.'); |
| 487 | 487 | return $result; |
| 488 | 488 | } |
| 489 | 489 | |
| 490 | - if(in_array($mode, array('all', 'assets')) && !in_array('assets.tar.gz', $files)) { |
|
| 490 | + if (in_array($mode, array('all', 'assets')) && !in_array('assets.tar.gz', $files)) { |
|
| 491 | 491 | $result->error('The snapshot is missing assets.'); |
| 492 | 492 | return $result; |
| 493 | 493 | } |
@@ -517,11 +517,11 @@ discard block |
||
| 517 | 517 | sprintf('find %s -type f -exec chmod 644 {} +', escapeshellarg($workingDir)) |
| 518 | 518 | ); |
| 519 | 519 | |
| 520 | - foreach($fixCmds as $cmd) { |
|
| 520 | + foreach ($fixCmds as $cmd) { |
|
| 521 | 521 | $process = new AbortableProcess($cmd); |
| 522 | 522 | $process->setTimeout(3600); |
| 523 | 523 | $process->run(); |
| 524 | - if(!$process->isSuccessful()) { |
|
| 524 | + if (!$process->isSuccessful()) { |
|
| 525 | 525 | throw new RuntimeException($process->getErrorOutput()); |
| 526 | 526 | } |
| 527 | 527 | } |
@@ -540,18 +540,18 @@ discard block |
||
| 540 | 540 | */ |
| 541 | 541 | public function setArchiveFromFiles($workingDir) { |
| 542 | 542 | $commands = array(); |
| 543 | - if($this->Mode == 'db') { |
|
| 544 | - if (file_exists($workingDir . '/database.sql')) { |
|
| 543 | + if ($this->Mode == 'db') { |
|
| 544 | + if (file_exists($workingDir.'/database.sql')) { |
|
| 545 | 545 | $commands[] = 'gzip database.sql'; |
| 546 | 546 | } |
| 547 | 547 | $commands[] = sprintf('tar -cf %s database.sql.gz', $this->ArchiveFile()->FullPath); |
| 548 | 548 | $commands[] = 'rm -f database.sql.gz'; |
| 549 | - } elseif($this->Mode == 'assets') { |
|
| 549 | + } elseif ($this->Mode == 'assets') { |
|
| 550 | 550 | $commands[] = 'GZIP=-1 tar --dereference -czf assets.tar.gz assets'; |
| 551 | 551 | $commands[] = sprintf('tar -cf %s assets.tar.gz', $this->ArchiveFile()->FullPath); |
| 552 | 552 | $commands[] = 'rm -f assets.tar.gz'; |
| 553 | 553 | } else { |
| 554 | - if (file_exists($workingDir . '/database.sql')) { |
|
| 554 | + if (file_exists($workingDir.'/database.sql')) { |
|
| 555 | 555 | $commands[] = 'gzip database.sql'; |
| 556 | 556 | } |
| 557 | 557 | $commands[] = 'GZIP=-1 tar --dereference -czf assets.tar.gz assets'; |
@@ -562,7 +562,7 @@ discard block |
||
| 562 | 562 | $process = new AbortableProcess(implode(' && ', $commands), $workingDir); |
| 563 | 563 | $process->setTimeout(3600); |
| 564 | 564 | $process->run(); |
| 565 | - if(!$process->isSuccessful()) { |
|
| 565 | + if (!$process->isSuccessful()) { |
|
| 566 | 566 | throw new RuntimeException($process->getErrorOutput()); |
| 567 | 567 | } |
| 568 | 568 | |
@@ -4,8 +4,8 @@ |
||
| 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()) { |