Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
freebsd
GitHub Repository: freebsd/phabricator
Path: blob/master/src/applications/metamta/management/PhabricatorMailManagementResendWorkflow.php
12256 views
1
<?php
2
3
final class PhabricatorMailManagementResendWorkflow
4
extends PhabricatorMailManagementWorkflow {
5
6
protected function didConstruct() {
7
$this
8
->setName('resend')
9
->setSynopsis(pht('Send mail again.'))
10
->setExamples(
11
'**resend** --id 1 --id 2')
12
->setArguments(
13
array(
14
array(
15
'name' => 'id',
16
'param' => 'id',
17
'help' => pht('Send mail with a given ID again.'),
18
'repeat' => true,
19
),
20
));
21
}
22
23
public function execute(PhutilArgumentParser $args) {
24
$console = PhutilConsole::getConsole();
25
26
$ids = $args->getArg('id');
27
if (!$ids) {
28
throw new PhutilArgumentUsageException(
29
pht(
30
"Use the '%s' flag to specify one or more messages to resend.",
31
'--id'));
32
}
33
34
$messages = id(new PhabricatorMetaMTAMail())->loadAllWhere(
35
'id IN (%Ld)',
36
$ids);
37
38
if ($ids) {
39
$ids = array_fuse($ids);
40
$missing = array_diff_key($ids, $messages);
41
if ($missing) {
42
throw new PhutilArgumentUsageException(
43
pht(
44
'Some specified messages do not exist: %s',
45
implode(', ', array_keys($missing))));
46
}
47
}
48
49
foreach ($messages as $message) {
50
$message->setStatus(PhabricatorMailOutboundStatus::STATUS_QUEUE);
51
$message->save();
52
53
$mailer_task = PhabricatorWorker::scheduleTask(
54
'PhabricatorMetaMTAWorker',
55
$message->getID(),
56
array(
57
'priority' => PhabricatorWorker::PRIORITY_ALERTS,
58
));
59
60
$console->writeOut(
61
"%s\n",
62
pht(
63
'Queued message #%d for resend.',
64
$message->getID()));
65
}
66
}
67
68
}
69
70