diff --git a/src/__phutil_library_map__.php b/src/__phutil_library_map__.php --- a/src/__phutil_library_map__.php +++ b/src/__phutil_library_map__.php @@ -2762,6 +2762,7 @@ 'PhrictionConstants' => 'applications/phriction/constants/PhrictionConstants.php', 'PhrictionContent' => 'applications/phriction/storage/PhrictionContent.php', 'PhrictionController' => 'applications/phriction/controller/PhrictionController.php', + 'PhrictionCreateConduitAPIMethod' => 'applications/phriction/conduit/PhrictionCreateConduitAPIMethod.php', 'PhrictionDAO' => 'applications/phriction/storage/PhrictionDAO.php', 'PhrictionDeleteController' => 'applications/phriction/controller/PhrictionDeleteController.php', 'PhrictionDiffController' => 'applications/phriction/controller/PhrictionDiffController.php', @@ -5966,6 +5967,7 @@ 'PhabricatorMarkupInterface', ), 'PhrictionController' => 'PhabricatorController', + 'PhrictionCreateConduitAPIMethod' => 'PhrictionConduitAPIMethod', 'PhrictionDAO' => 'PhabricatorLiskDAO', 'PhrictionDeleteController' => 'PhrictionController', 'PhrictionDiffController' => 'PhrictionController', diff --git a/src/applications/phriction/conduit/PhrictionEditConduitAPIMethod.php b/src/applications/phriction/conduit/PhrictionCreateConduitAPIMethod.php copy from src/applications/phriction/conduit/PhrictionEditConduitAPIMethod.php copy to src/applications/phriction/conduit/PhrictionCreateConduitAPIMethod.php --- a/src/applications/phriction/conduit/PhrictionEditConduitAPIMethod.php +++ b/src/applications/phriction/conduit/PhrictionCreateConduitAPIMethod.php @@ -1,50 +1,49 @@ 'required string', - 'title' => 'optional string', - 'content' => 'optional string', + 'title' => 'required string', + 'content' => 'required string', 'description' => 'optional string', ); } - public function defineReturnType() { return 'nonempty dict'; } - public function defineErrorTypes() { return array( ); } - protected function execute(ConduitAPIRequest $request) { $slug = $request->getValue('slug'); - + if (!strlen($slug)) { + throw new Exception(pht('No such document.')); + } $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.')); + if ($doc) { + throw new Exception(pht('Document already exists!')); } + $doc = PhrictionDocument::initializeNewDocument( + $request->getUser(), + $slug); + $xactions = array(); $xactions[] = id(new PhrictionTransaction()) ->setTransactionType(PhrictionTransaction::TYPE_TITLE) @@ -57,10 +56,15 @@ ->setActor($request->getUser()) ->setContentSourceFromConduitRequest($request) ->setContinueOnNoEffect(true) - ->setDescription($request->getValue('description')) - ->applyTransactions($doc, $xactions); + ->setDescription($request->getValue('description')); + + try { + $editor->applyTransactions($doc, $xactions); + } catch (PhabricatorApplicationTransactionValidationException $ex) { + // TODO - some magical hotness via T5873 + throw $ex; + } return $this->buildDocumentInfoDictionary($doc); } - } diff --git a/src/applications/phriction/conduit/PhrictionEditConduitAPIMethod.php b/src/applications/phriction/conduit/PhrictionEditConduitAPIMethod.php --- a/src/applications/phriction/conduit/PhrictionEditConduitAPIMethod.php +++ b/src/applications/phriction/conduit/PhrictionEditConduitAPIMethod.php @@ -7,7 +7,7 @@ } public function getMethodDescription() { - return 'Update a Phriction document.'; + return pht('Update a Phriction document.'); } public function defineParamTypes() { @@ -57,8 +57,14 @@ ->setActor($request->getUser()) ->setContentSourceFromConduitRequest($request) ->setContinueOnNoEffect(true) - ->setDescription($request->getValue('description')) - ->applyTransactions($doc, $xactions); + ->setDescription($request->getValue('description')); + + try { + $editor->applyTransactions($doc, $xactions); + } catch (PhabricatorApplicationTransactionValidationException $ex) { + // TODO - some magical hotness via T5873 + throw $ex; + } return $this->buildDocumentInfoDictionary($doc); }