1
0
Fork 0
mirror of https://we.phorge.it/source/phorge.git synced 2025-01-19 03:01:11 +01:00

Remove Controller->getHandle() and Controller->loadHandles()

Summary: Ref T7689. Modernize all callsites of these methods.

Test Plan:
- Poked at dashboards.
  - Pretty sure this code is technically unreachable right now.
- Viewed commit; viewed "Audit Status".
- Viewed a fund; viewed "Payable to"; viewed "Owner".
- Viewed herald rules; viewed "Author"; viewed "Applies To".
- Viewed a Legalpad document; viewed "Contributors".
- Viewed Phame post list; viewed blog; viewed post (viewed "Blog", viewed "Blogger").
- Viewed a macro; viewed "Audio".
- Viewed a Phriction page; viewed "Last Author".
- Viewed a Ponder question; viewed "Author".
- Viewed a Ponder answer; viewed header.
  - Behavior changed very slightly here; whatevs.
- Viewed a Countdown; viewed "Author".

Reviewers: btrahan

Reviewed By: btrahan

Subscribers: epriestley

Maniphest Tasks: T7689

Differential Revision: https://secure.phabricator.com/D12210
This commit is contained in:
epriestley 2015-03-30 07:55:33 -07:00
parent 0f52fc771d
commit 64dddc76c5
19 changed files with 41 additions and 111 deletions

View file

@ -3142,7 +3142,6 @@ phutil_register_library_map(array(
'function' => array( 'function' => array(
'celerity_generate_unique_node_id' => 'applications/celerity/api.php', 'celerity_generate_unique_node_id' => 'applications/celerity/api.php',
'celerity_get_resource_uri' => 'applications/celerity/api.php', 'celerity_get_resource_uri' => 'applications/celerity/api.php',
'implode_selected_handle_links' => 'applications/phid/handle/view/render.php',
'javelin_tag' => 'infrastructure/javelin/markup.php', 'javelin_tag' => 'infrastructure/javelin/markup.php',
'phabricator_date' => 'view/viewutils.php', 'phabricator_date' => 'view/viewutils.php',
'phabricator_datetime' => 'view/viewutils.php', 'phabricator_datetime' => 'view/viewutils.php',

View file

@ -426,20 +426,6 @@ abstract class PhabricatorController extends AphrontController {
return $response; return $response;
} }
protected function getHandle($phid) {
if (empty($this->handles[$phid])) {
throw new Exception(
"Attempting to access handle which wasn't loaded: {$phid}");
}
return $this->handles[$phid];
}
protected function loadHandles(array $phids) {
$phids = array_filter($phids);
$this->handles = $this->loadViewerHandles($phids);
return $this;
}
protected function loadViewerHandles(array $phids) { protected function loadViewerHandles(array $phids) {
return id(new PhabricatorHandleQuery()) return id(new PhabricatorHandleQuery())
->setViewer($this->getRequest()->getUser()) ->setViewer($this->getRequest()->getUser())

View file

@ -101,7 +101,6 @@ final class PhabricatorCountdownViewController
PhabricatorActionListView $actions) { PhabricatorActionListView $actions) {
$viewer = $this->getViewer(); $viewer = $this->getViewer();
$handles = $viewer->loadHandles(array($countdown->getAuthorPHID()));
$view = id(new PHUIPropertyListView()) $view = id(new PHUIPropertyListView())
->setUser($viewer) ->setUser($viewer)
@ -109,7 +108,7 @@ final class PhabricatorCountdownViewController
$view->addProperty( $view->addProperty(
pht('Author'), pht('Author'),
$handles[$countdown->getAuthorPHID()]->renderLink()); $viewer->renderHandle($countdown->getAuthorPHID()));
return $view; return $view;
} }

View file

@ -50,11 +50,6 @@ final class PhabricatorDashboardInstallController
'applicationClass', 'applicationClass',
'PhabricatorHomeApplication'); 'PhabricatorHomeApplication');
$handles = $this->loadHandles(array(
$object_phid,
$installer_phid,
));
if ($request->isFormPost()) { if ($request->isFormPost()) {
$dashboard_install = id(new PhabricatorDashboardInstall()) $dashboard_install = id(new PhabricatorDashboardInstall())
->loadOneWhere( ->loadOneWhere(
@ -121,7 +116,7 @@ final class PhabricatorDashboardInstallController
phutil_tag( phutil_tag(
'strong', 'strong',
array(), array(),
$this->getHandle($object_phid)->getName()))); $viewer->renderHandle($object_phid))));
} }
break; break;
default: default:

