|
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
|
|
|
$deployer = $deployment->Deployer(); |
|
14
|
|
|
$approver = $deployment->Approver(); |
|
|
|
|
|
|
15
|
|
|
if (!$approver || !$approver->exists()) { |
|
16
|
|
|
return false; |
|
17
|
|
|
} |
|
18
|
|
|
|
|
19
|
|
|
$email = new Email(); |
|
20
|
|
|
$email->setTo(sprintf('%s <%s>', $approver->Name, $approver->Email)); |
|
21
|
|
|
$email->replyTo(sprintf('%s <%s>', $deployer->Name, $deployer->Email)); |
|
|
|
|
|
|
22
|
|
|
$email->setSubject('Deployment has been scheduled'); |
|
23
|
|
|
$email->setTemplate('DeploymentNotificationSubmitted'); |
|
24
|
|
|
$email->populateTemplate($deployment); |
|
25
|
|
|
$email->send(); |
|
26
|
|
|
|
|
27
|
|
|
$log = $deployment->log(); |
|
28
|
|
|
$log->write(sprintf( |
|
29
|
|
|
'Deployment submitted email sent to approver %s <%s>', |
|
30
|
|
|
$approver->Name, |
|
31
|
|
|
$approver->Email |
|
32
|
|
|
)); |
|
33
|
|
|
} |
|
34
|
|
|
|
|
35
|
|
|
public function onQueue(TransitionEvent $e) { |
|
36
|
|
|
$deployment = $e->getStateMachine()->getObject(); |
|
37
|
|
|
|
|
38
|
|
|
$token = $deployment->enqueueDeployment(); |
|
39
|
|
|
$deployment->ResqueToken = $token; |
|
40
|
|
|
$deployment->write(); |
|
41
|
|
|
|
|
42
|
|
|
$log = $deployment->log(); |
|
43
|
|
|
$log->write(sprintf( |
|
44
|
|
|
'Deploy queued as job %s (sigFile is %s)', |
|
45
|
|
|
$token, |
|
46
|
|
|
DeployJob::sig_file_for_data_object($obj) |
|
|
|
|
|
|
47
|
|
|
)); |
|
48
|
|
|
} |
|
49
|
|
|
|
|
50
|
|
|
public function onAbort(TransitionEvent $e) { |
|
51
|
|
|
$deployment = $e->getStateMachine()->getObject(); |
|
52
|
|
|
|
|
53
|
|
|
// 2 is SIGINT - we can't use SIGINT constant in the mod_apache context. |
|
54
|
|
|
DeployJob::set_signal($deployment, 2); |
|
55
|
|
|
} |
|
56
|
|
|
} |
|
57
|
|
|
|
If you implement
__calland you know which methods are available, you can improve IDE auto-completion and static analysis by adding a @method annotation to the class.This is often the case, when
__callis implemented by a parent class and only the child class knows which methods exist: