Completed
Pull Request — master (#520)
by Sean
03:19
created

CreateEnvJob   A

Complexity

Total Complexity 7

Size/Duplication

Total Lines 61
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 6

Importance

Changes 3
Bugs 0 Features 0
Metric Value
wmc 7
c 3
b 0
f 0
lcom 1
cbo 6
dl 0
loc 61
rs 10

4 Methods

Rating   Name   Duplication   Size   Complexity  
A setUp() 0 4 1
A perform() 0 19 4
A updateStatus() 0 8 1
A DNData() 0 3 1
1
<?php
2
class CreateEnvJob extends DeploynautJob {
3
4
	/**
5
	 *
6
	 * @var array
7
	 */
8
	public $args;
9
10
	/**
11
	 *
12
	 */
13
	public function setUp() {
14
		$this->updateStatus('Started');
15
		chdir(BASE_PATH);
16
	}
17
18
	/**
19
	 *
20
	 */
21
	public function perform() {
22
		echo "[-] CreateEnvJob starting" . PHP_EOL;
23
		// This is a bit icky, but there is no easy way of capturing a failed deploy by using the PHP Resque
24
		try {
25
			$envCreate = DNCreateEnvironment::get()->byId($this->args['createID']);
26
			if(!($envCreate && $envCreate->exists())) {
27
				throw new RuntimeException(sprintf('Could not find create environment record %s', $args['createID']));
28
			}
29
30
			// This will throw and exception if it fails.
31
			$envCreate->createEnvironment();
32
33
		} catch(Exception $e) {
34
			echo "[-] CreateEnvJob failed" . PHP_EOL;
35
			throw $e;
36
		}
37
		$this->updateStatus('Finished');
38
		echo "[-] CreateEnvJob finished" . PHP_EOL;
39
	}
40
41
	/**
42
	 *
43
	 * @param string $status
44
	 * @global array $databaseConfig
45
	 */
46
	protected function updateStatus($status) {
47
		global $databaseConfig;
48
		DB::connect($databaseConfig);
49
50
		$record = DNCreateEnvironment::get()->byID($this->args['createID']);
51
		$record->Status = $status;
52
		$record->write();
53
	}
54
55
	/**
56
	 *
57
	 * @return DNData
58
	 */
59
	protected function DNData() {
60
		return DNData::inst();
61
	}
62
}
63
64