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

DNDeploymentHandlers::onAbort()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 6
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 2
Bugs 0 Features 0
Metric Value
dl 0
loc 6
rs 9.4285
c 2
b 0
f 0
cc 1
eloc 3
nc 1
nop 1
1
<?php
2
3
use \Finite\Event\TransitionEvent;
4
5
class DNDeploymentHandlers extends Object {
6
7
	public function onSubmit(TransitionEvent $e) {
8
		$deployment = $e->getStateMachine()->getObject();
9
		$this->sendEmailToApprover($deployment);
10
	}
11
12
	protected function sendEmailToApprover(DNDeployment $deployment) {
13
		if (!$deployment->Approver()->exists()) {
14
			return false;
15
		}
16
17
		$email = new Email();
18
		$email->setTo($deployment->Approver()->Email);
19
		$email->replyTo($deployment->Deployer()->Email);
0 ignored issues
show
Deprecated Code introduced by
The method Email::replyTo() has been deprecated with message: 4.0 Use the "setReplyTo" method instead

This method has been deprecated. The supplier of the class has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the method will be removed from the class and what other method or class to use instead.

Loading history...
20
		$email->setSubject('Deployment has been scheduled');
21
		$email->setTemplate('DeploymentNotificationSubmitted');
22
		$email->populateTemplate($deployment);
23
		$email->send();
24
25
		$log = $deployment->log();
26
		$log->write(sprintf('Email sent to approver %s <%s>', $approver->Name, $approver->Email));
0 ignored issues
show
Bug introduced by
The variable $approver does not exist. Did you forget to declare it?

This check marks access to variables or properties that have not been declared yet. While PHP has no explicit notion of declaring a variable, accessing it before a value is assigned to it is most likely a bug.

Loading history...
27
	}
28
29
	public function onQueue(TransitionEvent $e) {
30
		$deployment = $e->getStateMachine()->getObject();
31
32
		$token = $deployment->enqueueDeployment();
33
		$deployment->ResqueToken = $token;
34
		$deployment->write();
35
36
		$log = $deployment->log();
37
		$log->write(sprintf(
38
			'Deploy queued as job %s (sigFile is %s)',
39
			$token,
40
			DeployJob::sig_file_for_data_object($obj)
0 ignored issues
show
Bug introduced by
The variable $obj does not exist. Did you forget to declare it?

This check marks access to variables or properties that have not been declared yet. While PHP has no explicit notion of declaring a variable, accessing it before a value is assigned to it is most likely a bug.

Loading history...
41
		));
42
	}
43
44
	public function onAbort(TransitionEvent $e) {
45
		$deployment = $e->getStateMachine()->getObject();
46
47
		// 2 is SIGINT - we can't use SIGINT constant in the mod_apache context.
48
		DeployJob::set_signal($deployment, 2);
49
	}
50
}
51