2011-08-26 21:50:28 +02:00
|
|
|
<?php
|
|
|
|
|
Rename Conduit classes
Summary: Ref T5655. Rename Conduit classes and provide a `getAPIMethodName` method to declare the API method.
Test Plan:
```
> echo '{}' | arc --conduit-uri='http://phabricator.joshuaspence.com' call-conduit user.whoami
Waiting for JSON parameters on stdin...
{"error":null,"errorMessage":null,"response":{"phid":"PHID-USER-lioqffnwn6y475mu5ndb","userName":"josh","realName":"Joshua Spence","image":"http:\/\/phabricator.joshuaspence.com\/res\/1404425321T\/phabricator\/3eb28cd9\/rsrc\/image\/avatar.png","uri":"http:\/\/phabricator.joshuaspence.com\/p\/josh\/","roles":["admin","verified","approved","activated"]}}
```
Reviewers: epriestley, #blessed_reviewers
Reviewed By: epriestley, #blessed_reviewers
Subscribers: epriestley, Korvin, hach-que
Maniphest Tasks: T5655
Differential Revision: https://secure.phabricator.com/D9991
2014-07-25 02:54:15 +02:00
|
|
|
final class PhrictionEditConduitAPIMethod extends PhrictionConduitAPIMethod {
|
|
|
|
|
|
|
|
public function getAPIMethodName() {
|
|
|
|
return 'phriction.edit';
|
|
|
|
}
|
2011-08-26 21:50:28 +02:00
|
|
|
|
|
|
|
public function getMethodDescription() {
|
2014-11-07 20:46:25 +01:00
|
|
|
return pht('Update a Phriction document.');
|
2011-08-26 21:50:28 +02:00
|
|
|
}
|
|
|
|
|
2015-04-13 00:59:07 +02:00
|
|
|
protected function defineParamTypes() {
|
2011-08-26 21:50:28 +02:00
|
|
|
return array(
|
|
|
|
'slug' => 'required string',
|
|
|
|
'title' => 'optional string',
|
|
|
|
'content' => 'optional string',
|
|
|
|
'description' => 'optional string',
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2015-04-13 00:59:07 +02:00
|
|
|
protected function defineReturnType() {
|
2011-08-26 21:50:28 +02:00
|
|
|
return 'nonempty dict';
|
|
|
|
}
|
|
|
|
|
|
|
|
protected function execute(ConduitAPIRequest $request) {
|
|
|
|
$slug = $request->getValue('slug');
|
|
|
|
|
2014-05-19 21:41:12 +02:00
|
|
|
$doc = id(new PhrictionDocumentQuery())
|
|
|
|
->setViewer($request->getUser())
|
|
|
|
->withSlugs(array(PhabricatorSlug::normalize($slug)))
|
2014-11-06 23:01:06 +01:00
|
|
|
->needContent(true)
|
2014-05-19 21:41:12 +02:00
|
|
|
->requireCapabilities(
|
|
|
|
array(
|
|
|
|
PhabricatorPolicyCapability::CAN_VIEW,
|
|
|
|
PhabricatorPolicyCapability::CAN_EDIT,
|
|
|
|
))
|
|
|
|
->executeOne();
|
|
|
|
if (!$doc) {
|
|
|
|
throw new Exception(pht('No such document.'));
|
|
|
|
}
|
|
|
|
|
2014-11-06 23:01:06 +01:00
|
|
|
$xactions = array();
|
2018-12-10 21:47:54 +01:00
|
|
|
if ($request->getValue('title')) {
|
|
|
|
$xactions[] = id(new PhrictionTransaction())
|
|
|
|
->setTransactionType(
|
|
|
|
PhrictionDocumentTitleTransaction::TRANSACTIONTYPE)
|
|
|
|
->setNewValue($request->getValue('title'));
|
|
|
|
}
|
|
|
|
|
|
|
|
if ($request->getValue('content')) {
|
|
|
|
$xactions[] = id(new PhrictionTransaction())
|
|
|
|
->setTransactionType(
|
|
|
|
PhrictionDocumentContentTransaction::TRANSACTIONTYPE)
|
|
|
|
->setNewValue($request->getValue('content'));
|
|
|
|
}
|
2014-11-06 23:01:06 +01:00
|
|
|
|
|
|
|
$editor = id(new PhrictionTransactionEditor())
|
2012-10-10 19:18:23 +02:00
|
|
|
->setActor($request->getUser())
|
2016-03-25 13:56:16 +01:00
|
|
|
->setContentSource($request->newContentSource())
|
2014-11-06 23:01:06 +01:00
|
|
|
->setContinueOnNoEffect(true)
|
2018-02-15 14:42:01 +01:00
|
|
|
->setDescription((string)$request->getValue('description'));
|
2014-11-07 20:46:25 +01:00
|
|
|
|
|
|
|
try {
|
|
|
|
$editor->applyTransactions($doc, $xactions);
|
|
|
|
} catch (PhabricatorApplicationTransactionValidationException $ex) {
|
|
|
|
// TODO - some magical hotness via T5873
|
|
|
|
throw $ex;
|
|
|
|
}
|
2011-08-26 21:50:28 +02:00
|
|
|
|
2014-11-06 23:01:06 +01:00
|
|
|
return $this->buildDocumentInfoDictionary($doc);
|
2011-08-26 21:50:28 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
}
|