Page Menu
Home
c4science
Search
Configure Global Search
Log In
Files
F97581085
HeraldWebhookTestController.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, 10:59
Size
2 KB
Mime Type
text/x-php
Expires
Tue, Jan 7, 10:59 (1 d, 23 h)
Engine
blob
Format
Raw Data
Handle
23430662
Attached To
rPH Phabricator
HeraldWebhookTestController.php
View Options
<?php
final
class
HeraldWebhookTestController
extends
HeraldWebhookController
{
public
function
handleRequest
(
AphrontRequest
$request
)
{
$viewer
=
$this
->
getViewer
();
$hook
=
id
(
new
HeraldWebhookQuery
())
->
setViewer
(
$viewer
)
->
withIDs
(
array
(
$request
->
getURIData
(
'id'
)))
->
requireCapabilities
(
array
(
PhabricatorPolicyCapability
::
CAN_VIEW
,
PhabricatorPolicyCapability
::
CAN_EDIT
,
))
->
executeOne
();
if
(!
$hook
)
{
return
new
Aphront404Response
();
}
$v_object
=
null
;
$e_object
=
null
;
$errors
=
array
();
if
(
$request
->
isFormPost
())
{
$v_object
=
$request
->
getStr
(
'object'
);
if
(!
strlen
(
$v_object
))
{
$object
=
$hook
;
}
else
{
$objects
=
id
(
new
PhabricatorObjectQuery
())
->
setViewer
(
$viewer
)
->
withNames
(
array
(
$v_object
))
->
execute
();
if
(
$objects
)
{
$object
=
head
(
$objects
);
}
else
{
$e_object
=
pht
(
'Invalid'
);
$errors
[]
=
pht
(
'Specified object could not be loaded.'
);
}
}
if
(!
$errors
)
{
$xaction_query
=
PhabricatorApplicationTransactionQuery
::
newQueryForObject
(
$object
);
$xactions
=
$xaction_query
->
withObjectPHIDs
(
array
(
$object
->
getPHID
()))
->
setViewer
(
$viewer
)
->
setLimit
(
10
)
->
execute
();
$request
=
HeraldWebhookRequest
::
initializeNewWebhookRequest
(
$hook
)
->
setObjectPHID
(
$object
->
getPHID
())
->
setTriggerPHIDs
(
array
(
$viewer
->
getPHID
()))
->
setIsTestAction
(
true
)
->
setTransactionPHIDs
(
mpull
(
$xactions
,
'getPHID'
))
->
save
();
$request
->
queueCall
();
$next_uri
=
$hook
->
getURI
().
'request/'
.
$request
->
getID
().
'/'
;
return
id
(
new
AphrontRedirectResponse
())->
setURI
(
$next_uri
);
}
}
$instructions
=
<<<EOREMARKUP
Optionally, choose an object to generate test data for (like `D123` or `T234`).
The 10 most recent transactions for the object will be submitted to the webhook.
EOREMARKUP;
$form
=
id
(
new
AphrontFormView
())
->
setViewer
(
$viewer
)
->
appendControl
(
id
(
new
AphrontFormTextControl
())
->
setLabel
(
pht
(
'Object'
))
->
setName
(
'object'
)
->
setError
(
$e_object
)
->
setValue
(
$v_object
));
return
$this
->
newDialog
()
->
setErrors
(
$errors
)
->
setWidth
(
AphrontDialogView
::
WIDTH_FORM
)
->
setTitle
(
pht
(
'New Test Request'
))
->
appendParagraph
(
new
PHUIRemarkupView
(
$viewer
,
$instructions
))
->
appendForm
(
$form
)
->
addCancelButton
(
$hook
->
getURI
())
->
addSubmitButton
(
pht
(
'Test Webhook'
));
}
}
Event Timeline
Log In to Comment