Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
freebsd
GitHub Repository: freebsd/phabricator
Path: blob/master/src/applications/aphlict/management/PhabricatorAphlictManagementNotifyWorkflow.php
12256 views
1
<?php
2
3
final class PhabricatorAphlictManagementNotifyWorkflow
4
extends PhabricatorAphlictManagementWorkflow {
5
6
protected function didConstruct() {
7
$this
8
->setName('notify')
9
->setSynopsis(pht('Send a notification to a user.'))
10
->setArguments(
11
array(
12
array(
13
'name' => 'user',
14
'param' => 'username',
15
'help' => pht('User to notify.'),
16
),
17
array(
18
'name' => 'message',
19
'param' => 'text',
20
'help' => pht('Message to send.'),
21
),
22
));
23
}
24
25
public function execute(PhutilArgumentParser $args) {
26
$viewer = $this->getViewer();
27
28
$username = $args->getArg('user');
29
if (!strlen($username)) {
30
throw new PhutilArgumentUsageException(
31
pht(
32
'Specify a user to notify with "--user".'));
33
}
34
35
$user = id(new PhabricatorPeopleQuery())
36
->setViewer($viewer)
37
->withUsernames(array($username))
38
->executeOne();
39
40
if (!$user) {
41
throw new PhutilArgumentUsageException(
42
pht(
43
'No user with username "%s" exists.',
44
$username));
45
}
46
47
$message = $args->getArg('message');
48
if (!strlen($message)) {
49
throw new PhutilArgumentUsageException(
50
pht(
51
'Specify a message to send with "--message".'));
52
}
53
54
$application_phid = id(new PhabricatorNotificationsApplication())
55
->getPHID();
56
57
$content_source = $this->newContentSource();
58
59
$xactions = array();
60
61
$xactions[] = id(new PhabricatorUserTransaction())
62
->setTransactionType(
63
PhabricatorUserNotifyTransaction::TRANSACTIONTYPE)
64
->setNewValue($message)
65
->setForceNotifyPHIDs(array($user->getPHID()));
66
67
$editor = id(new PhabricatorUserTransactionEditor())
68
->setActor($viewer)
69
->setActingAsPHID($application_phid)
70
->setContentSource($content_source);
71
72
$editor->applyTransactions($user, $xactions);
73
74
echo tsprintf(
75
"%s\n",
76
pht('Sent notification.'));
77
78
return 0;
79
}
80
81
}
82
83