diff --git a/src/__phutil_library_map__.php b/src/__phutil_library_map__.php index 9f61ee4cae..2a23afa31e 100644 --- a/src/__phutil_library_map__.php +++ b/src/__phutil_library_map__.php @@ -1903,6 +1903,8 @@ phutil_register_library_map(array( 'ReleephObjectHandleLoader' => 'applications/releeph/ReleephObjectHandleLoader.php', 'ReleephOriginalCommitFieldSpecification' => 'applications/releeph/field/specification/ReleephOriginalCommitFieldSpecification.php', 'ReleephPHIDConstants' => 'applications/releeph/ReleephPHIDConstants.php', + 'ReleephPHIDTypeProject' => 'applications/releeph/phid/ReleephPHIDTypeProject.php', + 'ReleephPHIDTypeRequest' => 'applications/releeph/phid/ReleephPHIDTypeRequest.php', 'ReleephProject' => 'applications/releeph/storage/ReleephProject.php', 'ReleephProjectActionController' => 'applications/releeph/controller/project/ReleephProjectActionController.php', 'ReleephProjectController' => 'applications/releeph/controller/ReleephProjectController.php', @@ -3943,6 +3945,8 @@ phutil_register_library_map(array( 'ReleephLevelFieldSpecification' => 'ReleephFieldSpecification', 'ReleephObjectHandleLoader' => 'ObjectHandleLoader', 'ReleephOriginalCommitFieldSpecification' => 'ReleephFieldSpecification', + 'ReleephPHIDTypeProject' => 'PhabricatorPHIDType', + 'ReleephPHIDTypeRequest' => 'PhabricatorPHIDType', 'ReleephProject' => array( 0 => 'ReleephDAO', diff --git a/src/applications/releeph/ReleephObjectHandleLoader.php b/src/applications/releeph/ReleephObjectHandleLoader.php index 553ead7a51..484b5ebf7c 100644 --- a/src/applications/releeph/ReleephObjectHandleLoader.php +++ b/src/applications/releeph/ReleephObjectHandleLoader.php @@ -2,14 +2,6 @@ final class ReleephObjectHandleLoader extends ObjectHandleLoader { - /** - * The intention for phid.external-loaders is for each new 4-char PHID type - * to point to a different external loader for that type. - * - * For brevity, we instead just have this one class that can load any type of - * Releeph PHID. - */ - public function loadHandles(array $phids) { $types = array(); @@ -22,27 +14,6 @@ final class ReleephObjectHandleLoader extends ObjectHandleLoader { foreach ($types as $type => $phids) { switch ($type) { - case ReleephPHIDConstants::PHID_TYPE_RERQ: - $object = new ReleephRequest(); - - $instances = $object->loadAllWhere('phid in (%Ls)', $phids); - $instances = mpull($instances, null, 'getPHID'); - - foreach ($phids as $phid) { - $instance = $instances[$phid]; - $handle = new PhabricatorObjectHandle(); - $handle->setPHID($phid); - $handle->setType($type); - $handle->setURI('/RQ'.$instance->getID()); - - $name = 'RQ'.$instance->getID(); - $handle->setName($name); - $handle->setFullName($name.': '.$instance->getSummaryForDisplay()); - $handle->setComplete(true); - - $handles[$phid] = $handle; - } - break; case ReleephPHIDConstants::PHID_TYPE_REBR: $object = new ReleephBranch(); @@ -63,24 +34,6 @@ final class ReleephObjectHandleLoader extends ObjectHandleLoader { } break; - case ReleephPHIDConstants::PHID_TYPE_REPR: - $object = new ReleephProject(); - - $instances = $object->loadAllWhere('phid IN (%Ls)', $phids); - $instances = mpull($instances, null, 'getPHID'); - - foreach ($phids as $phid) { - $instance = $instances[$phid]; - $handle = new PhabricatorObjectHandle(); - $handle->setPHID($phid); - $handle->setType($type); - $handle->setURI($instance->getURI()); - $handle->setName($instance->getName()); // no fullName for proejcts - $handle->setComplete(true); - $handles[$phid] = $handle; - } - break; - default: throw new Exception('unknown type '.$type); } diff --git a/src/applications/releeph/ReleephPHIDConstants.php b/src/applications/releeph/ReleephPHIDConstants.php index 6265da6c83..c8df2329ce 100644 --- a/src/applications/releeph/ReleephPHIDConstants.php +++ b/src/applications/releeph/ReleephPHIDConstants.php @@ -1,9 +1,5 @@ setViewer($query->getViewer()) + ->withPHIDs($phids) + ->execute(); + } + + public function loadHandles( + PhabricatorHandleQuery $query, + array $handles, + array $objects) { + + foreach ($handles as $phid => $handle) { + $project = $objects[$phid]; + + $handle->setName($project->getName()); + $handle->setURI($project->getURI()); + } + } + + public function canLoadNamedObject($name) { + return false; + } + +} diff --git a/src/applications/releeph/phid/ReleephPHIDTypeRequest.php b/src/applications/releeph/phid/ReleephPHIDTypeRequest.php new file mode 100644 index 0000000000..116cda9503 --- /dev/null +++ b/src/applications/releeph/phid/ReleephPHIDTypeRequest.php @@ -0,0 +1,50 @@ +setViewer($query->getViewer()) + ->withPHIDs($phids) + ->execute(); + } + + public function loadHandles( + PhabricatorHandleQuery $query, + array $handles, + array $objects) { + + foreach ($handles as $phid => $handle) { + $request = $objects[$phid]; + + $id = $request->getID(); + $title = $request->getSummaryForDisplay(); + + $handle->setURI("/RQ{$id}"); + $handle->setName($title); + $handle->setFullName("RQ{$id}: {$title}"); + } + } + + public function canLoadNamedObject($name) { + return false; + } + +} diff --git a/src/applications/releeph/query/ReleephProjectQuery.php b/src/applications/releeph/query/ReleephProjectQuery.php index 5fa215cf0b..bbd4ad0744 100644 --- a/src/applications/releeph/query/ReleephProjectQuery.php +++ b/src/applications/releeph/query/ReleephProjectQuery.php @@ -4,6 +4,7 @@ final class ReleephProjectQuery extends PhabricatorCursorPagedPolicyAwareQuery { private $active; + private $phids; private $order = 'order-id'; const ORDER_ID = 'order-id'; @@ -19,6 +20,11 @@ final class ReleephProjectQuery return $this; } + public function withPHIDs(array $phids) { + $this->phids = $phids; + return $this; + } + public function loadPage() { $table = new ReleephProject(); $conn_r = $table->establishConnection('r'); @@ -44,6 +50,13 @@ final class ReleephProjectQuery $this->active); } + if ($this->phids) { + $where[] = qsprintf( + $conn_r, + 'phid IN (%Ls)', + $this->phids); + } + $where[] = $this->buildPagingClause($conn_r); return $this->formatWhereClause($where); diff --git a/src/applications/releeph/query/ReleephRequestQuery.php b/src/applications/releeph/query/ReleephRequestQuery.php index 01256f803e..516296d888 100644 --- a/src/applications/releeph/query/ReleephRequestQuery.php +++ b/src/applications/releeph/query/ReleephRequestQuery.php @@ -6,12 +6,18 @@ final class ReleephRequestQuery private $requestedCommitPHIDs; private $commitToRevMap; private $ids; + private $phids; public function withIDs(array $ids) { $this->ids = $ids; return $this; } + public function withPHIDs(array $phids) { + $this->phids = $phids; + return $this; + } + public function getRevisionPHID($commit_phid) { if ($this->commitToRevMap) { return idx($this->commitToRevMap, $commit_phid, null); @@ -69,6 +75,13 @@ final class ReleephRequestQuery $this->ids); } + if ($this->phids) { + $where[] = qsprintf( + $conn_r, + 'phid IN (%Ls)', + $this->phids); + } + if ($this->requestedCommitPHIDs) { $where[] = qsprintf( $conn_r, diff --git a/src/applications/releeph/storage/ReleephProject.php b/src/applications/releeph/storage/ReleephProject.php index 1bf090cb7a..3d6b88b7a2 100644 --- a/src/applications/releeph/storage/ReleephProject.php +++ b/src/applications/releeph/storage/ReleephProject.php @@ -37,8 +37,7 @@ final class ReleephProject extends ReleephDAO } public function generatePHID() { - return PhabricatorPHID::generateNewPHID( - ReleephPHIDConstants::PHID_TYPE_REPR); + return PhabricatorPHID::generateNewPHID(ReleephPHIDTypeProject::TYPECONST); } public function getDetail($key, $default = null) { diff --git a/src/applications/releeph/storage/ReleephRequestTransaction.php b/src/applications/releeph/storage/ReleephRequestTransaction.php index 0e1d997d4d..0ad1cb6422 100644 --- a/src/applications/releeph/storage/ReleephRequestTransaction.php +++ b/src/applications/releeph/storage/ReleephRequestTransaction.php @@ -16,7 +16,7 @@ final class ReleephRequestTransaction } public function getApplicationTransactionType() { - return ReleephPHIDConstants::PHID_TYPE_RERQ; + return ReleephPHIDTypeRequest::TYPECONST; } public function getApplicationTransactionCommentObject() {