From f29861713ea11b939775499f5e1ac1a4d43f9163 Mon Sep 17 00:00:00 2001 From: epriestley Date: Wed, 24 Jul 2013 11:32:31 -0700 Subject: [PATCH] Use Application PHIDs in Ponder Summary: Ref T2715. Switch Ponder to the new IDs. Test Plan: Ran `phid.lookup`; `phid.query`. Grepped for old constant Reviewers: btrahan Reviewed By: btrahan CC: aran Maniphest Tasks: T2715 Differential Revision: https://secure.phabricator.com/D6554 --- src/__phutil_library_map__.php | 2 + .../phid/PhabricatorObjectHandle.php | 1 - .../phid/PhabricatorPHIDConstants.php | 1 - .../handle/PhabricatorObjectHandleData.php | 26 ------- .../ponder/phid/PonderPHIDTypeQuestion.php | 75 +++++++++++++++++++ .../ponder/search/PonderSearchIndexer.php | 2 +- .../ponder/storage/PonderQuestion.php | 3 +- .../PhabricatorSearchAbstractDocument.php | 2 +- .../edges/constants/PhabricatorEdgeConfig.php | 1 - 9 files changed, 80 insertions(+), 33 deletions(-) create mode 100644 src/applications/ponder/phid/PonderPHIDTypeQuestion.php diff --git a/src/__phutil_library_map__.php b/src/__phutil_library_map__.php index 48ccd5ffc8..bbc70a7553 100644 --- a/src/__phutil_library_map__.php +++ b/src/__phutil_library_map__.php @@ -1864,6 +1864,7 @@ phutil_register_library_map(array( 'PonderDAO' => 'applications/ponder/storage/PonderDAO.php', 'PonderMail' => 'applications/ponder/mail/PonderMail.php', 'PonderMentionMail' => 'applications/ponder/mail/PonderMentionMail.php', + 'PonderPHIDTypeQuestion' => 'applications/ponder/phid/PonderPHIDTypeQuestion.php', 'PonderPostBodyView' => 'applications/ponder/view/PonderPostBodyView.php', 'PonderQuestion' => 'applications/ponder/storage/PonderQuestion.php', 'PonderQuestionAskController' => 'applications/ponder/controller/PonderQuestionAskController.php', @@ -3945,6 +3946,7 @@ phutil_register_library_map(array( 'PonderDAO' => 'PhabricatorLiskDAO', 'PonderMail' => 'PhabricatorMail', 'PonderMentionMail' => 'PonderMail', + 'PonderPHIDTypeQuestion' => 'PhabricatorPHIDType', 'PonderPostBodyView' => 'AphrontView', 'PonderQuestion' => array( diff --git a/src/applications/phid/PhabricatorObjectHandle.php b/src/applications/phid/PhabricatorObjectHandle.php index 3c25cb1fe2..c928d49e37 100644 --- a/src/applications/phid/PhabricatorObjectHandle.php +++ b/src/applications/phid/PhabricatorObjectHandle.php @@ -113,7 +113,6 @@ final class PhabricatorObjectHandle PhabricatorPHIDConstants::PHID_TYPE_PIMG => 'Pholio Image', PhabricatorPHIDConstants::PHID_TYPE_BLOG => 'Blog', PhabricatorPHIDConstants::PHID_TYPE_POST => 'Post', - PhabricatorPHIDConstants::PHID_TYPE_QUES => 'Question', PhabricatorPHIDConstants::PHID_TYPE_PVAR => 'Variable', PhabricatorPHIDConstants::PHID_TYPE_PSTE => 'Paste', PhabricatorPHIDConstants::PHID_TYPE_LEGD => 'Legalpad Document', diff --git a/src/applications/phid/PhabricatorPHIDConstants.php b/src/applications/phid/PhabricatorPHIDConstants.php index bb7992f510..213dfe75f3 100644 --- a/src/applications/phid/PhabricatorPHIDConstants.php +++ b/src/applications/phid/PhabricatorPHIDConstants.php @@ -17,7 +17,6 @@ final class PhabricatorPHIDConstants { const PHID_TYPE_POST = 'POST'; const PHID_TYPE_TOBJ = 'TOBJ'; const PHID_TYPE_BLOG = 'BLOG'; - const PHID_TYPE_QUES = 'QUES'; const PHID_TYPE_ANSW = 'ANSW'; const PHID_TYPE_PIMG = 'PIMG'; const PHID_TYPE_MCRO = 'MCRO'; diff --git a/src/applications/phid/handle/PhabricatorObjectHandleData.php b/src/applications/phid/handle/PhabricatorObjectHandleData.php index c2e4fb10f0..13622325da 100644 --- a/src/applications/phid/handle/PhabricatorObjectHandleData.php +++ b/src/applications/phid/handle/PhabricatorObjectHandleData.php @@ -68,13 +68,6 @@ final class PhabricatorObjectHandleData { $phids); return mpull($projects, null, 'getPHID'); - case PhabricatorPHIDConstants::PHID_TYPE_QUES: - $questions = id(new PonderQuestionQuery()) - ->setViewer($this->viewer) - ->withPHIDs($phids) - ->execute(); - return mpull($questions, null, 'getPHID'); - case PhabricatorPHIDConstants::PHID_TYPE_PIMG: $images = id(new PholioImage()) ->loadAllWhere('phid IN (%Ls)', $phids); @@ -300,25 +293,6 @@ final class PhabricatorObjectHandleData { } break; - case PhabricatorPHIDConstants::PHID_TYPE_QUES: - foreach ($phids as $phid) { - $handle = new PhabricatorObjectHandle(); - $handle->setPHID($phid); - $handle->setType($type); - if (empty($objects[$phid])) { - $handle->setName('Unknown Ponder Question'); - } else { - $question = $objects[$phid]; - $handle->setName('Q' . $question->getID()); - $handle->setFullName( - phutil_utf8_shorten($question->getTitle(), 60)); - $handle->setURI(new PhutilURI('/Q' . $question->getID())); - $handle->setComplete(true); - } - $handles[$phid] = $handle; - } - break; - case PhabricatorPHIDConstants::PHID_TYPE_PSTE: foreach ($phids as $phid) { $handle = new PhabricatorObjectHandle(); diff --git a/src/applications/ponder/phid/PonderPHIDTypeQuestion.php b/src/applications/ponder/phid/PonderPHIDTypeQuestion.php new file mode 100644 index 0000000000..08198b02e9 --- /dev/null +++ b/src/applications/ponder/phid/PonderPHIDTypeQuestion.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) { + $question = $objects[$phid]; + + $id = $question->getID(); + $title = $question->getTitle(); + + $handle->setName("Q{$id}"); + $handle->setURI("/Q{$id}"); + $handle->setFullName("Q{$id}: {$title}"); + } + } + + public function canLoadNamedObject($name) { + return preg_match('/^Q\d*[1-9]\d*$/', $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 PonderQuestionQuery()) + ->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/ponder/search/PonderSearchIndexer.php b/src/applications/ponder/search/PonderSearchIndexer.php index 8b2a00f909..113b37d8ea 100644 --- a/src/applications/ponder/search/PonderSearchIndexer.php +++ b/src/applications/ponder/search/PonderSearchIndexer.php @@ -14,7 +14,7 @@ final class PonderSearchIndexer $doc = new PhabricatorSearchAbstractDocument(); $doc->setPHID($question->getPHID()); - $doc->setDocumentType(PhabricatorPHIDConstants::PHID_TYPE_QUES); + $doc->setDocumentType(PonderPHIDTypeQuestion::TYPECONST); $doc->setDocumentTitle($question->getTitle()); $doc->setDocumentCreated($question->getDateCreated()); $doc->setDocumentModified($question->getDateModified()); diff --git a/src/applications/ponder/storage/PonderQuestion.php b/src/applications/ponder/storage/PonderQuestion.php index 88160a35a1..987e9bb3ac 100644 --- a/src/applications/ponder/storage/PonderQuestion.php +++ b/src/applications/ponder/storage/PonderQuestion.php @@ -33,8 +33,7 @@ final class PonderQuestion extends PonderDAO } public function generatePHID() { - return PhabricatorPHID::generateNewPHID( - PhabricatorPHIDConstants::PHID_TYPE_QUES); + return PhabricatorPHID::generateNewPHID(PonderPHIDTypeQuestion::TYPECONST); } public function setContentSource(PhabricatorContentSource $content_source) { diff --git a/src/applications/search/index/PhabricatorSearchAbstractDocument.php b/src/applications/search/index/PhabricatorSearchAbstractDocument.php index e339730904..0baf036b4c 100644 --- a/src/applications/search/index/PhabricatorSearchAbstractDocument.php +++ b/src/applications/search/index/PhabricatorSearchAbstractDocument.php @@ -20,7 +20,7 @@ final class PhabricatorSearchAbstractDocument { ManiphestPHIDTypeTask::TYPECONST => 'Maniphest Tasks', PhrictionPHIDTypeDocument::TYPECONST => 'Phriction Documents', PhabricatorPHIDConstants::PHID_TYPE_USER => 'Phabricator Users', - PhabricatorPHIDConstants::PHID_TYPE_QUES => 'Ponder Questions', + PonderPHIDTypeQuestion::TYPECONST => 'Ponder Questions', ); } diff --git a/src/infrastructure/edges/constants/PhabricatorEdgeConfig.php b/src/infrastructure/edges/constants/PhabricatorEdgeConfig.php index c0c56ed61e..6f63eeff20 100644 --- a/src/infrastructure/edges/constants/PhabricatorEdgeConfig.php +++ b/src/infrastructure/edges/constants/PhabricatorEdgeConfig.php @@ -158,7 +158,6 @@ final class PhabricatorEdgeConfig extends PhabricatorEdgeConstants { PhabricatorPHIDConstants::PHID_TYPE_TOBJ => 'HarbormasterObject', PhabricatorPHIDConstants::PHID_TYPE_BLOG => 'PhameBlog', PhabricatorPHIDConstants::PHID_TYPE_POST => 'PhamePost', - PhabricatorPHIDConstants::PHID_TYPE_QUES => 'PonderQuestion', PhabricatorPHIDConstants::PHID_TYPE_ANSW => 'PonderAnswer', PhabricatorPHIDConstants::PHID_TYPE_MCRO => 'PhabricatorFileImageMacro', PhabricatorPHIDConstants::PHID_TYPE_CONP => 'ConpherenceThread',