Completed
Pull Request — master (#421)
by Michael
1346:13 queued 1341:51
created

CreateEnvJob   A

Complexity

Total Complexity 8

Size/Duplication

Total Lines 69
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 5

Importance

Changes 5
Bugs 0 Features 2
Metric Value
wmc 8
c 5
b 0
f 2
lcom 1
cbo 5
dl 0
loc 69
rs 10

5 Methods

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