[ Index ] |
PHP Cross Reference of Phabricator |
[Summary view] [Print] [Text view]
1 <?php 2 3 final class PhrictionEditConduitAPIMethod extends PhrictionConduitAPIMethod { 4 5 public function getAPIMethodName() { 6 return 'phriction.edit'; 7 } 8 9 public function getMethodDescription() { 10 return pht('Update a Phriction document.'); 11 } 12 13 public function defineParamTypes() { 14 return array( 15 'slug' => 'required string', 16 'title' => 'optional string', 17 'content' => 'optional string', 18 'description' => 'optional string', 19 ); 20 } 21 22 public function defineReturnType() { 23 return 'nonempty dict'; 24 } 25 26 public function defineErrorTypes() { 27 return array( 28 ); 29 } 30 31 protected function execute(ConduitAPIRequest $request) { 32 $slug = $request->getValue('slug'); 33 34 $doc = id(new PhrictionDocumentQuery()) 35 ->setViewer($request->getUser()) 36 ->withSlugs(array(PhabricatorSlug::normalize($slug))) 37 ->needContent(true) 38 ->requireCapabilities( 39 array( 40 PhabricatorPolicyCapability::CAN_VIEW, 41 PhabricatorPolicyCapability::CAN_EDIT, 42 )) 43 ->executeOne(); 44 if (!$doc) { 45 throw new Exception(pht('No such document.')); 46 } 47 48 $xactions = array(); 49 $xactions[] = id(new PhrictionTransaction()) 50 ->setTransactionType(PhrictionTransaction::TYPE_TITLE) 51 ->setNewValue($request->getValue('title')); 52 $xactions[] = id(new PhrictionTransaction()) 53 ->setTransactionType(PhrictionTransaction::TYPE_CONTENT) 54 ->setNewValue($request->getValue('content')); 55 56 $editor = id(new PhrictionTransactionEditor()) 57 ->setActor($request->getUser()) 58 ->setContentSourceFromConduitRequest($request) 59 ->setContinueOnNoEffect(true) 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 } 68 69 return $this->buildDocumentInfoDictionary($doc); 70 } 71 72 }
title
Description
Body
title
Description
Body
title
Description
Body
title
Body
Generated: Sun Nov 30 09:20:46 2014 | Cross-referenced by PHPXref 0.7.1 |