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

CreateEnvJob::DNData()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 2

Duplication

Lines 0
Ratio 0 %
Metric Value
dl 0
loc 3
rs 10
cc 1
eloc 2
nc 1
nop 0
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