@@ -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 | } |
@@ -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 | } |
@@ -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 | } |
@@ -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 | } |
@@ -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 | } |
@@ -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 | } |
@@ -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 | } |
@@ -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 | } |
@@ -2,220 +2,220 @@ |
||
2 | 2 | class DNCommit extends ViewableData |
3 | 3 | { |
4 | 4 | |
5 | - /** |
|
6 | - * @var Gitonomy\Git\Commit |
|
7 | - */ |
|
8 | - protected $commit = null; |
|
9 | - |
|
10 | - protected $name = null; |
|
11 | - |
|
12 | - |
|
13 | - protected $references = null; |
|
14 | - |
|
15 | - /** |
|
16 | - * @var string |
|
17 | - */ |
|
18 | - protected $ownerBranchName = null; |
|
19 | - |
|
20 | - /** |
|
21 | - * @var string |
|
22 | - */ |
|
23 | - protected $buildname; |
|
24 | - |
|
25 | - /** |
|
26 | - * @var DNProject |
|
27 | - */ |
|
28 | - protected $project; |
|
29 | - |
|
30 | - /** |
|
31 | - * @var DNData |
|
32 | - */ |
|
33 | - protected $data; |
|
34 | - |
|
35 | - /** |
|
36 | - * @var string |
|
37 | - */ |
|
38 | - protected $subjectMessage; |
|
39 | - |
|
40 | - /** |
|
41 | - * @var string |
|
42 | - */ |
|
43 | - protected $bodyMessage; |
|
44 | - |
|
45 | - /** |
|
46 | - * @var array |
|
47 | - */ |
|
48 | - private static $casting = array( |
|
49 | - 'Name' => 'Text', |
|
50 | - 'SubjectMessage' => 'Text', |
|
51 | - 'Message' => 'Text', |
|
52 | - 'BodyMessage' => 'Text', |
|
53 | - 'Fullname' => 'Text', |
|
54 | - 'Filename' => 'Text', |
|
55 | - 'References' => 'Text', |
|
56 | - 'ownerBranchName' => 'Text' |
|
57 | - ); |
|
58 | - |
|
59 | - /** |
|
60 | - * @param Gitonomy\Git\Commit $commit |
|
61 | - * @param DNProject $project |
|
62 | - * @param DNData $data |
|
63 | - * @param string|null $ownerBranchName |
|
64 | - */ |
|
65 | - public function __construct(Gitonomy\Git\Commit $commit, DNProject $project, DNData $data, $ownerBranchName = null) |
|
66 | - { |
|
67 | - $this->commit = $commit; |
|
68 | - $this->buildname = $commit->getHash(); |
|
69 | - $this->project = $project; |
|
70 | - $this->data = $data; |
|
71 | - $this->ownerBranchName = $ownerBranchName; |
|
72 | - } |
|
73 | - |
|
74 | - /** |
|
75 | - * Return the hash of the commit, used to name this commit. |
|
76 | - * @return string |
|
77 | - */ |
|
78 | - public function Name() |
|
79 | - { |
|
80 | - if ($this->name == null) { |
|
81 | - $this->name = $this->commit->getFixedShortHash(8); |
|
82 | - } |
|
83 | - |
|
84 | - return htmlentities($this->name); |
|
85 | - } |
|
86 | - |
|
87 | - /** |
|
88 | - * Return the full SHA of the commit. |
|
89 | - * @return string |
|
90 | - */ |
|
91 | - public function SHA() |
|
92 | - { |
|
93 | - return htmlentities($this->commit->getHash()); |
|
94 | - } |
|
95 | - |
|
96 | - /** |
|
97 | - * Return the first line of the commit message. |
|
98 | - * @return string |
|
99 | - */ |
|
100 | - public function SubjectMessage() |
|
101 | - { |
|
102 | - if ($this->subjectMessage == null) { |
|
103 | - $this->subjectMessage = $this->commit->getSubjectMessage(); |
|
104 | - } |
|
105 | - |
|
106 | - return htmlentities($this->subjectMessage); |
|
107 | - } |
|
108 | - |
|
109 | - public function BodyMessage() |
|
110 | - { |
|
111 | - if ($this->bodyMessage == null) { |
|
112 | - $this->bodyMessage = $this->commit->getBodyMessage(); |
|
113 | - } |
|
114 | - |
|
115 | - return htmlentities($this->bodyMessage); |
|
116 | - } |
|
117 | - |
|
118 | - /** |
|
119 | - * @return ArrayList |
|
120 | - */ |
|
121 | - public function References() |
|
122 | - { |
|
123 | - if ($this->references !== null) { |
|
124 | - return $this->references; |
|
125 | - } |
|
126 | - $this->references = new ArrayList(); |
|
127 | - |
|
128 | - // Add tags |
|
129 | - foreach ($this->commit->resolveReferences() as $reference) { |
|
130 | - if ($reference instanceof \Gitonomy\Git\Reference\Tag) { |
|
131 | - $this->references->push(new ArrayData(array( |
|
132 | - 'Name' => $reference->getName(), |
|
133 | - 'Type' => 'Tag', |
|
134 | - ))); |
|
135 | - } |
|
136 | - } |
|
137 | - |
|
138 | - return $this->references; |
|
139 | - } |
|
140 | - |
|
141 | - /** |
|
142 | - * @return string |
|
143 | - */ |
|
144 | - public function FullName() |
|
145 | - { |
|
146 | - return htmlentities($this->commit->getHash()); |
|
147 | - } |
|
148 | - |
|
149 | - /** |
|
150 | - * @return string |
|
151 | - */ |
|
152 | - public function Filename() |
|
153 | - { |
|
154 | - return htmlentities($this->commit->getHash()); |
|
155 | - } |
|
156 | - |
|
157 | - /** |
|
158 | - * @return ArrayList |
|
159 | - */ |
|
160 | - public function CurrentlyDeployedTo() |
|
161 | - { |
|
162 | - $environments = $this->project->Environments(); |
|
163 | - $envList = new ArrayList(); |
|
164 | - foreach ($environments as $environment) { |
|
165 | - $deployments = DNDeployment::get() |
|
166 | - ->filter('Status', 'Finished') |
|
167 | - ->filter('EnvironmentID', $environment->ID) |
|
168 | - ->sort('LastEdited DESC'); |
|
169 | - if (!$deployments->count()) { |
|
170 | - continue; |
|
171 | - } |
|
172 | - $latest = $deployments->first(); |
|
173 | - if ($latest->SHA === $this->commit->getHash()) { |
|
174 | - $envList->push($environment); |
|
175 | - } |
|
176 | - } |
|
177 | - return $envList; |
|
178 | - } |
|
179 | - |
|
180 | - /** |
|
181 | - * @param string $environmentName |
|
182 | - * @return boolean True if this release has ever been deployed to the given environment |
|
183 | - */ |
|
184 | - public function EverDeployedTo($environmentName) |
|
185 | - { |
|
186 | - $environments = $this->project->Environments()->filter('Name', $environmentName); |
|
187 | - if (!$environments->count()) { |
|
188 | - return false; |
|
189 | - } |
|
190 | - |
|
191 | - $environment = $environments->first(); |
|
192 | - |
|
193 | - $deployments = DNDeployment::get() |
|
194 | - ->filter('Status', 'Finished') |
|
195 | - ->filter('EnvironmentID', $environment->ID); |
|
196 | - |
|
197 | - if ($deployments->count()) { |
|
198 | - return true; |
|
199 | - } |
|
200 | - |
|
201 | - return false; |
|
202 | - } |
|
203 | - |
|
204 | - /** |
|
205 | - * @return SS_Datetime |
|
206 | - */ |
|
207 | - public function Created() |
|
208 | - { |
|
209 | - $created = $this->commit->getCommitterDate(); |
|
210 | - |
|
211 | - // gitonomy sets the time to UTC, so now we set the timezone to |
|
212 | - // whatever PHP is set to (date.timezone). This will change in the future if each |
|
213 | - // deploynaut user has their own timezone |
|
214 | - $created->setTimezone(new DateTimeZone(date_default_timezone_get())); |
|
215 | - |
|
216 | - $d = new SS_Datetime(); |
|
217 | - $d->setValue($created->format('Y-m-d H:i:s')); |
|
218 | - |
|
219 | - return $d; |
|
220 | - } |
|
5 | + /** |
|
6 | + * @var Gitonomy\Git\Commit |
|
7 | + */ |
|
8 | + protected $commit = null; |
|
9 | + |
|
10 | + protected $name = null; |
|
11 | + |
|
12 | + |
|
13 | + protected $references = null; |
|
14 | + |
|
15 | + /** |
|
16 | + * @var string |
|
17 | + */ |
|
18 | + protected $ownerBranchName = null; |
|
19 | + |
|
20 | + /** |
|
21 | + * @var string |
|
22 | + */ |
|
23 | + protected $buildname; |
|
24 | + |
|
25 | + /** |
|
26 | + * @var DNProject |
|
27 | + */ |
|
28 | + protected $project; |
|
29 | + |
|
30 | + /** |
|
31 | + * @var DNData |
|
32 | + */ |
|
33 | + protected $data; |
|
34 | + |
|
35 | + /** |
|
36 | + * @var string |
|
37 | + */ |
|
38 | + protected $subjectMessage; |
|
39 | + |
|
40 | + /** |
|
41 | + * @var string |
|
42 | + */ |
|
43 | + protected $bodyMessage; |
|
44 | + |
|
45 | + /** |
|
46 | + * @var array |
|
47 | + */ |
|
48 | + private static $casting = array( |
|
49 | + 'Name' => 'Text', |
|
50 | + 'SubjectMessage' => 'Text', |
|
51 | + 'Message' => 'Text', |
|
52 | + 'BodyMessage' => 'Text', |
|
53 | + 'Fullname' => 'Text', |
|
54 | + 'Filename' => 'Text', |
|
55 | + 'References' => 'Text', |
|
56 | + 'ownerBranchName' => 'Text' |
|
57 | + ); |
|
58 | + |
|
59 | + /** |
|
60 | + * @param Gitonomy\Git\Commit $commit |
|
61 | + * @param DNProject $project |
|
62 | + * @param DNData $data |
|
63 | + * @param string|null $ownerBranchName |
|
64 | + */ |
|
65 | + public function __construct(Gitonomy\Git\Commit $commit, DNProject $project, DNData $data, $ownerBranchName = null) |
|
66 | + { |
|
67 | + $this->commit = $commit; |
|
68 | + $this->buildname = $commit->getHash(); |
|
69 | + $this->project = $project; |
|
70 | + $this->data = $data; |
|
71 | + $this->ownerBranchName = $ownerBranchName; |
|
72 | + } |
|
73 | + |
|
74 | + /** |
|
75 | + * Return the hash of the commit, used to name this commit. |
|
76 | + * @return string |
|
77 | + */ |
|
78 | + public function Name() |
|
79 | + { |
|
80 | + if ($this->name == null) { |
|
81 | + $this->name = $this->commit->getFixedShortHash(8); |
|
82 | + } |
|
83 | + |
|
84 | + return htmlentities($this->name); |
|
85 | + } |
|
86 | + |
|
87 | + /** |
|
88 | + * Return the full SHA of the commit. |
|
89 | + * @return string |
|
90 | + */ |
|
91 | + public function SHA() |
|
92 | + { |
|
93 | + return htmlentities($this->commit->getHash()); |
|
94 | + } |
|
95 | + |
|
96 | + /** |
|
97 | + * Return the first line of the commit message. |
|
98 | + * @return string |
|
99 | + */ |
|
100 | + public function SubjectMessage() |
|
101 | + { |
|
102 | + if ($this->subjectMessage == null) { |
|
103 | + $this->subjectMessage = $this->commit->getSubjectMessage(); |
|
104 | + } |
|
105 | + |
|
106 | + return htmlentities($this->subjectMessage); |
|
107 | + } |
|
108 | + |
|
109 | + public function BodyMessage() |
|
110 | + { |
|
111 | + if ($this->bodyMessage == null) { |
|
112 | + $this->bodyMessage = $this->commit->getBodyMessage(); |
|
113 | + } |
|
114 | + |
|
115 | + return htmlentities($this->bodyMessage); |
|
116 | + } |
|
117 | + |
|
118 | + /** |
|
119 | + * @return ArrayList |
|
120 | + */ |
|
121 | + public function References() |
|
122 | + { |
|
123 | + if ($this->references !== null) { |
|
124 | + return $this->references; |
|
125 | + } |
|
126 | + $this->references = new ArrayList(); |
|
127 | + |
|
128 | + // Add tags |
|
129 | + foreach ($this->commit->resolveReferences() as $reference) { |
|
130 | + if ($reference instanceof \Gitonomy\Git\Reference\Tag) { |
|
131 | + $this->references->push(new ArrayData(array( |
|
132 | + 'Name' => $reference->getName(), |
|
133 | + 'Type' => 'Tag', |
|
134 | + ))); |
|
135 | + } |
|
136 | + } |
|
137 | + |
|
138 | + return $this->references; |
|
139 | + } |
|
140 | + |
|
141 | + /** |
|
142 | + * @return string |
|
143 | + */ |
|
144 | + public function FullName() |
|
145 | + { |
|
146 | + return htmlentities($this->commit->getHash()); |
|
147 | + } |
|
148 | + |
|
149 | + /** |
|
150 | + * @return string |
|
151 | + */ |
|
152 | + public function Filename() |
|
153 | + { |
|
154 | + return htmlentities($this->commit->getHash()); |
|
155 | + } |
|
156 | + |
|
157 | + /** |
|
158 | + * @return ArrayList |
|
159 | + */ |
|
160 | + public function CurrentlyDeployedTo() |
|
161 | + { |
|
162 | + $environments = $this->project->Environments(); |
|
163 | + $envList = new ArrayList(); |
|
164 | + foreach ($environments as $environment) { |
|
165 | + $deployments = DNDeployment::get() |
|
166 | + ->filter('Status', 'Finished') |
|
167 | + ->filter('EnvironmentID', $environment->ID) |
|
168 | + ->sort('LastEdited DESC'); |
|
169 | + if (!$deployments->count()) { |
|
170 | + continue; |
|
171 | + } |
|
172 | + $latest = $deployments->first(); |
|
173 | + if ($latest->SHA === $this->commit->getHash()) { |
|
174 | + $envList->push($environment); |
|
175 | + } |
|
176 | + } |
|
177 | + return $envList; |
|
178 | + } |
|
179 | + |
|
180 | + /** |
|
181 | + * @param string $environmentName |
|
182 | + * @return boolean True if this release has ever been deployed to the given environment |
|
183 | + */ |
|
184 | + public function EverDeployedTo($environmentName) |
|
185 | + { |
|
186 | + $environments = $this->project->Environments()->filter('Name', $environmentName); |
|
187 | + if (!$environments->count()) { |
|
188 | + return false; |
|
189 | + } |
|
190 | + |
|
191 | + $environment = $environments->first(); |
|
192 | + |
|
193 | + $deployments = DNDeployment::get() |
|
194 | + ->filter('Status', 'Finished') |
|
195 | + ->filter('EnvironmentID', $environment->ID); |
|
196 | + |
|
197 | + if ($deployments->count()) { |
|
198 | + return true; |
|
199 | + } |
|
200 | + |
|
201 | + return false; |
|
202 | + } |
|
203 | + |
|
204 | + /** |
|
205 | + * @return SS_Datetime |
|
206 | + */ |
|
207 | + public function Created() |
|
208 | + { |
|
209 | + $created = $this->commit->getCommitterDate(); |
|
210 | + |
|
211 | + // gitonomy sets the time to UTC, so now we set the timezone to |
|
212 | + // whatever PHP is set to (date.timezone). This will change in the future if each |
|
213 | + // deploynaut user has their own timezone |
|
214 | + $created->setTimezone(new DateTimeZone(date_default_timezone_get())); |
|
215 | + |
|
216 | + $d = new SS_Datetime(); |
|
217 | + $d->setValue($created->format('Y-m-d H:i:s')); |
|
218 | + |
|
219 | + return $d; |
|
220 | + } |
|
221 | 221 | } |