From d3cf7874ede5003bc234207ec695167f3661c9ab Mon Sep 17 00:00:00 2001 From: epriestley Date: Mon, 22 Jul 2013 10:45:12 -0700 Subject: [PATCH] Use application PHIDs in Repositories Summary: Ref T2715. Move repositories to new app PHIDs. Test Plan: Used `phid.lookup`; `phid.query`; browsed Diffusion. Reviewers: btrahan Reviewed By: btrahan CC: aran Maniphest Tasks: T2715 Differential Revision: https://secure.phabricator.com/D6529 --- src/__phutil_library_map__.php | 2 + .../PhabricatorAuditListController.php | 2 +- .../phid/PhabricatorPHIDConstants.php | 1 - .../handle/PhabricatorObjectHandleData.php | 25 ------ ...habricatorRepositoryPHIDTypeRepository.php | 77 +++++++++++++++++++ ...abricatorRepositoryCommitSearchIndexer.php | 2 +- .../storage/PhabricatorRepository.php | 2 +- .../PhabricatorRepositoryTransaction.php | 2 +- 8 files changed, 83 insertions(+), 30 deletions(-) create mode 100644 src/applications/repository/phid/PhabricatorRepositoryPHIDTypeRepository.php diff --git a/src/__phutil_library_map__.php b/src/__phutil_library_map__.php index 921ccd4cf4..e7c0a58ec9 100644 --- a/src/__phutil_library_map__.php +++ b/src/__phutil_library_map__.php @@ -1458,6 +1458,7 @@ phutil_register_library_map(array( 'PhabricatorRepositoryMercurialCommitChangeParserWorker' => 'applications/repository/worker/commitchangeparser/PhabricatorRepositoryMercurialCommitChangeParserWorker.php', 'PhabricatorRepositoryMercurialCommitMessageParserWorker' => 'applications/repository/worker/commitmessageparser/PhabricatorRepositoryMercurialCommitMessageParserWorker.php', 'PhabricatorRepositoryPHIDTypeCommit' => 'applications/repository/phid/PhabricatorRepositoryPHIDTypeCommit.php', + 'PhabricatorRepositoryPHIDTypeRepository' => 'applications/repository/phid/PhabricatorRepositoryPHIDTypeRepository.php', 'PhabricatorRepositoryPullEngine' => 'applications/repository/engine/PhabricatorRepositoryPullEngine.php', 'PhabricatorRepositoryPullLocalDaemon' => 'applications/repository/daemon/PhabricatorRepositoryPullLocalDaemon.php', 'PhabricatorRepositoryQuery' => 'applications/repository/query/PhabricatorRepositoryQuery.php', @@ -3469,6 +3470,7 @@ phutil_register_library_map(array( 'PhabricatorRepositoryMercurialCommitChangeParserWorker' => 'PhabricatorRepositoryCommitChangeParserWorker', 'PhabricatorRepositoryMercurialCommitMessageParserWorker' => 'PhabricatorRepositoryCommitMessageParserWorker', 'PhabricatorRepositoryPHIDTypeCommit' => 'PhabricatorPHIDType', + 'PhabricatorRepositoryPHIDTypeRepository' => 'PhabricatorPHIDType', 'PhabricatorRepositoryPullEngine' => 'PhabricatorRepositoryEngine', 'PhabricatorRepositoryPullLocalDaemon' => 'PhabricatorDaemon', 'PhabricatorRepositoryQuery' => 'PhabricatorCursorPagedPolicyAwareQuery', diff --git a/src/applications/audit/controller/PhabricatorAuditListController.php b/src/applications/audit/controller/PhabricatorAuditListController.php index 2049e9779b..f9e44de0b3 100644 --- a/src/applications/audit/controller/PhabricatorAuditListController.php +++ b/src/applications/audit/controller/PhabricatorAuditListController.php @@ -235,7 +235,7 @@ final class PhabricatorAuditListController extends PhabricatorAuditController { } break; case 'repository': - if ($type !== PhabricatorPHIDConstants::PHID_TYPE_REPO) { + if ($type !== PhabricatorRepositoryPHIDTypeRepository::TYPECONST) { throw new Exception("PHID must be a repository PHID!"); } break; diff --git a/src/applications/phid/PhabricatorPHIDConstants.php b/src/applications/phid/PhabricatorPHIDConstants.php index 25e00a97da..222fbaaa1b 100644 --- a/src/applications/phid/PhabricatorPHIDConstants.php +++ b/src/applications/phid/PhabricatorPHIDConstants.php @@ -5,7 +5,6 @@ final class PhabricatorPHIDConstants { const PHID_TYPE_USER = 'USER'; const PHID_TYPE_UNKNOWN = '????'; const PHID_TYPE_MAGIC = '!!!!'; - const PHID_TYPE_REPO = 'REPO'; const PHID_TYPE_OPKG = 'OPKG'; const PHID_TYPE_PSTE = 'PSTE'; const PHID_TYPE_STRY = 'STRY'; diff --git a/src/applications/phid/handle/PhabricatorObjectHandleData.php b/src/applications/phid/handle/PhabricatorObjectHandleData.php index 70ce33b05e..8bb054072d 100644 --- a/src/applications/phid/handle/PhabricatorObjectHandleData.php +++ b/src/applications/phid/handle/PhabricatorObjectHandleData.php @@ -56,12 +56,6 @@ final class PhabricatorObjectHandleData { $phids); return mpull($users, null, 'getPHID'); - case PhabricatorPHIDConstants::PHID_TYPE_REPO: - // TODO: Update this to PhabricatorRepositoryQuery - $object = new PhabricatorRepository(); - $repositories = $object->loadAllWhere('phid in (%Ls)', $phids); - return mpull($repositories, null, 'getPHID'); - case PhabricatorPHIDConstants::PHID_TYPE_OPKG: $object = new PhabricatorOwnersPackage(); $packages = $object->loadAllWhere('phid in (%Ls)', $phids); @@ -282,25 +276,6 @@ final class PhabricatorObjectHandleData { } break; - case PhabricatorPHIDConstants::PHID_TYPE_REPO: - foreach ($phids as $phid) { - $handle = new PhabricatorObjectHandle(); - $handle->setPHID($phid); - $handle->setType($type); - if (empty($objects[$phid])) { - $handle->setName('Unknown Repository'); - } else { - $repository = $objects[$phid]; - $handle->setName('r'.$repository->getCallsign()); - $handle->setFullName("r" . $repository->getCallsign() . - " (" . $repository->getName() . ")"); - $handle->setURI('/diffusion/'.$repository->getCallsign().'/'); - $handle->setComplete(true); - } - $handles[$phid] = $handle; - } - break; - case PhabricatorPHIDConstants::PHID_TYPE_OPKG: foreach ($phids as $phid) { $handle = new PhabricatorObjectHandle(); diff --git a/src/applications/repository/phid/PhabricatorRepositoryPHIDTypeRepository.php b/src/applications/repository/phid/PhabricatorRepositoryPHIDTypeRepository.php new file mode 100644 index 0000000000..cfda831fd9 --- /dev/null +++ b/src/applications/repository/phid/PhabricatorRepositoryPHIDTypeRepository.php @@ -0,0 +1,77 @@ +setViewer($query->getViewer()) + ->withPHIDs($phids) + ->execute(); + } + + public function loadHandles( + PhabricatorHandleQuery $query, + array $handles, + array $objects) { + + foreach ($handles as $phid => $handle) { + $repository = $objects[$phid]; + + $callsign = $repository->getCallsign(); + $name = $repository->getName(); + + $handle->setName("r{$callsign}"); + $handle->setFullName("r{$callsign} ({$name})"); + $handle->setURI("/diffusion/{$callsign}/"); + } + } + + public function canLoadNamedObject($name) { + return preg_match('/^r[A-Z]+$/', $name); + } + + public function loadNamedObjects( + PhabricatorObjectQuery $query, + array $names) { + + $id_map = array(); + foreach ($names as $name) { + $id = substr($name, 1); + $id_map[$id][] = $name; + } + + $objects = id(new PhabricatorRepositoryQuery()) + ->setViewer($query->getViewer()) + ->withCallsigns(array_keys($id_map)) + ->execute(); + + $results = array(); + foreach ($objects as $object) { + $callsign = $object->getCallsign(); + foreach (idx($id_map, $callsign, array()) as $name) { + $results[$name] = $object; + } + } + + return $results; + } + +} diff --git a/src/applications/repository/search/PhabricatorRepositoryCommitSearchIndexer.php b/src/applications/repository/search/PhabricatorRepositoryCommitSearchIndexer.php index a5784d0791..a5ddd0da3c 100644 --- a/src/applications/repository/search/PhabricatorRepositoryCommitSearchIndexer.php +++ b/src/applications/repository/search/PhabricatorRepositoryCommitSearchIndexer.php @@ -63,7 +63,7 @@ final class PhabricatorRepositoryCommitSearchIndexer $doc->addRelationship( PhabricatorSearchRelationship::RELATIONSHIP_REPOSITORY, $repository->getPHID(), - PhabricatorPHIDConstants::PHID_TYPE_REPO, + PhabricatorRepositoryPHIDTypeRepository::TYPECONST, $date_created); $comments = id(new PhabricatorAuditComment())->loadAllWhere( diff --git a/src/applications/repository/storage/PhabricatorRepository.php b/src/applications/repository/storage/PhabricatorRepository.php index 1ea274fc47..d8e80d4c0b 100644 --- a/src/applications/repository/storage/PhabricatorRepository.php +++ b/src/applications/repository/storage/PhabricatorRepository.php @@ -46,7 +46,7 @@ final class PhabricatorRepository extends PhabricatorRepositoryDAO public function generatePHID() { return PhabricatorPHID::generateNewPHID( - PhabricatorPHIDConstants::PHID_TYPE_REPO); + PhabricatorRepositoryPHIDTypeRepository::TYPECONST); } public function toDictionary() { diff --git a/src/applications/repository/storage/PhabricatorRepositoryTransaction.php b/src/applications/repository/storage/PhabricatorRepositoryTransaction.php index 1b24d15636..24d99c168c 100644 --- a/src/applications/repository/storage/PhabricatorRepositoryTransaction.php +++ b/src/applications/repository/storage/PhabricatorRepositoryTransaction.php @@ -12,7 +12,7 @@ final class PhabricatorRepositoryTransaction } public function getApplicationTransactionType() { - return PhabricatorPHIDConstants::PHID_TYPE_REPO; + return PhabricatorRepositoryPHIDTypeRepository::TYPECONST; } public function getApplicationTransactionCommentObject() {