View file

@ -53,7 +53,6 @@ final class PhabricatorDashboardUninstallController
} }
$installer_phid = $viewer->getPHID(); $installer_phid = $viewer->getPHID();
$handles = $this->loadHandles(array($object_phid, $installer_phid));
if ($request->isFormPost()) { if ($request->isFormPost()) {
$dashboard_install->delete(); $dashboard_install->delete();
@ -83,6 +82,8 @@ final class PhabricatorDashboardUninstallController
$object_phid, $object_phid,
$installer_phid) { $installer_phid) {
$viewer = $this->getViewer();
$body = array(); $body = array();
switch ($application_class) { switch ($application_class) {
case 'PhabricatorHomeApplication': case 'PhabricatorHomeApplication':
@ -106,7 +107,7 @@ final class PhabricatorDashboardUninstallController
pht( pht(
'Are you sure you want to uninstall this dashboard as the home '. 'Are you sure you want to uninstall this dashboard as the home '.
'page for %s?', 'page for %s?',
$this->getHandle($object_phid)->getName())); $viewer->renderHandle($object_phid)));
} }
break; break;
} }

View file

@ -1021,9 +1021,7 @@ final class DiffusionCommitController extends DiffusionController {
private function renderAuditStatusView(array $audit_requests) { private function renderAuditStatusView(array $audit_requests) {
assert_instances_of($audit_requests, 'PhabricatorRepositoryAuditRequest'); assert_instances_of($audit_requests, 'PhabricatorRepositoryAuditRequest');
$viewer = $this->getViewer();
$phids = mpull($audit_requests, 'getAuditorPHID');
$this->loadHandles($phids);
$authority_map = array_fill_keys($this->auditAuthorityPHIDs, true); $authority_map = array_fill_keys($this->auditAuthorityPHIDs, true);
@ -1043,7 +1041,7 @@ final class DiffusionCommitController extends DiffusionController {
$item->setNote($note); $item->setNote($note);
$auditor_phid = $request->getAuditorPHID(); $auditor_phid = $request->getAuditorPHID();
$target = $this->getHandle($auditor_phid)->renderLink(); $target = $viewer->renderHandle($auditor_phid);
$item->setTarget($target); $item->setTarget($target);
if (isset($authority_map[$auditor_phid])) { if (isset($authority_map[$auditor_phid])) {

View file

@ -70,9 +70,6 @@ final class DiffusionPushEventViewController
private function buildPropertyList(PhabricatorRepositoryPushEvent $event) { private function buildPropertyList(PhabricatorRepositoryPushEvent $event) {
$viewer = $this->getRequest()->getUser(); $viewer = $this->getRequest()->getUser();
$this->loadHandles(array($event->getPusherPHID()));
$view = new PHUIPropertyListView(); $view = new PHUIPropertyListView();
$view->addProperty( $view->addProperty(
@ -81,7 +78,7 @@ final class DiffusionPushEventViewController
$view->addProperty( $view->addProperty(
pht('Pushed By'), pht('Pushed By'),
$this->getHandle($event->getPusherPHID())->renderLink()); $viewer->renderHandle($event->getPusherPHID()));
$view->addProperty( $view->addProperty(
pht('Pushed Via'), pht('Pushed Via'),

View file

@ -87,19 +87,14 @@ final class FundInitiativeViewController
$owner_phid = $initiative->getOwnerPHID(); $owner_phid = $initiative->getOwnerPHID();
$merchant_phid = $initiative->getMerchantPHID(); $merchant_phid = $initiative->getMerchantPHID();
$this->loadHandles(
array(
$owner_phid,
$merchant_phid,
));
$view->addProperty( $view->addProperty(
pht('Owner'), pht('Owner'),
$this->getHandle($owner_phid)->renderLink()); $viewer->renderHandle($owner_phid));
$view->addProperty( $view->addProperty(
pht('Payable to Merchant'), pht('Payable to Merchant'),
$this->getHandle($merchant_phid)->renderLink()); $viewer->renderHandle($merchant_phid));
$view->addProperty( $view->addProperty(
pht('Total Funding'), pht('Total Funding'),

View file

@ -115,8 +115,6 @@ final class HeraldRuleViewController extends HeraldController {
$viewer = $this->getRequest()->getUser(); $viewer = $this->getRequest()->getUser();
$handles = $viewer->loadHandles(HeraldAdapter::getHandlePHIDs($rule));
$view = id(new PHUIPropertyListView()) $view = id(new PHUIPropertyListView())
->setUser($viewer) ->setUser($viewer)
->setObject($rule) ->setObject($rule)
@ -129,10 +127,9 @@ final class HeraldRuleViewController extends HeraldController {
if ($rule->isPersonalRule()) { if ($rule->isPersonalRule()) {
$view->addProperty( $view->addProperty(
pht('Author'), pht('Author'),
$this->getHandle($rule->getAuthorPHID())->renderLink()); $viewer->renderHandle($rule->getAuthorPHID()));
} }
$adapter = HeraldAdapter::getAdapterForContentType($rule->getContentType()); $adapter = HeraldAdapter::getAdapterForContentType($rule->getContentType());
if ($adapter) { if ($adapter) {
$view->addProperty( $view->addProperty(
@ -144,7 +141,7 @@ final class HeraldRuleViewController extends HeraldController {
if ($rule->isObjectRule()) { if ($rule->isObjectRule()) {
$view->addProperty( $view->addProperty(
pht('Trigger Object'), pht('Trigger Object'),
$this->getHandle($rule->getTriggerObjectPHID())->renderLink()); $viewer->renderHandle($rule->getTriggerObjectPHID()));
} }
$view->invokeWillRenderEvent(); $view->invokeWillRenderEvent();
@ -153,6 +150,7 @@ final class HeraldRuleViewController extends HeraldController {
pht('Rule Description'), pht('Rule Description'),
PHUIPropertyListView::ICON_SUMMARY); PHUIPropertyListView::ICON_SUMMARY);
$handles = $viewer->loadHandles(HeraldAdapter::getHandlePHIDs($rule));
$view->addTextContent($adapter->renderRuleAsText($rule, $handles)); $view->addTextContent($adapter->renderRuleAsText($rule, $handles));
} }

View file

@ -33,15 +33,6 @@ final class LegalpadDocumentManageController extends LegalpadController {
$document->getPHID()); $document->getPHID());
$document_body = $document->getDocumentBody(); $document_body = $document->getDocumentBody();
$phids = array();
$phids[] = $document_body->getCreatorPHID();
foreach ($subscribers as $subscriber) {
$phids[] = $subscriber;
}
foreach ($document->getContributors() as $contributor) {
$phids[] = $contributor;
}
$this->loadHandles($phids);
$engine = id(new PhabricatorMarkupEngine()) $engine = id(new PhabricatorMarkupEngine())
->setViewer($user); ->setViewer($user);
@ -167,21 +158,19 @@ final class LegalpadDocumentManageController extends LegalpadController {
$properties->addProperty( $properties->addProperty(
pht('Updated By'), pht('Updated By'),
$this->getHandle( $user->renderHandle($document->getDocumentBody()->getCreatorPHID()));
$document->getDocumentBody()->getCreatorPHID())->renderLink());
$properties->addProperty( $properties->addProperty(
pht('Versions'), pht('Versions'),
$document->getVersions()); $document->getVersions());
$contributor_view = array(); if ($document->getContributors()) {
foreach ($document->getContributors() as $contributor) { $properties->addProperty(
$contributor_view[] = $this->getHandle($contributor)->renderLink(); pht('Contributors'),
$user
->renderHandleList($document->getContributors())
->setAsInline(true));
} }
$contributor_view = phutil_implode_html(', ', $contributor_view);
$properties->addProperty(
pht('Contributors'),
$contributor_view);
$properties->invokeWillRenderEvent(); $properties->invokeWillRenderEvent();

View file

@ -150,6 +150,7 @@ final class PhabricatorMacroViewController
private function buildPropertyView( private function buildPropertyView(
PhabricatorFileImageMacro $macro, PhabricatorFileImageMacro $macro,
PhabricatorActionListView $actions) { PhabricatorActionListView $actions) {
$viewer = $this->getViewer();
$view = id(new PHUIPropertyListView()) $view = id(new PHUIPropertyListView())
->setUser($this->getRequest()->getUser()) ->setUser($this->getRequest()->getUser())
@ -167,10 +168,9 @@ final class PhabricatorMacroViewController
$audio_phid = $macro->getAudioPHID(); $audio_phid = $macro->getAudioPHID();
if ($audio_phid) { if ($audio_phid) {
$this->loadHandles(array($audio_phid));
$view->addProperty( $view->addProperty(
pht('Audio'), pht('Audio'),
$this->getHandle($audio_phid)->renderLink()); $viewer->renderHandle($audio_phid));
} }
$view->invokeWillRenderEvent(); $view->invokeWillRenderEvent();

View file

@ -58,14 +58,6 @@ final class PhabricatorPasteViewController extends PhabricatorPasteController {
->execute(); ->execute();
$fork_phids = mpull($forks, 'getPHID'); $fork_phids = mpull($forks, 'getPHID');
$this->loadHandles(
array_merge(
array(
$paste->getAuthorPHID(),
$paste->getParentPHID(),
),
$fork_phids));
$header = $this->buildHeaderView($paste); $header = $this->buildHeaderView($paste);
$actions = $this->buildActionView($user, $paste, $file); $actions = $this->buildActionView($user, $paste, $file);
$properties = $this->buildPropertyView($paste, $fork_phids, $actions); $properties = $this->buildPropertyView($paste, $fork_phids, $actions);

View file

@ -33,16 +33,24 @@ abstract class PhameController extends PhabricatorController {
$nodata) { $nodata) {
assert_instances_of($posts, 'PhamePost'); assert_instances_of($posts, 'PhamePost');
$stories = array(); $handle_phids = array();
foreach ($posts as $post) { foreach ($posts as $post) {
$blogger = $this->getHandle($post->getBloggerPHID())->renderLink(); $handle_phids[] = $post->getBloggerPHID();
$blogger_uri = $this->getHandle($post->getBloggerPHID())->getURI(); if ($post->getBlog()) {
$blogger_image = $this->getHandle($post->getBloggerPHID())->getImageURI(); $handle_phids[] = $post->getBlog()->getPHID();
}
}
$handles = $viewer->loadHandles($handle_phids);
$stories = array();
foreach ($posts as $post) {
$blogger = $handles[$post->getBloggerPHID()]->renderLink();
$blogger_uri = $handles[$post->getBloggerPHID()]->getURI();
$blogger_image = $handles[$post->getBloggerPHID()]->getImageURI();
$blog = null; $blog = null;
if ($post->getBlog()) { if ($post->getBlog()) {
$blog = $this->getHandle($post->getBlog()->getPHID())->renderLink(); $blog = $handles[$post->getBlog()->getPHID()]->renderLink();
} }
$phame_post = ''; $phame_post = '';

View file

@ -35,11 +35,6 @@ final class PhameBlogViewController extends PhameController {
->setUser($user) ->setUser($user)
->setPolicyObject($blog); ->setPolicyObject($blog);
$handle_phids = array_merge(
mpull($posts, 'getBloggerPHID'),
mpull($posts, 'getBlogPHID'));
$this->loadHandles($handle_phids);
$actions = $this->renderActions($blog, $user); $actions = $this->renderActions($blog, $user);
$properties = $this->renderProperties($blog, $user, $actions); $properties = $this->renderProperties($blog, $user, $actions);
$post_list = $this->renderPostList( $post_list = $this->renderPostList(

View file

@ -62,11 +62,6 @@ final class PhamePostListController extends PhameController {
$posts = $query->executeWithCursorPager($pager); $posts = $query->executeWithCursorPager($pager);
$handle_phids = array_merge(
mpull($posts, 'getBloggerPHID'),
mpull($posts, 'getBlogPHID'));
$this->loadHandles($handle_phids);
require_celerity_resource('phame-css'); require_celerity_resource('phame-css');
$post_list = $this->renderPostList($posts, $user, $nodata); $post_list = $this->renderPostList($posts, $user, $nodata);
$post_list = id(new PHUIBoxView()) $post_list = id(new PHUIBoxView())

View file

@ -23,11 +23,6 @@ final class PhamePostViewController extends PhameController {
$nav = $this->renderSideNavFilterView(); $nav = $this->renderSideNavFilterView();
$this->loadHandles(
array(
$post->getBlogPHID(),
$post->getBloggerPHID(),
));
$actions = $this->renderActions($post, $user); $actions = $this->renderActions($post, $user);
$properties = $this->renderProperties($post, $user, $actions); $properties = $this->renderProperties($post, $user, $actions);
@ -168,13 +163,11 @@ final class PhamePostViewController extends PhameController {
$properties->addProperty( $properties->addProperty(
pht('Blog'), pht('Blog'),
$post->getBlogPHID() $user->renderHandle($post->getBlogPHID()));
? $this->getHandle($post->getBlogPHID())->renderLink()
: null);
$properties->addProperty( $properties->addProperty(
pht('Blogger'), pht('Blogger'),
$this->getHandle($post->getBloggerPHID())->renderLink()); $user->renderHandle($post->getBloggerPHID()));
$properties->addProperty( $properties->addProperty(
pht('Published'), pht('Published'),

View file

@ -35,7 +35,6 @@ final class PhortuneAccountListController extends PhortuneController {
'accounts are used to make purchases.')); 'accounts are used to make purchases.'));
foreach ($accounts as $account) { foreach ($accounts as $account) {
$this->loadHandles($account->getMemberPHIDs());
$item = id(new PHUIObjectItemView()) $item = id(new PHUIObjectItemView())
->setObjectName(pht('Account %d', $account->getID())) ->setObjectName(pht('Account %d', $account->getID()))
->setHeader($account->getName()) ->setHeader($account->getName())

View file

@ -250,13 +250,9 @@ final class PhrictionDocumentController
->setUser($viewer) ->setUser($viewer)
->setObject($document); ->setObject($document);
$phids = array($content->getAuthorPHID());
$this->loadHandles($phids);
$view->addProperty( $view->addProperty(
pht('Last Author'), pht('Last Author'),
$this->getHandle($content->getAuthorPHID())->renderLink()); $viewer->renderHandle($content->getAuthorPHID()));
$age = time() - $content->getDateCreated(); $age = time() - $content->getDateCreated();
$age = floor($age / (60 * 60 * 24)); $age = floor($age / (60 * 60 * 24));

View file

@ -141,15 +141,13 @@ final class PonderQuestionViewController extends PonderController {
->setObject($question) ->setObject($question)
->setActionList($actions); ->setActionList($actions);
$this->loadHandles(array($question->getAuthorPHID()));
$view->addProperty( $view->addProperty(
pht('Status'), pht('Status'),
PonderQuestionStatus::getQuestionStatusFullName($question->getStatus())); PonderQuestionStatus::getQuestionStatusFullName($question->getStatus()));
$view->addProperty( $view->addProperty(
pht('Author'), pht('Author'),
$this->getHandle($question->getAuthorPHID())->renderLink()); $viewer->renderHandle($question->getAuthorPHID()));
$view->addProperty( $view->addProperty(
pht('Created'), pht('Created'),
@ -221,9 +219,6 @@ final class PonderQuestionViewController extends PonderController {
$out = array(); $out = array();
$phids = mpull($answers, 'getAuthorPHID');
$this->loadHandles($phids);
$xactions = id(new PonderAnswerTransactionQuery()) $xactions = id(new PonderAnswerTransactionQuery())
->setViewer($viewer) ->setViewer($viewer)
->withTransactionTypes(array(PhabricatorTransactions::TYPE_COMMENT)) ->withTransactionTypes(array(PhabricatorTransactions::TYPE_COMMENT))
@ -253,7 +248,7 @@ final class PonderQuestionViewController extends PonderController {
$out[] = id(new PhabricatorAnchorView()) $out[] = id(new PhabricatorAnchorView())
->setAnchorName("A$id"); ->setAnchorName("A$id");
$header = id(new PHUIHeaderView()) $header = id(new PHUIHeaderView())
->setHeader($this->getHandle($author_phid)->getFullName()); ->setHeader($viewer->renderHandle($author_phid));
$actions = $this->buildAnswerActions($answer); $actions = $this->buildAnswerActions($answer);
$properties = $this->buildAnswerProperties($answer, $actions); $properties = $this->buildAnswerProperties($answer, $actions);