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); |
|
|
|
|
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('Deployment submitted email sent to approver %s <%s>', $approver->Name, $approver->Email)); |
|
|
|
|
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) |
|
|
|
|
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
|
|
|
|
If you implement
__call
and 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
__call
is implemented by a parent class and only the child class knows which methods exist: