Completed
Pull Request — master (#421)
by Michael
1349:23 queued 1346:09
created

CreateEnvJob   A

Complexity

Total Complexity 8

Size/Duplication

Total Lines 70
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 70
rs 10

5 Methods

Rating   Name   Duplication   Size   Complexity  
A setUp() 0 4 1
A tearDown() 0 4 1
A perform() 0 19 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
		echo "[-] CreateEnvJob starting" . PHP_EOL;
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
			$envCreate = DNCreateEnvironment::get()->byId($this->args['createID']);
35
			if(!($envCreate && $envCreate->exists())) {
36
				throw new RuntimeException(sprintf('Could not find create environment record %s', $args['createID']));
37
			}
38
39
			// This will throw and exception if it fails.
40
			$envCreate->createEnvironment();
41
42
		} catch(Exception $e) {
43
			$this->updateStatus('Failed');
44
			echo "[-] CreateEnvJob failed" . PHP_EOL;
45
			throw $e;
46
		}
47
		echo "[-] CreateEnvJob finished" . PHP_EOL;
48
	}
49
50
	/**
51
	 *
52
	 * @param string $status
53
	 * @global array $databaseConfig
54
	 */
55
	protected function updateStatus($status) {
56
		global $databaseConfig;
57
		DB::connect($databaseConfig);
58
59
		$record = DNCreateEnvironment::get()->byID($this->args['createID']);
60
		$record->Status = $status;
61
		$record->write();
62
	}
63
64
	/**
65
	 *
66
	 * @return DNData
67
	 */
68
	protected function DNData() {
69
		return DNData::inst();
70
	}
71
}
72
73