Page Menu
Home
c4science
Search
Configure Global Search
Log In
Files
F97596466
PhabricatorAphlictManagementNotifyWorkflow.php
No One
Temporary
Actions
Download File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Award Token
Subscribers
None
File Metadata
Details
File Info
Storage
Attached
Created
Sun, Jan 5, 14:13
Size
2 KB
Mime Type
text/x-php
Expires
Tue, Jan 7, 14:13 (2 d)
Engine
blob
Format
Raw Data
Handle
23359023
Attached To
rPH Phabricator
PhabricatorAphlictManagementNotifyWorkflow.php
View Options
<?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
;
}
}
Event Timeline
Log In to Comment