Path: blob/master/src/applications/aphlict/management/PhabricatorAphlictManagementNotifyWorkflow.php
12256 views
<?php12final class PhabricatorAphlictManagementNotifyWorkflow3extends PhabricatorAphlictManagementWorkflow {45protected function didConstruct() {6$this7->setName('notify')8->setSynopsis(pht('Send a notification to a user.'))9->setArguments(10array(11array(12'name' => 'user',13'param' => 'username',14'help' => pht('User to notify.'),15),16array(17'name' => 'message',18'param' => 'text',19'help' => pht('Message to send.'),20),21));22}2324public function execute(PhutilArgumentParser $args) {25$viewer = $this->getViewer();2627$username = $args->getArg('user');28if (!strlen($username)) {29throw new PhutilArgumentUsageException(30pht(31'Specify a user to notify with "--user".'));32}3334$user = id(new PhabricatorPeopleQuery())35->setViewer($viewer)36->withUsernames(array($username))37->executeOne();3839if (!$user) {40throw new PhutilArgumentUsageException(41pht(42'No user with username "%s" exists.',43$username));44}4546$message = $args->getArg('message');47if (!strlen($message)) {48throw new PhutilArgumentUsageException(49pht(50'Specify a message to send with "--message".'));51}5253$application_phid = id(new PhabricatorNotificationsApplication())54->getPHID();5556$content_source = $this->newContentSource();5758$xactions = array();5960$xactions[] = id(new PhabricatorUserTransaction())61->setTransactionType(62PhabricatorUserNotifyTransaction::TRANSACTIONTYPE)63->setNewValue($message)64->setForceNotifyPHIDs(array($user->getPHID()));6566$editor = id(new PhabricatorUserTransactionEditor())67->setActor($viewer)68->setActingAsPHID($application_phid)69->setContentSource($content_source);7071$editor->applyTransactions($user, $xactions);7273echo tsprintf(74"%s\n",75pht('Sent notification.'));7677return 0;78}7980}818283