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

CreateEnvJob::perform()   A

Complexity

Conditions 4
Paths 5

Size

Total Lines 18
Code Lines 11

Duplication

Lines 0
Ratio 0 %

Importance

Changes 5
Bugs 0 Features 2
Metric Value
c 5
b 0
f 2
dl 0
loc 18
rs 9.2
cc 4
eloc 11
nc 5
nop 0
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