From 6dda35897adb016b959843f4c631a04284473706 Mon Sep 17 00:00:00 2001 From: epriestley Date: Fri, 24 May 2013 10:48:34 -0700 Subject: [PATCH] Use setContentSourceFromRequest() in more places Summary: I introduced this helper at some point, clean up all the code duplication around content sources. Test Plan: Grepped; hit edit interfaces for most/all of these. Reviewers: btrahan, chad, edward Reviewed By: chad CC: aran Differential Revision: https://secure.phabricator.com/D6030 --- .../controller/PhabricatorConfigEditController.php | 7 +------ .../config/editor/PhabricatorConfigEditor.php | 8 +------- .../conpherence/controller/ConpherenceNewController.php | 8 ++------ .../controller/ConpherenceUpdateController.php | 7 +------ .../controller/PhabricatorMacroCommentController.php | 7 +------ .../controller/PhabricatorMacroDisableController.php | 7 +------ .../macro/controller/PhabricatorMacroEditController.php | 7 +------ .../metamta/contentsource/PhabricatorContentSource.php | 8 ++++++++ .../phlux/controller/PhluxEditController.php | 7 +------ .../pholio/controller/PholioInlineSaveController.php | 9 +-------- .../pholio/controller/PholioMockCommentController.php | 8 +------- .../pholio/controller/PholioMockEditController.php | 8 +------- .../phortune/controller/PhortuneController.php | 7 +------ .../request/ReleephRequestActionController.php | 7 +------ .../request/ReleephRequestCommentController.php | 7 +------ .../controller/request/ReleephRequestEditController.php | 7 +------ .../PhabricatorSubscriptionsEditController.php | 7 +------ ...icatorApplicationTransactionCommentEditController.php | 7 +------ .../storage/PhabricatorApplicationTransactionComment.php | 5 +++++ 19 files changed, 31 insertions(+), 107 deletions(-) diff --git a/src/applications/config/controller/PhabricatorConfigEditController.php b/src/applications/config/controller/PhabricatorConfigEditController.php index b5ff45195d..1e82c02ace 100644 --- a/src/applications/config/controller/PhabricatorConfigEditController.php +++ b/src/applications/config/controller/PhabricatorConfigEditController.php @@ -73,12 +73,7 @@ final class PhabricatorConfigEditController $editor = id(new PhabricatorConfigEditor()) ->setActor($user) ->setContinueOnNoEffect(true) - ->setContentSource( - PhabricatorContentSource::newForSource( - PhabricatorContentSource::SOURCE_WEB, - array( - 'ip' => $request->getRemoteAddr(), - ))); + ->setContentSourceFromRequest($request); try { $editor->applyTransactions($config_entry, array($xaction)); diff --git a/src/applications/config/editor/PhabricatorConfigEditor.php b/src/applications/config/editor/PhabricatorConfigEditor.php index 2468e9eb79..48533de047 100644 --- a/src/applications/config/editor/PhabricatorConfigEditor.php +++ b/src/applications/config/editor/PhabricatorConfigEditor.php @@ -117,13 +117,7 @@ final class PhabricatorConfigEditor $editor = id(new PhabricatorConfigEditor()) ->setActor($request->getUser()) ->setContinueOnNoEffect(true) - ->setContentSource( - PhabricatorContentSource::newForSource( - PhabricatorContentSource::SOURCE_WEB, - array( - 'ip' => $request->getRemoteAddr(), - ))); - + ->setContentSourceFromRequest($request); $editor->applyTransactions($config_entry, array($xaction)); } diff --git a/src/applications/conpherence/controller/ConpherenceNewController.php b/src/applications/conpherence/controller/ConpherenceNewController.php index 83b3c8af7f..7c9d553cba 100644 --- a/src/applications/conpherence/controller/ConpherenceNewController.php +++ b/src/applications/conpherence/controller/ConpherenceNewController.php @@ -73,13 +73,9 @@ final class ConpherenceNewController extends ConpherenceController { id(new ConpherenceTransactionComment()) ->setContent($message) ->setConpherencePHID($conpherence->getPHID())); - $content_source = PhabricatorContentSource::newForSource( - PhabricatorContentSource::SOURCE_WEB, - array( - 'ip' => $request->getRemoteAddr() - )); + id(new ConpherenceEditor()) - ->setContentSource($content_source) + ->setContentSourceFromRequest($request) ->setContinueOnNoEffect(true) ->setActor($user) ->applyTransactions($conpherence, $xactions); diff --git a/src/applications/conpherence/controller/ConpherenceUpdateController.php b/src/applications/conpherence/controller/ConpherenceUpdateController.php index 889e635602..06116f2527 100644 --- a/src/applications/conpherence/controller/ConpherenceUpdateController.php +++ b/src/applications/conpherence/controller/ConpherenceUpdateController.php @@ -40,14 +40,9 @@ final class ConpherenceUpdateController $e_file = array(); $errors = array(); if ($request->isFormPost()) { - $content_source = PhabricatorContentSource::newForSource( - PhabricatorContentSource::SOURCE_WEB, - array( - 'ip' => $request->getRemoteAddr() - )); $editor = id(new ConpherenceEditor()) ->setContinueOnNoEffect($request->isContinueRequest()) - ->setContentSource($content_source) + ->setContentSourceFromRequest($request) ->setActor($user); switch ($action) { diff --git a/src/applications/macro/controller/PhabricatorMacroCommentController.php b/src/applications/macro/controller/PhabricatorMacroCommentController.php index bccc40c65c..3d40791c1d 100644 --- a/src/applications/macro/controller/PhabricatorMacroCommentController.php +++ b/src/applications/macro/controller/PhabricatorMacroCommentController.php @@ -40,12 +40,7 @@ final class PhabricatorMacroCommentController $editor = id(new PhabricatorMacroEditor()) ->setActor($user) ->setContinueOnNoEffect($request->isContinueRequest()) - ->setContentSource( - PhabricatorContentSource::newForSource( - PhabricatorContentSource::SOURCE_WEB, - array( - 'ip' => $request->getRemoteAddr(), - ))) + ->setContentSourceFromRequest($request) ->setIsPreview($is_preview); try { diff --git a/src/applications/macro/controller/PhabricatorMacroDisableController.php b/src/applications/macro/controller/PhabricatorMacroDisableController.php index a0f386afe8..ef9076688d 100644 --- a/src/applications/macro/controller/PhabricatorMacroDisableController.php +++ b/src/applications/macro/controller/PhabricatorMacroDisableController.php @@ -35,12 +35,7 @@ final class PhabricatorMacroDisableController $editor = id(new PhabricatorMacroEditor()) ->setActor($user) - ->setContentSource( - PhabricatorContentSource::newForSource( - PhabricatorContentSource::SOURCE_WEB, - array( - 'ip' => $request->getRemoteAddr(), - ))); + ->setContentSourceFromRequest($request); $xactions = $editor->applyTransactions($macro, array($xaction)); diff --git a/src/applications/macro/controller/PhabricatorMacroEditController.php b/src/applications/macro/controller/PhabricatorMacroEditController.php index be3ebc6ab9..d7130f191c 100644 --- a/src/applications/macro/controller/PhabricatorMacroEditController.php +++ b/src/applications/macro/controller/PhabricatorMacroEditController.php @@ -118,12 +118,7 @@ final class PhabricatorMacroEditController $editor = id(new PhabricatorMacroEditor()) ->setActor($user) ->setContinueOnNoEffect(true) - ->setContentSource( - PhabricatorContentSource::newForSource( - PhabricatorContentSource::SOURCE_WEB, - array( - 'ip' => $request->getRemoteAddr(), - ))); + ->setContentSourceFromRequest($request); $xactions = $editor->applyTransactions($original, $xactions); diff --git a/src/applications/metamta/contentsource/PhabricatorContentSource.php b/src/applications/metamta/contentsource/PhabricatorContentSource.php index aae5d4291d..414016fbcc 100644 --- a/src/applications/metamta/contentsource/PhabricatorContentSource.php +++ b/src/applications/metamta/contentsource/PhabricatorContentSource.php @@ -38,6 +38,14 @@ final class PhabricatorContentSource { return $obj; } + public static function newFromRequest(AphrontRequest $request) { + return self::newForSource( + PhabricatorContentSource::SOURCE_WEB, + array( + 'ip' => $request->getRemoteAddr(), + )); + } + public function serialize() { return json_encode(array( 'source' => $this->getSource(), diff --git a/src/applications/phlux/controller/PhluxEditController.php b/src/applications/phlux/controller/PhluxEditController.php index f6efd6f156..93f5afa7bc 100644 --- a/src/applications/phlux/controller/PhluxEditController.php +++ b/src/applications/phlux/controller/PhluxEditController.php @@ -69,12 +69,7 @@ final class PhluxEditController extends PhluxController { $editor = id(new PhluxVariableEditor()) ->setActor($user) ->setContinueOnNoEffect(true) - ->setContentSource( - PhabricatorContentSource::newForSource( - PhabricatorContentSource::SOURCE_WEB, - array( - 'ip' => $request->getRemoteAddr(), - ))); + ->setContentSourceFromRequest($request); $xactions = array(); $xactions[] = id(new PhluxTransaction()) diff --git a/src/applications/pholio/controller/PholioInlineSaveController.php b/src/applications/pholio/controller/PholioInlineSaveController.php index 54fda6cbd3..300e39be70 100644 --- a/src/applications/pholio/controller/PholioInlineSaveController.php +++ b/src/applications/pholio/controller/PholioInlineSaveController.php @@ -42,14 +42,7 @@ final class PholioInlineSaveController extends PholioController { $draft->setAuthorPHID($user->getPHID()); $draft->setEditPolicy($user->getPHID()); $draft->setViewPolicy(PhabricatorPolicies::POLICY_PUBLIC); - - $content_source = PhabricatorContentSource::newForSource( - PhabricatorContentSource::SOURCE_WEB, - array( - 'ip' => $request->getRemoteAddr(), - )); - - $draft->setContentSource($content_source); + $draft->setContentSourceFromRequest($request); $draft->setWidth($request->getInt('endX') - $request->getInt('startX')); $draft->setHeight($request->getInt('endY') - $request->getInt('startY')); diff --git a/src/applications/pholio/controller/PholioMockCommentController.php b/src/applications/pholio/controller/PholioMockCommentController.php index af0b1b6e73..3fd514205e 100644 --- a/src/applications/pholio/controller/PholioMockCommentController.php +++ b/src/applications/pholio/controller/PholioMockCommentController.php @@ -37,12 +37,6 @@ final class PholioMockCommentController extends PholioController { $comment = $request->getStr('comment'); - $content_source = PhabricatorContentSource::newForSource( - PhabricatorContentSource::SOURCE_WEB, - array( - 'ip' => $request->getRemoteAddr(), - )); - $xactions = array(); $inline_comments = id(new PholioTransactionComment())->loadAllWhere( @@ -66,7 +60,7 @@ final class PholioMockCommentController extends PholioController { $editor = id(new PholioMockEditor()) ->setActor($user) - ->setContentSource($content_source) + ->setContentSourceFromRequest($request) ->setContinueOnNoEffect($request->isContinueRequest()) ->setIsPreview($is_preview); diff --git a/src/applications/pholio/controller/PholioMockEditController.php b/src/applications/pholio/controller/PholioMockEditController.php index 571a40feee..cc6453d7a0 100644 --- a/src/applications/pholio/controller/PholioMockEditController.php +++ b/src/applications/pholio/controller/PholioMockEditController.php @@ -110,12 +110,6 @@ final class PholioMockEditController extends PholioController { } if (!$errors) { - $content_source = PhabricatorContentSource::newForSource( - PhabricatorContentSource::SOURCE_WEB, - array( - 'ip' => $request->getRemoteAddr(), - )); - foreach ($xactions as $type => $value) { $xactions[$type] = id(new PholioTransaction()) ->setTransactionType($type) @@ -124,7 +118,7 @@ final class PholioMockEditController extends PholioController { $mock->openTransaction(); $editor = id(new PholioMockEditor()) - ->setContentSource($content_source) + ->setContentSourceFromRequest($request) ->setContinueOnNoEffect(true) ->setActor($user); diff --git a/src/applications/phortune/controller/PhortuneController.php b/src/applications/phortune/controller/PhortuneController.php index 70c0d44e93..c11ddb3326 100644 --- a/src/applications/phortune/controller/PhortuneController.php +++ b/src/applications/phortune/controller/PhortuneController.php @@ -39,12 +39,7 @@ abstract class PhortuneController extends PhabricatorController { $editor = id(new PhortuneAccountEditor()) ->setActor($user) - ->setContentSource( - PhabricatorContentSource::newForSource( - PhabricatorContentSource::SOURCE_WEB, - array( - 'ip' => $request->getRemoteAddr(), - ))); + ->setContentSourceFromRequest($request); // We create an account for you the first time you visit Phortune. $unguarded = AphrontWriteGuard::beginScopedUnguardedWrites(); diff --git a/src/applications/releeph/controller/request/ReleephRequestActionController.php b/src/applications/releeph/controller/request/ReleephRequestActionController.php index 1c9daea570..64e1945e06 100644 --- a/src/applications/releeph/controller/request/ReleephRequestActionController.php +++ b/src/applications/releeph/controller/request/ReleephRequestActionController.php @@ -28,12 +28,7 @@ final class ReleephRequestActionController extends ReleephController { $editor = id(new ReleephRequestTransactionalEditor()) ->setActor($user) ->setContinueOnNoEffect(true) - ->setContentSource( - PhabricatorContentSource::newForSource( - PhabricatorContentSource::SOURCE_WEB, - array( - 'ip' => $request->getRemoteAddr(), - ))); + ->setContentSourceFromRequest($request); $xactions = array(); diff --git a/src/applications/releeph/controller/request/ReleephRequestCommentController.php b/src/applications/releeph/controller/request/ReleephRequestCommentController.php index 09e1f6186c..bcb16b9808 100644 --- a/src/applications/releeph/controller/request/ReleephRequestCommentController.php +++ b/src/applications/releeph/controller/request/ReleephRequestCommentController.php @@ -28,12 +28,7 @@ final class ReleephRequestCommentController $editor = id(new ReleephRequestTransactionalEditor()) ->setActor($user) ->setContinueOnNoEffect($request->isContinueRequest()) - ->setContentSource( - PhabricatorContentSource::newForSource( - PhabricatorContentSource::SOURCE_WEB, - array( - 'ip' => $request->getRemoteAddr(), - ))) + ->setContentSourceFromRequest($request) ->setIsPreview($is_preview); try { diff --git a/src/applications/releeph/controller/request/ReleephRequestEditController.php b/src/applications/releeph/controller/request/ReleephRequestEditController.php index 95775d2bcd..e53ac2955f 100644 --- a/src/applications/releeph/controller/request/ReleephRequestEditController.php +++ b/src/applications/releeph/controller/request/ReleephRequestEditController.php @@ -140,12 +140,7 @@ final class ReleephRequestEditController extends ReleephController { $editor = id(new ReleephRequestTransactionalEditor()) ->setActor($user) ->setContinueOnNoEffect(true) - ->setContentSource( - PhabricatorContentSource::newForSource( - PhabricatorContentSource::SOURCE_WEB, - array( - 'ip' => $request->getRemoteAddr(), - ))); + ->setContentSourceFromRequest($request); $editor->applyTransactions($rq, $xactions); return id(new AphrontRedirectResponse())->setURI($origin_uri); } diff --git a/src/applications/subscriptions/controller/PhabricatorSubscriptionsEditController.php b/src/applications/subscriptions/controller/PhabricatorSubscriptionsEditController.php index e3f5824374..ace77ff978 100644 --- a/src/applications/subscriptions/controller/PhabricatorSubscriptionsEditController.php +++ b/src/applications/subscriptions/controller/PhabricatorSubscriptionsEditController.php @@ -76,12 +76,7 @@ final class PhabricatorSubscriptionsEditController $editor = id($object->getApplicationTransactionEditor()) ->setActor($user) ->setContinueOnNoEffect(true) - ->setContentSource( - PhabricatorContentSource::newForSource( - PhabricatorContentSource::SOURCE_WEB, - array( - 'ip' => $request->getRemoteAddr(), - ))); + ->setContentSourceFromRequest($request); $editor->applyTransactions($object, array($xaction)); } else { diff --git a/src/applications/transactions/controller/PhabricatorApplicationTransactionCommentEditController.php b/src/applications/transactions/controller/PhabricatorApplicationTransactionCommentEditController.php index f89e274b5c..022b482caf 100644 --- a/src/applications/transactions/controller/PhabricatorApplicationTransactionCommentEditController.php +++ b/src/applications/transactions/controller/PhabricatorApplicationTransactionCommentEditController.php @@ -49,12 +49,7 @@ final class PhabricatorApplicationTransactionCommentEditController $editor = id(new PhabricatorApplicationTransactionCommentEditor()) ->setActor($user) - ->setContentSource( - $content_source = PhabricatorContentSource::newForSource( - PhabricatorContentSource::SOURCE_WEB, - array( - 'ip' => $request->getRemoteAddr(), - ))) + ->setContentSourceFromRequest($request) ->applyEdit($xaction, $comment); if ($request->isAjax()) { diff --git a/src/applications/transactions/storage/PhabricatorApplicationTransactionComment.php b/src/applications/transactions/storage/PhabricatorApplicationTransactionComment.php index 7b526f7758..818beb9c4d 100644 --- a/src/applications/transactions/storage/PhabricatorApplicationTransactionComment.php +++ b/src/applications/transactions/storage/PhabricatorApplicationTransactionComment.php @@ -47,6 +47,11 @@ abstract class PhabricatorApplicationTransactionComment return $this; } + public function setContentSourceFromRequest(AphrontRequest $request) { + return $this->setContentSource( + PhabricatorContentSource::newFromRequest($request)); + } + public function getContentSource() { return PhabricatorContentSource::newFromSerialized($this->contentSource); }