Completed
Pull Request — master (#672)
by Sean
06:29
created

CreateEnvJob::DNData()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 3
rs 10
c 0
b 0
f 0
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
24
		$log = new DeploynautLogFile($this->args['logfile']);
25
		$envCreate = DNCreateEnvironment::get()->byId($this->args['createID']);
26
27
		// This is a bit icky, but there is no easy way of capturing a failed deploy by using the PHP Resque
28
		try {
29
			if(!($envCreate && $envCreate->exists())) {
30
				throw new RuntimeException(sprintf('Could not find create environment record %s', $args['createID']));
31
			}
32
33
			// This will throw and exception if it fails.
34
			$envCreate->createEnvironment();
35
36
		} catch(Exception $e) {
37
			$log->write($e->getMessage());
38
			echo "[-] CreateEnvJob failed" . PHP_EOL;
39
			throw $e;
40
		}
41
		$this->updateStatus('Finished');
42
		echo "[-] CreateEnvJob finished" . PHP_EOL;
43
	}
44
45
	/**
46
	 *
47
	 * @param string $status
48
	 * @global array $databaseConfig
49
	 */
50
	protected function updateStatus($status) {
51
		global $databaseConfig;
0 ignored issues
show
Compatibility Best Practice introduced by
Use of global functionality is not recommended; it makes your code harder to test, and less reusable.

Instead of relying on global state, we recommend one of these alternatives:

1. Pass all data via parameters

function myFunction($a, $b) {
    // Do something
}

2. Create a class that maintains your state

class MyClass {
    private $a;
    private $b;

    public function __construct($a, $b) {
        $this->a = $a;
        $this->b = $b;
    }

    public function myFunction() {
        // Do something
    }
}
Loading history...
52
		DB::connect($databaseConfig);
53
54
		$record = DNCreateEnvironment::get()->byID($this->args['createID']);
55
		$record->Status = $status;
56
		$record->write();
57
	}
58
59
	/**
60
	 *
61
	 * @return DNData
62
	 */
63
	protected function DNData() {
64
		return DNData::inst();
65
	}
66
}
67
68