Remove product literal strings in "pht()", part 8
[phabricator.git] / src / applications / aphlict / management / PhabricatorAphlictManagementNotifyWorkflow.php
bloba7653e74b5377d3caa0f0f716c102b6bf0a0604c
1 <?php
3 final class PhabricatorAphlictManagementNotifyWorkflow
4 extends PhabricatorAphlictManagementWorkflow {
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.'),
17 array(
18 'name' => 'message',
19 'param' => 'text',
20 'help' => pht('Message to send.'),
22 ));
25 public function execute(PhutilArgumentParser $args) {
26 $viewer = $this->getViewer();
28 $username = $args->getArg('user');
29 if (!strlen($username)) {
30 throw new PhutilArgumentUsageException(
31 pht(
32 'Specify a user to notify with "--user".'));
35 $user = id(new PhabricatorPeopleQuery())
36 ->setViewer($viewer)
37 ->withUsernames(array($username))
38 ->executeOne();
40 if (!$user) {
41 throw new PhutilArgumentUsageException(
42 pht(
43 'No user with username "%s" exists.',
44 $username));
47 $message = $args->getArg('message');
48 if (!strlen($message)) {
49 throw new PhutilArgumentUsageException(
50 pht(
51 'Specify a message to send with "--message".'));
54 $application_phid = id(new PhabricatorNotificationsApplication())
55 ->getPHID();
57 $content_source = $this->newContentSource();
59 $xactions = array();
61 $xactions[] = id(new PhabricatorUserTransaction())
62 ->setTransactionType(
63 PhabricatorUserNotifyTransaction::TRANSACTIONTYPE)
64 ->setNewValue($message)
65 ->setForceNotifyPHIDs(array($user->getPHID()));
67 $editor = id(new PhabricatorUserTransactionEditor())
68 ->setActor($viewer)
69 ->setActingAsPHID($application_phid)
70 ->setContentSource($content_source);
72 $editor->applyTransactions($user, $xactions);
74 echo tsprintf(
75 "%s\n",
76 pht('Sent notification.'));
78 return 0;