From 1643685e72166740a7f1abb41a7bc8fd83133324 Mon Sep 17 00:00:00 2001 From: Chad Little Date: Wed, 22 Jul 2015 13:32:25 -0700 Subject: [PATCH] Modernize Phame process handlers Summary: Converts Phame to use handleRequest where appropriate. Test Plan: Write some blog posts, publish, edit, view. Reviewers: btrahan, epriestley Reviewed By: epriestley Subscribers: epriestley, Korvin Maniphest Tasks: T8628 Differential Revision: https://secure.phabricator.com/D13677 --- .../post/PhamePostFramedController.php | 14 ++-- .../post/PhamePostListController.php | 66 ++++++++----------- .../post/PhamePostNotLiveController.php | 12 +--- .../post/PhamePostPublishController.php | 12 +--- .../post/PhamePostUnpublishController.php | 12 +--- 5 files changed, 42 insertions(+), 74 deletions(-) diff --git a/src/applications/phame/controller/post/PhamePostFramedController.php b/src/applications/phame/controller/post/PhamePostFramedController.php index 635c120928..46f723aa81 100644 --- a/src/applications/phame/controller/post/PhamePostFramedController.php +++ b/src/applications/phame/controller/post/PhamePostFramedController.php @@ -2,19 +2,13 @@ final class PhamePostFramedController extends PhameController { - private $id; - - public function willProcessRequest(array $data) { - $this->id = $data['id']; - } - - public function processRequest() { - $request = $this->getRequest(); - $user = $request->getUser(); + public function handleRequest(AphrontRequest $request) { + $user = $request->getViewer(); + $id = $request->getURIData('id'); $post = id(new PhamePostQuery()) ->setViewer($user) - ->withIDs(array($this->id)) + ->withIDs(array($id)) ->requireCapabilities( array( PhabricatorPolicyCapability::CAN_EDIT, diff --git a/src/applications/phame/controller/post/PhamePostListController.php b/src/applications/phame/controller/post/PhamePostListController.php index 90ba2a1ae7..6a02129bd8 100644 --- a/src/applications/phame/controller/post/PhamePostListController.php +++ b/src/applications/phame/controller/post/PhamePostListController.php @@ -2,60 +2,52 @@ final class PhamePostListController extends PhameController { - private $bloggername; - private $filter; - - public function willProcessRequest(array $data) { - $this->filter = idx($data, 'filter', 'blogger'); - $this->bloggername = idx($data, 'bloggername'); - } - - public function processRequest() { - $request = $this->getRequest(); - $user = $request->getUser(); + public function handleRequest(AphrontRequest $request) { + $viewer = $request->getViewer(); + $filter = $request->getURIData('filter'); + $bloggername = $request->getURIData('bloggername'); $query = id(new PhamePostQuery()) - ->setViewer($user); + ->setViewer($viewer); $nav = $this->renderSideNavFilterView(); $nodata = null; - switch ($this->filter) { + switch ($filter) { case 'draft': - $query->withBloggerPHIDs(array($user->getPHID())); + $query->withBloggerPHIDs(array($viewer->getPHID())); $query->withVisibility(PhamePost::VISIBILITY_DRAFT); $nodata = pht('You have no unpublished drafts.'); $title = pht('Unpublished Drafts'); $nav->selectFilter('post/draft'); break; - case 'blogger': - if ($this->bloggername) { - $blogger = id(new PhabricatorUser())->loadOneWhere( - 'username = %s', - $this->bloggername); - if (!$blogger) { - return new Aphront404Response(); - } - } else { - $blogger = $user; - } - - $query->withBloggerPHIDs(array($blogger->getPHID())); - if ($blogger->getPHID() == $user->getPHID()) { - $nav->selectFilter('post'); - $nodata = pht('You have not written any posts.'); - } else { - $nodata = pht('%s has not written any posts.', $blogger); - } - $title = pht('Posts by %s', $blogger); - break; case 'all': $nodata = pht('There are no visible posts.'); $title = pht('Posts'); $nav->selectFilter('post/all'); break; default: - throw new Exception(pht("Unknown filter '%s'!", $this->filter)); + case 'blogger': + if ($bloggername) { + $blogger = id(new PhabricatorUser())->loadOneWhere( + 'username = %s', + $bloggername); + if (!$blogger) { + return new Aphront404Response(); + } + } else { + $blogger = $viewer; + } + + $query->withBloggerPHIDs(array($blogger->getPHID())); + if ($blogger->getPHID() == $viewer->getPHID()) { + $nav->selectFilter('post'); + $nodata = pht('You have not written any posts.'); + } else { + $nodata = pht('%s has not written any posts.', $blogger); + } + $title = pht('Posts by %s', $blogger); + break; } $pager = id(new AphrontCursorPagerView()) @@ -64,7 +56,7 @@ final class PhamePostListController extends PhameController { $posts = $query->executeWithCursorPager($pager); require_celerity_resource('phame-css'); - $post_list = $this->renderPostList($posts, $user, $nodata); + $post_list = $this->renderPostList($posts, $viewer, $nodata); $post_list = id(new PHUIObjectBoxView()) ->setHeaderText($title) ->appendChild($post_list); diff --git a/src/applications/phame/controller/post/PhamePostNotLiveController.php b/src/applications/phame/controller/post/PhamePostNotLiveController.php index 8cfddb8436..3f69860003 100644 --- a/src/applications/phame/controller/post/PhamePostNotLiveController.php +++ b/src/applications/phame/controller/post/PhamePostNotLiveController.php @@ -2,19 +2,13 @@ final class PhamePostNotLiveController extends PhameController { - private $id; - - public function willProcessRequest(array $data) { - $this->id = $data['id']; - } - - public function processRequest() { - $request = $this->getRequest(); + public function handleRequest(AphrontRequest $request) { $user = $request->getUser(); + $id = $request->getURIData('id'); $post = id(new PhamePostQuery()) ->setViewer($user) - ->withIDs(array($this->id)) + ->withIDs(array($id)) ->executeOne(); if (!$post) { return new Aphront404Response(); diff --git a/src/applications/phame/controller/post/PhamePostPublishController.php b/src/applications/phame/controller/post/PhamePostPublishController.php index fcc7b29dc8..1b3cac79a4 100644 --- a/src/applications/phame/controller/post/PhamePostPublishController.php +++ b/src/applications/phame/controller/post/PhamePostPublishController.php @@ -2,19 +2,13 @@ final class PhamePostPublishController extends PhameController { - private $id; - - public function willProcessRequest(array $data) { - $this->id = $data['id']; - } - - public function processRequest() { - $request = $this->getRequest(); + public function handleRequest(AphrontRequest $request) { $user = $request->getUser(); + $id = $request->getURIData('id'); $post = id(new PhamePostQuery()) ->setViewer($user) - ->withIDs(array($this->id)) + ->withIDs(array($id)) ->requireCapabilities( array( PhabricatorPolicyCapability::CAN_EDIT, diff --git a/src/applications/phame/controller/post/PhamePostUnpublishController.php b/src/applications/phame/controller/post/PhamePostUnpublishController.php index 52c29da120..e2634e710e 100644 --- a/src/applications/phame/controller/post/PhamePostUnpublishController.php +++ b/src/applications/phame/controller/post/PhamePostUnpublishController.php @@ -2,19 +2,13 @@ final class PhamePostUnpublishController extends PhameController { - private $id; - - public function willProcessRequest(array $data) { - $this->id = $data['id']; - } - - public function processRequest() { - $request = $this->getRequest(); + public function handleRequest(AphrontRequest $request) { $user = $request->getUser(); + $id = $request->getURIData('id'); $post = id(new PhamePostQuery()) ->setViewer($user) - ->withIDs(array($this->id)) + ->withIDs(array($id)) ->requireCapabilities( array( PhabricatorPolicyCapability::CAN_EDIT,