From 18a9fe85c8359710b619c8b8de47ea559ffafafc Mon Sep 17 00:00:00 2001 From: Chad Little Date: Mon, 27 Jul 2015 09:04:08 -0700 Subject: [PATCH] Convert Macro to handleRequest Summary: Converts Macro app Test Plan: Make Macro, Make meme Reviewers: epriestley Reviewed By: epriestley Subscribers: epriestley, Korvin Maniphest Tasks: T8628 Differential Revision: https://secure.phabricator.com/D13724 --- .../PhabricatorMacroAudioController.php | 14 +++------ .../PhabricatorMacroCommentController.php | 20 +++++-------- .../PhabricatorMacroDisableController.php | 22 +++++--------- .../PhabricatorMacroEditController.php | 30 ++++++++----------- .../PhabricatorMacroListController.php | 10 ++----- .../PhabricatorMacroMemeController.php | 13 ++++---- .../PhabricatorMacroMemeDialogController.php | 11 ++++--- .../PhabricatorMacroViewController.php | 22 +++++--------- 8 files changed, 53 insertions(+), 89 deletions(-) diff --git a/src/applications/macro/controller/PhabricatorMacroAudioController.php b/src/applications/macro/controller/PhabricatorMacroAudioController.php index e46b7c78e8..92b98e5564 100644 --- a/src/applications/macro/controller/PhabricatorMacroAudioController.php +++ b/src/applications/macro/controller/PhabricatorMacroAudioController.php @@ -2,26 +2,20 @@ final class PhabricatorMacroAudioController extends PhabricatorMacroController { - private $id; + public function handleRequest(AphrontRequest $request) { + $viewer = $request->getViewer(); + $id = $request->getURIData('id'); - public function willProcessRequest(array $data) { - $this->id = idx($data, 'id'); - } - - public function processRequest() { $this->requireApplicationCapability( PhabricatorMacroManageCapability::CAPABILITY); - $request = $this->getRequest(); - $viewer = $request->getUser(); - $macro = id(new PhabricatorMacroQuery()) ->setViewer($viewer) ->requireCapabilities( array( PhabricatorPolicyCapability::CAN_VIEW, )) - ->withIDs(array($this->id)) + ->withIDs(array($id)) ->executeOne(); if (!$macro) { diff --git a/src/applications/macro/controller/PhabricatorMacroCommentController.php b/src/applications/macro/controller/PhabricatorMacroCommentController.php index f438e9b31a..f038140be1 100644 --- a/src/applications/macro/controller/PhabricatorMacroCommentController.php +++ b/src/applications/macro/controller/PhabricatorMacroCommentController.php @@ -3,23 +3,17 @@ final class PhabricatorMacroCommentController extends PhabricatorMacroController { - private $id; - - public function willProcessRequest(array $data) { - $this->id = idx($data, 'id'); - } - - public function processRequest() { - $request = $this->getRequest(); - $user = $request->getUser(); + public function handleRequest(AphrontRequest $request) { + $viewer = $request->getViewer(); + $id = $request->getURIData('id'); if (!$request->isFormPost()) { return new Aphront400Response(); } $macro = id(new PhabricatorMacroQuery()) - ->setViewer($user) - ->withIDs(array($this->id)) + ->setViewer($viewer) + ->withIDs(array($id)) ->executeOne(); if (!$macro) { return new Aphront404Response(); @@ -38,7 +32,7 @@ final class PhabricatorMacroCommentController ->setContent($request->getStr('comment'))); $editor = id(new PhabricatorMacroEditor()) - ->setActor($user) + ->setActor($viewer) ->setContinueOnNoEffect($request->isContinueRequest()) ->setContentSourceFromRequest($request) ->setIsPreview($is_preview); @@ -57,7 +51,7 @@ final class PhabricatorMacroCommentController if ($request->isAjax() && $is_preview) { return id(new PhabricatorApplicationTransactionResponse()) - ->setViewer($user) + ->setViewer($viewer) ->setTransactions($xactions) ->setIsPreview($is_preview); } else { diff --git a/src/applications/macro/controller/PhabricatorMacroDisableController.php b/src/applications/macro/controller/PhabricatorMacroDisableController.php index 0804e119e5..a9868647f0 100644 --- a/src/applications/macro/controller/PhabricatorMacroDisableController.php +++ b/src/applications/macro/controller/PhabricatorMacroDisableController.php @@ -3,28 +3,22 @@ final class PhabricatorMacroDisableController extends PhabricatorMacroController { - private $id; + public function handleRequest(AphrontRequest $request) { + $viewer = $request->getViewer(); + $id = $request->getURIData('id'); - public function willProcessRequest(array $data) { - $this->id = $data['id']; - } - - public function processRequest() { $this->requireApplicationCapability( PhabricatorMacroManageCapability::CAPABILITY); - $request = $this->getRequest(); - $user = $request->getUser(); - $macro = id(new PhabricatorMacroQuery()) - ->setViewer($user) - ->withIDs(array($this->id)) + ->setViewer($viewer) + ->withIDs(array($id)) ->executeOne(); if (!$macro) { return new Aphront404Response(); } - $view_uri = $this->getApplicationURI('/view/'.$this->id.'/'); + $view_uri = $this->getApplicationURI('/view/'.$id.'/'); if ($request->isDialogFormPost() || $macro->getIsDisabled()) { $xaction = id(new PhabricatorMacroTransaction()) @@ -32,7 +26,7 @@ final class PhabricatorMacroDisableController ->setNewValue($macro->getIsDisabled() ? 0 : 1); $editor = id(new PhabricatorMacroEditor()) - ->setActor($user) + ->setActor($viewer) ->setContentSourceFromRequest($request); $xactions = $editor->applyTransactions($macro, array($xaction)); @@ -52,7 +46,7 @@ final class PhabricatorMacroDisableController 'Really disable the much-beloved image macro %s? '. 'It will be sorely missed.', $macro->getName()))) - ->setSubmitURI($this->getApplicationURI('/disable/'.$this->id.'/')) + ->setSubmitURI($this->getApplicationURI('/disable/'.$id.'/')) ->addSubmitButton(pht('Disable')) ->addCancelButton($view_uri); diff --git a/src/applications/macro/controller/PhabricatorMacroEditController.php b/src/applications/macro/controller/PhabricatorMacroEditController.php index f15e5364c2..9e988ef637 100644 --- a/src/applications/macro/controller/PhabricatorMacroEditController.php +++ b/src/applications/macro/controller/PhabricatorMacroEditController.php @@ -2,23 +2,17 @@ final class PhabricatorMacroEditController extends PhabricatorMacroController { - private $id; + public function handleRequest(AphrontRequest $request) { + $viewer = $request->getViewer(); + $id = $request->getURIData('id'); - public function willProcessRequest(array $data) { - $this->id = idx($data, 'id'); - } - - public function processRequest() { $this->requireApplicationCapability( PhabricatorMacroManageCapability::CAPABILITY); - $request = $this->getRequest(); - $user = $request->getUser(); - - if ($this->id) { + if ($id) { $macro = id(new PhabricatorMacroQuery()) - ->setViewer($user) - ->withIDs(array($this->id)) + ->setViewer($viewer) + ->withIDs(array($id)) ->needFiles(true) ->executeOne(); if (!$macro) { @@ -26,7 +20,7 @@ final class PhabricatorMacroEditController extends PhabricatorMacroController { } } else { $macro = new PhabricatorFileImageMacro(); - $macro->setAuthorPHID($user->getPHID()); + $macro->setAuthorPHID($viewer->getPHID()); } $errors = array(); @@ -66,7 +60,7 @@ final class PhabricatorMacroEditController extends PhabricatorMacroController { $_FILES['file'], array( 'name' => $request->getStr('name'), - 'authorPHID' => $user->getPHID(), + 'authorPHID' => $viewer->getPHID(), 'isExplicitUpload' => true, 'canCDN' => true, )); @@ -75,7 +69,7 @@ final class PhabricatorMacroEditController extends PhabricatorMacroController { // Rate limit outbound fetches to make this mechanism less useful for // scanning networks and ports. PhabricatorSystemActionEngine::willTakeAction( - array($user->getPHID()), + array($viewer->getPHID()), new PhabricatorFilesOutboundRequestAction(), 1); @@ -101,7 +95,7 @@ final class PhabricatorMacroEditController extends PhabricatorMacroController { $mime_type)); } else { $file - ->setAuthorPHID($user->getPHID()) + ->setAuthorPHID($viewer->getPHID()) ->save(); } } catch (HTTPFutureHTTPResponseStatus $status) { @@ -114,7 +108,7 @@ final class PhabricatorMacroEditController extends PhabricatorMacroController { } } else if ($request->getStr('phid')) { $file = id(new PhabricatorFileQuery()) - ->setViewer($user) + ->setViewer($viewer) ->withPHIDs(array($request->getStr('phid'))) ->executeOne(); } @@ -152,7 +146,7 @@ final class PhabricatorMacroEditController extends PhabricatorMacroController { } $editor = id(new PhabricatorMacroEditor()) - ->setActor($user) + ->setActor($viewer) ->setContinueOnNoEffect(true) ->setContentSourceFromRequest($request); diff --git a/src/applications/macro/controller/PhabricatorMacroListController.php b/src/applications/macro/controller/PhabricatorMacroListController.php index 730f8de3b1..3847117275 100644 --- a/src/applications/macro/controller/PhabricatorMacroListController.php +++ b/src/applications/macro/controller/PhabricatorMacroListController.php @@ -2,19 +2,15 @@ final class PhabricatorMacroListController extends PhabricatorMacroController { - private $key; - public function shouldAllowPublic() { return true; } - public function willProcessRequest(array $data) { - $this->key = idx($data, 'key'); - } + public function handleRequest(AphrontRequest $request) { + $key = $request->getURIData('key'); - public function processRequest() { $controller = id(new PhabricatorApplicationSearchController()) - ->setQueryKey($this->key) + ->setQueryKey($key) ->setSearchEngine(new PhabricatorMacroSearchEngine()) ->setNavigation($this->buildSideNavView()); diff --git a/src/applications/macro/controller/PhabricatorMacroMemeController.php b/src/applications/macro/controller/PhabricatorMacroMemeController.php index ff25a8a8a4..03b13f6205 100644 --- a/src/applications/macro/controller/PhabricatorMacroMemeController.php +++ b/src/applications/macro/controller/PhabricatorMacroMemeController.php @@ -7,14 +7,13 @@ final class PhabricatorMacroMemeController return true; } - public function processRequest() { - $request = $this->getRequest(); + public function handleRequest(AphrontRequest $request) { $macro_name = $request->getStr('macro'); $upper_text = $request->getStr('uppertext'); $lower_text = $request->getStr('lowertext'); - $user = $request->getUser(); + $viewer = $request->getViewer(); - $uri = self::generateMacro($user, $macro_name, + $uri = self::generateMacro($viewer, $macro_name, $upper_text, $lower_text); if ($uri === false) { return new Aphront404Response(); @@ -24,10 +23,10 @@ final class PhabricatorMacroMemeController ->setURI($uri); } - public static function generateMacro($user, $macro_name, $upper_text, + public static function generateMacro($viewer, $macro_name, $upper_text, $lower_text) { $macro = id(new PhabricatorMacroQuery()) - ->setViewer($user) + ->setViewer($viewer) ->withNames(array($macro_name)) ->needFiles(true) ->executeOne(); @@ -46,7 +45,7 @@ final class PhabricatorMacroMemeController if ($xform) { $memefile = id(new PhabricatorFileQuery()) - ->setViewer($user) + ->setViewer($viewer) ->withPHIDs(array($xform->getTransformedPHID())) ->executeOne(); if ($memefile) { diff --git a/src/applications/macro/controller/PhabricatorMacroMemeDialogController.php b/src/applications/macro/controller/PhabricatorMacroMemeDialogController.php index 25a223f5ac..5851cc5ad8 100644 --- a/src/applications/macro/controller/PhabricatorMacroMemeDialogController.php +++ b/src/applications/macro/controller/PhabricatorMacroMemeDialogController.php @@ -3,9 +3,8 @@ final class PhabricatorMacroMemeDialogController extends PhabricatorMacroController { - public function processRequest() { - $request = $this->getRequest(); - $user = $request->getUser(); + public function handleRequest(AphrontRequest $request) { + $viewer = $request->getViewer(); $phid = head($request->getArr('macro')); $above = $request->getStr('above'); @@ -19,7 +18,7 @@ final class PhabricatorMacroMemeDialogController $errors[] = pht('Macro name is required.'); } else { $macro = id(new PhabricatorMacroQuery()) - ->setViewer($user) + ->setViewer($viewer) ->withPHIDs(array($phid)) ->executeOne(); if (!$macro) { @@ -45,7 +44,7 @@ final class PhabricatorMacroMemeDialogController } $view = id(new AphrontFormView()) - ->setUser($user) + ->setUser($viewer) ->appendControl( id(new AphrontFormTokenizerControl()) ->setLabel(pht('Macro')) @@ -65,7 +64,7 @@ final class PhabricatorMacroMemeDialogController ->setValue($below)); $dialog = id(new AphrontDialogView()) - ->setUser($user) + ->setUser($viewer) ->setTitle(pht('Create Meme')) ->appendForm($view) ->addCancelButton('/') diff --git a/src/applications/macro/controller/PhabricatorMacroViewController.php b/src/applications/macro/controller/PhabricatorMacroViewController.php index a031c7f92b..8915954fc4 100644 --- a/src/applications/macro/controller/PhabricatorMacroViewController.php +++ b/src/applications/macro/controller/PhabricatorMacroViewController.php @@ -3,23 +3,17 @@ final class PhabricatorMacroViewController extends PhabricatorMacroController { - private $id; - - public function willProcessRequest(array $data) { - $this->id = $data['id']; - } - public function shouldAllowPublic() { return true; } - public function processRequest() { - $request = $this->getRequest(); - $user = $request->getUser(); + public function handleRequest(AphrontRequest $request) { + $viewer = $request->getViewer(); + $id = $request->getURIData('id'); $macro = id(new PhabricatorMacroQuery()) - ->setViewer($user) - ->withIDs(array($this->id)) + ->setViewer($viewer) + ->withIDs(array($id)) ->needFiles(true) ->executeOne(); if (!$macro) { @@ -55,7 +49,7 @@ final class PhabricatorMacroViewController new PhabricatorMacroTransactionQuery()); $header = id(new PHUIHeaderView()) - ->setUser($user) + ->setUser($viewer) ->setPolicyObject($macro) ->setHeader($title_long); @@ -71,10 +65,10 @@ final class PhabricatorMacroViewController ? pht('Add Comment') : pht('Grovel in Awe'); - $draft = PhabricatorDraft::newFromUserAndKey($user, $macro->getPHID()); + $draft = PhabricatorDraft::newFromUserAndKey($viewer, $macro->getPHID()); $add_comment_form = id(new PhabricatorApplicationTransactionCommentView()) - ->setUser($user) + ->setUser($viewer) ->setObjectPHID($macro->getPHID()) ->setDraft($draft) ->setHeaderText($comment_header)