From 3a80c512c77a15e5823eac89e85411dd40cc3aa0 Mon Sep 17 00:00:00 2001 From: epriestley Date: Fri, 26 Jul 2013 10:31:26 -0700 Subject: [PATCH] Move OwnersPackage to Appliation PHIDs Summary: Ref T2715. Test Plan: `phid.query` Reviewers: btrahan Reviewed By: btrahan CC: aran Maniphest Tasks: T2715 Differential Revision: https://secure.phabricator.com/D6572 --- src/__phutil_library_map__.php | 2 + .../PhabricatorAuditListController.php | 2 +- .../phid/PhabricatorOwnersPHIDTypePackage.php | 45 +++++++++++++++++++ .../query/PhabricatorOwnersPackageQuery.php | 15 ++++++- .../phid/PhabricatorPHIDConstants.php | 1 - .../handle/PhabricatorObjectHandleData.php | 22 --------- 6 files changed, 62 insertions(+), 25 deletions(-) create mode 100644 src/applications/owners/phid/PhabricatorOwnersPHIDTypePackage.php diff --git a/src/__phutil_library_map__.php b/src/__phutil_library_map__.php index f8015d3f0f..07b76d8362 100644 --- a/src/__phutil_library_map__.php +++ b/src/__phutil_library_map__.php @@ -1342,6 +1342,7 @@ phutil_register_library_map(array( 'PhabricatorOwnersEditController' => 'applications/owners/controller/PhabricatorOwnersEditController.php', 'PhabricatorOwnersListController' => 'applications/owners/controller/PhabricatorOwnersListController.php', 'PhabricatorOwnersOwner' => 'applications/owners/storage/PhabricatorOwnersOwner.php', + 'PhabricatorOwnersPHIDTypePackage' => 'applications/owners/phid/PhabricatorOwnersPHIDTypePackage.php', 'PhabricatorOwnersPackage' => 'applications/owners/storage/PhabricatorOwnersPackage.php', 'PhabricatorOwnersPackagePathValidator' => 'applications/repository/worker/commitchangeparser/PhabricatorOwnersPackagePathValidator.php', 'PhabricatorOwnersPackageQuery' => 'applications/owners/query/PhabricatorOwnersPackageQuery.php', @@ -3358,6 +3359,7 @@ phutil_register_library_map(array( 'PhabricatorOwnersEditController' => 'PhabricatorOwnersController', 'PhabricatorOwnersListController' => 'PhabricatorOwnersController', 'PhabricatorOwnersOwner' => 'PhabricatorOwnersDAO', + 'PhabricatorOwnersPHIDTypePackage' => 'PhabricatorPHIDType', 'PhabricatorOwnersPackage' => array( 0 => 'PhabricatorOwnersDAO', diff --git a/src/applications/audit/controller/PhabricatorAuditListController.php b/src/applications/audit/controller/PhabricatorAuditListController.php index f9e44de0b3..345c4ad006 100644 --- a/src/applications/audit/controller/PhabricatorAuditListController.php +++ b/src/applications/audit/controller/PhabricatorAuditListController.php @@ -225,7 +225,7 @@ final class PhabricatorAuditListController extends PhabricatorAuditController { break; case 'package': case 'packagecommits': - if ($type !== PhabricatorPHIDConstants::PHID_TYPE_OPKG) { + if ($type !== PhabricatorOwnersPHIDTypePackage::TYPECONST) { throw new Exception("PHID must be a package PHID!"); } break; diff --git a/src/applications/owners/phid/PhabricatorOwnersPHIDTypePackage.php b/src/applications/owners/phid/PhabricatorOwnersPHIDTypePackage.php new file mode 100644 index 0000000000..cf8ce0b667 --- /dev/null +++ b/src/applications/owners/phid/PhabricatorOwnersPHIDTypePackage.php @@ -0,0 +1,45 @@ +setViewer($query->getViewer()) + ->withPHIDs($phids) + ->execute(); + } + + public function loadHandles( + PhabricatorHandleQuery $query, + array $handles, + array $objects) { + + foreach ($handles as $phid => $handle) { + $package = $objects[$phid]; + + $name = $package->getName(); + $id = $package->getID(); + + $handle->setName($name); + $handle->setURI("/owners/package/{$id}/"); + } + } + +} diff --git a/src/applications/owners/query/PhabricatorOwnersPackageQuery.php b/src/applications/owners/query/PhabricatorOwnersPackageQuery.php index db85ce5a35..68b0dfe0ed 100644 --- a/src/applications/owners/query/PhabricatorOwnersPackageQuery.php +++ b/src/applications/owners/query/PhabricatorOwnersPackageQuery.php @@ -3,6 +3,7 @@ final class PhabricatorOwnersPackageQuery extends PhabricatorCursorPagedPolicyAwareQuery { + private $phids; private $ownerPHIDs; /** @@ -13,6 +14,11 @@ final class PhabricatorOwnersPackageQuery return $this; } + public function withPHIDs(array $phids) { + $this->phids = $phids; + return $this; + } + protected function loadPage() { $table = new PhabricatorOwnersPackage(); $conn_r = $table->establishConnection('r'); @@ -39,12 +45,19 @@ final class PhabricatorOwnersPackageQuery id(new PhabricatorOwnersOwner())->getTableName()); } - return implode('', $joins); + return implode(' ', $joins); } private function buildWhereClause(AphrontDatabaseConnection $conn_r) { $where = array(); + if ($this->phids) { + $where[] = qsprintf( + $conn_r, + 'p.phid IN (%Ls)', + $this->phids); + } + if ($this->ownerPHIDs) { $base_phids = $this->ownerPHIDs; diff --git a/src/applications/phid/PhabricatorPHIDConstants.php b/src/applications/phid/PhabricatorPHIDConstants.php index e5fd7a3ac1..e321dc4620 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_OPKG = 'OPKG'; const PHID_TYPE_STRY = 'STRY'; const PHID_TYPE_APRJ = 'APRJ'; const PHID_TYPE_ACMT = 'ACMT'; diff --git a/src/applications/phid/handle/PhabricatorObjectHandleData.php b/src/applications/phid/handle/PhabricatorObjectHandleData.php index 29e87c40d7..f7834bcaa6 100644 --- a/src/applications/phid/handle/PhabricatorObjectHandleData.php +++ b/src/applications/phid/handle/PhabricatorObjectHandleData.php @@ -56,11 +56,6 @@ final class PhabricatorObjectHandleData { $phids); return mpull($users, null, 'getPHID'); - case PhabricatorPHIDConstants::PHID_TYPE_OPKG: - $object = new PhabricatorOwnersPackage(); - $packages = $object->loadAllWhere('phid in (%Ls)', $phids); - return mpull($packages, null, 'getPHID'); - case PhabricatorPHIDConstants::PHID_TYPE_APRJ: $project_dao = new PhabricatorRepositoryArcanistProject(); $projects = $project_dao->loadAllWhere( @@ -227,23 +222,6 @@ final class PhabricatorObjectHandleData { } break; - case PhabricatorPHIDConstants::PHID_TYPE_OPKG: - foreach ($phids as $phid) { - $handle = new PhabricatorObjectHandle(); - $handle->setPHID($phid); - $handle->setType($type); - if (empty($objects[$phid])) { - $handle->setName('Unknown Package'); - } else { - $package = $objects[$phid]; - $handle->setName($package->getName()); - $handle->setURI('/owners/package/'.$package->getID().'/'); - $handle->setComplete(true); - } - $handles[$phid] = $handle; - } - break; - case PhabricatorPHIDConstants::PHID_TYPE_APRJ: foreach ($phids as $phid) { $handle = new PhabricatorObjectHandle();