From 2ff57f6938a54e96cd910a14b650b4023ff32aa6 Mon Sep 17 00:00:00 2001 From: epriestley Date: Sun, 21 Jul 2013 12:40:51 -0700 Subject: [PATCH] Use application PHIDs in Pholio Mocks Summary: Ref T2715. Switch mocks to the new stuff. Test Plan: Used `phid.query` and `phid.lookup` to find mocks. Reviewers: btrahan Reviewed By: btrahan CC: aran Maniphest Tasks: T2715 Differential Revision: https://secure.phabricator.com/D6517 --- src/__phutil_library_map__.php | 2 + .../phid/PhabricatorObjectHandle.php | 1 - .../phid/PhabricatorPHIDConstants.php | 1 - .../handle/PhabricatorObjectHandleData.php | 27 +------ .../phid/storage/PhabricatorPHID.php | 8 -- .../pholio/phid/PholioPHIDTypeMock.php | 75 +++++++++++++++++++ .../pholio/storage/PholioTransaction.php | 2 +- .../PhabricatorSearchAttachController.php | 6 +- .../PhabricatorSearchSelectController.php | 6 +- .../edges/constants/PhabricatorEdgeConfig.php | 1 - src/view/phui/PHUIFeedStoryView.php | 2 +- 11 files changed, 86 insertions(+), 45 deletions(-) create mode 100644 src/applications/pholio/phid/PholioPHIDTypeMock.php diff --git a/src/__phutil_library_map__.php b/src/__phutil_library_map__.php index 79b5a3f93d..c63a3bd51d 100644 --- a/src/__phutil_library_map__.php +++ b/src/__phutil_library_map__.php @@ -1746,6 +1746,7 @@ phutil_register_library_map(array( 'PholioMockMailReceiver' => 'applications/pholio/mail/PholioMockMailReceiver.php', 'PholioMockQuery' => 'applications/pholio/query/PholioMockQuery.php', 'PholioMockViewController' => 'applications/pholio/controller/PholioMockViewController.php', + 'PholioPHIDTypeMock' => 'applications/pholio/phid/PholioPHIDTypeMock.php', 'PholioRemarkupRule' => 'applications/pholio/remarkup/PholioRemarkupRule.php', 'PholioReplyHandler' => 'applications/pholio/mail/PholioReplyHandler.php', 'PholioSearchIndexer' => 'applications/pholio/search/PholioSearchIndexer.php', @@ -3769,6 +3770,7 @@ phutil_register_library_map(array( 'PholioMockMailReceiver' => 'PhabricatorObjectMailReceiver', 'PholioMockQuery' => 'PhabricatorCursorPagedPolicyAwareQuery', 'PholioMockViewController' => 'PholioController', + 'PholioPHIDTypeMock' => 'PhabricatorPHIDType', 'PholioRemarkupRule' => 'PhabricatorRemarkupRuleObject', 'PholioReplyHandler' => 'PhabricatorMailReplyHandler', 'PholioSearchIndexer' => 'PhabricatorSearchDocumentIndexer', diff --git a/src/applications/phid/PhabricatorObjectHandle.php b/src/applications/phid/PhabricatorObjectHandle.php index bdb21c15cc..015e3408f9 100644 --- a/src/applications/phid/PhabricatorObjectHandle.php +++ b/src/applications/phid/PhabricatorObjectHandle.php @@ -111,7 +111,6 @@ final class PhabricatorObjectHandle PhabricatorPHIDConstants::PHID_TYPE_USER => 'User', PhabricatorPHIDConstants::PHID_TYPE_WIKI => 'Phriction Document', PhabricatorPHIDConstants::PHID_TYPE_MCRO => 'Image Macro', - PhabricatorPHIDConstants::PHID_TYPE_MOCK => 'Pholio Mock', PhabricatorPHIDConstants::PHID_TYPE_PIMG => 'Pholio Image', PhabricatorPHIDConstants::PHID_TYPE_FILE => 'File', PhabricatorPHIDConstants::PHID_TYPE_BLOG => 'Blog', diff --git a/src/applications/phid/PhabricatorPHIDConstants.php b/src/applications/phid/PhabricatorPHIDConstants.php index 323ef1123e..aa8fc4d4d4 100644 --- a/src/applications/phid/PhabricatorPHIDConstants.php +++ b/src/applications/phid/PhabricatorPHIDConstants.php @@ -23,7 +23,6 @@ final class PhabricatorPHIDConstants { const PHID_TYPE_BLOG = 'BLOG'; const PHID_TYPE_QUES = 'QUES'; const PHID_TYPE_ANSW = 'ANSW'; - const PHID_TYPE_MOCK = 'MOCK'; const PHID_TYPE_PIMG = 'PIMG'; const PHID_TYPE_MCRO = 'MCRO'; const PHID_TYPE_CONF = 'CONF'; diff --git a/src/applications/phid/handle/PhabricatorObjectHandleData.php b/src/applications/phid/handle/PhabricatorObjectHandleData.php index 0cca29c84e..fa5f788552 100644 --- a/src/applications/phid/handle/PhabricatorObjectHandleData.php +++ b/src/applications/phid/handle/PhabricatorObjectHandleData.php @@ -110,13 +110,6 @@ final class PhabricatorObjectHandleData { ->execute(); return mpull($questions, null, 'getPHID'); - case PhabricatorPHIDConstants::PHID_TYPE_MOCK: - $mocks = id(new PholioMockQuery()) - ->setViewer($this->viewer) - ->withPHIDs($phids) - ->execute(); - return mpull($mocks, null, 'getPHID'); - case PhabricatorPHIDConstants::PHID_TYPE_PIMG: $images = id(new PholioImage()) ->loadAllWhere('phid IN (%Ls)', $phids); @@ -131,7 +124,7 @@ final class PhabricatorObjectHandleData { foreach ($subtypes as $subtype => $subtype_phids) { // TODO: Do this magically. switch ($subtype) { - case PhabricatorPHIDConstants::PHID_TYPE_MOCK: + case PholioPHIDTypeMock::TYPECONST: $results = id(new PholioTransactionQuery()) ->setViewer($this->viewer) ->withPHIDs($subtype_phids) @@ -524,24 +517,6 @@ final class PhabricatorObjectHandleData { } break; - case PhabricatorPHIDConstants::PHID_TYPE_MOCK: - foreach ($phids as $phid) { - $handle = new PhabricatorObjectHandle(); - $handle->setPHID($phid); - $handle->setType($type); - if (empty($objects[$phid])) { - $handle->setName('Unknown Mock'); - } else { - $mock = $objects[$phid]; - $handle->setName('M'.$mock->getID()); - $handle->setFullName('M'.$mock->getID().': '.$mock->getName()); - $handle->setURI('/M'.$mock->getID()); - $handle->setComplete(true); - } - $handles[$phid] = $handle; - } - break; - case PhabricatorPHIDConstants::PHID_TYPE_PIMG: foreach ($phids as $phid) { $handle = new PhabricatorObjectHandle(); diff --git a/src/applications/phid/storage/PhabricatorPHID.php b/src/applications/phid/storage/PhabricatorPHID.php index 94fc239224..13b476b79d 100644 --- a/src/applications/phid/storage/PhabricatorPHID.php +++ b/src/applications/phid/storage/PhabricatorPHID.php @@ -44,14 +44,6 @@ final class PhabricatorPHID { return $name; } - if (preg_match('/^m(\d+)$/i', $name, $match)) { - $objects = id(new PholioMockQuery()) - ->setViewer($viewer) - ->withIDs(array($match[1])) - ->execute(); - $object = head($objects); - } - if ($object) { return $object->getPHID(); } diff --git a/src/applications/pholio/phid/PholioPHIDTypeMock.php b/src/applications/pholio/phid/PholioPHIDTypeMock.php new file mode 100644 index 0000000000..dfc4467688 --- /dev/null +++ b/src/applications/pholio/phid/PholioPHIDTypeMock.php @@ -0,0 +1,75 @@ +setViewer($query->getViewer()) + ->withPHIDs($phids) + ->execute(); + } + + public function loadHandles( + PhabricatorHandleQuery $query, + array $handles, + array $objects) { + + foreach ($handles as $phid => $handle) { + $mock = $objects[$phid]; + + $id = $mock->getID(); + $name = $mock->getName(); + + $handle->setURI("/M{$id}"); + $handle->setName("M{$id}"); + $handle->setFullName("M{$id}: {$name}"); + } + } + + public function canLoadNamedObject($name) { + return preg_match('/^M\d*[1-9]\d*$/i', $name); + } + + public function loadNamedObjects( + PhabricatorObjectQuery $query, + array $names) { + + $id_map = array(); + foreach ($names as $name) { + $id = (int)substr($name, 1); + $id_map[$id][] = $name; + } + + $objects = id(new PholioMockQuery()) + ->setViewer($query->getViewer()) + ->withIDs(array_keys($id_map)) + ->execute(); + + $results = array(); + foreach ($objects as $id => $object) { + foreach (idx($id_map, $id, array()) as $name) { + $results[$name] = $object; + } + } + + return $results; + } + +} diff --git a/src/applications/pholio/storage/PholioTransaction.php b/src/applications/pholio/storage/PholioTransaction.php index feee223603..93ec4d4335 100644 --- a/src/applications/pholio/storage/PholioTransaction.php +++ b/src/applications/pholio/storage/PholioTransaction.php @@ -10,7 +10,7 @@ final class PholioTransaction extends PhabricatorApplicationTransaction { } public function getApplicationTransactionType() { - return PhabricatorPHIDConstants::PHID_TYPE_MOCK; + return PholioPHIDTypeMock::TYPECONST; } public function getApplicationTransactionCommentObject() { diff --git a/src/applications/search/controller/PhabricatorSearchAttachController.php b/src/applications/search/controller/PhabricatorSearchAttachController.php index a76429d7b3..bc4483162a 100644 --- a/src/applications/search/controller/PhabricatorSearchAttachController.php +++ b/src/applications/search/controller/PhabricatorSearchAttachController.php @@ -210,7 +210,7 @@ final class PhabricatorSearchAttachController $noun = 'Commits'; $selected = 'created'; break; - case PhabricatorPHIDConstants::PHID_TYPE_MOCK: + case PholioPHIDTypeMock::TYPECONST: $noun = 'Mocks'; $selected = 'created'; break; @@ -251,7 +251,7 @@ final class PhabricatorSearchAttachController } private function getFilters(array $strings) { - if ($this->type == PhabricatorPHIDConstants::PHID_TYPE_MOCK) { + if ($this->type == PholioPHIDTypeMock::TYPECONST) { $filters = array( 'created' => 'Created By Me', 'all' => 'All '.$strings['target_plural_noun'], @@ -272,7 +272,7 @@ final class PhabricatorSearchAttachController $t_cmit = PhabricatorRepositoryPHIDTypeCommit::TYPECONST; $t_task = ManiphestPHIDTypeTask::TYPECONST; $t_drev = DifferentialPHIDTypeRevision::TYPECONST; - $t_mock = PhabricatorPHIDConstants::PHID_TYPE_MOCK; + $t_mock = PholioPHIDTypeMock::TYPECONST; $map = array( $t_cmit => array( diff --git a/src/applications/search/controller/PhabricatorSearchSelectController.php b/src/applications/search/controller/PhabricatorSearchSelectController.php index 9cbef3d97a..0d6bbc30b0 100644 --- a/src/applications/search/controller/PhabricatorSearchSelectController.php +++ b/src/applications/search/controller/PhabricatorSearchSelectController.php @@ -33,7 +33,7 @@ final class PhabricatorSearchSelectController $query->setParameter('author', array($user->getPHID())); // TODO - if / when we allow pholio mocks to be archived, etc // update this - if ($this->type != PhabricatorPHIDConstants::PHID_TYPE_MOCK) { + if ($this->type != PholioPHIDTypeMock::TYPECONST) { $query->setParameter('open', 1); } break; @@ -73,7 +73,7 @@ final class PhabricatorSearchSelectController case DifferentialPHIDTypeRevision::TYPECONST: $pattern = '/\bD(\d+)\b/i'; break; - case PhabricatorPHIDConstants::PHID_TYPE_MOCK: + case PholioPHIDTypeMock::TYPECONST: $pattern = '/\bM(\d+)\b/i'; break; } @@ -104,7 +104,7 @@ final class PhabricatorSearchSelectController 'id IN (%Ld)', $object_ids); break; - case PhabricatorPHIDConstants::PHID_TYPE_MOCK: + case PholioPHIDTypeMock::TYPECONST: $objects = id(new PholioMock())->loadAllWhere( 'id IN (%Ld)', $object_ids); diff --git a/src/infrastructure/edges/constants/PhabricatorEdgeConfig.php b/src/infrastructure/edges/constants/PhabricatorEdgeConfig.php index f50f9c5223..09a15ebae8 100644 --- a/src/infrastructure/edges/constants/PhabricatorEdgeConfig.php +++ b/src/infrastructure/edges/constants/PhabricatorEdgeConfig.php @@ -162,7 +162,6 @@ final class PhabricatorEdgeConfig extends PhabricatorEdgeConstants { PhabricatorPHIDConstants::PHID_TYPE_POST => 'PhamePost', PhabricatorPHIDConstants::PHID_TYPE_QUES => 'PonderQuestion', PhabricatorPHIDConstants::PHID_TYPE_ANSW => 'PonderAnswer', - PhabricatorPHIDConstants::PHID_TYPE_MOCK => 'PholioMock', PhabricatorPHIDConstants::PHID_TYPE_MCRO => 'PhabricatorFileImageMacro', PhabricatorPHIDConstants::PHID_TYPE_CONP => 'ConpherenceThread', PhabricatorPHIDConstants::PHID_TYPE_WIKI => 'PhrictionDocument', diff --git a/src/view/phui/PHUIFeedStoryView.php b/src/view/phui/PHUIFeedStoryView.php index 0c455ad9e8..7d1a397fd0 100644 --- a/src/view/phui/PHUIFeedStoryView.php +++ b/src/view/phui/PHUIFeedStoryView.php @@ -234,7 +234,7 @@ final class PHUIFeedStoryView extends AphrontView { public function setAppIconFromPHID($phid) { switch (phid_get_type($phid)) { - case PhabricatorPHIDConstants::PHID_TYPE_MOCK: + case PholioPHIDTypeMock::TYPECONST: $this->setAppIcon("pholio-dark"); break; case PhabricatorPHIDConstants::PHID_TYPE_MCRO: