Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
freebsd
GitHub Repository: freebsd/phabricator
Path: blob/master/src/applications/metamta/herald/PhabricatorMetaMTAEmailHeraldAction.php
12256 views
1
<?php
2
3
abstract class PhabricatorMetaMTAEmailHeraldAction
4
extends HeraldAction {
5
6
const DO_SEND = 'do.send';
7
const DO_FORCE = 'do.force';
8
9
public function getRequiredAdapterStates() {
10
return array(
11
HeraldMailableState::STATECONST,
12
);
13
}
14
15
public function supportsObject($object) {
16
return self::isMailGeneratingObject($object);
17
}
18
19
public static function isMailGeneratingObject($object) {
20
// NOTE: This implementation lacks generality, but there's no great way to
21
// figure out if something generates email right now.
22
23
if ($object instanceof DifferentialDiff) {
24
return false;
25
}
26
27
if ($object instanceof PhabricatorMetaMTAMail) {
28
return false;
29
}
30
31
return true;
32
}
33
34
public function getActionGroupKey() {
35
return HeraldNotifyActionGroup::ACTIONGROUPKEY;
36
}
37
38
protected function applyEmail(array $phids, $force) {
39
$adapter = $this->getAdapter();
40
41
$allowed_types = array(
42
PhabricatorPeopleUserPHIDType::TYPECONST,
43
PhabricatorProjectProjectPHIDType::TYPECONST,
44
);
45
46
// There's no stateful behavior for this action: we always just send an
47
// email.
48
$current = array();
49
50
$targets = $this->loadStandardTargets($phids, $allowed_types, $current);
51
if (!$targets) {
52
return;
53
}
54
55
$phids = array_fuse(array_keys($targets));
56
57
foreach ($phids as $phid) {
58
$adapter->addEmailPHID($phid, $force);
59
}
60
61
if ($force) {
62
$this->logEffect(self::DO_FORCE, $phids);
63
} else {
64
$this->logEffect(self::DO_SEND, $phids);
65
}
66
}
67
68
protected function getActionEffectMap() {
69
return array(
70
self::DO_SEND => array(
71
'icon' => 'fa-envelope',
72
'color' => 'green',
73
'name' => pht('Sent Mail'),
74
),
75
self::DO_FORCE => array(
76
'icon' => 'fa-envelope',
77
'color' => 'blue',
78
'name' => pht('Forced Mail'),
79
),
80
);
81
}
82
83
protected function renderActionEffectDescription($type, $data) {
84
switch ($type) {
85
case self::DO_SEND:
86
return pht(
87
'Queued email to be delivered to %s target(s): %s.',
88
phutil_count($data),
89
$this->renderHandleList($data));
90
case self::DO_FORCE:
91
return pht(
92
'Queued email to be delivered to %s target(s), ignoring their '.
93
'notification preferences: %s.',
94
phutil_count($data),
95
$this->renderHandleList($data));
96
}
97
}
98
99
}
100
101