@@ -82,6 +82,9 @@ |
||
82 | 82 | 'Deployer.Name' => 'Deployer' |
83 | 83 | ); |
84 | 84 | |
85 | + /** |
|
86 | + * @param false|string $token |
|
87 | + */ |
|
85 | 88 | public function setResqueToken($token) { |
86 | 89 | $this->ResqueToken = $token; |
87 | 90 | } |
@@ -263,12 +263,12 @@ |
||
263 | 263 | |
264 | 264 | // failover for older deployments |
265 | 265 | $started = $deployment->Created; |
266 | - if($deployment->DeployStarted) { |
|
266 | + if ($deployment->DeployStarted) { |
|
267 | 267 | $started = $deployment->DeployStarted; |
268 | 268 | } |
269 | 269 | |
270 | 270 | $requested = $deployment->Created; |
271 | - if($deployment->DeployRequested) { |
|
271 | + if ($deployment->DeployRequested) { |
|
272 | 272 | $requested = $deployment->DeployRequested; |
273 | 273 | } |
274 | 274 |
@@ -180,7 +180,7 @@ discard block |
||
180 | 180 | */ |
181 | 181 | public function Backend() { |
182 | 182 | $backends = array_keys($this->config()->get('allowed_backends', Config::FIRST_SET)); |
183 | - switch(sizeof($backends)) { |
|
183 | + switch (sizeof($backends)) { |
|
184 | 184 | // Nothing allowed, use the default value "DeploymentBackend" |
185 | 185 | case 0: |
186 | 186 | $backend = "DeploymentBackend"; |
@@ -194,7 +194,7 @@ discard block |
||
194 | 194 | // Multiple choices, use our choice if it's legal, otherwise default to the first item on the list |
195 | 195 | default: |
196 | 196 | $backend = $this->BackendIdentifier; |
197 | - if(!in_array($backend, $backends)) { |
|
197 | + if (!in_array($backend, $backends)) { |
|
198 | 198 | $backend = $backends[0]; |
199 | 199 | } |
200 | 200 | } |
@@ -256,14 +256,14 @@ discard block |
||
256 | 256 | |
257 | 257 | public function getBareURL() { |
258 | 258 | $url = parse_url($this->URL); |
259 | - if(isset($url['host'])) { |
|
259 | + if (isset($url['host'])) { |
|
260 | 260 | return strtolower($url['host']); |
261 | 261 | } |
262 | 262 | } |
263 | 263 | |
264 | 264 | public function getBareDefaultURL() { |
265 | 265 | $url = parse_url($this->getDefaultURL()); |
266 | - if(isset($url['host'])) { |
|
266 | + if (isset($url['host'])) { |
|
267 | 267 | return strtolower($url['host']); |
268 | 268 | } |
269 | 269 | } |
@@ -275,20 +275,20 @@ discard block |
||
275 | 275 | * @return boolean |
276 | 276 | */ |
277 | 277 | public function canView($member = null) { |
278 | - if(!$member) { |
|
278 | + if (!$member) { |
|
279 | 279 | $member = Member::currentUser(); |
280 | 280 | } |
281 | - if(!$member) { |
|
281 | + if (!$member) { |
|
282 | 282 | return false; |
283 | 283 | } |
284 | 284 | // Must be logged in to check permissions |
285 | 285 | |
286 | - if(Permission::checkMember($member, 'ADMIN')) { |
|
286 | + if (Permission::checkMember($member, 'ADMIN')) { |
|
287 | 287 | return true; |
288 | 288 | } |
289 | 289 | |
290 | 290 | // if no Viewers or ViewerGroups defined, fallback to DNProject::canView permissions |
291 | - if($this->Viewers()->exists() || $this->ViewerGroups()->exists()) { |
|
291 | + if ($this->Viewers()->exists() || $this->ViewerGroups()->exists()) { |
|
292 | 292 | return $this->Viewers()->byID($member->ID) |
293 | 293 | || $member->inGroups($this->ViewerGroups()); |
294 | 294 | } |
@@ -303,10 +303,10 @@ discard block |
||
303 | 303 | * @return boolean |
304 | 304 | */ |
305 | 305 | public function canDeploy($member = null) { |
306 | - if(!$member) { |
|
306 | + if (!$member) { |
|
307 | 307 | $member = Member::currentUser(); |
308 | 308 | } |
309 | - if(!$member) { |
|
309 | + if (!$member) { |
|
310 | 310 | return false; |
311 | 311 | } |
312 | 312 | // Must be logged in to check permissions |
@@ -338,10 +338,10 @@ discard block |
||
338 | 338 | * @return boolean true if $member can restore, and false if they can't. |
339 | 339 | */ |
340 | 340 | public function canRestore($member = null) { |
341 | - if(!$member) { |
|
341 | + if (!$member) { |
|
342 | 342 | $member = Member::currentUser(); |
343 | 343 | } |
344 | - if(!$member) { |
|
344 | + if (!$member) { |
|
345 | 345 | return false; |
346 | 346 | } |
347 | 347 | // Must be logged in to check permissions |
@@ -365,15 +365,15 @@ discard block |
||
365 | 365 | */ |
366 | 366 | public function canBackup($member = null) { |
367 | 367 | $project = $this->Project(); |
368 | - if($project->HasDiskQuota() && $project->HasExceededDiskQuota()) { |
|
368 | + if ($project->HasDiskQuota() && $project->HasExceededDiskQuota()) { |
|
369 | 369 | return false; |
370 | 370 | } |
371 | 371 | |
372 | - if(!$member) { |
|
372 | + if (!$member) { |
|
373 | 373 | $member = Member::currentUser(); |
374 | 374 | } |
375 | 375 | // Must be logged in to check permissions |
376 | - if(!$member) { |
|
376 | + if (!$member) { |
|
377 | 377 | return false; |
378 | 378 | } |
379 | 379 | |
@@ -400,14 +400,14 @@ discard block |
||
400 | 400 | */ |
401 | 401 | public function canUploadArchive($member = null) { |
402 | 402 | $project = $this->Project(); |
403 | - if($project->HasDiskQuota() && $project->HasExceededDiskQuota()) { |
|
403 | + if ($project->HasDiskQuota() && $project->HasExceededDiskQuota()) { |
|
404 | 404 | return false; |
405 | 405 | } |
406 | 406 | |
407 | - if(!$member) { |
|
407 | + if (!$member) { |
|
408 | 408 | $member = Member::currentUser(); |
409 | 409 | } |
410 | - if(!$member) { |
|
410 | + if (!$member) { |
|
411 | 411 | return false; |
412 | 412 | } |
413 | 413 | // Must be logged in to check permissions |
@@ -430,10 +430,10 @@ discard block |
||
430 | 430 | * @return boolean true if $member can download archives from this environment, false if they can't. |
431 | 431 | */ |
432 | 432 | public function canDownloadArchive($member = null) { |
433 | - if(!$member) { |
|
433 | + if (!$member) { |
|
434 | 434 | $member = Member::currentUser(); |
435 | 435 | } |
436 | - if(!$member) { |
|
436 | + if (!$member) { |
|
437 | 437 | return false; |
438 | 438 | } |
439 | 439 | // Must be logged in to check permissions |
@@ -456,10 +456,10 @@ discard block |
||
456 | 456 | * @return boolean true if $member can delete archives from this environment, false if they can't. |
457 | 457 | */ |
458 | 458 | public function canDeleteArchive($member = null) { |
459 | - if(!$member) { |
|
459 | + if (!$member) { |
|
460 | 460 | $member = Member::currentUser(); |
461 | 461 | } |
462 | - if(!$member) { |
|
462 | + if (!$member) { |
|
463 | 463 | return false; |
464 | 464 | } |
465 | 465 | // Must be logged in to check permissions |
@@ -589,18 +589,18 @@ discard block |
||
589 | 589 | 'State' => DNDeployment::STATE_COMPLETED |
590 | 590 | ))->sort('LastEdited DESC')->first(); |
591 | 591 | |
592 | - if(!$deploy || (!$deploy->SHA)) { |
|
592 | + if (!$deploy || (!$deploy->SHA)) { |
|
593 | 593 | return false; |
594 | 594 | } |
595 | 595 | |
596 | 596 | $repo = $this->Project()->getRepository(); |
597 | - if(!$repo) { |
|
597 | + if (!$repo) { |
|
598 | 598 | return $deploy; |
599 | 599 | } |
600 | 600 | |
601 | 601 | try { |
602 | 602 | $commit = $repo->getCommit($deploy->SHA); |
603 | - if($commit) { |
|
603 | + if ($commit) { |
|
604 | 604 | $deploy->Message = Convert::raw2xml($commit->getMessage()); |
605 | 605 | $deploy->Committer = Convert::raw2xml($commit->getCommitterName()); |
606 | 606 | $deploy->CommitDate = $commit->getCommitterDate()->Format('d/m/Y g:ia'); |
@@ -608,7 +608,7 @@ discard block |
||
608 | 608 | $deploy->AuthorDate = $commit->getAuthorDate()->Format('d/m/Y g:ia'); |
609 | 609 | } |
610 | 610 | // We can't find this SHA, so we ignore adding a commit message to the deployment |
611 | - } catch(Exception $ex) { } |
|
611 | + } catch (Exception $ex) { } |
|
612 | 612 | |
613 | 613 | return $deploy; |
614 | 614 | } |
@@ -621,7 +621,7 @@ discard block |
||
621 | 621 | public function DeployHistory($orderBy = '') { |
622 | 622 | |
623 | 623 | $sort = []; |
624 | - if($orderBy != '') { |
|
624 | + if ($orderBy != '') { |
|
625 | 625 | $sort[$orderBy] = 'DESC'; |
626 | 626 | } |
627 | 627 | // default / fallback sort order |
@@ -661,17 +661,17 @@ discard block |
||
661 | 661 | protected function getCommitData($sha) { |
662 | 662 | try { |
663 | 663 | $repo = $this->Project()->getRepository(); |
664 | - if($repo !== false) { |
|
664 | + if ($repo !== false) { |
|
665 | 665 | $commit = new \Gitonomy\Git\Commit($repo, $sha); |
666 | 666 | return [ |
667 | - 'AuthorName' => (string)Convert::raw2xml($commit->getAuthorName()), |
|
668 | - 'AuthorEmail' => (string)Convert::raw2xml($commit->getAuthorEmail()), |
|
669 | - 'Message' => (string)Convert::raw2xml($commit->getMessage()), |
|
667 | + 'AuthorName' => (string) Convert::raw2xml($commit->getAuthorName()), |
|
668 | + 'AuthorEmail' => (string) Convert::raw2xml($commit->getAuthorEmail()), |
|
669 | + 'Message' => (string) Convert::raw2xml($commit->getMessage()), |
|
670 | 670 | 'ShortHash' => Convert::raw2xml($commit->getFixedShortHash(8)), |
671 | 671 | 'Hash' => Convert::raw2xml($commit->getHash()) |
672 | 672 | ]; |
673 | 673 | } |
674 | - } catch(\Gitonomy\Git\Exception\ReferenceNotFoundException $exc) { |
|
674 | + } catch (\Gitonomy\Git\Exception\ReferenceNotFoundException $exc) { |
|
675 | 675 | SS_Log::log($exc, SS_Log::WARN); |
676 | 676 | } |
677 | 677 | return array( |
@@ -743,12 +743,12 @@ discard block |
||
743 | 743 | $fields = new FieldList(new TabSet('Root')); |
744 | 744 | |
745 | 745 | $project = $this->Project(); |
746 | - if($project && $project->exists()) { |
|
746 | + if ($project && $project->exists()) { |
|
747 | 747 | $viewerGroups = $project->Viewers(); |
748 | 748 | $groups = $viewerGroups->sort('Title')->map()->toArray(); |
749 | 749 | $members = array(); |
750 | - foreach($viewerGroups as $group) { |
|
751 | - foreach($group->Members()->map() as $k => $v) { |
|
750 | + foreach ($viewerGroups as $group) { |
|
751 | + foreach ($group->Members()->map() as $k => $v) { |
|
752 | 752 | $members[$k] = $v; |
753 | 753 | } |
754 | 754 | } |
@@ -785,7 +785,7 @@ discard block |
||
785 | 785 | // Backend identifier - pick from a named list of configurations specified in YML config |
786 | 786 | $backends = $this->config()->get('allowed_backends', Config::FIRST_SET); |
787 | 787 | // If there's only 1 backend, then user selection isn't needed |
788 | - if(sizeof($backends) > 1) { |
|
788 | + if (sizeof($backends) > 1) { |
|
789 | 789 | $fields->addFieldToTab('Root.Main', DropdownField::create('BackendIdentifier', 'Deployment backend') |
790 | 790 | ->setSource($backends) |
791 | 791 | ->setDescription('What kind of deployment system should be used to deploy to this environment')); |
@@ -834,7 +834,7 @@ discard block |
||
834 | 834 | ->buildPermissionField('ArchiveUploaderGroups', 'ArchiveUploaders', $groups, $members) |
835 | 835 | ->setTitle('Who can upload?') |
836 | 836 | ->setDescription( |
837 | - 'Users who can upload archives linked to this environment into Deploynaut.<br />' . |
|
837 | + 'Users who can upload archives linked to this environment into Deploynaut.<br />'. |
|
838 | 838 | 'Linking them to an environment allows limiting download permissions (see below).' |
839 | 839 | ), |
840 | 840 | |
@@ -854,14 +854,14 @@ discard block |
||
854 | 854 | )); |
855 | 855 | |
856 | 856 | // The Main.DeployConfig |
857 | - if($this->Project()->exists()) { |
|
857 | + if ($this->Project()->exists()) { |
|
858 | 858 | $this->setDeployConfigurationFields($fields); |
859 | 859 | } |
860 | 860 | |
861 | 861 | // The DataArchives |
862 | 862 | $dataArchiveConfig = GridFieldConfig_RecordViewer::create(); |
863 | 863 | $dataArchiveConfig->removeComponentsByType('GridFieldAddNewButton'); |
864 | - if(class_exists('GridFieldBulkManager')) { |
|
864 | + if (class_exists('GridFieldBulkManager')) { |
|
865 | 865 | $dataArchiveConfig->addComponent(new GridFieldBulkManager()); |
866 | 866 | } |
867 | 867 | $dataArchive = GridField::create('DataArchives', 'Data Archives', $this->DataArchives(), $dataArchiveConfig); |
@@ -870,7 +870,7 @@ discard block |
||
870 | 870 | // Deployments |
871 | 871 | $deploymentsConfig = GridFieldConfig_RecordEditor::create(); |
872 | 872 | $deploymentsConfig->removeComponentsByType('GridFieldAddNewButton'); |
873 | - if(class_exists('GridFieldBulkManager')) { |
|
873 | + if (class_exists('GridFieldBulkManager')) { |
|
874 | 874 | $deploymentsConfig->addComponent(new GridFieldBulkManager()); |
875 | 875 | } |
876 | 876 | $deployments = GridField::create('Deployments', 'Deployments', $this->Deployments(), $deploymentsConfig); |
@@ -881,7 +881,7 @@ discard block |
||
881 | 881 | // Add actions |
882 | 882 | $action = new FormAction('check', 'Check Connection'); |
883 | 883 | $action->setUseButtonTag(true); |
884 | - $dataURL = Director::absoluteBaseURL() . 'naut/api/' . $this->Project()->Name . '/' . $this->Name . '/ping'; |
|
884 | + $dataURL = Director::absoluteBaseURL().'naut/api/'.$this->Project()->Name.'/'.$this->Name.'/ping'; |
|
885 | 885 | $action->setAttribute('data-url', $dataURL); |
886 | 886 | $fields->insertBefore($action, 'Name'); |
887 | 887 | |
@@ -894,11 +894,11 @@ discard block |
||
894 | 894 | * @param FieldList $fields |
895 | 895 | */ |
896 | 896 | protected function setDeployConfigurationFields(&$fields) { |
897 | - if(!$this->config()->get('allow_web_editing')) { |
|
897 | + if (!$this->config()->get('allow_web_editing')) { |
|
898 | 898 | return; |
899 | 899 | } |
900 | 900 | |
901 | - if($this->envFileExists()) { |
|
901 | + if ($this->envFileExists()) { |
|
902 | 902 | $deployConfig = new TextareaField('DeployConfig', 'Deploy config', $this->getEnvironmentConfig()); |
903 | 903 | $deployConfig->setRows(40); |
904 | 904 | $fields->insertAfter($deployConfig, 'Filename'); |
@@ -918,8 +918,8 @@ discard block |
||
918 | 918 | */ |
919 | 919 | public function onBeforeWrite() { |
920 | 920 | parent::onBeforeWrite(); |
921 | - if($this->Name && $this->Name . '.rb' != $this->Filename) { |
|
922 | - $this->Filename = $this->Name . '.rb'; |
|
921 | + if ($this->Name && $this->Name.'.rb' != $this->Filename) { |
|
922 | + $this->Filename = $this->Name.'.rb'; |
|
923 | 923 | } |
924 | 924 | $this->checkEnvironmentPath(); |
925 | 925 | $this->writeConfigFile(); |
@@ -928,13 +928,13 @@ discard block |
||
928 | 928 | public function onAfterWrite() { |
929 | 929 | parent::onAfterWrite(); |
930 | 930 | |
931 | - if($this->Usage === self::PRODUCTION || $this->Usage === self::UAT) { |
|
931 | + if ($this->Usage === self::PRODUCTION || $this->Usage === self::UAT) { |
|
932 | 932 | $conflicting = DNEnvironment::get() |
933 | 933 | ->filter('ProjectID', $this->ProjectID) |
934 | 934 | ->filter('Usage', $this->Usage) |
935 | 935 | ->exclude('ID', $this->ID); |
936 | 936 | |
937 | - foreach($conflicting as $otherEnvironment) { |
|
937 | + foreach ($conflicting as $otherEnvironment) { |
|
938 | 938 | $otherEnvironment->Usage = self::UNSPECIFIED; |
939 | 939 | $otherEnvironment->write(); |
940 | 940 | } |
@@ -948,7 +948,7 @@ discard block |
||
948 | 948 | protected function checkEnvironmentPath() { |
949 | 949 | // Create folder if it doesn't exist |
950 | 950 | $configDir = dirname($this->getConfigFilename()); |
951 | - if(!file_exists($configDir) && $configDir) { |
|
951 | + if (!file_exists($configDir) && $configDir) { |
|
952 | 952 | mkdir($configDir, 0777, true); |
953 | 953 | } |
954 | 954 | } |
@@ -957,18 +957,18 @@ discard block |
||
957 | 957 | * Write the deployment config file to filesystem |
958 | 958 | */ |
959 | 959 | protected function writeConfigFile() { |
960 | - if(!$this->config()->get('allow_web_editing')) { |
|
960 | + if (!$this->config()->get('allow_web_editing')) { |
|
961 | 961 | return; |
962 | 962 | } |
963 | 963 | |
964 | 964 | // Create a basic new environment config from a template |
965 | - if(!$this->envFileExists() |
|
965 | + if (!$this->envFileExists() |
|
966 | 966 | && $this->Filename |
967 | 967 | && $this->CreateEnvConfig |
968 | 968 | ) { |
969 | - $templateFile = $this->config()->template_file ?: BASE_PATH . '/deploynaut/environment.template'; |
|
969 | + $templateFile = $this->config()->template_file ?: BASE_PATH.'/deploynaut/environment.template'; |
|
970 | 970 | file_put_contents($this->getConfigFilename(), file_get_contents($templateFile)); |
971 | - } else if($this->envFileExists() && $this->DeployConfig) { |
|
971 | + } else if ($this->envFileExists() && $this->DeployConfig) { |
|
972 | 972 | file_put_contents($this->getConfigFilename(), $this->DeployConfig); |
973 | 973 | } |
974 | 974 | } |
@@ -979,12 +979,12 @@ discard block |
||
979 | 979 | public function onAfterDelete() { |
980 | 980 | parent::onAfterDelete(); |
981 | 981 | // Create a basic new environment config from a template |
982 | - if($this->config()->get('allow_web_editing') && $this->envFileExists()) { |
|
982 | + if ($this->config()->get('allow_web_editing') && $this->envFileExists()) { |
|
983 | 983 | unlink($this->getConfigFilename()); |
984 | 984 | } |
985 | 985 | |
986 | 986 | $create = $this->CreateEnvironment(); |
987 | - if($create && $create->exists()) { |
|
987 | + if ($create && $create->exists()) { |
|
988 | 988 | $create->delete(); |
989 | 989 | } |
990 | 990 | } |
@@ -993,7 +993,7 @@ discard block |
||
993 | 993 | * @return string |
994 | 994 | */ |
995 | 995 | protected function getEnvironmentConfig() { |
996 | - if(!$this->envFileExists()) { |
|
996 | + if (!$this->envFileExists()) { |
|
997 | 997 | return ''; |
998 | 998 | } |
999 | 999 | return file_get_contents($this->getConfigFilename()); |
@@ -1003,7 +1003,7 @@ discard block |
||
1003 | 1003 | * @return boolean |
1004 | 1004 | */ |
1005 | 1005 | protected function envFileExists() { |
1006 | - if(!$this->getConfigFilename()) { |
|
1006 | + if (!$this->getConfigFilename()) { |
|
1007 | 1007 | return false; |
1008 | 1008 | } |
1009 | 1009 | return file_exists($this->getConfigFilename()); |
@@ -1015,13 +1015,13 @@ discard block |
||
1015 | 1015 | * @return string |
1016 | 1016 | */ |
1017 | 1017 | public function getConfigFilename() { |
1018 | - if(!$this->Project()->exists()) { |
|
1018 | + if (!$this->Project()->exists()) { |
|
1019 | 1019 | return ''; |
1020 | 1020 | } |
1021 | - if(!$this->Filename) { |
|
1021 | + if (!$this->Filename) { |
|
1022 | 1022 | return ''; |
1023 | 1023 | } |
1024 | - return $this->DNData()->getEnvironmentDir() . '/' . $this->Project()->Name . '/' . $this->Filename; |
|
1024 | + return $this->DNData()->getEnvironmentDir().'/'.$this->Project()->Name.'/'.$this->Filename; |
|
1025 | 1025 | } |
1026 | 1026 | |
1027 | 1027 | /** |
@@ -1034,24 +1034,24 @@ discard block |
||
1034 | 1034 | */ |
1035 | 1035 | public static function array_to_viewabledata($array) { |
1036 | 1036 | // Don't transform non-arrays |
1037 | - if(!is_array($array)) { |
|
1037 | + if (!is_array($array)) { |
|
1038 | 1038 | return $array; |
1039 | 1039 | } |
1040 | 1040 | |
1041 | 1041 | // Figure out whether this is indexed or associative |
1042 | 1042 | $keys = array_keys($array); |
1043 | 1043 | $assoc = ($keys != array_keys($keys)); |
1044 | - if($assoc) { |
|
1044 | + if ($assoc) { |
|
1045 | 1045 | // Treat as viewable data |
1046 | 1046 | $data = new ArrayData(array()); |
1047 | - foreach($array as $key => $value) { |
|
1047 | + foreach ($array as $key => $value) { |
|
1048 | 1048 | $data->setField($key, self::array_to_viewabledata($value)); |
1049 | 1049 | } |
1050 | 1050 | return $data; |
1051 | 1051 | } else { |
1052 | 1052 | // Treat this as basic non-associative list |
1053 | 1053 | $list = new ArrayList(); |
1054 | - foreach($array as $value) { |
|
1054 | + foreach ($array as $value) { |
|
1055 | 1055 | $list->push(self::array_to_viewabledata($value)); |
1056 | 1056 | } |
1057 | 1057 | return $list; |
@@ -1062,7 +1062,7 @@ discard block |
||
1062 | 1062 | $result = parent::validate(); |
1063 | 1063 | $backend = $this->Backend(); |
1064 | 1064 | |
1065 | - if(strcasecmp('test', $this->Name) === 0 && get_class($backend) == 'CapistranoDeploymentBackend') { |
|
1065 | + if (strcasecmp('test', $this->Name) === 0 && get_class($backend) == 'CapistranoDeploymentBackend') { |
|
1066 | 1066 | $result->error('"test" is not a valid environment name when using Capistrano backend.'); |
1067 | 1067 | } |
1068 | 1068 |