Page MenuHomePhabricator

D19866.diff
No OneTemporary

D19866.diff

diff --git a/src/__phutil_library_map__.php b/src/__phutil_library_map__.php
--- a/src/__phutil_library_map__.php
+++ b/src/__phutil_library_map__.php
@@ -2085,6 +2085,7 @@
'PhabricatorAmazonAuthProvider' => 'applications/auth/provider/PhabricatorAmazonAuthProvider.php',
'PhabricatorAnchorView' => 'view/layout/PhabricatorAnchorView.php',
'PhabricatorAphlictManagementDebugWorkflow' => 'applications/aphlict/management/PhabricatorAphlictManagementDebugWorkflow.php',
+ 'PhabricatorAphlictManagementNotifyWorkflow' => 'applications/aphlict/management/PhabricatorAphlictManagementNotifyWorkflow.php',
'PhabricatorAphlictManagementRestartWorkflow' => 'applications/aphlict/management/PhabricatorAphlictManagementRestartWorkflow.php',
'PhabricatorAphlictManagementStartWorkflow' => 'applications/aphlict/management/PhabricatorAphlictManagementStartWorkflow.php',
'PhabricatorAphlictManagementStatusWorkflow' => 'applications/aphlict/management/PhabricatorAphlictManagementStatusWorkflow.php',
@@ -7702,6 +7703,7 @@
'PhabricatorAmazonAuthProvider' => 'PhabricatorOAuth2AuthProvider',
'PhabricatorAnchorView' => 'AphrontView',
'PhabricatorAphlictManagementDebugWorkflow' => 'PhabricatorAphlictManagementWorkflow',
+ 'PhabricatorAphlictManagementNotifyWorkflow' => 'PhabricatorAphlictManagementWorkflow',
'PhabricatorAphlictManagementRestartWorkflow' => 'PhabricatorAphlictManagementWorkflow',
'PhabricatorAphlictManagementStartWorkflow' => 'PhabricatorAphlictManagementWorkflow',
'PhabricatorAphlictManagementStatusWorkflow' => 'PhabricatorAphlictManagementWorkflow',
diff --git a/src/applications/aphlict/management/PhabricatorAphlictManagementNotifyWorkflow.php b/src/applications/aphlict/management/PhabricatorAphlictManagementNotifyWorkflow.php
new file mode 100644
--- /dev/null
+++ b/src/applications/aphlict/management/PhabricatorAphlictManagementNotifyWorkflow.php
@@ -0,0 +1,81 @@
+<?php
+
+final class PhabricatorAphlictManagementNotifyWorkflow
+ extends PhabricatorAphlictManagementWorkflow {
+
+ protected function didConstruct() {
+ $this
+ ->setName('notify')
+ ->setSynopsis(pht('Send a notification to a user.'))
+ ->setArguments(
+ array(
+ array(
+ 'name' => 'user',
+ 'param' => 'username',
+ 'help' => pht('User to notify.'),
+ ),
+ array(
+ 'name' => 'message',
+ 'param' => 'text',
+ 'help' => pht('Message to send.'),
+ ),
+ ));
+ }
+
+ public function execute(PhutilArgumentParser $args) {
+ $viewer = $this->getViewer();
+
+ $username = $args->getArg('user');
+ if (!strlen($username)) {
+ throw new PhutilArgumentUsageException(
+ pht(
+ 'Specify a user to notify with "--user".'));
+ }
+
+ $user = id(new PhabricatorPeopleQuery())
+ ->setViewer($viewer)
+ ->withUsernames(array($username))
+ ->executeOne();
+
+ if (!$user) {
+ throw new PhutilArgumentUsageException(
+ pht(
+ 'No user with username "%s" exists.',
+ $username));
+ }
+
+ $message = $args->getArg('message');
+ if (!strlen($message)) {
+ throw new PhutilArgumentUsageException(
+ pht(
+ 'Specify a message to send with "--message".'));
+ }
+
+ $application_phid = id(new PhabricatorNotificationsApplication())
+ ->getPHID();
+
+ $content_source = $this->newContentSource();
+
+ $xactions = array();
+
+ $xactions[] = id(new PhabricatorUserTransaction())
+ ->setTransactionType(
+ PhabricatorUserNotifyTransaction::TRANSACTIONTYPE)
+ ->setNewValue($message)
+ ->setForceNotifyPHIDs(array($user->getPHID()));
+
+ $editor = id(new PhabricatorUserTransactionEditor())
+ ->setActor($viewer)
+ ->setActingAsPHID($application_phid)
+ ->setContentSource($content_source);
+
+ $editor->applyTransactions($user, $xactions);
+
+ echo tsprintf(
+ "%s\n",
+ pht('Sent notification.'));
+
+ return 0;
+ }
+
+}

File Metadata

Mime Type
text/plain
Expires
Wed, Jan 22, 9:52 AM (9 h, 47 m)
Storage Engine
blob
Storage Format
Encrypted (AES-256-CBC)
Storage Handle
7029218
Default Alt Text
D19866.diff (3 KB)

Event Timeline