@recaptime-dev's working patches + fork for Phorge, a community fork of Phabricator. (Upstream dev and stable branches are at upstream/main and upstream/stable respectively.) hq.recaptime.dev/wiki/Phorge
phorge phabricator
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

Phriction - add "create" conduit endpoint

Summary: Fixes T6262. Ref T4029. Also gets us ready for T5873 for these end points. I can file something new about someday adding phriction.query, etc but I think we'll remember and can look at that post T5873.

Test Plan: made a document via conduit and it worked!

Reviewers: epriestley

Reviewed By: epriestley

Subscribers: Korvin, epriestley

Maniphest Tasks: T6262, T4029

Differential Revision: https://secure.phabricator.com/D10813

+81 -3
+2
src/__phutil_library_map__.php
··· 2762 2762 'PhrictionConstants' => 'applications/phriction/constants/PhrictionConstants.php', 2763 2763 'PhrictionContent' => 'applications/phriction/storage/PhrictionContent.php', 2764 2764 'PhrictionController' => 'applications/phriction/controller/PhrictionController.php', 2765 + 'PhrictionCreateConduitAPIMethod' => 'applications/phriction/conduit/PhrictionCreateConduitAPIMethod.php', 2765 2766 'PhrictionDAO' => 'applications/phriction/storage/PhrictionDAO.php', 2766 2767 'PhrictionDeleteController' => 'applications/phriction/controller/PhrictionDeleteController.php', 2767 2768 'PhrictionDiffController' => 'applications/phriction/controller/PhrictionDiffController.php', ··· 5966 5967 'PhabricatorMarkupInterface', 5967 5968 ), 5968 5969 'PhrictionController' => 'PhabricatorController', 5970 + 'PhrictionCreateConduitAPIMethod' => 'PhrictionConduitAPIMethod', 5969 5971 'PhrictionDAO' => 'PhabricatorLiskDAO', 5970 5972 'PhrictionDeleteController' => 'PhrictionController', 5971 5973 'PhrictionDiffController' => 'PhrictionController',
+70
src/applications/phriction/conduit/PhrictionCreateConduitAPIMethod.php
··· 1 + <?php 2 + 3 + final class PhrictionCreateConduitAPIMethod extends PhrictionConduitAPIMethod { 4 + public function getAPIMethodName() { 5 + return 'phriction.create'; 6 + } 7 + public function getMethodDescription() { 8 + return pht('Create a Phriction document.'); 9 + } 10 + public function defineParamTypes() { 11 + return array( 12 + 'slug' => 'required string', 13 + 'title' => 'required string', 14 + 'content' => 'required string', 15 + 'description' => 'optional string', 16 + ); 17 + } 18 + public function defineReturnType() { 19 + return 'nonempty dict'; 20 + } 21 + public function defineErrorTypes() { 22 + return array( 23 + ); 24 + } 25 + protected function execute(ConduitAPIRequest $request) { 26 + $slug = $request->getValue('slug'); 27 + if (!strlen($slug)) { 28 + throw new Exception(pht('No such document.')); 29 + } 30 + $doc = id(new PhrictionDocumentQuery()) 31 + ->setViewer($request->getUser()) 32 + ->withSlugs(array(PhabricatorSlug::normalize($slug))) 33 + ->requireCapabilities( 34 + array( 35 + PhabricatorPolicyCapability::CAN_VIEW, 36 + PhabricatorPolicyCapability::CAN_EDIT, 37 + )) 38 + ->executeOne(); 39 + if ($doc) { 40 + throw new Exception(pht('Document already exists!')); 41 + } 42 + 43 + $doc = PhrictionDocument::initializeNewDocument( 44 + $request->getUser(), 45 + $slug); 46 + 47 + $xactions = array(); 48 + $xactions[] = id(new PhrictionTransaction()) 49 + ->setTransactionType(PhrictionTransaction::TYPE_TITLE) 50 + ->setNewValue($request->getValue('title')); 51 + $xactions[] = id(new PhrictionTransaction()) 52 + ->setTransactionType(PhrictionTransaction::TYPE_CONTENT) 53 + ->setNewValue($request->getValue('content')); 54 + 55 + $editor = id(new PhrictionTransactionEditor()) 56 + ->setActor($request->getUser()) 57 + ->setContentSourceFromConduitRequest($request) 58 + ->setContinueOnNoEffect(true) 59 + ->setDescription($request->getValue('description')); 60 + 61 + try { 62 + $editor->applyTransactions($doc, $xactions); 63 + } catch (PhabricatorApplicationTransactionValidationException $ex) { 64 + // TODO - some magical hotness via T5873 65 + throw $ex; 66 + } 67 + 68 + return $this->buildDocumentInfoDictionary($doc); 69 + } 70 + }
+9 -3
src/applications/phriction/conduit/PhrictionEditConduitAPIMethod.php
··· 7 7 } 8 8 9 9 public function getMethodDescription() { 10 - return 'Update a Phriction document.'; 10 + return pht('Update a Phriction document.'); 11 11 } 12 12 13 13 public function defineParamTypes() { ··· 57 57 ->setActor($request->getUser()) 58 58 ->setContentSourceFromConduitRequest($request) 59 59 ->setContinueOnNoEffect(true) 60 - ->setDescription($request->getValue('description')) 61 - ->applyTransactions($doc, $xactions); 60 + ->setDescription($request->getValue('description')); 61 + 62 + try { 63 + $editor->applyTransactions($doc, $xactions); 64 + } catch (PhabricatorApplicationTransactionValidationException $ex) { 65 + // TODO - some magical hotness via T5873 66 + throw $ex; 67 + } 62 68 63 69 return $this->buildDocumentInfoDictionary($doc); 64 70 }