1
0
Fork 0
mirror of https://we.phorge.it/source/phorge.git synced 2024-12-11 16:16:14 +01:00
phorge-phorge/src/applications/phriction/conduit/PhrictionEditConduitAPIMethod.php
Austin McKinley 00a7071e2d Fix handling of Phriction conduit edits
Summary: See https://discourse.phabricator-community.org/t/conduit-method-phriction-edit-requires-title-while-the-docs-say-its-optional/2176. Make code consistent with documentation by not requiring either `content` or `title`.

Test Plan: Hit the method via the UI and no longer got an error on missing `content` or `title` fields.

Reviewers: epriestley

Reviewed By: epriestley

Subscribers: Korvin

Differential Revision: https://secure.phabricator.com/D19862
2018-12-10 13:38:13 -08:00

74 lines
2.1 KiB
PHP

<?php
final class PhrictionEditConduitAPIMethod extends PhrictionConduitAPIMethod {
public function getAPIMethodName() {
return 'phriction.edit';
}
public function getMethodDescription() {
return pht('Update a Phriction document.');
}
protected function defineParamTypes() {
return array(
'slug' => 'required string',
'title' => 'optional string',
'content' => 'optional string',
'description' => 'optional string',
);
}
protected function defineReturnType() {
return 'nonempty dict';
}
protected function execute(ConduitAPIRequest $request) {
$slug = $request->getValue('slug');
$doc = id(new PhrictionDocumentQuery())
->setViewer($request->getUser())
->withSlugs(array(PhabricatorSlug::normalize($slug)))
->needContent(true)
->requireCapabilities(
array(
PhabricatorPolicyCapability::CAN_VIEW,
PhabricatorPolicyCapability::CAN_EDIT,
))
->executeOne();
if (!$doc) {
throw new Exception(pht('No such document.'));
}
$xactions = array();
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'));
}
$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);
}
}