|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
use \Finite\Event\TransitionEvent; |
|
4
|
|
|
|
|
5
|
|
|
class DNDeploymentHandlers extends Object { |
|
|
|
|
|
|
6
|
|
|
|
|
7
|
|
|
public function onNew(TransitionEvent $e) { |
|
8
|
|
|
/** @var DNDeployment $deployment */ |
|
9
|
|
|
$deployment = $e->getStateMachine()->getObject(); |
|
10
|
|
|
$deployment->DeployRequested = null; |
|
11
|
|
|
$deployment->write(); |
|
12
|
|
|
} |
|
13
|
|
|
|
|
14
|
|
|
public function onSubmit(TransitionEvent $e) { |
|
15
|
|
|
/** @var DNDeployment $deployment */ |
|
16
|
|
|
$deployment = $e->getStateMachine()->getObject(); |
|
17
|
|
|
$deployment->DeployRequested = SS_Datetime::now()->Rfc2822(); |
|
18
|
|
|
$deployment->write(); |
|
19
|
|
|
$this->sendEmailToApprover($deployment); |
|
20
|
|
|
} |
|
21
|
|
|
|
|
22
|
|
|
public function onApprove(TransitionEvent $e) { |
|
|
|
|
|
|
23
|
|
|
// @todo send email to requester that it's approved |
|
24
|
|
|
} |
|
25
|
|
|
|
|
26
|
|
|
public function onReject(TransitionEvent $e) { |
|
|
|
|
|
|
27
|
|
|
// @todo send email to requester that it's rejected |
|
28
|
|
|
} |
|
29
|
|
|
|
|
30
|
|
|
public function onQueue(TransitionEvent $e) { |
|
31
|
|
|
/** @var DNDeployment $deployment */ |
|
32
|
|
|
$deployment = $e->getStateMachine()->getObject(); |
|
33
|
|
|
|
|
34
|
|
|
$token = $deployment->enqueueDeployment(); |
|
35
|
|
|
$deployment->setResqueToken($token); |
|
36
|
|
|
$deployment->DeployStarted = SS_Datetime::now()->Rfc2822(); |
|
37
|
|
|
$deployment->write(); |
|
38
|
|
|
|
|
39
|
|
|
$log = $deployment->log(); |
|
40
|
|
|
$log->write(sprintf( |
|
41
|
|
|
'Deploy queued as job %s (sigFile is %s)', |
|
42
|
|
|
$token, |
|
43
|
|
|
$deployment->getSigFile() |
|
44
|
|
|
)); |
|
45
|
|
|
} |
|
46
|
|
|
|
|
47
|
|
|
public function onAbort(TransitionEvent $e) { |
|
48
|
|
|
$deployment = $e->getStateMachine()->getObject(); |
|
49
|
|
|
|
|
50
|
|
|
// 2 is SIGINT - we can't use SIGINT constant in the mod_apache context. |
|
51
|
|
|
$deployment->setSignal(2); |
|
52
|
|
|
} |
|
53
|
|
|
|
|
54
|
|
|
protected function sendEmailToApprover(DNDeployment $deployment) { |
|
55
|
|
|
$deployer = $deployment->Deployer(); |
|
56
|
|
|
$approver = $deployment->Approver(); |
|
|
|
|
|
|
57
|
|
|
if (!$approver || !$approver->exists()) { |
|
58
|
|
|
return false; |
|
59
|
|
|
} |
|
60
|
|
|
|
|
61
|
|
|
$email = Email::create(); |
|
62
|
|
|
$email->setTo(sprintf('%s <%s>', $approver->Name, $approver->Email)); |
|
63
|
|
|
$email->replyTo(sprintf('%s <%s>', $deployer->Name, $deployer->Email)); |
|
|
|
|
|
|
64
|
|
|
$email->setSubject('Deployment has been submitted'); |
|
65
|
|
|
$email->setTemplate('DeploymentNotificationSubmitted'); |
|
66
|
|
|
$email->populateTemplate($deployment); |
|
67
|
|
|
$email->send(); |
|
68
|
|
|
|
|
69
|
|
|
$log = $deployment->log(); |
|
70
|
|
|
$log->write(sprintf( |
|
71
|
|
|
'Deployment submitted email sent to approver %s <%s>', |
|
72
|
|
|
$approver->Name, |
|
73
|
|
|
$approver->Email |
|
74
|
|
|
)); |
|
75
|
|
|
} |
|
76
|
|
|
} |
|
77
|
|
|
|
You can fix this by adding a namespace to your class:
When choosing a vendor namespace, try to pick something that is not too generic to avoid conflicts with other libraries.