1
0
Fork 0
mirror of https://we.phorge.it/source/phorge.git synced 2024-12-21 21:10:56 +01:00

Use application handle infrastructure for Releeph Requests and Releeph Projects

Summary: Ref T2715.

Test Plan: Used `phid.query` to query handles. Browsed Releeph.

Reviewers: btrahan

Reviewed By: btrahan

CC: aran

Maniphest Tasks: T2715

Differential Revision: https://secure.phabricator.com/D6510
This commit is contained in:
epriestley 2013-07-21 08:41:38 -07:00
parent 1fb39a20d3
commit f2ed56147d
9 changed files with 128 additions and 54 deletions

View file

@ -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',

View file

@ -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);
}

View file

@ -1,9 +1,5 @@
<?php
final class ReleephPHIDConstants {
// Releeph
const PHID_TYPE_REPR = 'REPR';
const PHID_TYPE_REBR = 'REBR';
const PHID_TYPE_RERQ = 'RERQ';
}

View file

@ -0,0 +1,46 @@
<?php
final class ReleephPHIDTypeProject extends PhabricatorPHIDType {
const TYPECONST = 'REPR';
public function getTypeConstant() {
return self::TYPECONST;
}
public function getTypeName() {
return pht('Releeph Project');
}
public function newObject() {
return new ReleephProject();
}
public function loadObjects(
PhabricatorObjectQuery $query,
array $phids) {
return id(new ReleephProjectQuery())
->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;
}
}

View file

@ -0,0 +1,50 @@
<?php
final class ReleephPHIDTypeRequest extends PhabricatorPHIDType {
const TYPECONST = 'RERQ';
public function getTypeConstant() {
return self::TYPECONST;
}
public function getTypeName() {
return pht('Releeph Request');
}
public function newObject() {
return new ReleephRequest();
}
public function loadObjects(
PhabricatorObjectQuery $query,
array $phids) {
return id(new ReleephRequestQuery())
->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;
}
}

View file

@ -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);

View file

@ -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,

View file

@ -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) {

View file

@ -16,7 +16,7 @@ final class ReleephRequestTransaction
}
public function getApplicationTransactionType() {
return ReleephPHIDConstants::PHID_TYPE_RERQ;
return ReleephPHIDTypeRequest::TYPECONST;
}
public function getApplicationTransactionCommentObject() {