From 0a71593e6d65899331e073d27e7e4d70fa2817d7 Mon Sep 17 00:00:00 2001 From: Bob Trahan Date: Fri, 26 Jul 2013 12:05:33 -0700 Subject: [PATCH] Move LegalpadDocument to new phid stuff Summary: ref T2715 - apologies btw as I didn't catch the "start from the bottom" ask until recently... :/ Test Plan: phid.query for some legalpad documents... booya. also loaded legalpad. Reviewers: epriestley Reviewed By: epriestley CC: aran, Korvin Maniphest Tasks: T2715 Differential Revision: https://secure.phabricator.com/D6576 --- src/__phutil_library_map__.php | 2 + .../PhabricatorLegalpadPHIDTypeDocument.php | 76 +++++++++++++++++++ .../legalpad/storage/LegalpadDocument.php | 2 +- .../legalpad/storage/LegalpadTransaction.php | 2 +- .../phid/PhabricatorObjectHandle.php | 1 - .../phid/PhabricatorPHIDConstants.php | 1 - .../handle/PhabricatorObjectHandleData.php | 27 ------- .../edges/constants/PhabricatorEdgeConfig.php | 1 - 8 files changed, 80 insertions(+), 32 deletions(-) create mode 100644 src/applications/legalpad/phid/PhabricatorLegalpadPHIDTypeDocument.php diff --git a/src/__phutil_library_map__.php b/src/__phutil_library_map__.php index 27025879ae..ebd59b101f 100644 --- a/src/__phutil_library_map__.php +++ b/src/__phutil_library_map__.php @@ -1200,6 +1200,7 @@ phutil_register_library_map(array( 'PhabricatorJumpNavHandler' => 'applications/search/engine/PhabricatorJumpNavHandler.php', 'PhabricatorKeyValueDatabaseCache' => 'applications/cache/PhabricatorKeyValueDatabaseCache.php', 'PhabricatorLegalpadConfigOptions' => 'applications/legalpad/config/PhabricatorLegalpadConfigOptions.php', + 'PhabricatorLegalpadPHIDTypeDocument' => 'applications/legalpad/phid/PhabricatorLegalpadPHIDTypeDocument.php', 'PhabricatorLintEngine' => 'infrastructure/lint/PhabricatorLintEngine.php', 'PhabricatorLipsumArtist' => 'applications/lipsum/image/PhabricatorLipsumArtist.php', 'PhabricatorLipsumGenerateWorkflow' => 'applications/lipsum/management/PhabricatorLipsumGenerateWorkflow.php', @@ -3222,6 +3223,7 @@ phutil_register_library_map(array( 'PhabricatorJavelinLinter' => 'ArcanistLinter', 'PhabricatorKeyValueDatabaseCache' => 'PhutilKeyValueCache', 'PhabricatorLegalpadConfigOptions' => 'PhabricatorApplicationConfigOptions', + 'PhabricatorLegalpadPHIDTypeDocument' => 'PhabricatorPHIDType', 'PhabricatorLintEngine' => 'PhutilLintEngine', 'PhabricatorLipsumGenerateWorkflow' => 'PhabricatorLipsumManagementWorkflow', 'PhabricatorLipsumManagementWorkflow' => 'PhutilArgumentWorkflow', diff --git a/src/applications/legalpad/phid/PhabricatorLegalpadPHIDTypeDocument.php b/src/applications/legalpad/phid/PhabricatorLegalpadPHIDTypeDocument.php new file mode 100644 index 0000000000..345c8252e8 --- /dev/null +++ b/src/applications/legalpad/phid/PhabricatorLegalpadPHIDTypeDocument.php @@ -0,0 +1,76 @@ +needDocumentBodies(true) + ->withPHIDs($phids) + ->setViewer($query->getViewer()) + ->execute(); + } + + public function loadHandles( + PhabricatorHandleQuery $query, + array $handles, + array $objects) { + + foreach ($handles as $phid => $handle) { + $document = $objects[$phid]; + $name = $document->getDocumentBody()->getTitle(); + $handle->setName($name); + $handle->setFullName($name); + $handle->setURI('/legalpad/view/'.$document->getID().'/'); + } + } + + public function canLoadNamedObject($name) { + return preg_match('/^L\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 LegalpadDocumentQuery()) + ->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/legalpad/storage/LegalpadDocument.php b/src/applications/legalpad/storage/LegalpadDocument.php index 2ec63fa679..2f5b25e937 100644 --- a/src/applications/legalpad/storage/LegalpadDocument.php +++ b/src/applications/legalpad/storage/LegalpadDocument.php @@ -34,7 +34,7 @@ final class LegalpadDocument extends LegalpadDAO public function generatePHID() { return PhabricatorPHID::generateNewPHID( - PhabricatorPHIDConstants::PHID_TYPE_LEGD); + PhabricatorLegalpadPHIDTypeDocument::TYPECONST); } public function getDocumentBody() { diff --git a/src/applications/legalpad/storage/LegalpadTransaction.php b/src/applications/legalpad/storage/LegalpadTransaction.php index 7c9e74d597..e829812eab 100644 --- a/src/applications/legalpad/storage/LegalpadTransaction.php +++ b/src/applications/legalpad/storage/LegalpadTransaction.php @@ -10,7 +10,7 @@ final class LegalpadTransaction extends PhabricatorApplicationTransaction { } public function getApplicationTransactionType() { - return PhabricatorPHIDConstants::PHID_TYPE_LEGD; + return PhabricatorLegalpadPHIDTypeDocument::TYPECONST; } public function getApplicationTransactionCommentObject() { diff --git a/src/applications/phid/PhabricatorObjectHandle.php b/src/applications/phid/PhabricatorObjectHandle.php index ec8f2d35e0..5b3478020f 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_BLOG => 'Blog', PhabricatorPHIDConstants::PHID_TYPE_POST => 'Post', - PhabricatorPHIDConstants::PHID_TYPE_LEGD => 'Legalpad Document', ); return idx($map, $this->getType(), $this->getType()); diff --git a/src/applications/phid/PhabricatorPHIDConstants.php b/src/applications/phid/PhabricatorPHIDConstants.php index e321dc4620..d92dc9960d 100644 --- a/src/applications/phid/PhabricatorPHIDConstants.php +++ b/src/applications/phid/PhabricatorPHIDConstants.php @@ -23,7 +23,6 @@ final class PhabricatorPHIDConstants { const PHID_TYPE_PAYM = 'PAYM'; const PHID_TYPE_CHRG = 'CHRG'; const PHID_TYPE_CART = 'CART'; - const PHID_TYPE_LEGD = 'LEGD'; const PHID_TYPE_LEGB = 'LEGB'; const PHID_TYPE_XACT = 'XACT'; diff --git a/src/applications/phid/handle/PhabricatorObjectHandleData.php b/src/applications/phid/handle/PhabricatorObjectHandleData.php index f7834bcaa6..0f79312fda 100644 --- a/src/applications/phid/handle/PhabricatorObjectHandleData.php +++ b/src/applications/phid/handle/PhabricatorObjectHandleData.php @@ -104,14 +104,6 @@ final class PhabricatorObjectHandleData { ->execute(); return mpull($posts, null, 'getPHID'); - case PhabricatorPHIDConstants::PHID_TYPE_LEGD: - $legds = id(new LegalpadDocumentQuery()) - ->needDocumentBodies(true) - ->withPHIDs($phids) - ->setViewer($this->viewer) - ->execute(); - return mpull($legds, null, 'getPHID'); - case PhabricatorPHIDConstants::PHID_TYPE_CONP: $confs = id(new ConpherenceThreadQuery()) ->withPHIDs($phids) @@ -119,7 +111,6 @@ final class PhabricatorObjectHandleData { ->execute(); return mpull($confs, null, 'getPHID'); - } return array(); @@ -274,24 +265,6 @@ final class PhabricatorObjectHandleData { } break; - case PhabricatorPHIDConstants::PHID_TYPE_LEGD: - foreach ($phids as $phid) { - $handle = new PhabricatorObjectHandle(); - $handle->setPHID($phid); - $handle->setType($type); - if (empty($objects[$phid])) { - $handle->setName(pht('Unknown Legalpad Document')); - } else { - $document = $objects[$phid]; - $handle->setName($document->getDocumentBody()->getTitle()); - $handle->setFullName($document->getDocumentBody()->getTitle()); - $handle->setURI('/legalpad/view/'.$document->getID().'/'); - $handle->setComplete(true); - } - $handles[$phid] = $handle; - } - break; - case PhabricatorPHIDConstants::PHID_TYPE_CONP: foreach ($phids as $phid) { $handle = new PhabricatorObjectHandle(); diff --git a/src/infrastructure/edges/constants/PhabricatorEdgeConfig.php b/src/infrastructure/edges/constants/PhabricatorEdgeConfig.php index ffeea89b41..5016d81d3f 100644 --- a/src/infrastructure/edges/constants/PhabricatorEdgeConfig.php +++ b/src/infrastructure/edges/constants/PhabricatorEdgeConfig.php @@ -164,7 +164,6 @@ final class PhabricatorEdgeConfig extends PhabricatorEdgeConstants { PhabricatorPHIDConstants::PHID_TYPE_PRCH => 'PhortunePurchase', PhabricatorPHIDConstants::PHID_TYPE_CHRG => 'PhortuneCharge', PhabricatorPHIDConstants::PHID_TYPE_XOBJ => 'DoorkeeperExternalObject', - PhabricatorPHIDConstants::PHID_TYPE_LEGD => 'LegalpadDocument', ); $class = idx($class_map, $phid_type);