@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.

Phame - create conduit API to create posts

Summary:
nothing too crazy here. try to be smart about some defaults (i.e. phame title is optional and can be derived from title; post as not a draft by default; etc). Fixes T3695.

also do a little re-factoring to centralizing initializing new posts and turning posts into dictionaries. also change blogs => posts in another conduit method so it makes sense and stuff.

Test Plan: made some posts via conduit. testing trying to specify blogger, phame title, and isDraft, all worked nicely

Reviewers: chad, epriestley

Reviewed By: epriestley

Subscribers: aran, epriestley, Korvin

Maniphest Tasks: T3695

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

+132 -21
+2
src/__phutil_library_map__.php
··· 210 210 'ConduitAPI_paste_info_Method' => 'applications/paste/conduit/ConduitAPI_paste_info_Method.php', 211 211 'ConduitAPI_paste_query_Method' => 'applications/paste/conduit/ConduitAPI_paste_query_Method.php', 212 212 'ConduitAPI_phame_Method' => 'applications/phame/conduit/ConduitAPI_phame_Method.php', 213 + 'ConduitAPI_phame_createpost_Method' => 'applications/phame/conduit/ConduitAPI_phame_createpost_Method.php', 213 214 'ConduitAPI_phame_query_Method' => 'applications/phame/conduit/ConduitAPI_phame_query_Method.php', 214 215 'ConduitAPI_phame_queryposts_Method' => 'applications/phame/conduit/ConduitAPI_phame_queryposts_Method.php', 215 216 'ConduitAPI_phid_Method' => 'applications/phid/conduit/ConduitAPI_phid_Method.php', ··· 2738 2739 'ConduitAPI_paste_info_Method' => 'ConduitAPI_paste_Method', 2739 2740 'ConduitAPI_paste_query_Method' => 'ConduitAPI_paste_Method', 2740 2741 'ConduitAPI_phame_Method' => 'ConduitAPIMethod', 2742 + 'ConduitAPI_phame_createpost_Method' => 'ConduitAPI_phame_Method', 2741 2743 'ConduitAPI_phame_query_Method' => 'ConduitAPI_phame_Method', 2742 2744 'ConduitAPI_phame_queryposts_Method' => 'ConduitAPI_phame_Method', 2743 2745 'ConduitAPI_phid_Method' => 'ConduitAPIMethod',
+97
src/applications/phame/conduit/ConduitAPI_phame_createpost_Method.php
··· 1 + <?php 2 + 3 + final class ConduitAPI_phame_createpost_Method extends ConduitAPI_phame_Method { 4 + 5 + public function getMethodDescription() { 6 + return pht('Create a phame post.'); 7 + } 8 + 9 + public function getMethodStatus() { 10 + return self::METHOD_STATUS_UNSTABLE; 11 + } 12 + 13 + public function defineParamTypes() { 14 + return array( 15 + 'blogPHID' => 'required phid', 16 + 'title' => 'required string', 17 + 'body' => 'required string', 18 + 'phameTitle' => 'optional string', 19 + 'bloggerPHID' => 'optional phid', 20 + 'isDraft' => 'optional bool', 21 + ); 22 + } 23 + 24 + public function defineReturnType() { 25 + return 'list<dict>'; 26 + } 27 + 28 + public function defineErrorTypes() { 29 + return array( 30 + 'ERR-INVALID-PARAMETER' => 31 + pht('Missing or malformed parameter.'), 32 + 'ERR-INVALID-BLOG' => 33 + pht('Invalid blog PHID or user can not post to blog.'), 34 + ); 35 + } 36 + 37 + protected function execute(ConduitAPIRequest $request) { 38 + $user = $request->getUser(); 39 + $blog_phid = $request->getValue('blogPHID'); 40 + $title = $request->getValue('title'); 41 + $body = $request->getValue('body'); 42 + $exception_description = array(); 43 + if (!$blog_phid) { 44 + $exception_description[] = pht('No blog phid.'); 45 + } 46 + if (!strlen($title)) { 47 + $exception_description[] = pht('No post title.'); 48 + } 49 + if (!strlen($body)) { 50 + $exception_description[] = pht('No post body.'); 51 + } 52 + if ($exception_description) { 53 + throw id(new ConduitException('ERR-INVALID-PARAMETER')) 54 + ->setErrorDescription(implode("\n", $exception_description)); 55 + } 56 + 57 + $blogger_phid = $request->getValue('bloggerPHID'); 58 + if ($blogger_phid) { 59 + $blogger = id(new PhabricatorPeopleQuery()) 60 + ->setViewer($user) 61 + ->withPHIDs(array($blogger_phid)) 62 + ->executeOne(); 63 + } else { 64 + $blogger = $user; 65 + } 66 + 67 + $blog = id(new PhameBlogQuery()) 68 + ->setViewer($blogger) 69 + ->withPHIDs(array($blog_phid)) 70 + ->requireCapabilities( 71 + array( 72 + PhabricatorPolicyCapability::CAN_JOIN, 73 + )) 74 + ->executeOne(); 75 + 76 + if (!$blog) { 77 + throw new ConduitException('ERR-INVALID-BLOG'); 78 + } 79 + 80 + $post = PhamePost::initializePost($blogger, $blog); 81 + $is_draft = $request->getValue('isDraft', false); 82 + if (!$is_draft) { 83 + $post->setDatePublished(time()); 84 + $post->setVisibility(PhamePost::VISIBILITY_PUBLISHED); 85 + } 86 + $post->setTitle($title); 87 + $phame_title = $request->getValue( 88 + 'phameTitle', 89 + phutil_utf8_shorten($title, 64)); 90 + $post->setPhameTitle(PhabricatorSlug::normalize($phame_title)); 91 + $post->setBody($body); 92 + $post->save(); 93 + 94 + return $post->toDictionary(); 95 + } 96 + 97 + }
+3 -15
src/applications/phame/conduit/ConduitAPI_phame_queryposts_Method.php
··· 95 95 $query->setLimit($limit); 96 96 } 97 97 98 - $blogs = $query->execute(); 98 + $posts = $query->execute(); 99 99 100 100 $results = array(); 101 - foreach ($blogs as $blog) { 102 - $results[] = array( 103 - 'id' => $blog->getID(), 104 - 'phid' => $blog->getPHID(), 105 - 'blogPHID' => $blog->getBlogPHID(), 106 - 'bloggerPHID' => $blog->getBloggerPHID(), 107 - 'viewURI' => $blog->getViewURI(), 108 - 'title' => $blog->getTitle(), 109 - 'phameTitle' => $blog->getPhameTitle(), 110 - 'body' => $blog->getBody(), 111 - 'summary' => PhabricatorMarkupEngine::summarize($blog->getBody()), 112 - 'datePublished' => $blog->getDatePublished(), 113 - 'published' => !$blog->isDraft(), 114 - ); 101 + foreach ($posts as $post) { 102 + $results[] = $post->toDictionary(); 115 103 } 116 104 117 105 return $results;
+1 -6
src/applications/phame/controller/post/PhamePostEditController.php
··· 46 46 return new Aphront404Response(); 47 47 } 48 48 49 - $post = id(new PhamePost()) 50 - ->setBloggerPHID($user->getPHID()) 51 - ->setBlogPHID($blog->getPHID()) 52 - ->setBlog($blog) 53 - ->setDatePublished(0) 54 - ->setVisibility(PhamePost::VISIBILITY_DRAFT); 49 + $post = PhamePost::initializePost($user, $blog); 55 50 $cancel_uri = $this->getApplicationURI('/blog/view/'.$blog->getID().'/'); 56 51 57 52 $submit_button = pht('Save Draft');
+29
src/applications/phame/storage/PhamePost.php
··· 26 26 27 27 private $blog; 28 28 29 + public static function initializePost( 30 + PhabricatorUser $blogger, 31 + PhameBlog $blog) { 32 + 33 + $post = id(new PhamePost()) 34 + ->setBloggerPHID($blogger->getPHID()) 35 + ->setBlogPHID($blog->getPHID()) 36 + ->setBlog($blog) 37 + ->setDatePublished(0) 38 + ->setVisibility(self::VISIBILITY_DRAFT); 39 + return $post; 40 + } 41 + 29 42 public function setBlog(PhameBlog $blog) { 30 43 $this->blog = $blog; 31 44 return $this; ··· 80 93 public function generatePHID() { 81 94 return PhabricatorPHID::generateNewPHID( 82 95 PhabricatorPhamePHIDTypePost::TYPECONST); 96 + } 97 + 98 + public function toDictionary() { 99 + return array( 100 + 'id' => $this->getID(), 101 + 'phid' => $this->getPHID(), 102 + 'blogPHID' => $this->getBlogPHID(), 103 + 'bloggerPHID' => $this->getBloggerPHID(), 104 + 'viewURI' => $this->getViewURI(), 105 + 'title' => $this->getTitle(), 106 + 'phameTitle' => $this->getPhameTitle(), 107 + 'body' => $this->getBody(), 108 + 'summary' => PhabricatorMarkupEngine::summarize($this->getBody()), 109 + 'datePublished' => $this->getDatePublished(), 110 + 'published' => !$this->isDraft(), 111 + ); 83 112 } 84 113 85 114 public static function getVisibilityOptionsForSelect() {