Page Menu
Home
Phorge
Search
Configure Global Search
Log In
Files
F1625183
PhrictionCreateConduitAPIMethod.php
No One
Temporary
Actions
Download File
Edit File
Delete File
View Transforms
Subscribe
Flag For Later
Award Token
Size
2 KB
Referenced Files
None
Subscribers
None
PhrictionCreateConduitAPIMethod.php
View Options
<?php
final
class
PhrictionCreateConduitAPIMethod
extends
PhrictionConduitAPIMethod
{
public
function
getAPIMethodName
()
{
return
'phriction.create'
;
}
public
function
getMethodDescription
()
{
return
pht
(
'Create a Phriction document.'
);
}
protected
function
defineParamTypes
()
{
return
array
(
'slug'
=>
'required string'
,
'title'
=>
'required string'
,
'content'
=>
'required string'
,
'description'
=>
'optional string'
,
);
}
protected
function
defineReturnType
()
{
return
'nonempty dict'
;
}
protected
function
execute
(
ConduitAPIRequest
$request
)
{
$slug
=
$request
->
getValue
(
'slug'
);
if
(!
phutil_nonempty_string
(
$slug
))
{
throw
new
Exception
(
pht
(
'No such document.'
));
}
$doc
=
id
(
new
PhrictionDocumentQuery
())
->
setViewer
(
$request
->
getUser
())
->
withSlugs
(
array
(
PhabricatorSlug
::
normalize
(
$slug
)))
->
requireCapabilities
(
array
(
PhabricatorPolicyCapability
::
CAN_VIEW
,
PhabricatorPolicyCapability
::
CAN_EDIT
,
))
->
executeOne
();
if
(
$doc
)
{
throw
new
Exception
(
pht
(
'Document already exists!'
));
}
$doc
=
PhrictionDocument
::
initializeNewDocument
(
$request
->
getUser
(),
$slug
);
$xactions
=
array
();
$xactions
[]
=
id
(
new
PhrictionTransaction
())
->
setTransactionType
(
PhrictionDocumentTitleTransaction
::
TRANSACTIONTYPE
)
->
setNewValue
(
$request
->
getValue
(
'title'
));
$xactions
[]
=
id
(
new
PhrictionTransaction
())
->
setTransactionType
(
PhrictionDocumentContentTransaction
::
TRANSACTIONTYPE
)
->
setNewValue
(
$request
->
getValue
(
'content'
));
$editor
=
id
(
new
PhrictionTransactionEditor
())
->
setActor
(
$request
->
getUser
())
->
setContentSource
(
$request
->
newContentSource
())
->
setContinueOnNoEffect
(
true
)
->
setDescription
((
string
)
$request
->
getValue
(
'description'
));
try
{
$editor
->
applyTransactions
(
$doc
,
$xactions
);
}
catch
(
PhabricatorApplicationTransactionValidationException
$ex
)
{
// TODO - some magical hotness via T5873
throw
$ex
;
}
return
$this
->
buildDocumentInfoDictionary
(
$doc
);
}
}
File Metadata
Details
Attached
Mime Type
text/x-php
Expires
Wed, Jul 16, 5:55 PM (1 d, 19 h)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
366875
Default Alt Text
PhrictionCreateConduitAPIMethod.php (2 KB)
Attached To
Mode
rP Phorge
Attached
Detach File
Event Timeline
Log In to Comment