@@ -11,45 +11,45 @@ |
||
11 | 11 | class DataArchiveFileField extends FileField |
12 | 12 | { |
13 | 13 | |
14 | - /** |
|
15 | - * @param DataObjectInterface $record |
|
16 | - * @return bool|DataArchiveFileField |
|
17 | - */ |
|
18 | - public function saveInto(DataObjectInterface $record) |
|
19 | - { |
|
20 | - if (!isset($_FILES[$this->name])) { |
|
21 | - return false; |
|
22 | - } |
|
23 | - |
|
24 | - if (!($record instanceof DNDataArchive)) { |
|
25 | - throw new LogicException('Saving into wrong type, expected DNDataArchive'); |
|
26 | - } |
|
27 | - |
|
28 | - $dataArchive = $record; |
|
29 | - |
|
30 | - /** @var DNDataTransfer $dataTransfer */ |
|
31 | - $dataTransfer = $dataArchive->DataTransfers()->First(); |
|
32 | - if (!$dataTransfer) { |
|
33 | - throw new LogicException('No transfer found'); |
|
34 | - } |
|
35 | - |
|
36 | - $fileClass = File::get_class_for_file_extension(pathinfo($_FILES[$this->name]['name'], PATHINFO_EXTENSION)); |
|
37 | - $file = new $fileClass(); |
|
38 | - // Hack: loadIntoFile assumes paths relative to assets, |
|
39 | - // otherwise it creates the whole structure *within* that folder |
|
40 | - $absolutePath = $dataArchive->generateFilepath($dataTransfer); |
|
41 | - $relativePath = preg_replace('#^' . preg_quote(ASSETS_PATH) . '/#', '', $absolutePath); |
|
42 | - $this->upload->loadIntoFile($_FILES[$this->name], $file, $relativePath); |
|
43 | - if ($this->upload->isError()) { |
|
44 | - return false; |
|
45 | - } |
|
46 | - |
|
47 | - $file = $this->upload->getFile(); |
|
48 | - if ($this->relationAutoSetting) { |
|
49 | - // save to record |
|
50 | - $record->{$this->name . 'ID'} = $file->ID; |
|
51 | - } |
|
52 | - |
|
53 | - return $this; |
|
54 | - } |
|
14 | + /** |
|
15 | + * @param DataObjectInterface $record |
|
16 | + * @return bool|DataArchiveFileField |
|
17 | + */ |
|
18 | + public function saveInto(DataObjectInterface $record) |
|
19 | + { |
|
20 | + if (!isset($_FILES[$this->name])) { |
|
21 | + return false; |
|
22 | + } |
|
23 | + |
|
24 | + if (!($record instanceof DNDataArchive)) { |
|
25 | + throw new LogicException('Saving into wrong type, expected DNDataArchive'); |
|
26 | + } |
|
27 | + |
|
28 | + $dataArchive = $record; |
|
29 | + |
|
30 | + /** @var DNDataTransfer $dataTransfer */ |
|
31 | + $dataTransfer = $dataArchive->DataTransfers()->First(); |
|
32 | + if (!$dataTransfer) { |
|
33 | + throw new LogicException('No transfer found'); |
|
34 | + } |
|
35 | + |
|
36 | + $fileClass = File::get_class_for_file_extension(pathinfo($_FILES[$this->name]['name'], PATHINFO_EXTENSION)); |
|
37 | + $file = new $fileClass(); |
|
38 | + // Hack: loadIntoFile assumes paths relative to assets, |
|
39 | + // otherwise it creates the whole structure *within* that folder |
|
40 | + $absolutePath = $dataArchive->generateFilepath($dataTransfer); |
|
41 | + $relativePath = preg_replace('#^' . preg_quote(ASSETS_PATH) . '/#', '', $absolutePath); |
|
42 | + $this->upload->loadIntoFile($_FILES[$this->name], $file, $relativePath); |
|
43 | + if ($this->upload->isError()) { |
|
44 | + return false; |
|
45 | + } |
|
46 | + |
|
47 | + $file = $this->upload->getFile(); |
|
48 | + if ($this->relationAutoSetting) { |
|
49 | + // save to record |
|
50 | + $record->{$this->name . 'ID'} = $file->ID; |
|
51 | + } |
|
52 | + |
|
53 | + return $this; |
|
54 | + } |
|
55 | 55 | } |
@@ -17,11 +17,11 @@ discard block |
||
17 | 17 | */ |
18 | 18 | public function saveInto(DataObjectInterface $record) |
19 | 19 | { |
20 | - if (!isset($_FILES[$this->name])) { |
|
20 | + if(!isset($_FILES[$this->name])) { |
|
21 | 21 | return false; |
22 | 22 | } |
23 | 23 | |
24 | - if (!($record instanceof DNDataArchive)) { |
|
24 | + if(!($record instanceof DNDataArchive)) { |
|
25 | 25 | throw new LogicException('Saving into wrong type, expected DNDataArchive'); |
26 | 26 | } |
27 | 27 | |
@@ -29,7 +29,7 @@ discard block |
||
29 | 29 | |
30 | 30 | /** @var DNDataTransfer $dataTransfer */ |
31 | 31 | $dataTransfer = $dataArchive->DataTransfers()->First(); |
32 | - if (!$dataTransfer) { |
|
32 | + if(!$dataTransfer) { |
|
33 | 33 | throw new LogicException('No transfer found'); |
34 | 34 | } |
35 | 35 | |
@@ -40,12 +40,12 @@ discard block |
||
40 | 40 | $absolutePath = $dataArchive->generateFilepath($dataTransfer); |
41 | 41 | $relativePath = preg_replace('#^' . preg_quote(ASSETS_PATH) . '/#', '', $absolutePath); |
42 | 42 | $this->upload->loadIntoFile($_FILES[$this->name], $file, $relativePath); |
43 | - if ($this->upload->isError()) { |
|
43 | + if($this->upload->isError()) { |
|
44 | 44 | return false; |
45 | 45 | } |
46 | 46 | |
47 | 47 | $file = $this->upload->getFile(); |
48 | - if ($this->relationAutoSetting) { |
|
48 | + if($this->relationAutoSetting) { |
|
49 | 49 | // save to record |
50 | 50 | $record->{$this->name . 'ID'} = $file->ID; |
51 | 51 | } |
@@ -8,15 +8,13 @@ |
||
8 | 8 | * of FileField to set the folder path *before* uploading the file, |
9 | 9 | * at which point we don't have a {@link DataTransfer} ID yet, so can't generate the path. |
10 | 10 | */ |
11 | -class DataArchiveFileField extends FileField |
|
12 | -{ |
|
11 | +class DataArchiveFileField extends FileField { |
|
13 | 12 | |
14 | 13 | /** |
15 | 14 | * @param DataObjectInterface $record |
16 | 15 | * @return bool|DataArchiveFileField |
17 | 16 | */ |
18 | - public function saveInto(DataObjectInterface $record) |
|
19 | - { |
|
17 | + public function saveInto(DataObjectInterface $record) { |
|
20 | 18 | if (!isset($_FILES[$this->name])) { |
21 | 19 | return false; |
22 | 20 | } |
@@ -3,23 +3,23 @@ |
||
3 | 3 | class TabbedSelectionGroup extends SelectionGroup |
4 | 4 | { |
5 | 5 | |
6 | - /** |
|
7 | - * @return ArrayList |
|
8 | - */ |
|
9 | - public function FieldList() |
|
10 | - { |
|
11 | - $items = CompositeField::FieldList()->toArray(); |
|
12 | - $fields = new ArrayList(); |
|
6 | + /** |
|
7 | + * @return ArrayList |
|
8 | + */ |
|
9 | + public function FieldList() |
|
10 | + { |
|
11 | + $items = CompositeField::FieldList()->toArray(); |
|
12 | + $fields = new ArrayList(); |
|
13 | 13 | |
14 | - foreach ($items as $item) { |
|
15 | - $extra = array( |
|
16 | - 'Selected' => $this->value == $item->getValue(), |
|
17 | - ); |
|
14 | + foreach ($items as $item) { |
|
15 | + $extra = array( |
|
16 | + 'Selected' => $this->value == $item->getValue(), |
|
17 | + ); |
|
18 | 18 | |
19 | - $item = $item->customise($extra); |
|
20 | - $fields->push($item); |
|
21 | - } |
|
19 | + $item = $item->customise($extra); |
|
20 | + $fields->push($item); |
|
21 | + } |
|
22 | 22 | |
23 | - return $fields; |
|
24 | - } |
|
23 | + return $fields; |
|
24 | + } |
|
25 | 25 | } |
@@ -11,7 +11,7 @@ |
||
11 | 11 | $items = CompositeField::FieldList()->toArray(); |
12 | 12 | $fields = new ArrayList(); |
13 | 13 | |
14 | - foreach ($items as $item) { |
|
14 | + foreach($items as $item) { |
|
15 | 15 | $extra = array( |
16 | 16 | 'Selected' => $this->value == $item->getValue(), |
17 | 17 | ); |
@@ -1,13 +1,11 @@ |
||
1 | 1 | <?php |
2 | 2 | |
3 | -class TabbedSelectionGroup extends SelectionGroup |
|
4 | -{ |
|
3 | +class TabbedSelectionGroup extends SelectionGroup { |
|
5 | 4 | |
6 | 5 | /** |
7 | 6 | * @return ArrayList |
8 | 7 | */ |
9 | - public function FieldList() |
|
10 | - { |
|
8 | + public function FieldList() { |
|
11 | 9 | $items = CompositeField::FieldList()->toArray(); |
12 | 10 | $fields = new ArrayList(); |
13 | 11 |
@@ -2,75 +2,75 @@ |
||
2 | 2 | class CreateEnvJob |
3 | 3 | { |
4 | 4 | |
5 | - /** |
|
6 | - * |
|
7 | - * @var array |
|
8 | - */ |
|
9 | - public $args; |
|
5 | + /** |
|
6 | + * |
|
7 | + * @var array |
|
8 | + */ |
|
9 | + public $args; |
|
10 | 10 | |
11 | - /** |
|
12 | - * |
|
13 | - */ |
|
14 | - public function setUp() |
|
15 | - { |
|
16 | - $this->updateStatus('Started'); |
|
17 | - chdir(BASE_PATH); |
|
18 | - } |
|
11 | + /** |
|
12 | + * |
|
13 | + */ |
|
14 | + public function setUp() |
|
15 | + { |
|
16 | + $this->updateStatus('Started'); |
|
17 | + chdir(BASE_PATH); |
|
18 | + } |
|
19 | 19 | |
20 | - /** |
|
21 | - * |
|
22 | - * @global array $databaseConfig |
|
23 | - */ |
|
24 | - public function tearDown() |
|
25 | - { |
|
26 | - $this->updateStatus('Finished'); |
|
27 | - chdir(BASE_PATH); |
|
28 | - } |
|
20 | + /** |
|
21 | + * |
|
22 | + * @global array $databaseConfig |
|
23 | + */ |
|
24 | + public function tearDown() |
|
25 | + { |
|
26 | + $this->updateStatus('Finished'); |
|
27 | + chdir(BASE_PATH); |
|
28 | + } |
|
29 | 29 | |
30 | - /** |
|
31 | - * |
|
32 | - */ |
|
33 | - public function perform() |
|
34 | - { |
|
35 | - echo "[-] CreateEnvJob starting" . PHP_EOL; |
|
36 | - // This is a bit icky, but there is no easy way of capturing a failed deploy by using the PHP Resque |
|
37 | - try { |
|
38 | - $envCreate = DNCreateEnvironment::get()->byId($this->args['createID']); |
|
39 | - if (!($envCreate && $envCreate->exists())) { |
|
40 | - throw new RuntimeException(sprintf('Could not find create environment record %s', $args['createID'])); |
|
41 | - } |
|
30 | + /** |
|
31 | + * |
|
32 | + */ |
|
33 | + public function perform() |
|
34 | + { |
|
35 | + echo "[-] CreateEnvJob starting" . PHP_EOL; |
|
36 | + // This is a bit icky, but there is no easy way of capturing a failed deploy by using the PHP Resque |
|
37 | + try { |
|
38 | + $envCreate = DNCreateEnvironment::get()->byId($this->args['createID']); |
|
39 | + if (!($envCreate && $envCreate->exists())) { |
|
40 | + throw new RuntimeException(sprintf('Could not find create environment record %s', $args['createID'])); |
|
41 | + } |
|
42 | 42 | |
43 | - // This will throw and exception if it fails. |
|
44 | - $envCreate->createEnvironment(); |
|
45 | - } catch (Exception $e) { |
|
46 | - $this->updateStatus('Failed'); |
|
47 | - echo "[-] CreateEnvJob failed" . PHP_EOL; |
|
48 | - throw $e; |
|
49 | - } |
|
50 | - echo "[-] CreateEnvJob finished" . PHP_EOL; |
|
51 | - } |
|
43 | + // This will throw and exception if it fails. |
|
44 | + $envCreate->createEnvironment(); |
|
45 | + } catch (Exception $e) { |
|
46 | + $this->updateStatus('Failed'); |
|
47 | + echo "[-] CreateEnvJob failed" . PHP_EOL; |
|
48 | + throw $e; |
|
49 | + } |
|
50 | + echo "[-] CreateEnvJob finished" . PHP_EOL; |
|
51 | + } |
|
52 | 52 | |
53 | - /** |
|
54 | - * |
|
55 | - * @param string $status |
|
56 | - * @global array $databaseConfig |
|
57 | - */ |
|
58 | - protected function updateStatus($status) |
|
59 | - { |
|
60 | - global $databaseConfig; |
|
61 | - DB::connect($databaseConfig); |
|
53 | + /** |
|
54 | + * |
|
55 | + * @param string $status |
|
56 | + * @global array $databaseConfig |
|
57 | + */ |
|
58 | + protected function updateStatus($status) |
|
59 | + { |
|
60 | + global $databaseConfig; |
|
61 | + DB::connect($databaseConfig); |
|
62 | 62 | |
63 | - $record = DNCreateEnvironment::get()->byID($this->args['createID']); |
|
64 | - $record->Status = $status; |
|
65 | - $record->write(); |
|
66 | - } |
|
63 | + $record = DNCreateEnvironment::get()->byID($this->args['createID']); |
|
64 | + $record->Status = $status; |
|
65 | + $record->write(); |
|
66 | + } |
|
67 | 67 | |
68 | - /** |
|
69 | - * |
|
70 | - * @return DNData |
|
71 | - */ |
|
72 | - protected function DNData() |
|
73 | - { |
|
74 | - return DNData::inst(); |
|
75 | - } |
|
68 | + /** |
|
69 | + * |
|
70 | + * @return DNData |
|
71 | + */ |
|
72 | + protected function DNData() |
|
73 | + { |
|
74 | + return DNData::inst(); |
|
75 | + } |
|
76 | 76 | } |
@@ -36,13 +36,13 @@ |
||
36 | 36 | // This is a bit icky, but there is no easy way of capturing a failed deploy by using the PHP Resque |
37 | 37 | try { |
38 | 38 | $envCreate = DNCreateEnvironment::get()->byId($this->args['createID']); |
39 | - if (!($envCreate && $envCreate->exists())) { |
|
39 | + if(!($envCreate && $envCreate->exists())) { |
|
40 | 40 | throw new RuntimeException(sprintf('Could not find create environment record %s', $args['createID'])); |
41 | 41 | } |
42 | 42 | |
43 | 43 | // This will throw and exception if it fails. |
44 | 44 | $envCreate->createEnvironment(); |
45 | - } catch (Exception $e) { |
|
45 | + } catch(Exception $e) { |
|
46 | 46 | $this->updateStatus('Failed'); |
47 | 47 | echo "[-] CreateEnvJob failed" . PHP_EOL; |
48 | 48 | throw $e; |
@@ -1,6 +1,5 @@ discard block |
||
1 | 1 | <?php |
2 | -class CreateEnvJob |
|
3 | -{ |
|
2 | +class CreateEnvJob { |
|
4 | 3 | |
5 | 4 | /** |
6 | 5 | * |
@@ -11,8 +10,7 @@ discard block |
||
11 | 10 | /** |
12 | 11 | * |
13 | 12 | */ |
14 | - public function setUp() |
|
15 | - { |
|
13 | + public function setUp() { |
|
16 | 14 | $this->updateStatus('Started'); |
17 | 15 | chdir(BASE_PATH); |
18 | 16 | } |
@@ -21,8 +19,7 @@ discard block |
||
21 | 19 | * |
22 | 20 | * @global array $databaseConfig |
23 | 21 | */ |
24 | - public function tearDown() |
|
25 | - { |
|
22 | + public function tearDown() { |
|
26 | 23 | $this->updateStatus('Finished'); |
27 | 24 | chdir(BASE_PATH); |
28 | 25 | } |
@@ -30,8 +27,7 @@ discard block |
||
30 | 27 | /** |
31 | 28 | * |
32 | 29 | */ |
33 | - public function perform() |
|
34 | - { |
|
30 | + public function perform() { |
|
35 | 31 | echo "[-] CreateEnvJob starting" . PHP_EOL; |
36 | 32 | // This is a bit icky, but there is no easy way of capturing a failed deploy by using the PHP Resque |
37 | 33 | try { |
@@ -55,8 +51,7 @@ discard block |
||
55 | 51 | * @param string $status |
56 | 52 | * @global array $databaseConfig |
57 | 53 | */ |
58 | - protected function updateStatus($status) |
|
59 | - { |
|
54 | + protected function updateStatus($status) { |
|
60 | 55 | global $databaseConfig; |
61 | 56 | DB::connect($databaseConfig); |
62 | 57 | |
@@ -69,8 +64,7 @@ discard block |
||
69 | 64 | * |
70 | 65 | * @return DNData |
71 | 66 | */ |
72 | - protected function DNData() |
|
73 | - { |
|
67 | + protected function DNData() { |
|
74 | 68 | return DNData::inst(); |
75 | 69 | } |
76 | 70 | } |
@@ -10,124 +10,124 @@ |
||
10 | 10 | class DataTransferJob |
11 | 11 | { |
12 | 12 | |
13 | - /** |
|
14 | - * set by a resque worker |
|
15 | - */ |
|
16 | - public $args = array(); |
|
17 | - |
|
18 | - public function setUp() |
|
19 | - { |
|
20 | - $this->updateStatus('Started'); |
|
21 | - chdir(BASE_PATH); |
|
22 | - } |
|
23 | - |
|
24 | - public function tearDown() |
|
25 | - { |
|
26 | - $this->updateStatus('Finished'); |
|
27 | - chdir(BASE_PATH); |
|
28 | - } |
|
29 | - |
|
30 | - public function perform() |
|
31 | - { |
|
32 | - echo "[-] DataTransferJob starting" . PHP_EOL; |
|
33 | - $log = new DeploynautLogFile($this->args['logfile']); |
|
34 | - $dataTransfer = DNDataTransfer::get()->byID($this->args['dataTransferID']); |
|
35 | - $environment = $dataTransfer->Environment(); |
|
36 | - $backupDataTransfer = null; |
|
37 | - |
|
38 | - if (!empty($this->args['backupBeforePush']) && $dataTransfer->Direction == 'push') { |
|
39 | - $backupDataTransfer = DNDataTransfer::create(); |
|
40 | - $backupDataTransfer->EnvironmentID = $environment->ID; |
|
41 | - $backupDataTransfer->Direction = 'get'; |
|
42 | - $backupDataTransfer->Mode = $dataTransfer->Mode; |
|
43 | - $backupDataTransfer->DataArchiveID = null; |
|
44 | - $backupDataTransfer->ResqueToken = $dataTransfer->ResqueToken; |
|
45 | - $backupDataTransfer->AuthorID = $dataTransfer->AuthorID; |
|
46 | - $backupDataTransfer->write(); |
|
47 | - |
|
48 | - $dataTransfer->BackupDataTransferID = $backupDataTransfer->ID; |
|
49 | - $dataTransfer->write(); |
|
50 | - } |
|
51 | - |
|
52 | - // This is a bit icky, but there is no easy way of capturing a failed run by using the PHP Resque |
|
53 | - try { |
|
54 | - // Disallow concurrent jobs (don't rely on queuing implementation to restrict this) |
|
55 | - // Only consider data transfers started in the last 30 minutes (older jobs probably got stuck) |
|
56 | - $runningTransfers = DNDataTransfer::get() |
|
57 | - ->filter(array( |
|
58 | - 'EnvironmentID' => $environment->ID, |
|
59 | - 'Status' => array('Queued', 'Started'), |
|
60 | - 'Created:GreaterThan' => strtotime('-30 minutes') |
|
61 | - )) |
|
62 | - ->exclude('ID', $dataTransfer->ID); |
|
63 | - |
|
64 | - if ($runningTransfers->count()) { |
|
65 | - $runningTransfer = $runningTransfers->first(); |
|
66 | - $log->write(sprintf( |
|
67 | - '[-] Error: another transfer is in progress (started at %s by %s)', |
|
68 | - $runningTransfer->dbObject('Created')->Nice(), |
|
69 | - $runningTransfer->Author()->Title |
|
70 | - )); |
|
71 | - throw new RuntimeException(sprintf( |
|
72 | - 'Another transfer is in progress (started at %s by %s)', |
|
73 | - $runningTransfer->dbObject('Created')->Nice(), |
|
74 | - $runningTransfer->Author()->Title |
|
75 | - )); |
|
76 | - } |
|
77 | - |
|
78 | - |
|
79 | - // before we push data to an environment, we'll make a backup first |
|
80 | - if ($backupDataTransfer) { |
|
81 | - $log->write('Backing up existing data'); |
|
82 | - $environment->Backend()->dataTransfer( |
|
83 | - $backupDataTransfer, |
|
84 | - $log |
|
85 | - ); |
|
86 | - } |
|
87 | - |
|
88 | - $environment->Backend()->dataTransfer( |
|
89 | - $dataTransfer, |
|
90 | - $log |
|
91 | - ); |
|
92 | - } catch (RuntimeException $exc) { |
|
93 | - $log->write($exc->getMessage()); |
|
94 | - |
|
95 | - if ($backupDataTransfer) { |
|
96 | - $backupDataTransfer->Status = 'Failed'; |
|
97 | - $backupDataTransfer->write(); |
|
98 | - } |
|
99 | - |
|
100 | - $this->updateStatus('Failed'); |
|
101 | - echo "[-] DataTransferJob failed" . PHP_EOL; |
|
102 | - throw $exc; |
|
103 | - } |
|
104 | - |
|
105 | - if ($backupDataTransfer) { |
|
106 | - $backupDataTransfer->Status = 'Finished'; |
|
107 | - $backupDataTransfer->write(); |
|
108 | - } |
|
109 | - |
|
110 | - echo "[-] DataTransferJob finished" . PHP_EOL; |
|
111 | - } |
|
112 | - |
|
113 | - /** |
|
114 | - * @param string $status |
|
115 | - * @global array $databaseConfig |
|
116 | - */ |
|
117 | - protected function updateStatus($status) |
|
118 | - { |
|
119 | - global $databaseConfig; |
|
120 | - DB::connect($databaseConfig); |
|
121 | - $env = DNDataTransfer::get()->byID($this->args['dataTransferID']); |
|
122 | - $env->Status = $status; |
|
123 | - $env->write(); |
|
124 | - } |
|
125 | - |
|
126 | - /** |
|
127 | - * @return DNData |
|
128 | - */ |
|
129 | - protected function DNData() |
|
130 | - { |
|
131 | - return DNData::inst(); |
|
132 | - } |
|
13 | + /** |
|
14 | + * set by a resque worker |
|
15 | + */ |
|
16 | + public $args = array(); |
|
17 | + |
|
18 | + public function setUp() |
|
19 | + { |
|
20 | + $this->updateStatus('Started'); |
|
21 | + chdir(BASE_PATH); |
|
22 | + } |
|
23 | + |
|
24 | + public function tearDown() |
|
25 | + { |
|
26 | + $this->updateStatus('Finished'); |
|
27 | + chdir(BASE_PATH); |
|
28 | + } |
|
29 | + |
|
30 | + public function perform() |
|
31 | + { |
|
32 | + echo "[-] DataTransferJob starting" . PHP_EOL; |
|
33 | + $log = new DeploynautLogFile($this->args['logfile']); |
|
34 | + $dataTransfer = DNDataTransfer::get()->byID($this->args['dataTransferID']); |
|
35 | + $environment = $dataTransfer->Environment(); |
|
36 | + $backupDataTransfer = null; |
|
37 | + |
|
38 | + if (!empty($this->args['backupBeforePush']) && $dataTransfer->Direction == 'push') { |
|
39 | + $backupDataTransfer = DNDataTransfer::create(); |
|
40 | + $backupDataTransfer->EnvironmentID = $environment->ID; |
|
41 | + $backupDataTransfer->Direction = 'get'; |
|
42 | + $backupDataTransfer->Mode = $dataTransfer->Mode; |
|
43 | + $backupDataTransfer->DataArchiveID = null; |
|
44 | + $backupDataTransfer->ResqueToken = $dataTransfer->ResqueToken; |
|
45 | + $backupDataTransfer->AuthorID = $dataTransfer->AuthorID; |
|
46 | + $backupDataTransfer->write(); |
|
47 | + |
|
48 | + $dataTransfer->BackupDataTransferID = $backupDataTransfer->ID; |
|
49 | + $dataTransfer->write(); |
|
50 | + } |
|
51 | + |
|
52 | + // This is a bit icky, but there is no easy way of capturing a failed run by using the PHP Resque |
|
53 | + try { |
|
54 | + // Disallow concurrent jobs (don't rely on queuing implementation to restrict this) |
|
55 | + // Only consider data transfers started in the last 30 minutes (older jobs probably got stuck) |
|
56 | + $runningTransfers = DNDataTransfer::get() |
|
57 | + ->filter(array( |
|
58 | + 'EnvironmentID' => $environment->ID, |
|
59 | + 'Status' => array('Queued', 'Started'), |
|
60 | + 'Created:GreaterThan' => strtotime('-30 minutes') |
|
61 | + )) |
|
62 | + ->exclude('ID', $dataTransfer->ID); |
|
63 | + |
|
64 | + if ($runningTransfers->count()) { |
|
65 | + $runningTransfer = $runningTransfers->first(); |
|
66 | + $log->write(sprintf( |
|
67 | + '[-] Error: another transfer is in progress (started at %s by %s)', |
|
68 | + $runningTransfer->dbObject('Created')->Nice(), |
|
69 | + $runningTransfer->Author()->Title |
|
70 | + )); |
|
71 | + throw new RuntimeException(sprintf( |
|
72 | + 'Another transfer is in progress (started at %s by %s)', |
|
73 | + $runningTransfer->dbObject('Created')->Nice(), |
|
74 | + $runningTransfer->Author()->Title |
|
75 | + )); |
|
76 | + } |
|
77 | + |
|
78 | + |
|
79 | + // before we push data to an environment, we'll make a backup first |
|
80 | + if ($backupDataTransfer) { |
|
81 | + $log->write('Backing up existing data'); |
|
82 | + $environment->Backend()->dataTransfer( |
|
83 | + $backupDataTransfer, |
|
84 | + $log |
|
85 | + ); |
|
86 | + } |
|
87 | + |
|
88 | + $environment->Backend()->dataTransfer( |
|
89 | + $dataTransfer, |
|
90 | + $log |
|
91 | + ); |
|
92 | + } catch (RuntimeException $exc) { |
|
93 | + $log->write($exc->getMessage()); |
|
94 | + |
|
95 | + if ($backupDataTransfer) { |
|
96 | + $backupDataTransfer->Status = 'Failed'; |
|
97 | + $backupDataTransfer->write(); |
|
98 | + } |
|
99 | + |
|
100 | + $this->updateStatus('Failed'); |
|
101 | + echo "[-] DataTransferJob failed" . PHP_EOL; |
|
102 | + throw $exc; |
|
103 | + } |
|
104 | + |
|
105 | + if ($backupDataTransfer) { |
|
106 | + $backupDataTransfer->Status = 'Finished'; |
|
107 | + $backupDataTransfer->write(); |
|
108 | + } |
|
109 | + |
|
110 | + echo "[-] DataTransferJob finished" . PHP_EOL; |
|
111 | + } |
|
112 | + |
|
113 | + /** |
|
114 | + * @param string $status |
|
115 | + * @global array $databaseConfig |
|
116 | + */ |
|
117 | + protected function updateStatus($status) |
|
118 | + { |
|
119 | + global $databaseConfig; |
|
120 | + DB::connect($databaseConfig); |
|
121 | + $env = DNDataTransfer::get()->byID($this->args['dataTransferID']); |
|
122 | + $env->Status = $status; |
|
123 | + $env->write(); |
|
124 | + } |
|
125 | + |
|
126 | + /** |
|
127 | + * @return DNData |
|
128 | + */ |
|
129 | + protected function DNData() |
|
130 | + { |
|
131 | + return DNData::inst(); |
|
132 | + } |
|
133 | 133 | } |
@@ -35,7 +35,7 @@ discard block |
||
35 | 35 | $environment = $dataTransfer->Environment(); |
36 | 36 | $backupDataTransfer = null; |
37 | 37 | |
38 | - if (!empty($this->args['backupBeforePush']) && $dataTransfer->Direction == 'push') { |
|
38 | + if(!empty($this->args['backupBeforePush']) && $dataTransfer->Direction == 'push') { |
|
39 | 39 | $backupDataTransfer = DNDataTransfer::create(); |
40 | 40 | $backupDataTransfer->EnvironmentID = $environment->ID; |
41 | 41 | $backupDataTransfer->Direction = 'get'; |
@@ -61,7 +61,7 @@ discard block |
||
61 | 61 | )) |
62 | 62 | ->exclude('ID', $dataTransfer->ID); |
63 | 63 | |
64 | - if ($runningTransfers->count()) { |
|
64 | + if($runningTransfers->count()) { |
|
65 | 65 | $runningTransfer = $runningTransfers->first(); |
66 | 66 | $log->write(sprintf( |
67 | 67 | '[-] Error: another transfer is in progress (started at %s by %s)', |
@@ -77,7 +77,7 @@ discard block |
||
77 | 77 | |
78 | 78 | |
79 | 79 | // before we push data to an environment, we'll make a backup first |
80 | - if ($backupDataTransfer) { |
|
80 | + if($backupDataTransfer) { |
|
81 | 81 | $log->write('Backing up existing data'); |
82 | 82 | $environment->Backend()->dataTransfer( |
83 | 83 | $backupDataTransfer, |
@@ -89,10 +89,10 @@ discard block |
||
89 | 89 | $dataTransfer, |
90 | 90 | $log |
91 | 91 | ); |
92 | - } catch (RuntimeException $exc) { |
|
92 | + } catch(RuntimeException $exc) { |
|
93 | 93 | $log->write($exc->getMessage()); |
94 | 94 | |
95 | - if ($backupDataTransfer) { |
|
95 | + if($backupDataTransfer) { |
|
96 | 96 | $backupDataTransfer->Status = 'Failed'; |
97 | 97 | $backupDataTransfer->write(); |
98 | 98 | } |
@@ -102,7 +102,7 @@ discard block |
||
102 | 102 | throw $exc; |
103 | 103 | } |
104 | 104 | |
105 | - if ($backupDataTransfer) { |
|
105 | + if($backupDataTransfer) { |
|
106 | 106 | $backupDataTransfer->Status = 'Finished'; |
107 | 107 | $backupDataTransfer->write(); |
108 | 108 | } |
@@ -7,28 +7,24 @@ discard block |
||
7 | 7 | * @package deploynaut |
8 | 8 | * @subpackage jobs |
9 | 9 | */ |
10 | -class DataTransferJob |
|
11 | -{ |
|
10 | +class DataTransferJob { |
|
12 | 11 | |
13 | 12 | /** |
14 | 13 | * set by a resque worker |
15 | 14 | */ |
16 | 15 | public $args = array(); |
17 | 16 | |
18 | - public function setUp() |
|
19 | - { |
|
17 | + public function setUp() { |
|
20 | 18 | $this->updateStatus('Started'); |
21 | 19 | chdir(BASE_PATH); |
22 | 20 | } |
23 | 21 | |
24 | - public function tearDown() |
|
25 | - { |
|
22 | + public function tearDown() { |
|
26 | 23 | $this->updateStatus('Finished'); |
27 | 24 | chdir(BASE_PATH); |
28 | 25 | } |
29 | 26 | |
30 | - public function perform() |
|
31 | - { |
|
27 | + public function perform() { |
|
32 | 28 | echo "[-] DataTransferJob starting" . PHP_EOL; |
33 | 29 | $log = new DeploynautLogFile($this->args['logfile']); |
34 | 30 | $dataTransfer = DNDataTransfer::get()->byID($this->args['dataTransferID']); |
@@ -114,8 +110,7 @@ discard block |
||
114 | 110 | * @param string $status |
115 | 111 | * @global array $databaseConfig |
116 | 112 | */ |
117 | - protected function updateStatus($status) |
|
118 | - { |
|
113 | + protected function updateStatus($status) { |
|
119 | 114 | global $databaseConfig; |
120 | 115 | DB::connect($databaseConfig); |
121 | 116 | $env = DNDataTransfer::get()->byID($this->args['dataTransferID']); |
@@ -126,8 +121,7 @@ discard block |
||
126 | 121 | /** |
127 | 122 | * @return DNData |
128 | 123 | */ |
129 | - protected function DNData() |
|
130 | - { |
|
124 | + protected function DNData() { |
|
131 | 125 | return DNData::inst(); |
132 | 126 | } |
133 | 127 | } |
@@ -6,89 +6,89 @@ |
||
6 | 6 | class DeployJob |
7 | 7 | { |
8 | 8 | |
9 | - /** |
|
10 | - * @var array |
|
11 | - */ |
|
12 | - public $args; |
|
9 | + /** |
|
10 | + * @var array |
|
11 | + */ |
|
12 | + public $args; |
|
13 | 13 | |
14 | - public function setUp() |
|
15 | - { |
|
16 | - $this->updateStatus('Started'); |
|
17 | - chdir(BASE_PATH); |
|
18 | - } |
|
14 | + public function setUp() |
|
15 | + { |
|
16 | + $this->updateStatus('Started'); |
|
17 | + chdir(BASE_PATH); |
|
18 | + } |
|
19 | 19 | |
20 | - public function tearDown() |
|
21 | - { |
|
22 | - $this->updateStatus('Finished'); |
|
23 | - chdir(BASE_PATH); |
|
24 | - } |
|
20 | + public function tearDown() |
|
21 | + { |
|
22 | + $this->updateStatus('Finished'); |
|
23 | + chdir(BASE_PATH); |
|
24 | + } |
|
25 | 25 | |
26 | - public function perform() |
|
27 | - { |
|
28 | - echo "[-] DeployJob starting" . PHP_EOL; |
|
29 | - $log = new DeploynautLogFile($this->args['logfile']); |
|
30 | - $DNProject = $this->DNData()->DNProjectList()->filter('Name', $this->args['projectName'])->First(); |
|
31 | - $DNEnvironment = $DNProject->Environments()->filter('Name', $this->args['environmentName'])->First(); |
|
32 | - // This is a bit icky, but there is no easy way of capturing a failed deploy by using the PHP Resque |
|
33 | - try { |
|
34 | - // Disallow concurrent deployments (don't rely on queuing implementation to restrict this) |
|
35 | - // Only consider deployments started in the last 30 minutes (older jobs probably got stuck) |
|
36 | - $runningDeployments = DNDeployment::get() |
|
37 | - ->filter(array( |
|
38 | - 'EnvironmentID' => $DNEnvironment->ID, |
|
39 | - 'Status' => array('Queued', 'Started'), |
|
40 | - 'Created:GreaterThan' => strtotime('-30 minutes') |
|
41 | - )) |
|
42 | - ->exclude('ID', $this->args['deploymentID']); |
|
26 | + public function perform() |
|
27 | + { |
|
28 | + echo "[-] DeployJob starting" . PHP_EOL; |
|
29 | + $log = new DeploynautLogFile($this->args['logfile']); |
|
30 | + $DNProject = $this->DNData()->DNProjectList()->filter('Name', $this->args['projectName'])->First(); |
|
31 | + $DNEnvironment = $DNProject->Environments()->filter('Name', $this->args['environmentName'])->First(); |
|
32 | + // This is a bit icky, but there is no easy way of capturing a failed deploy by using the PHP Resque |
|
33 | + try { |
|
34 | + // Disallow concurrent deployments (don't rely on queuing implementation to restrict this) |
|
35 | + // Only consider deployments started in the last 30 minutes (older jobs probably got stuck) |
|
36 | + $runningDeployments = DNDeployment::get() |
|
37 | + ->filter(array( |
|
38 | + 'EnvironmentID' => $DNEnvironment->ID, |
|
39 | + 'Status' => array('Queued', 'Started'), |
|
40 | + 'Created:GreaterThan' => strtotime('-30 minutes') |
|
41 | + )) |
|
42 | + ->exclude('ID', $this->args['deploymentID']); |
|
43 | 43 | |
44 | - if ($runningDeployments->count()) { |
|
45 | - $runningDeployment = $runningDeployments->first(); |
|
46 | - $log->write(sprintf( |
|
47 | - '[-] Error: another deployment is in progress (started at %s by %s)', |
|
48 | - $runningDeployment->dbObject('Created')->Nice(), |
|
49 | - $runningDeployment->Deployer()->Title |
|
50 | - )); |
|
51 | - throw new RuntimeException(sprintf( |
|
52 | - 'Another deployment is in progress (started at %s by %s)', |
|
53 | - $runningDeployment->dbObject('Created')->Nice(), |
|
54 | - $runningDeployment->Deployer()->Title |
|
55 | - )); |
|
56 | - } |
|
44 | + if ($runningDeployments->count()) { |
|
45 | + $runningDeployment = $runningDeployments->first(); |
|
46 | + $log->write(sprintf( |
|
47 | + '[-] Error: another deployment is in progress (started at %s by %s)', |
|
48 | + $runningDeployment->dbObject('Created')->Nice(), |
|
49 | + $runningDeployment->Deployer()->Title |
|
50 | + )); |
|
51 | + throw new RuntimeException(sprintf( |
|
52 | + 'Another deployment is in progress (started at %s by %s)', |
|
53 | + $runningDeployment->dbObject('Created')->Nice(), |
|
54 | + $runningDeployment->Deployer()->Title |
|
55 | + )); |
|
56 | + } |
|
57 | 57 | |
58 | - $DNEnvironment->Backend()->deploy( |
|
59 | - $DNEnvironment, |
|
60 | - $log, |
|
61 | - $DNProject, |
|
62 | - // Pass all args to give the backend full visibility. These args also contain |
|
63 | - // all options from the DeploymentStrategy merged in, including sha. |
|
64 | - $this->args |
|
65 | - ); |
|
66 | - } catch (Exception $e) { |
|
67 | - $this->updateStatus('Failed'); |
|
68 | - echo "[-] DeployJob failed" . PHP_EOL; |
|
69 | - throw $e; |
|
70 | - } |
|
71 | - echo "[-] DeployJob finished" . PHP_EOL; |
|
72 | - } |
|
58 | + $DNEnvironment->Backend()->deploy( |
|
59 | + $DNEnvironment, |
|
60 | + $log, |
|
61 | + $DNProject, |
|
62 | + // Pass all args to give the backend full visibility. These args also contain |
|
63 | + // all options from the DeploymentStrategy merged in, including sha. |
|
64 | + $this->args |
|
65 | + ); |
|
66 | + } catch (Exception $e) { |
|
67 | + $this->updateStatus('Failed'); |
|
68 | + echo "[-] DeployJob failed" . PHP_EOL; |
|
69 | + throw $e; |
|
70 | + } |
|
71 | + echo "[-] DeployJob finished" . PHP_EOL; |
|
72 | + } |
|
73 | 73 | |
74 | - /** |
|
75 | - * @param string $status |
|
76 | - * @global array $databaseConfig |
|
77 | - */ |
|
78 | - protected function updateStatus($status) |
|
79 | - { |
|
80 | - global $databaseConfig; |
|
81 | - DB::connect($databaseConfig); |
|
82 | - $dnDeployment = DNDeployment::get()->byID($this->args['deploymentID']); |
|
83 | - $dnDeployment->Status = $status; |
|
84 | - $dnDeployment->write(); |
|
85 | - } |
|
74 | + /** |
|
75 | + * @param string $status |
|
76 | + * @global array $databaseConfig |
|
77 | + */ |
|
78 | + protected function updateStatus($status) |
|
79 | + { |
|
80 | + global $databaseConfig; |
|
81 | + DB::connect($databaseConfig); |
|
82 | + $dnDeployment = DNDeployment::get()->byID($this->args['deploymentID']); |
|
83 | + $dnDeployment->Status = $status; |
|
84 | + $dnDeployment->write(); |
|
85 | + } |
|
86 | 86 | |
87 | - /** |
|
88 | - * @return DNData |
|
89 | - */ |
|
90 | - protected function DNData() |
|
91 | - { |
|
92 | - return DNData::inst(); |
|
93 | - } |
|
87 | + /** |
|
88 | + * @return DNData |
|
89 | + */ |
|
90 | + protected function DNData() |
|
91 | + { |
|
92 | + return DNData::inst(); |
|
93 | + } |
|
94 | 94 | } |
@@ -41,7 +41,7 @@ discard block |
||
41 | 41 | )) |
42 | 42 | ->exclude('ID', $this->args['deploymentID']); |
43 | 43 | |
44 | - if ($runningDeployments->count()) { |
|
44 | + if($runningDeployments->count()) { |
|
45 | 45 | $runningDeployment = $runningDeployments->first(); |
46 | 46 | $log->write(sprintf( |
47 | 47 | '[-] Error: another deployment is in progress (started at %s by %s)', |
@@ -63,7 +63,7 @@ discard block |
||
63 | 63 | // all options from the DeploymentStrategy merged in, including sha. |
64 | 64 | $this->args |
65 | 65 | ); |
66 | - } catch (Exception $e) { |
|
66 | + } catch(Exception $e) { |
|
67 | 67 | $this->updateStatus('Failed'); |
68 | 68 | echo "[-] DeployJob failed" . PHP_EOL; |
69 | 69 | throw $e; |
@@ -3,28 +3,24 @@ discard block |
||
3 | 3 | /** |
4 | 4 | * Runs a deployment via the most appropriate backend |
5 | 5 | */ |
6 | -class DeployJob |
|
7 | -{ |
|
6 | +class DeployJob { |
|
8 | 7 | |
9 | 8 | /** |
10 | 9 | * @var array |
11 | 10 | */ |
12 | 11 | public $args; |
13 | 12 | |
14 | - public function setUp() |
|
15 | - { |
|
13 | + public function setUp() { |
|
16 | 14 | $this->updateStatus('Started'); |
17 | 15 | chdir(BASE_PATH); |
18 | 16 | } |
19 | 17 | |
20 | - public function tearDown() |
|
21 | - { |
|
18 | + public function tearDown() { |
|
22 | 19 | $this->updateStatus('Finished'); |
23 | 20 | chdir(BASE_PATH); |
24 | 21 | } |
25 | 22 | |
26 | - public function perform() |
|
27 | - { |
|
23 | + public function perform() { |
|
28 | 24 | echo "[-] DeployJob starting" . PHP_EOL; |
29 | 25 | $log = new DeploynautLogFile($this->args['logfile']); |
30 | 26 | $DNProject = $this->DNData()->DNProjectList()->filter('Name', $this->args['projectName'])->First(); |
@@ -75,8 +71,7 @@ discard block |
||
75 | 71 | * @param string $status |
76 | 72 | * @global array $databaseConfig |
77 | 73 | */ |
78 | - protected function updateStatus($status) |
|
79 | - { |
|
74 | + protected function updateStatus($status) { |
|
80 | 75 | global $databaseConfig; |
81 | 76 | DB::connect($databaseConfig); |
82 | 77 | $dnDeployment = DNDeployment::get()->byID($this->args['deploymentID']); |
@@ -87,8 +82,7 @@ discard block |
||
87 | 82 | /** |
88 | 83 | * @return DNData |
89 | 84 | */ |
90 | - protected function DNData() |
|
91 | - { |
|
85 | + protected function DNData() { |
|
92 | 86 | return DNData::inst(); |
93 | 87 | } |
94 | 88 | } |
@@ -3,161 +3,161 @@ |
||
3 | 3 | class FetchJob |
4 | 4 | { |
5 | 5 | |
6 | - public $args; |
|
7 | - |
|
8 | - /** |
|
9 | - * @var DNProject |
|
10 | - */ |
|
11 | - protected $project; |
|
12 | - |
|
13 | - /** |
|
14 | - * @var DeploynautLogFile |
|
15 | - */ |
|
16 | - protected $log; |
|
17 | - |
|
18 | - /** |
|
19 | - * @var string |
|
20 | - */ |
|
21 | - protected $user; |
|
22 | - |
|
23 | - /** |
|
24 | - * @global array $databaseConfig |
|
25 | - */ |
|
26 | - public function setUp() |
|
27 | - { |
|
28 | - global $databaseConfig; |
|
29 | - DB::connect($databaseConfig); |
|
30 | - |
|
31 | - $this->updateStatus('Started'); |
|
32 | - chdir(BASE_PATH); |
|
33 | - } |
|
34 | - |
|
35 | - public function tearDown() |
|
36 | - { |
|
37 | - $this->updateStatus('Finished'); |
|
38 | - chdir(BASE_PATH); |
|
39 | - } |
|
40 | - |
|
41 | - public function perform() |
|
42 | - { |
|
43 | - set_time_limit(0); |
|
44 | - |
|
45 | - if (!empty($this->args['logfile'])) { |
|
46 | - $this->log = new DeploynautLogFile($this->args['logfile']); |
|
47 | - } |
|
48 | - |
|
49 | - $this->project = DNProject::get()->byId($this->args['projectID']); |
|
50 | - if (!($this->project && $this->project->exists())) { |
|
51 | - throw new RuntimeException(sprintf('Project ID %s not found', $this->args['projectID'])); |
|
52 | - } |
|
53 | - |
|
54 | - $this->user = DNData::inst()->getGitUser() ?: null; |
|
55 | - |
|
56 | - // Disallow concurrent git fetches on the same project. |
|
57 | - // Only consider fetches started in the last 30 minutes (older jobs probably got stuck) |
|
58 | - if (!empty($this->args['fetchID'])) { |
|
59 | - $runningFetches = DNGitFetch::get() |
|
60 | - ->filter(array( |
|
61 | - 'ProjectID' => $this->project->ID, |
|
62 | - 'Status' => array('Queued', 'Started'), |
|
63 | - 'Created:GreaterThan' => strtotime('-30 minutes') |
|
64 | - )) |
|
65 | - ->exclude('ID', $this->args['fetchID']); |
|
66 | - |
|
67 | - if ($runningFetches->count()) { |
|
68 | - $runningFetch = $runningFetches->first(); |
|
69 | - $message = sprintf( |
|
70 | - 'Another fetch is in progress (started at %s by %s)', |
|
71 | - $runningFetch->dbObject('Created')->Nice(), |
|
72 | - $runningFetch->Deployer()->Title |
|
73 | - ); |
|
74 | - if ($this->log) { |
|
75 | - $this->log->write($message); |
|
76 | - } |
|
77 | - throw new RuntimeException($message); |
|
78 | - } |
|
79 | - } |
|
80 | - |
|
81 | - // Decide whether we need to just update what we already have |
|
82 | - // or initiate a clone if no local repo exists. |
|
83 | - try { |
|
84 | - if ($this->project->repoExists() && empty($this->args['forceClone'])) { |
|
85 | - $this->fetchRepo(); |
|
86 | - } else { |
|
87 | - $this->cloneRepo(); |
|
88 | - } |
|
89 | - } catch (Exception $e) { |
|
90 | - $this->updateStatus('Failed'); |
|
91 | - if ($this->log) { |
|
92 | - $this->log->write($e->getMessage()); |
|
93 | - } |
|
94 | - throw $e; |
|
95 | - } |
|
96 | - } |
|
97 | - |
|
98 | - protected function fetchRepo() |
|
99 | - { |
|
100 | - $this->runCommand( |
|
101 | - 'git fetch -p origin +refs/heads/*:refs/heads/* --tags', |
|
102 | - $this->project->getLocalCVSPath() |
|
103 | - ); |
|
104 | - } |
|
105 | - |
|
106 | - protected function cloneRepo() |
|
107 | - { |
|
108 | - if (file_exists($this->project->getLocalCVSPath())) { |
|
109 | - $this->runCommand(sprintf( |
|
110 | - 'rm -rf %s', |
|
111 | - escapeshellarg($this->project->getLocalCVSPath()) |
|
112 | - )); |
|
113 | - } |
|
114 | - |
|
115 | - $this->runCommand(sprintf( |
|
116 | - 'git clone --bare -q %s %s', |
|
117 | - escapeshellarg($this->project->CVSPath), |
|
118 | - escapeshellarg($this->project->getLocalCVSPath()) |
|
119 | - )); |
|
120 | - } |
|
121 | - |
|
122 | - /** |
|
123 | - * Run a shell command. |
|
124 | - * |
|
125 | - * @param string $command The command to run |
|
126 | - * @param string|null $workingDir The working dir to run command in |
|
127 | - * @throws RuntimeException |
|
128 | - */ |
|
129 | - protected function runCommand($command, $workingDir = null) |
|
130 | - { |
|
131 | - if (!empty($this->user)) { |
|
132 | - $command = sprintf('sudo -u %s %s', $this->user, $command); |
|
133 | - } |
|
134 | - if ($this->log) { |
|
135 | - $this->log->write(sprintf('Running command: %s', $command)); |
|
136 | - } |
|
137 | - $process = new \Symfony\Component\Process\Process($command, $workingDir); |
|
138 | - $process->setEnv($this->project->getProcessEnv()); |
|
139 | - $process->setTimeout(1800); |
|
140 | - $process->run(); |
|
141 | - if (!$process->isSuccessful()) { |
|
142 | - throw new RuntimeException($process->getErrorOutput()); |
|
143 | - } |
|
144 | - } |
|
145 | - |
|
146 | - /** |
|
147 | - * @param string $status |
|
148 | - * @global array $databaseConfig |
|
149 | - */ |
|
150 | - protected function updateStatus($status) |
|
151 | - { |
|
152 | - global $databaseConfig; |
|
153 | - DB::connect($databaseConfig); |
|
154 | - |
|
155 | - if (!empty($this->args['fetchID'])) { |
|
156 | - $fetch = DNGitFetch::get()->byID($this->args['fetchID']); |
|
157 | - if ($fetch && $fetch->exists()) { |
|
158 | - $fetch->Status = $status; |
|
159 | - $fetch->write(); |
|
160 | - } |
|
161 | - } |
|
162 | - } |
|
6 | + public $args; |
|
7 | + |
|
8 | + /** |
|
9 | + * @var DNProject |
|
10 | + */ |
|
11 | + protected $project; |
|
12 | + |
|
13 | + /** |
|
14 | + * @var DeploynautLogFile |
|
15 | + */ |
|
16 | + protected $log; |
|
17 | + |
|
18 | + /** |
|
19 | + * @var string |
|
20 | + */ |
|
21 | + protected $user; |
|
22 | + |
|
23 | + /** |
|
24 | + * @global array $databaseConfig |
|
25 | + */ |
|
26 | + public function setUp() |
|
27 | + { |
|
28 | + global $databaseConfig; |
|
29 | + DB::connect($databaseConfig); |
|
30 | + |
|
31 | + $this->updateStatus('Started'); |
|
32 | + chdir(BASE_PATH); |
|
33 | + } |
|
34 | + |
|
35 | + public function tearDown() |
|
36 | + { |
|
37 | + $this->updateStatus('Finished'); |
|
38 | + chdir(BASE_PATH); |
|
39 | + } |
|
40 | + |
|
41 | + public function perform() |
|
42 | + { |
|
43 | + set_time_limit(0); |
|
44 | + |
|
45 | + if (!empty($this->args['logfile'])) { |
|
46 | + $this->log = new DeploynautLogFile($this->args['logfile']); |
|
47 | + } |
|
48 | + |
|
49 | + $this->project = DNProject::get()->byId($this->args['projectID']); |
|
50 | + if (!($this->project && $this->project->exists())) { |
|
51 | + throw new RuntimeException(sprintf('Project ID %s not found', $this->args['projectID'])); |
|
52 | + } |
|
53 | + |
|
54 | + $this->user = DNData::inst()->getGitUser() ?: null; |
|
55 | + |
|
56 | + // Disallow concurrent git fetches on the same project. |
|
57 | + // Only consider fetches started in the last 30 minutes (older jobs probably got stuck) |
|
58 | + if (!empty($this->args['fetchID'])) { |
|
59 | + $runningFetches = DNGitFetch::get() |
|
60 | + ->filter(array( |
|
61 | + 'ProjectID' => $this->project->ID, |
|
62 | + 'Status' => array('Queued', 'Started'), |
|
63 | + 'Created:GreaterThan' => strtotime('-30 minutes') |
|
64 | + )) |
|
65 | + ->exclude('ID', $this->args['fetchID']); |
|
66 | + |
|
67 | + if ($runningFetches->count()) { |
|
68 | + $runningFetch = $runningFetches->first(); |
|
69 | + $message = sprintf( |
|
70 | + 'Another fetch is in progress (started at %s by %s)', |
|
71 | + $runningFetch->dbObject('Created')->Nice(), |
|
72 | + $runningFetch->Deployer()->Title |
|
73 | + ); |
|
74 | + if ($this->log) { |
|
75 | + $this->log->write($message); |
|
76 | + } |
|
77 | + throw new RuntimeException($message); |
|
78 | + } |
|
79 | + } |
|
80 | + |
|
81 | + // Decide whether we need to just update what we already have |
|
82 | + // or initiate a clone if no local repo exists. |
|
83 | + try { |
|
84 | + if ($this->project->repoExists() && empty($this->args['forceClone'])) { |
|
85 | + $this->fetchRepo(); |
|
86 | + } else { |
|
87 | + $this->cloneRepo(); |
|
88 | + } |
|
89 | + } catch (Exception $e) { |
|
90 | + $this->updateStatus('Failed'); |
|
91 | + if ($this->log) { |
|
92 | + $this->log->write($e->getMessage()); |
|
93 | + } |
|
94 | + throw $e; |
|
95 | + } |
|
96 | + } |
|
97 | + |
|
98 | + protected function fetchRepo() |
|
99 | + { |
|
100 | + $this->runCommand( |
|
101 | + 'git fetch -p origin +refs/heads/*:refs/heads/* --tags', |
|
102 | + $this->project->getLocalCVSPath() |
|
103 | + ); |
|
104 | + } |
|
105 | + |
|
106 | + protected function cloneRepo() |
|
107 | + { |
|
108 | + if (file_exists($this->project->getLocalCVSPath())) { |
|
109 | + $this->runCommand(sprintf( |
|
110 | + 'rm -rf %s', |
|
111 | + escapeshellarg($this->project->getLocalCVSPath()) |
|
112 | + )); |
|
113 | + } |
|
114 | + |
|
115 | + $this->runCommand(sprintf( |
|
116 | + 'git clone --bare -q %s %s', |
|
117 | + escapeshellarg($this->project->CVSPath), |
|
118 | + escapeshellarg($this->project->getLocalCVSPath()) |
|
119 | + )); |
|
120 | + } |
|
121 | + |
|
122 | + /** |
|
123 | + * Run a shell command. |
|
124 | + * |
|
125 | + * @param string $command The command to run |
|
126 | + * @param string|null $workingDir The working dir to run command in |
|
127 | + * @throws RuntimeException |
|
128 | + */ |
|
129 | + protected function runCommand($command, $workingDir = null) |
|
130 | + { |
|
131 | + if (!empty($this->user)) { |
|
132 | + $command = sprintf('sudo -u %s %s', $this->user, $command); |
|
133 | + } |
|
134 | + if ($this->log) { |
|
135 | + $this->log->write(sprintf('Running command: %s', $command)); |
|
136 | + } |
|
137 | + $process = new \Symfony\Component\Process\Process($command, $workingDir); |
|
138 | + $process->setEnv($this->project->getProcessEnv()); |
|
139 | + $process->setTimeout(1800); |
|
140 | + $process->run(); |
|
141 | + if (!$process->isSuccessful()) { |
|
142 | + throw new RuntimeException($process->getErrorOutput()); |
|
143 | + } |
|
144 | + } |
|
145 | + |
|
146 | + /** |
|
147 | + * @param string $status |
|
148 | + * @global array $databaseConfig |
|
149 | + */ |
|
150 | + protected function updateStatus($status) |
|
151 | + { |
|
152 | + global $databaseConfig; |
|
153 | + DB::connect($databaseConfig); |
|
154 | + |
|
155 | + if (!empty($this->args['fetchID'])) { |
|
156 | + $fetch = DNGitFetch::get()->byID($this->args['fetchID']); |
|
157 | + if ($fetch && $fetch->exists()) { |
|
158 | + $fetch->Status = $status; |
|
159 | + $fetch->write(); |
|
160 | + } |
|
161 | + } |
|
162 | + } |
|
163 | 163 | } |
@@ -42,12 +42,12 @@ discard block |
||
42 | 42 | { |
43 | 43 | set_time_limit(0); |
44 | 44 | |
45 | - if (!empty($this->args['logfile'])) { |
|
45 | + if(!empty($this->args['logfile'])) { |
|
46 | 46 | $this->log = new DeploynautLogFile($this->args['logfile']); |
47 | 47 | } |
48 | 48 | |
49 | 49 | $this->project = DNProject::get()->byId($this->args['projectID']); |
50 | - if (!($this->project && $this->project->exists())) { |
|
50 | + if(!($this->project && $this->project->exists())) { |
|
51 | 51 | throw new RuntimeException(sprintf('Project ID %s not found', $this->args['projectID'])); |
52 | 52 | } |
53 | 53 | |
@@ -55,7 +55,7 @@ discard block |
||
55 | 55 | |
56 | 56 | // Disallow concurrent git fetches on the same project. |
57 | 57 | // Only consider fetches started in the last 30 minutes (older jobs probably got stuck) |
58 | - if (!empty($this->args['fetchID'])) { |
|
58 | + if(!empty($this->args['fetchID'])) { |
|
59 | 59 | $runningFetches = DNGitFetch::get() |
60 | 60 | ->filter(array( |
61 | 61 | 'ProjectID' => $this->project->ID, |
@@ -64,14 +64,14 @@ discard block |
||
64 | 64 | )) |
65 | 65 | ->exclude('ID', $this->args['fetchID']); |
66 | 66 | |
67 | - if ($runningFetches->count()) { |
|
67 | + if($runningFetches->count()) { |
|
68 | 68 | $runningFetch = $runningFetches->first(); |
69 | 69 | $message = sprintf( |
70 | 70 | 'Another fetch is in progress (started at %s by %s)', |
71 | 71 | $runningFetch->dbObject('Created')->Nice(), |
72 | 72 | $runningFetch->Deployer()->Title |
73 | 73 | ); |
74 | - if ($this->log) { |
|
74 | + if($this->log) { |
|
75 | 75 | $this->log->write($message); |
76 | 76 | } |
77 | 77 | throw new RuntimeException($message); |
@@ -81,14 +81,14 @@ discard block |
||
81 | 81 | // Decide whether we need to just update what we already have |
82 | 82 | // or initiate a clone if no local repo exists. |
83 | 83 | try { |
84 | - if ($this->project->repoExists() && empty($this->args['forceClone'])) { |
|
84 | + if($this->project->repoExists() && empty($this->args['forceClone'])) { |
|
85 | 85 | $this->fetchRepo(); |
86 | 86 | } else { |
87 | 87 | $this->cloneRepo(); |
88 | 88 | } |
89 | - } catch (Exception $e) { |
|
89 | + } catch(Exception $e) { |
|
90 | 90 | $this->updateStatus('Failed'); |
91 | - if ($this->log) { |
|
91 | + if($this->log) { |
|
92 | 92 | $this->log->write($e->getMessage()); |
93 | 93 | } |
94 | 94 | throw $e; |
@@ -105,7 +105,7 @@ discard block |
||
105 | 105 | |
106 | 106 | protected function cloneRepo() |
107 | 107 | { |
108 | - if (file_exists($this->project->getLocalCVSPath())) { |
|
108 | + if(file_exists($this->project->getLocalCVSPath())) { |
|
109 | 109 | $this->runCommand(sprintf( |
110 | 110 | 'rm -rf %s', |
111 | 111 | escapeshellarg($this->project->getLocalCVSPath()) |
@@ -128,17 +128,17 @@ discard block |
||
128 | 128 | */ |
129 | 129 | protected function runCommand($command, $workingDir = null) |
130 | 130 | { |
131 | - if (!empty($this->user)) { |
|
131 | + if(!empty($this->user)) { |
|
132 | 132 | $command = sprintf('sudo -u %s %s', $this->user, $command); |
133 | 133 | } |
134 | - if ($this->log) { |
|
134 | + if($this->log) { |
|
135 | 135 | $this->log->write(sprintf('Running command: %s', $command)); |
136 | 136 | } |
137 | 137 | $process = new \Symfony\Component\Process\Process($command, $workingDir); |
138 | 138 | $process->setEnv($this->project->getProcessEnv()); |
139 | 139 | $process->setTimeout(1800); |
140 | 140 | $process->run(); |
141 | - if (!$process->isSuccessful()) { |
|
141 | + if(!$process->isSuccessful()) { |
|
142 | 142 | throw new RuntimeException($process->getErrorOutput()); |
143 | 143 | } |
144 | 144 | } |
@@ -152,9 +152,9 @@ discard block |
||
152 | 152 | global $databaseConfig; |
153 | 153 | DB::connect($databaseConfig); |
154 | 154 | |
155 | - if (!empty($this->args['fetchID'])) { |
|
155 | + if(!empty($this->args['fetchID'])) { |
|
156 | 156 | $fetch = DNGitFetch::get()->byID($this->args['fetchID']); |
157 | - if ($fetch && $fetch->exists()) { |
|
157 | + if($fetch && $fetch->exists()) { |
|
158 | 158 | $fetch->Status = $status; |
159 | 159 | $fetch->write(); |
160 | 160 | } |
@@ -1,7 +1,6 @@ discard block |
||
1 | 1 | <?php |
2 | 2 | |
3 | -class FetchJob |
|
4 | -{ |
|
3 | +class FetchJob { |
|
5 | 4 | |
6 | 5 | public $args; |
7 | 6 | |
@@ -23,8 +22,7 @@ discard block |
||
23 | 22 | /** |
24 | 23 | * @global array $databaseConfig |
25 | 24 | */ |
26 | - public function setUp() |
|
27 | - { |
|
25 | + public function setUp() { |
|
28 | 26 | global $databaseConfig; |
29 | 27 | DB::connect($databaseConfig); |
30 | 28 | |
@@ -32,14 +30,12 @@ discard block |
||
32 | 30 | chdir(BASE_PATH); |
33 | 31 | } |
34 | 32 | |
35 | - public function tearDown() |
|
36 | - { |
|
33 | + public function tearDown() { |
|
37 | 34 | $this->updateStatus('Finished'); |
38 | 35 | chdir(BASE_PATH); |
39 | 36 | } |
40 | 37 | |
41 | - public function perform() |
|
42 | - { |
|
38 | + public function perform() { |
|
43 | 39 | set_time_limit(0); |
44 | 40 | |
45 | 41 | if (!empty($this->args['logfile'])) { |
@@ -95,16 +91,14 @@ discard block |
||
95 | 91 | } |
96 | 92 | } |
97 | 93 | |
98 | - protected function fetchRepo() |
|
99 | - { |
|
94 | + protected function fetchRepo() { |
|
100 | 95 | $this->runCommand( |
101 | 96 | 'git fetch -p origin +refs/heads/*:refs/heads/* --tags', |
102 | 97 | $this->project->getLocalCVSPath() |
103 | 98 | ); |
104 | 99 | } |
105 | 100 | |
106 | - protected function cloneRepo() |
|
107 | - { |
|
101 | + protected function cloneRepo() { |
|
108 | 102 | if (file_exists($this->project->getLocalCVSPath())) { |
109 | 103 | $this->runCommand(sprintf( |
110 | 104 | 'rm -rf %s', |
@@ -126,8 +120,7 @@ discard block |
||
126 | 120 | * @param string|null $workingDir The working dir to run command in |
127 | 121 | * @throws RuntimeException |
128 | 122 | */ |
129 | - protected function runCommand($command, $workingDir = null) |
|
130 | - { |
|
123 | + protected function runCommand($command, $workingDir = null) { |
|
131 | 124 | if (!empty($this->user)) { |
132 | 125 | $command = sprintf('sudo -u %s %s', $this->user, $command); |
133 | 126 | } |
@@ -147,8 +140,7 @@ discard block |
||
147 | 140 | * @param string $status |
148 | 141 | * @global array $databaseConfig |
149 | 142 | */ |
150 | - protected function updateStatus($status) |
|
151 | - { |
|
143 | + protected function updateStatus($status) { |
|
152 | 144 | global $databaseConfig; |
153 | 145 | DB::connect($databaseConfig); |
154 | 146 |
@@ -7,38 +7,38 @@ |
||
7 | 7 | class PingJob |
8 | 8 | { |
9 | 9 | |
10 | - /** |
|
11 | - * @var array |
|
12 | - */ |
|
13 | - public $args; |
|
10 | + /** |
|
11 | + * @var array |
|
12 | + */ |
|
13 | + public $args; |
|
14 | 14 | |
15 | - /** |
|
16 | - * @global array $databaseConfig |
|
17 | - */ |
|
18 | - public function setUp() |
|
19 | - { |
|
20 | - global $databaseConfig; |
|
21 | - DB::connect($databaseConfig); |
|
22 | - chdir(BASE_PATH); |
|
23 | - } |
|
15 | + /** |
|
16 | + * @global array $databaseConfig |
|
17 | + */ |
|
18 | + public function setUp() |
|
19 | + { |
|
20 | + global $databaseConfig; |
|
21 | + DB::connect($databaseConfig); |
|
22 | + chdir(BASE_PATH); |
|
23 | + } |
|
24 | 24 | |
25 | - /** |
|
26 | - * @return DNData |
|
27 | - */ |
|
28 | - public function DNData() |
|
29 | - { |
|
30 | - return DNData::inst(); |
|
31 | - } |
|
25 | + /** |
|
26 | + * @return DNData |
|
27 | + */ |
|
28 | + public function DNData() |
|
29 | + { |
|
30 | + return DNData::inst(); |
|
31 | + } |
|
32 | 32 | |
33 | - /** |
|
34 | - * Do the actual job by calling the appropiate backend |
|
35 | - */ |
|
36 | - public function perform() |
|
37 | - { |
|
38 | - echo "[-] PingJob starting" . PHP_EOL; |
|
39 | - $log = new DeploynautLogFile($this->args['logfile']); |
|
40 | - $DNProject = $this->DNData()->DNProjectList()->filter('Name', $this->args['projectName'])->First(); |
|
41 | - $DNEnvironment = $DNProject->Environments()->filter('Name', $this->args['environmentName'])->First(); |
|
42 | - $DNEnvironment->Backend()->ping($DNEnvironment, $log, $DNProject); |
|
43 | - } |
|
33 | + /** |
|
34 | + * Do the actual job by calling the appropiate backend |
|
35 | + */ |
|
36 | + public function perform() |
|
37 | + { |
|
38 | + echo "[-] PingJob starting" . PHP_EOL; |
|
39 | + $log = new DeploynautLogFile($this->args['logfile']); |
|
40 | + $DNProject = $this->DNData()->DNProjectList()->filter('Name', $this->args['projectName'])->First(); |
|
41 | + $DNEnvironment = $DNProject->Environments()->filter('Name', $this->args['environmentName'])->First(); |
|
42 | + $DNEnvironment->Backend()->ping($DNEnvironment, $log, $DNProject); |
|
43 | + } |
|
44 | 44 | } |
@@ -4,8 +4,7 @@ discard block |
||
4 | 4 | * Runs a capistrano job that will check the connection and that all folders with |
5 | 5 | * permission are setup correctly |
6 | 6 | */ |
7 | -class PingJob |
|
8 | -{ |
|
7 | +class PingJob { |
|
9 | 8 | |
10 | 9 | /** |
11 | 10 | * @var array |
@@ -15,8 +14,7 @@ discard block |
||
15 | 14 | /** |
16 | 15 | * @global array $databaseConfig |
17 | 16 | */ |
18 | - public function setUp() |
|
19 | - { |
|
17 | + public function setUp() { |
|
20 | 18 | global $databaseConfig; |
21 | 19 | DB::connect($databaseConfig); |
22 | 20 | chdir(BASE_PATH); |
@@ -25,16 +23,14 @@ discard block |
||
25 | 23 | /** |
26 | 24 | * @return DNData |
27 | 25 | */ |
28 | - public function DNData() |
|
29 | - { |
|
26 | + public function DNData() { |
|
30 | 27 | return DNData::inst(); |
31 | 28 | } |
32 | 29 | |
33 | 30 | /** |
34 | 31 | * Do the actual job by calling the appropiate backend |
35 | 32 | */ |
36 | - public function perform() |
|
37 | - { |
|
33 | + public function perform() { |
|
38 | 34 | echo "[-] PingJob starting" . PHP_EOL; |
39 | 35 | $log = new DeploynautLogFile($this->args['logfile']); |
40 | 36 | $DNProject = $this->DNData()->DNProjectList()->filter('Name', $this->args['projectName'])->First(); |
@@ -8,113 +8,113 @@ |
||
8 | 8 | class DNBranch extends ViewableData |
9 | 9 | { |
10 | 10 | |
11 | - /** |
|
12 | - * @var Gitonomy\Git\Reference\Branch |
|
13 | - */ |
|
14 | - protected $branch = null; |
|
15 | - |
|
16 | - /** |
|
17 | - * @var DNProject |
|
18 | - */ |
|
19 | - protected $project = null; |
|
20 | - |
|
21 | - /** |
|
22 | - * @var DNData |
|
23 | - */ |
|
24 | - protected $data = null; |
|
25 | - |
|
26 | - private static $casting = array( |
|
27 | - 'Name' => 'Text', |
|
28 | - 'SHA' => 'Text' |
|
29 | - ); |
|
30 | - |
|
31 | - /** |
|
32 | - * @var SS_Datetime |
|
33 | - */ |
|
34 | - protected $_lastUpdatedCache = ''; |
|
35 | - |
|
36 | - /** |
|
37 | - * @param DNProject $project |
|
38 | - * @param DNData $data |
|
39 | - */ |
|
40 | - public function __construct(Gitonomy\Git\Reference\Branch $branch, DNProject $project, DNData $data) |
|
41 | - { |
|
42 | - $this->branch = $branch; |
|
43 | - $this->project = $project; |
|
44 | - $this->data = $data; |
|
45 | - } |
|
46 | - |
|
47 | - public function __toString() |
|
48 | - { |
|
49 | - return $this->Name(); |
|
50 | - } |
|
51 | - |
|
52 | - /** |
|
53 | - * @return string |
|
54 | - */ |
|
55 | - public function Name() |
|
56 | - { |
|
57 | - return (string)htmlentities($this->branch->getName()); |
|
58 | - } |
|
59 | - |
|
60 | - public function Link() |
|
61 | - { |
|
62 | - // Use a get-var for branch so that it can handle unsafe chars better |
|
63 | - return Controller::join_links($this->project->Link(), 'branch?name=' . urlencode($this->Name())); |
|
64 | - } |
|
65 | - |
|
66 | - /** |
|
67 | - * @return string |
|
68 | - */ |
|
69 | - public function SHA() |
|
70 | - { |
|
71 | - return (string)htmlentities($this->branch->getCommit()->getHash()); |
|
72 | - } |
|
73 | - |
|
74 | - /** |
|
75 | - * Provides a DNBuildList of builds found in this project. |
|
76 | - */ |
|
77 | - public function DNBuildList() |
|
78 | - { |
|
79 | - $blockBranch = $this->branch->getName() == 'master' ? null : 'master'; |
|
80 | - return DNReferenceList::create($this->project, $this->data, $this->branch, $blockBranch); |
|
81 | - } |
|
82 | - |
|
83 | - /** |
|
84 | - * @return SS_Datetime |
|
85 | - */ |
|
86 | - public function LastUpdated() |
|
87 | - { |
|
88 | - if ($this->_lastUpdatedCache) { |
|
89 | - return $this->_lastUpdatedCache; |
|
90 | - } |
|
91 | - try { |
|
92 | - $created = $this->branch->getCommit()->getCommitterDate(); |
|
93 | - } catch (Exception $e) { |
|
94 | - //occasionally parsing will fail this is a fallback to make it still work |
|
95 | - return new SS_Datetime(); |
|
96 | - } |
|
97 | - // gitonomy sets the time to UTC, so now we set the timezone to |
|
98 | - // whatever PHP is set to (date.timezone). This will change in the future if each |
|
99 | - // deploynaut user has their own timezone |
|
100 | - |
|
101 | - $created->setTimezone(new DateTimeZone(date_default_timezone_get())); |
|
102 | - |
|
103 | - $date = new SS_Datetime(); |
|
104 | - $date->setValue($created->format('Y-m-d H:i:s')); |
|
105 | - $this->_lastUpdatedCache = $date; |
|
106 | - return $date; |
|
107 | - } |
|
108 | - |
|
109 | - /** |
|
110 | - * @return string |
|
111 | - */ |
|
112 | - public function IsOpenByDefault() |
|
113 | - { |
|
114 | - if ($this->Name() == 'master') { |
|
115 | - return " open"; |
|
116 | - } else { |
|
117 | - return ""; |
|
118 | - } |
|
119 | - } |
|
11 | + /** |
|
12 | + * @var Gitonomy\Git\Reference\Branch |
|
13 | + */ |
|
14 | + protected $branch = null; |
|
15 | + |
|
16 | + /** |
|
17 | + * @var DNProject |
|
18 | + */ |
|
19 | + protected $project = null; |
|
20 | + |
|
21 | + /** |
|
22 | + * @var DNData |
|
23 | + */ |
|
24 | + protected $data = null; |
|
25 | + |
|
26 | + private static $casting = array( |
|
27 | + 'Name' => 'Text', |
|
28 | + 'SHA' => 'Text' |
|
29 | + ); |
|
30 | + |
|
31 | + /** |
|
32 | + * @var SS_Datetime |
|
33 | + */ |
|
34 | + protected $_lastUpdatedCache = ''; |
|
35 | + |
|
36 | + /** |
|
37 | + * @param DNProject $project |
|
38 | + * @param DNData $data |
|
39 | + */ |
|
40 | + public function __construct(Gitonomy\Git\Reference\Branch $branch, DNProject $project, DNData $data) |
|
41 | + { |
|
42 | + $this->branch = $branch; |
|
43 | + $this->project = $project; |
|
44 | + $this->data = $data; |
|
45 | + } |
|
46 | + |
|
47 | + public function __toString() |
|
48 | + { |
|
49 | + return $this->Name(); |
|
50 | + } |
|
51 | + |
|
52 | + /** |
|
53 | + * @return string |
|
54 | + */ |
|
55 | + public function Name() |
|
56 | + { |
|
57 | + return (string)htmlentities($this->branch->getName()); |
|
58 | + } |
|
59 | + |
|
60 | + public function Link() |
|
61 | + { |
|
62 | + // Use a get-var for branch so that it can handle unsafe chars better |
|
63 | + return Controller::join_links($this->project->Link(), 'branch?name=' . urlencode($this->Name())); |
|
64 | + } |
|
65 | + |
|
66 | + /** |
|
67 | + * @return string |
|
68 | + */ |
|
69 | + public function SHA() |
|
70 | + { |
|
71 | + return (string)htmlentities($this->branch->getCommit()->getHash()); |
|
72 | + } |
|
73 | + |
|
74 | + /** |
|
75 | + * Provides a DNBuildList of builds found in this project. |
|
76 | + */ |
|
77 | + public function DNBuildList() |
|
78 | + { |
|
79 | + $blockBranch = $this->branch->getName() == 'master' ? null : 'master'; |
|
80 | + return DNReferenceList::create($this->project, $this->data, $this->branch, $blockBranch); |
|
81 | + } |
|
82 | + |
|
83 | + /** |
|
84 | + * @return SS_Datetime |
|
85 | + */ |
|
86 | + public function LastUpdated() |
|
87 | + { |
|
88 | + if ($this->_lastUpdatedCache) { |
|
89 | + return $this->_lastUpdatedCache; |
|
90 | + } |
|
91 | + try { |
|
92 | + $created = $this->branch->getCommit()->getCommitterDate(); |
|
93 | + } catch (Exception $e) { |
|
94 | + //occasionally parsing will fail this is a fallback to make it still work |
|
95 | + return new SS_Datetime(); |
|
96 | + } |
|
97 | + // gitonomy sets the time to UTC, so now we set the timezone to |
|
98 | + // whatever PHP is set to (date.timezone). This will change in the future if each |
|
99 | + // deploynaut user has their own timezone |
|
100 | + |
|
101 | + $created->setTimezone(new DateTimeZone(date_default_timezone_get())); |
|
102 | + |
|
103 | + $date = new SS_Datetime(); |
|
104 | + $date->setValue($created->format('Y-m-d H:i:s')); |
|
105 | + $this->_lastUpdatedCache = $date; |
|
106 | + return $date; |
|
107 | + } |
|
108 | + |
|
109 | + /** |
|
110 | + * @return string |
|
111 | + */ |
|
112 | + public function IsOpenByDefault() |
|
113 | + { |
|
114 | + if ($this->Name() == 'master') { |
|
115 | + return " open"; |
|
116 | + } else { |
|
117 | + return ""; |
|
118 | + } |
|
119 | + } |
|
120 | 120 | } |
@@ -85,12 +85,12 @@ discard block |
||
85 | 85 | */ |
86 | 86 | public function LastUpdated() |
87 | 87 | { |
88 | - if ($this->_lastUpdatedCache) { |
|
88 | + if($this->_lastUpdatedCache) { |
|
89 | 89 | return $this->_lastUpdatedCache; |
90 | 90 | } |
91 | 91 | try { |
92 | 92 | $created = $this->branch->getCommit()->getCommitterDate(); |
93 | - } catch (Exception $e) { |
|
93 | + } catch(Exception $e) { |
|
94 | 94 | //occasionally parsing will fail this is a fallback to make it still work |
95 | 95 | return new SS_Datetime(); |
96 | 96 | } |
@@ -111,7 +111,7 @@ discard block |
||
111 | 111 | */ |
112 | 112 | public function IsOpenByDefault() |
113 | 113 | { |
114 | - if ($this->Name() == 'master') { |
|
114 | + if($this->Name() == 'master') { |
|
115 | 115 | return " open"; |
116 | 116 | } else { |
117 | 117 | return ""; |
@@ -5,8 +5,7 @@ discard block |
||
5 | 5 | * |
6 | 6 | * @method string getName() |
7 | 7 | */ |
8 | -class DNBranch extends ViewableData |
|
9 | -{ |
|
8 | +class DNBranch extends ViewableData { |
|
10 | 9 | |
11 | 10 | /** |
12 | 11 | * @var Gitonomy\Git\Reference\Branch |
@@ -37,28 +36,24 @@ discard block |
||
37 | 36 | * @param DNProject $project |
38 | 37 | * @param DNData $data |
39 | 38 | */ |
40 | - public function __construct(Gitonomy\Git\Reference\Branch $branch, DNProject $project, DNData $data) |
|
41 | - { |
|
39 | + public function __construct(Gitonomy\Git\Reference\Branch $branch, DNProject $project, DNData $data) { |
|
42 | 40 | $this->branch = $branch; |
43 | 41 | $this->project = $project; |
44 | 42 | $this->data = $data; |
45 | 43 | } |
46 | 44 | |
47 | - public function __toString() |
|
48 | - { |
|
45 | + public function __toString() { |
|
49 | 46 | return $this->Name(); |
50 | 47 | } |
51 | 48 | |
52 | 49 | /** |
53 | 50 | * @return string |
54 | 51 | */ |
55 | - public function Name() |
|
56 | - { |
|
52 | + public function Name() { |
|
57 | 53 | return (string)htmlentities($this->branch->getName()); |
58 | 54 | } |
59 | 55 | |
60 | - public function Link() |
|
61 | - { |
|
56 | + public function Link() { |
|
62 | 57 | // Use a get-var for branch so that it can handle unsafe chars better |
63 | 58 | return Controller::join_links($this->project->Link(), 'branch?name=' . urlencode($this->Name())); |
64 | 59 | } |
@@ -66,16 +61,14 @@ discard block |
||
66 | 61 | /** |
67 | 62 | * @return string |
68 | 63 | */ |
69 | - public function SHA() |
|
70 | - { |
|
64 | + public function SHA() { |
|
71 | 65 | return (string)htmlentities($this->branch->getCommit()->getHash()); |
72 | 66 | } |
73 | 67 | |
74 | 68 | /** |
75 | 69 | * Provides a DNBuildList of builds found in this project. |
76 | 70 | */ |
77 | - public function DNBuildList() |
|
78 | - { |
|
71 | + public function DNBuildList() { |
|
79 | 72 | $blockBranch = $this->branch->getName() == 'master' ? null : 'master'; |
80 | 73 | return DNReferenceList::create($this->project, $this->data, $this->branch, $blockBranch); |
81 | 74 | } |
@@ -83,8 +76,7 @@ discard block |
||
83 | 76 | /** |
84 | 77 | * @return SS_Datetime |
85 | 78 | */ |
86 | - public function LastUpdated() |
|
87 | - { |
|
79 | + public function LastUpdated() { |
|
88 | 80 | if ($this->_lastUpdatedCache) { |
89 | 81 | return $this->_lastUpdatedCache; |
90 | 82 | } |
@@ -109,8 +101,7 @@ discard block |
||
109 | 101 | /** |
110 | 102 | * @return string |
111 | 103 | */ |
112 | - public function IsOpenByDefault() |
|
113 | - { |
|
104 | + public function IsOpenByDefault() { |
|
114 | 105 | if ($this->Name() == 'master') { |
115 | 106 | return " open"; |
116 | 107 | } else { |
@@ -6,120 +6,120 @@ |
||
6 | 6 | class DNBranchList extends ArrayList |
7 | 7 | { |
8 | 8 | |
9 | - /** |
|
10 | - * @var string |
|
11 | - */ |
|
12 | - protected static $refs_dir = ''; |
|
13 | - |
|
14 | - /** |
|
15 | - * @var bool |
|
16 | - */ |
|
17 | - protected $loaded = false; |
|
18 | - |
|
19 | - /** |
|
20 | - * @var array |
|
21 | - */ |
|
22 | - protected $builds = array(); |
|
23 | - |
|
24 | - /** |
|
25 | - * @var DNProject |
|
26 | - */ |
|
27 | - protected $project; |
|
28 | - |
|
29 | - /** |
|
30 | - * @var DNData |
|
31 | - */ |
|
32 | - protected $data; |
|
33 | - |
|
34 | - public static function set_refs_dir($refsDir) |
|
35 | - { |
|
36 | - self::$refs_dir = $refsDir; |
|
37 | - } |
|
38 | - |
|
39 | - public static function get_refs_dir() |
|
40 | - { |
|
41 | - return self::$refs_dir; |
|
42 | - } |
|
43 | - |
|
44 | - /** |
|
45 | - * @param DNProject $project |
|
46 | - * @param DNData $data |
|
47 | - */ |
|
48 | - public function __construct(DNProject $project, DNData $data) |
|
49 | - { |
|
50 | - $this->project = $project; |
|
51 | - $this->data = $data; |
|
52 | - parent::__construct(array()); |
|
53 | - } |
|
54 | - |
|
55 | - /** |
|
56 | - * @return array |
|
57 | - */ |
|
58 | - protected function getReferences() |
|
59 | - { |
|
60 | - $branches = array(); |
|
61 | - // Placeholder to put master branch first |
|
62 | - $firstBranch = null; |
|
63 | - |
|
64 | - try { |
|
65 | - $repository = new Gitonomy\Git\Repository($this->project->getLocalCVSPath()); |
|
66 | - } catch (Exception $e) { |
|
67 | - return $branches; |
|
68 | - } |
|
69 | - |
|
70 | - foreach ($repository->getReferences()->getBranches() as $branch) { |
|
71 | - /** @var DNBranch $obj */ |
|
72 | - $obj = DNBranch::create($branch, $this->project, $this->data); |
|
73 | - if ($branch->getName() == 'master') { |
|
74 | - $firstBranch = array($branch->getName() => $obj); |
|
75 | - } else { |
|
76 | - $branches[$branch->getName()] = $obj; |
|
77 | - } |
|
78 | - } |
|
79 | - if ($firstBranch) { |
|
80 | - $branches = $firstBranch + $branches; |
|
81 | - } |
|
82 | - |
|
83 | - return $branches; |
|
84 | - } |
|
85 | - |
|
86 | - /** |
|
87 | - * Find a branch in this set by branch name. |
|
88 | - * |
|
89 | - * @param $name |
|
90 | - * |
|
91 | - * @return string |
|
92 | - */ |
|
93 | - public function byName($name) |
|
94 | - { |
|
95 | - if ($this->loaded === false) { |
|
96 | - $this->getIterator(); |
|
97 | - } |
|
98 | - |
|
99 | - if (isset($this->items[$name])) { |
|
100 | - return $this->items[$name]; |
|
101 | - } |
|
102 | - |
|
103 | - return ''; |
|
104 | - } |
|
105 | - |
|
106 | - /** |
|
107 | - * Returns an Iterator for this ArrayList. |
|
108 | - * This function allows you to use ArrayList in foreach loops |
|
109 | - * |
|
110 | - * @return ArrayIterator |
|
111 | - */ |
|
112 | - public function getIterator() |
|
113 | - { |
|
114 | - if ($this->loaded === false) { |
|
115 | - $this->items = $this->getReferences(); |
|
116 | - $this->loaded = true; |
|
117 | - } |
|
118 | - foreach ($this->items as $i => $item) { |
|
119 | - if (is_array($item)) { |
|
120 | - $this->items[$i] = new ArrayData($item); |
|
121 | - } |
|
122 | - } |
|
123 | - return new ArrayIterator($this->items); |
|
124 | - } |
|
9 | + /** |
|
10 | + * @var string |
|
11 | + */ |
|
12 | + protected static $refs_dir = ''; |
|
13 | + |
|
14 | + /** |
|
15 | + * @var bool |
|
16 | + */ |
|
17 | + protected $loaded = false; |
|
18 | + |
|
19 | + /** |
|
20 | + * @var array |
|
21 | + */ |
|
22 | + protected $builds = array(); |
|
23 | + |
|
24 | + /** |
|
25 | + * @var DNProject |
|
26 | + */ |
|
27 | + protected $project; |
|
28 | + |
|
29 | + /** |
|
30 | + * @var DNData |
|
31 | + */ |
|
32 | + protected $data; |
|
33 | + |
|
34 | + public static function set_refs_dir($refsDir) |
|
35 | + { |
|
36 | + self::$refs_dir = $refsDir; |
|
37 | + } |
|
38 | + |
|
39 | + public static function get_refs_dir() |
|
40 | + { |
|
41 | + return self::$refs_dir; |
|
42 | + } |
|
43 | + |
|
44 | + /** |
|
45 | + * @param DNProject $project |
|
46 | + * @param DNData $data |
|
47 | + */ |
|
48 | + public function __construct(DNProject $project, DNData $data) |
|
49 | + { |
|
50 | + $this->project = $project; |
|
51 | + $this->data = $data; |
|
52 | + parent::__construct(array()); |
|
53 | + } |
|
54 | + |
|
55 | + /** |
|
56 | + * @return array |
|
57 | + */ |
|
58 | + protected function getReferences() |
|
59 | + { |
|
60 | + $branches = array(); |
|
61 | + // Placeholder to put master branch first |
|
62 | + $firstBranch = null; |
|
63 | + |
|
64 | + try { |
|
65 | + $repository = new Gitonomy\Git\Repository($this->project->getLocalCVSPath()); |
|
66 | + } catch (Exception $e) { |
|
67 | + return $branches; |
|
68 | + } |
|
69 | + |
|
70 | + foreach ($repository->getReferences()->getBranches() as $branch) { |
|
71 | + /** @var DNBranch $obj */ |
|
72 | + $obj = DNBranch::create($branch, $this->project, $this->data); |
|
73 | + if ($branch->getName() == 'master') { |
|
74 | + $firstBranch = array($branch->getName() => $obj); |
|
75 | + } else { |
|
76 | + $branches[$branch->getName()] = $obj; |
|
77 | + } |
|
78 | + } |
|
79 | + if ($firstBranch) { |
|
80 | + $branches = $firstBranch + $branches; |
|
81 | + } |
|
82 | + |
|
83 | + return $branches; |
|
84 | + } |
|
85 | + |
|
86 | + /** |
|
87 | + * Find a branch in this set by branch name. |
|
88 | + * |
|
89 | + * @param $name |
|
90 | + * |
|
91 | + * @return string |
|
92 | + */ |
|
93 | + public function byName($name) |
|
94 | + { |
|
95 | + if ($this->loaded === false) { |
|
96 | + $this->getIterator(); |
|
97 | + } |
|
98 | + |
|
99 | + if (isset($this->items[$name])) { |
|
100 | + return $this->items[$name]; |
|
101 | + } |
|
102 | + |
|
103 | + return ''; |
|
104 | + } |
|
105 | + |
|
106 | + /** |
|
107 | + * Returns an Iterator for this ArrayList. |
|
108 | + * This function allows you to use ArrayList in foreach loops |
|
109 | + * |
|
110 | + * @return ArrayIterator |
|
111 | + */ |
|
112 | + public function getIterator() |
|
113 | + { |
|
114 | + if ($this->loaded === false) { |
|
115 | + $this->items = $this->getReferences(); |
|
116 | + $this->loaded = true; |
|
117 | + } |
|
118 | + foreach ($this->items as $i => $item) { |
|
119 | + if (is_array($item)) { |
|
120 | + $this->items[$i] = new ArrayData($item); |
|
121 | + } |
|
122 | + } |
|
123 | + return new ArrayIterator($this->items); |
|
124 | + } |
|
125 | 125 | } |
@@ -63,20 +63,20 @@ discard block |
||
63 | 63 | |
64 | 64 | try { |
65 | 65 | $repository = new Gitonomy\Git\Repository($this->project->getLocalCVSPath()); |
66 | - } catch (Exception $e) { |
|
66 | + } catch(Exception $e) { |
|
67 | 67 | return $branches; |
68 | 68 | } |
69 | 69 | |
70 | - foreach ($repository->getReferences()->getBranches() as $branch) { |
|
70 | + foreach($repository->getReferences()->getBranches() as $branch) { |
|
71 | 71 | /** @var DNBranch $obj */ |
72 | 72 | $obj = DNBranch::create($branch, $this->project, $this->data); |
73 | - if ($branch->getName() == 'master') { |
|
73 | + if($branch->getName() == 'master') { |
|
74 | 74 | $firstBranch = array($branch->getName() => $obj); |
75 | 75 | } else { |
76 | 76 | $branches[$branch->getName()] = $obj; |
77 | 77 | } |
78 | 78 | } |
79 | - if ($firstBranch) { |
|
79 | + if($firstBranch) { |
|
80 | 80 | $branches = $firstBranch + $branches; |
81 | 81 | } |
82 | 82 | |
@@ -92,11 +92,11 @@ discard block |
||
92 | 92 | */ |
93 | 93 | public function byName($name) |
94 | 94 | { |
95 | - if ($this->loaded === false) { |
|
95 | + if($this->loaded === false) { |
|
96 | 96 | $this->getIterator(); |
97 | 97 | } |
98 | 98 | |
99 | - if (isset($this->items[$name])) { |
|
99 | + if(isset($this->items[$name])) { |
|
100 | 100 | return $this->items[$name]; |
101 | 101 | } |
102 | 102 | |
@@ -111,12 +111,12 @@ discard block |
||
111 | 111 | */ |
112 | 112 | public function getIterator() |
113 | 113 | { |
114 | - if ($this->loaded === false) { |
|
114 | + if($this->loaded === false) { |
|
115 | 115 | $this->items = $this->getReferences(); |
116 | 116 | $this->loaded = true; |
117 | 117 | } |
118 | - foreach ($this->items as $i => $item) { |
|
119 | - if (is_array($item)) { |
|
118 | + foreach($this->items as $i => $item) { |
|
119 | + if(is_array($item)) { |
|
120 | 120 | $this->items[$i] = new ArrayData($item); |
121 | 121 | } |
122 | 122 | } |
@@ -3,8 +3,7 @@ discard block |
||
3 | 3 | /** |
4 | 4 | * Class DNBranchList |
5 | 5 | */ |
6 | -class DNBranchList extends ArrayList |
|
7 | -{ |
|
6 | +class DNBranchList extends ArrayList { |
|
8 | 7 | |
9 | 8 | /** |
10 | 9 | * @var string |
@@ -31,13 +30,11 @@ discard block |
||
31 | 30 | */ |
32 | 31 | protected $data; |
33 | 32 | |
34 | - public static function set_refs_dir($refsDir) |
|
35 | - { |
|
33 | + public static function set_refs_dir($refsDir) { |
|
36 | 34 | self::$refs_dir = $refsDir; |
37 | 35 | } |
38 | 36 | |
39 | - public static function get_refs_dir() |
|
40 | - { |
|
37 | + public static function get_refs_dir() { |
|
41 | 38 | return self::$refs_dir; |
42 | 39 | } |
43 | 40 | |
@@ -45,8 +42,7 @@ discard block |
||
45 | 42 | * @param DNProject $project |
46 | 43 | * @param DNData $data |
47 | 44 | */ |
48 | - public function __construct(DNProject $project, DNData $data) |
|
49 | - { |
|
45 | + public function __construct(DNProject $project, DNData $data) { |
|
50 | 46 | $this->project = $project; |
51 | 47 | $this->data = $data; |
52 | 48 | parent::__construct(array()); |
@@ -55,8 +51,7 @@ discard block |
||
55 | 51 | /** |
56 | 52 | * @return array |
57 | 53 | */ |
58 | - protected function getReferences() |
|
59 | - { |
|
54 | + protected function getReferences() { |
|
60 | 55 | $branches = array(); |
61 | 56 | // Placeholder to put master branch first |
62 | 57 | $firstBranch = null; |
@@ -90,8 +85,7 @@ discard block |
||
90 | 85 | * |
91 | 86 | * @return string |
92 | 87 | */ |
93 | - public function byName($name) |
|
94 | - { |
|
88 | + public function byName($name) { |
|
95 | 89 | if ($this->loaded === false) { |
96 | 90 | $this->getIterator(); |
97 | 91 | } |
@@ -109,8 +103,7 @@ discard block |
||
109 | 103 | * |
110 | 104 | * @return ArrayIterator |
111 | 105 | */ |
112 | - public function getIterator() |
|
113 | - { |
|
106 | + public function getIterator() { |
|
114 | 107 | if ($this->loaded === false) { |
115 | 108 | $this->items = $this->getReferences(); |
116 | 109 | $this->loaded = true; |