From adeefa940f29ef081d5fe917ed9d8682bba7f2a8 Mon Sep 17 00:00:00 2001 From: epriestley Date: Wed, 24 Jul 2013 14:06:10 -0700 Subject: [PATCH] Use application PHIDs in Macro Summary: Ref T2715. Move Macro to application PHIDs. Test Plan: Used `conduit.query` to look up macros. Reviewers: btrahan Reviewed By: btrahan CC: aran Maniphest Tasks: T2715 Differential Revision: https://secure.phabricator.com/D6556 --- src/__phutil_library_map__.php | 2 + .../phid/PhabricatorMacroPHIDTypeMacro.php | 50 +++++++++++++++++++ .../storage/PhabricatorFileImageMacro.php | 2 +- .../storage/PhabricatorMacroTransaction.php | 2 +- .../phid/PhabricatorObjectHandle.php | 1 - .../phid/PhabricatorPHIDConstants.php | 1 - .../handle/PhabricatorObjectHandleData.php | 27 +--------- .../edges/constants/PhabricatorEdgeConfig.php | 1 - src/view/phui/PHUIFeedStoryView.php | 2 +- 9 files changed, 56 insertions(+), 32 deletions(-) create mode 100644 src/applications/macro/phid/PhabricatorMacroPHIDTypeMacro.php diff --git a/src/__phutil_library_map__.php b/src/__phutil_library_map__.php index 29018480cc..a6522345cc 100644 --- a/src/__phutil_library_map__.php +++ b/src/__phutil_library_map__.php @@ -1214,6 +1214,7 @@ phutil_register_library_map(array( 'PhabricatorMacroMailReceiver' => 'applications/macro/mail/PhabricatorMacroMailReceiver.php', 'PhabricatorMacroMemeController' => 'applications/macro/controller/PhabricatorMacroMemeController.php', 'PhabricatorMacroMemeDialogController' => 'applications/macro/controller/PhabricatorMacroMemeDialogController.php', + 'PhabricatorMacroPHIDTypeMacro' => 'applications/macro/phid/PhabricatorMacroPHIDTypeMacro.php', 'PhabricatorMacroQuery' => 'applications/macro/query/PhabricatorMacroQuery.php', 'PhabricatorMacroReplyHandler' => 'applications/macro/mail/PhabricatorMacroReplyHandler.php', 'PhabricatorMacroSearchEngine' => 'applications/macro/query/PhabricatorMacroSearchEngine.php', @@ -3227,6 +3228,7 @@ phutil_register_library_map(array( 'PhabricatorMacroMailReceiver' => 'PhabricatorObjectMailReceiver', 'PhabricatorMacroMemeController' => 'PhabricatorMacroController', 'PhabricatorMacroMemeDialogController' => 'PhabricatorMacroController', + 'PhabricatorMacroPHIDTypeMacro' => 'PhabricatorPHIDType', 'PhabricatorMacroQuery' => 'PhabricatorCursorPagedPolicyAwareQuery', 'PhabricatorMacroReplyHandler' => 'PhabricatorMailReplyHandler', 'PhabricatorMacroSearchEngine' => 'PhabricatorApplicationSearchEngine', diff --git a/src/applications/macro/phid/PhabricatorMacroPHIDTypeMacro.php b/src/applications/macro/phid/PhabricatorMacroPHIDTypeMacro.php new file mode 100644 index 0000000000..906ddcfafd --- /dev/null +++ b/src/applications/macro/phid/PhabricatorMacroPHIDTypeMacro.php @@ -0,0 +1,50 @@ +setViewer($query->getViewer()) + ->withPHIDs($phids) + ->execute(); + } + + public function loadHandles( + PhabricatorHandleQuery $query, + array $handles, + array $objects) { + + foreach ($handles as $phid => $handle) { + $macro = $objects[$phid]; + + $id = $macro->getID(); + $name = $macro->getName(); + + $handle->setName($name); + $handle->setFullName(pht('Image Macro "%s"', $name)); + $handle->setURI("/macro/view/{$id}/"); + } + } + + public function canLoadNamedObject($name) { + return false; + } + +} diff --git a/src/applications/macro/storage/PhabricatorFileImageMacro.php b/src/applications/macro/storage/PhabricatorFileImageMacro.php index e76a7e31a8..7fb8935b36 100644 --- a/src/applications/macro/storage/PhabricatorFileImageMacro.php +++ b/src/applications/macro/storage/PhabricatorFileImageMacro.php @@ -35,7 +35,7 @@ final class PhabricatorFileImageMacro extends PhabricatorFileDAO public function generatePHID() { return PhabricatorPHID::generateNewPHID( - PhabricatorPHIDConstants::PHID_TYPE_MCRO); + PhabricatorMacroPHIDTypeMacro::TYPECONST); } public function isAutomaticallySubscribed($phid) { diff --git a/src/applications/macro/storage/PhabricatorMacroTransaction.php b/src/applications/macro/storage/PhabricatorMacroTransaction.php index bd0ac70c49..bfac84cdd6 100644 --- a/src/applications/macro/storage/PhabricatorMacroTransaction.php +++ b/src/applications/macro/storage/PhabricatorMacroTransaction.php @@ -12,7 +12,7 @@ final class PhabricatorMacroTransaction } public function getApplicationTransactionType() { - return PhabricatorPHIDConstants::PHID_TYPE_MCRO; + return PhabricatorMacroPHIDTypeMacro::TYPECONST; } public function getApplicationTransactionCommentObject() { diff --git a/src/applications/phid/PhabricatorObjectHandle.php b/src/applications/phid/PhabricatorObjectHandle.php index 54c66c0363..de292cfd96 100644 --- a/src/applications/phid/PhabricatorObjectHandle.php +++ b/src/applications/phid/PhabricatorObjectHandle.php @@ -109,7 +109,6 @@ final class PhabricatorObjectHandle static $map = array( PhabricatorPHIDConstants::PHID_TYPE_USER => 'User', - PhabricatorPHIDConstants::PHID_TYPE_MCRO => 'Image Macro', PhabricatorPHIDConstants::PHID_TYPE_PIMG => 'Pholio Image', PhabricatorPHIDConstants::PHID_TYPE_BLOG => 'Blog', PhabricatorPHIDConstants::PHID_TYPE_POST => 'Post', diff --git a/src/applications/phid/PhabricatorPHIDConstants.php b/src/applications/phid/PhabricatorPHIDConstants.php index c9d9057f86..83c72e3a51 100644 --- a/src/applications/phid/PhabricatorPHIDConstants.php +++ b/src/applications/phid/PhabricatorPHIDConstants.php @@ -18,7 +18,6 @@ final class PhabricatorPHIDConstants { const PHID_TYPE_BLOG = 'BLOG'; const PHID_TYPE_ANSW = 'ANSW'; const PHID_TYPE_PIMG = 'PIMG'; - const PHID_TYPE_MCRO = 'MCRO'; const PHID_TYPE_CONP = 'CONP'; const PHID_TYPE_PVAR = 'PVAR'; const PHID_TYPE_ACNT = 'ACNT'; diff --git a/src/applications/phid/handle/PhabricatorObjectHandleData.php b/src/applications/phid/handle/PhabricatorObjectHandleData.php index c861b77c0a..66987464f9 100644 --- a/src/applications/phid/handle/PhabricatorObjectHandleData.php +++ b/src/applications/phid/handle/PhabricatorObjectHandleData.php @@ -89,7 +89,7 @@ final class PhabricatorObjectHandleData { ->execute(); $xactions += mpull($results, null, 'getPHID'); break; - case PhabricatorPHIDConstants::PHID_TYPE_MCRO: + case PhabricatorMacroPHIDTypeMacro::TYPECONST: $results = id(new PhabricatorMacroTransactionQuery()) ->setViewer($this->viewer) ->withPHIDs($subtype_phids) @@ -100,13 +100,6 @@ final class PhabricatorObjectHandleData { } return mpull($xactions, null, 'getPHID'); - case PhabricatorPHIDConstants::PHID_TYPE_MCRO: - $macros = id(new PhabricatorMacroQuery()) - ->setViewer($this->viewer) - ->withPHIDs($phids) - ->execute(); - return mpull($macros, null, 'getPHID'); - case PhabricatorPHIDConstants::PHID_TYPE_BLOG: $blogs = id(new PhameBlogQuery()) ->withPHIDs($phids) @@ -341,24 +334,6 @@ final class PhabricatorObjectHandleData { } break; - case PhabricatorPHIDConstants::PHID_TYPE_MCRO: - foreach ($phids as $phid) { - $handle = new PhabricatorObjectHandle(); - $handle->setPHID($phid); - $handle->setType($type); - if (empty($objects[$phid])) { - $handle->setName('Unknown Macro'); - } else { - $macro = $objects[$phid]; - $handle->setName($macro->getName()); - $handle->setFullName('Image Macro "'.$macro->getName().'"'); - $handle->setURI('/macro/view/'.$macro->getID().'/'); - $handle->setComplete(true); - } - $handles[$phid] = $handle; - } - break; - case PhabricatorPHIDConstants::PHID_TYPE_PVAR: foreach ($phids as $phid) { $handle = new PhabricatorObjectHandle(); diff --git a/src/infrastructure/edges/constants/PhabricatorEdgeConfig.php b/src/infrastructure/edges/constants/PhabricatorEdgeConfig.php index 6f63eeff20..ffeea89b41 100644 --- a/src/infrastructure/edges/constants/PhabricatorEdgeConfig.php +++ b/src/infrastructure/edges/constants/PhabricatorEdgeConfig.php @@ -159,7 +159,6 @@ final class PhabricatorEdgeConfig extends PhabricatorEdgeConstants { PhabricatorPHIDConstants::PHID_TYPE_BLOG => 'PhameBlog', PhabricatorPHIDConstants::PHID_TYPE_POST => 'PhamePost', PhabricatorPHIDConstants::PHID_TYPE_ANSW => 'PonderAnswer', - PhabricatorPHIDConstants::PHID_TYPE_MCRO => 'PhabricatorFileImageMacro', PhabricatorPHIDConstants::PHID_TYPE_CONP => 'ConpherenceThread', PhabricatorPHIDConstants::PHID_TYPE_ACNT => 'PhortuneAccount', PhabricatorPHIDConstants::PHID_TYPE_PRCH => 'PhortunePurchase', diff --git a/src/view/phui/PHUIFeedStoryView.php b/src/view/phui/PHUIFeedStoryView.php index 7d1a397fd0..1ed6f67e33 100644 --- a/src/view/phui/PHUIFeedStoryView.php +++ b/src/view/phui/PHUIFeedStoryView.php @@ -237,7 +237,7 @@ final class PHUIFeedStoryView extends AphrontView { case PholioPHIDTypeMock::TYPECONST: $this->setAppIcon("pholio-dark"); break; - case PhabricatorPHIDConstants::PHID_TYPE_MCRO: + case PhabricatorMacroPHIDTypeMacro::TYPECONST: $this->setAppIcon("macro-dark"); break; }