mirror of
https://we.phorge.it/source/phorge.git
synced 2024-12-28 16:30:59 +01:00
Move DifferentialRevision to application PHIDs
Summary: Ref T2715. Test Plan: Used `phid.lookup` and `phid.query` to load handles. Grepped for `PHID_TYPE_DREV`. Reviewers: btrahan Reviewed By: btrahan CC: aran Maniphest Tasks: T2715 Differential Revision: https://secure.phabricator.com/D6509
This commit is contained in:
parent
5ca419174a
commit
1fb39a20d3
18 changed files with 104 additions and 55 deletions
|
@ -8,7 +8,7 @@ foreach (new LiskMigrationIterator($table) as $rev) {
|
|||
$id = $rev->getID();
|
||||
echo "Revision {$id}: ";
|
||||
|
||||
$deps = $rev->getAttachedPHIDs(PhabricatorPHIDConstants::PHID_TYPE_DREV);
|
||||
$deps = $rev->getAttachedPHIDs(DifferentialPHIDTypeRevision::TYPECONST);
|
||||
if (!$deps) {
|
||||
echo "-\n";
|
||||
continue;
|
||||
|
|
|
@ -8,7 +8,7 @@ foreach (new LiskMigrationIterator($table) as $task) {
|
|||
$id = $task->getID();
|
||||
echo "Task {$id}: ";
|
||||
|
||||
$revs = $task->getAttachedPHIDs(PhabricatorPHIDConstants::PHID_TYPE_DREV);
|
||||
$revs = $task->getAttachedPHIDs(DifferentialPHIDTypeRevision::TYPECONST);
|
||||
if (!$revs) {
|
||||
echo "-\n";
|
||||
continue;
|
||||
|
|
|
@ -383,6 +383,7 @@ phutil_register_library_map(array(
|
|||
'DifferentialMailPhase' => 'applications/differential/constants/DifferentialMailPhase.php',
|
||||
'DifferentialManiphestTasksFieldSpecification' => 'applications/differential/field/specification/DifferentialManiphestTasksFieldSpecification.php',
|
||||
'DifferentialNewDiffMail' => 'applications/differential/mail/DifferentialNewDiffMail.php',
|
||||
'DifferentialPHIDTypeRevision' => 'applications/differential/phid/DifferentialPHIDTypeRevision.php',
|
||||
'DifferentialParseRenderTestCase' => 'applications/differential/__tests__/DifferentialParseRenderTestCase.php',
|
||||
'DifferentialPathFieldSpecification' => 'applications/differential/field/specification/DifferentialPathFieldSpecification.php',
|
||||
'DifferentialPeopleMenuEventListener' => 'applications/differential/events/DifferentialPeopleMenuEventListener.php',
|
||||
|
@ -2340,6 +2341,7 @@ phutil_register_library_map(array(
|
|||
'DifferentialMail' => 'PhabricatorMail',
|
||||
'DifferentialManiphestTasksFieldSpecification' => 'DifferentialFieldSpecification',
|
||||
'DifferentialNewDiffMail' => 'DifferentialReviewRequestMail',
|
||||
'DifferentialPHIDTypeRevision' => 'PhabricatorPHIDType',
|
||||
'DifferentialParseRenderTestCase' => 'PhabricatorTestCase',
|
||||
'DifferentialPathFieldSpecification' => 'DifferentialFieldSpecification',
|
||||
'DifferentialPeopleMenuEventListener' => 'PhutilEventListener',
|
||||
|
|
|
@ -0,0 +1,85 @@
|
|||
<?php
|
||||
|
||||
final class DifferentialPHIDTypeRevision extends PhabricatorPHIDType {
|
||||
|
||||
const TYPECONST = 'DREV';
|
||||
|
||||
public function getTypeConstant() {
|
||||
return self::TYPECONST;
|
||||
}
|
||||
|
||||
public function getTypeName() {
|
||||
return pht('Differential Revision');
|
||||
}
|
||||
|
||||
public function newObject() {
|
||||
return new DifferentialRevision();
|
||||
}
|
||||
|
||||
public function loadObjects(
|
||||
PhabricatorObjectQuery $query,
|
||||
array $phids) {
|
||||
|
||||
return id(new DifferentialRevisionQuery())
|
||||
->setViewer($query->getViewer())
|
||||
->withPHIDs($phids)
|
||||
->execute();
|
||||
}
|
||||
|
||||
public function loadHandles(
|
||||
PhabricatorHandleQuery $query,
|
||||
array $handles,
|
||||
array $objects) {
|
||||
|
||||
static $closed_statuses = array(
|
||||
ArcanistDifferentialRevisionStatus::CLOSED => true,
|
||||
ArcanistDifferentialRevisionStatus::ABANDONED => true,
|
||||
);
|
||||
|
||||
foreach ($handles as $phid => $handle) {
|
||||
$revision = $objects[$phid];
|
||||
|
||||
$title = $revision->getTitle();
|
||||
$id = $revision->getID();
|
||||
$status = $revision->getStatus();
|
||||
|
||||
$handle->setName($title);
|
||||
$handle->setURI("/D{$id}");
|
||||
$handle->setFullName("D{$id}: {$title}");
|
||||
|
||||
if (isset($closed_statuses[$status])) {
|
||||
$handle->setStatus(PhabricatorObjectHandleStatus::STATUS_CLOSED);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public function canLoadNamedObject($name) {
|
||||
return preg_match('/^D\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 DifferentialRevisionQuery())
|
||||
->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;
|
||||
}
|
||||
|
||||
}
|
|
@ -15,7 +15,7 @@ final class DifferentialSearchIndexer
|
|||
|
||||
$doc = new PhabricatorSearchAbstractDocument();
|
||||
$doc->setPHID($rev->getPHID());
|
||||
$doc->setDocumentType(PhabricatorPHIDConstants::PHID_TYPE_DREV);
|
||||
$doc->setDocumentType(DifferentialPHIDTypeRevision::TYPECONST);
|
||||
$doc->setDocumentTitle($rev->getTitle());
|
||||
$doc->setDocumentCreated($rev->getDateCreated());
|
||||
$doc->setDocumentModified($rev->getDateModified());
|
||||
|
@ -49,7 +49,7 @@ final class DifferentialSearchIndexer
|
|||
$doc->addRelationship(
|
||||
PhabricatorSearchRelationship::RELATIONSHIP_OPEN,
|
||||
$rev->getPHID(),
|
||||
PhabricatorPHIDConstants::PHID_TYPE_DREV,
|
||||
DifferentialPHIDTypeRevision::TYPECONST,
|
||||
time());
|
||||
}
|
||||
|
||||
|
|
|
@ -138,7 +138,7 @@ final class DifferentialRevision extends DifferentialDAO
|
|||
|
||||
public function generatePHID() {
|
||||
return PhabricatorPHID::generateNewPHID(
|
||||
PhabricatorPHIDConstants::PHID_TYPE_DREV);
|
||||
DifferentialPHIDTypeRevision::TYPECONST);
|
||||
}
|
||||
|
||||
public function loadDiffs() {
|
||||
|
|
|
@ -7,7 +7,7 @@ final class DifferentialTransaction extends PhabricatorApplicationTransaction {
|
|||
}
|
||||
|
||||
public function getApplicationTransactionType() {
|
||||
return PhabricatorPHIDConstants::PHID_TYPE_DREV;
|
||||
return DifferentialPHIDTypeRevision::TYPECONST;
|
||||
}
|
||||
|
||||
public function getApplicationTransactionCommentObject() {
|
||||
|
|
|
@ -241,7 +241,7 @@ final class ManiphestTransactionDetailView extends ManiphestView {
|
|||
$new_raw = nonempty($new, array());
|
||||
|
||||
$attach_types = array(
|
||||
PhabricatorPHIDConstants::PHID_TYPE_DREV,
|
||||
DifferentialPHIDTypeRevision::TYPECONST,
|
||||
PhabricatorPHIDConstants::PHID_TYPE_FILE,
|
||||
);
|
||||
|
||||
|
@ -265,7 +265,7 @@ final class ManiphestTransactionDetailView extends ManiphestView {
|
|||
$links = implode("\n", $links);
|
||||
|
||||
switch ($attach_type) {
|
||||
case PhabricatorPHIDConstants::PHID_TYPE_DREV:
|
||||
case DifferentialPHIDTypeRevision::TYPECONST:
|
||||
$title = 'ATTACHED REVISIONS';
|
||||
break;
|
||||
case PhabricatorPHIDConstants::PHID_TYPE_FILE:
|
||||
|
@ -482,7 +482,7 @@ final class ManiphestTransactionDetailView extends ManiphestView {
|
|||
$new_raw = nonempty($new, array());
|
||||
|
||||
foreach (array(
|
||||
PhabricatorPHIDConstants::PHID_TYPE_DREV,
|
||||
DifferentialPHIDTypeRevision::TYPECONST,
|
||||
PhabricatorPHIDConstants::PHID_TYPE_TASK,
|
||||
PhabricatorPHIDConstants::PHID_TYPE_FILE) as $attach_type) {
|
||||
$old = array_keys(idx($old_raw, $attach_type, array()));
|
||||
|
@ -650,7 +650,7 @@ final class ManiphestTransactionDetailView extends ManiphestView {
|
|||
*/
|
||||
private function getAttachName($attach_type, $count) {
|
||||
switch ($attach_type) {
|
||||
case PhabricatorPHIDConstants::PHID_TYPE_DREV:
|
||||
case DifferentialPHIDTypeRevision::TYPECONST:
|
||||
return pht('Differential Revision(s)', $count);
|
||||
case PhabricatorPHIDConstants::PHID_TYPE_FILE:
|
||||
return pht('file(s)', $count);
|
||||
|
|
|
@ -110,7 +110,6 @@ final class PhabricatorObjectHandle
|
|||
static $map = array(
|
||||
PhabricatorPHIDConstants::PHID_TYPE_USER => 'User',
|
||||
PhabricatorPHIDConstants::PHID_TYPE_TASK => 'Task',
|
||||
PhabricatorPHIDConstants::PHID_TYPE_DREV => 'Revision',
|
||||
PhabricatorPHIDConstants::PHID_TYPE_CMIT => 'Commit',
|
||||
PhabricatorPHIDConstants::PHID_TYPE_WIKI => 'Phriction Document',
|
||||
PhabricatorPHIDConstants::PHID_TYPE_MCRO => 'Image Macro',
|
||||
|
|
|
@ -4,7 +4,6 @@ final class PhabricatorPHIDConstants {
|
|||
|
||||
const PHID_TYPE_USER = 'USER';
|
||||
const PHID_TYPE_MLST = 'MLST';
|
||||
const PHID_TYPE_DREV = 'DREV';
|
||||
const PHID_TYPE_TASK = 'TASK';
|
||||
const PHID_TYPE_FILE = 'FILE';
|
||||
const PHID_TYPE_PROJ = 'PROJ';
|
||||
|
|
|
@ -115,13 +115,6 @@ final class PhabricatorObjectHandleData {
|
|||
$lists = $object->loadAllWhere('phid IN (%Ls)', $phids);
|
||||
return mpull($lists, null, 'getPHID');
|
||||
|
||||
case PhabricatorPHIDConstants::PHID_TYPE_DREV:
|
||||
$revisions = id(new DifferentialRevisionQuery())
|
||||
->setViewer($this->viewer)
|
||||
->withPHIDs($phids)
|
||||
->execute();
|
||||
return mpull($revisions, null, 'getPHID');
|
||||
|
||||
case PhabricatorPHIDConstants::PHID_TYPE_WIKI:
|
||||
// TODO: Update this to PhrictionDocumentQuery, already pre-package
|
||||
// content DAO
|
||||
|
@ -355,32 +348,6 @@ final class PhabricatorObjectHandleData {
|
|||
}
|
||||
break;
|
||||
|
||||
case PhabricatorPHIDConstants::PHID_TYPE_DREV:
|
||||
foreach ($phids as $phid) {
|
||||
$handle = new PhabricatorObjectHandle();
|
||||
$handle->setPHID($phid);
|
||||
$handle->setType($type);
|
||||
if (empty($objects[$phid])) {
|
||||
$handle->setName('Unknown Revision');
|
||||
} else {
|
||||
$rev = $objects[$phid];
|
||||
$handle->setName('D'.$rev->getID());
|
||||
$handle->setURI('/D'.$rev->getID());
|
||||
$handle->setFullName('D'.$rev->getID().': '.$rev->getTitle());
|
||||
$handle->setComplete(true);
|
||||
|
||||
$status = $rev->getStatus();
|
||||
if (($status == ArcanistDifferentialRevisionStatus::CLOSED) ||
|
||||
($status == ArcanistDifferentialRevisionStatus::ABANDONED)) {
|
||||
$closed = PhabricatorObjectHandleStatus::STATUS_CLOSED;
|
||||
$handle->setStatus($closed);
|
||||
}
|
||||
|
||||
}
|
||||
$handles[$phid] = $handle;
|
||||
}
|
||||
break;
|
||||
|
||||
case PhabricatorPHIDConstants::PHID_TYPE_CMIT:
|
||||
foreach ($phids as $phid) {
|
||||
$handle = new PhabricatorObjectHandle();
|
||||
|
|
|
@ -64,8 +64,6 @@ final class PhabricatorPHID {
|
|||
}
|
||||
}
|
||||
}
|
||||
} else if (preg_match('/^d(\d+)$/i', $name, $match)) {
|
||||
$object = id(new DifferentialRevision())->load($match[1]);
|
||||
} else if (preg_match('/^t(\d+)$/i', $name, $match)) {
|
||||
$object = id(new ManiphestTask())->load($match[1]);
|
||||
} else if (preg_match('/^m(\d+)$/i', $name, $match)) {
|
||||
|
|
|
@ -198,7 +198,7 @@ final class PhabricatorSearchAttachController
|
|||
|
||||
private function getStrings() {
|
||||
switch ($this->type) {
|
||||
case PhabricatorPHIDConstants::PHID_TYPE_DREV:
|
||||
case DifferentialPHIDTypeRevision::TYPECONST:
|
||||
$noun = 'Revisions';
|
||||
$selected = 'created';
|
||||
break;
|
||||
|
@ -271,7 +271,7 @@ final class PhabricatorSearchAttachController
|
|||
private function getEdgeType($src_type, $dst_type) {
|
||||
$t_cmit = PhabricatorPHIDConstants::PHID_TYPE_CMIT;
|
||||
$t_task = PhabricatorPHIDConstants::PHID_TYPE_TASK;
|
||||
$t_drev = PhabricatorPHIDConstants::PHID_TYPE_DREV;
|
||||
$t_drev = DifferentialPHIDTypeRevision::TYPECONST;
|
||||
$t_mock = PhabricatorPHIDConstants::PHID_TYPE_MOCK;
|
||||
|
||||
$map = array(
|
||||
|
|
|
@ -47,7 +47,7 @@ final class PhabricatorSearchController
|
|||
$query->setParameter('open', 1);
|
||||
$query->setParameter(
|
||||
'type',
|
||||
PhabricatorPHIDConstants::PHID_TYPE_DREV);
|
||||
DifferentialPHIDTypeRevision::TYPECONST);
|
||||
break;
|
||||
case PhabricatorSearchScope::SCOPE_OPEN_TASKS:
|
||||
$query->setParameter('open', 1);
|
||||
|
|
|
@ -70,7 +70,7 @@ final class PhabricatorSearchSelectController
|
|||
case PhabricatorPHIDConstants::PHID_TYPE_TASK:
|
||||
$pattern = '/\bT(\d+)\b/i';
|
||||
break;
|
||||
case PhabricatorPHIDConstants::PHID_TYPE_DREV:
|
||||
case DifferentialPHIDTypeRevision::TYPECONST:
|
||||
$pattern = '/\bD(\d+)\b/i';
|
||||
break;
|
||||
case PhabricatorPHIDConstants::PHID_TYPE_MOCK:
|
||||
|
@ -94,7 +94,7 @@ final class PhabricatorSearchSelectController
|
|||
}
|
||||
|
||||
switch ($this->type) {
|
||||
case PhabricatorPHIDConstants::PHID_TYPE_DREV:
|
||||
case DifferentialPHIDTypeRevision::TYPECONST:
|
||||
$objects = id(new DifferentialRevision())->loadAllWhere(
|
||||
'id IN (%Ld)',
|
||||
$object_ids);
|
||||
|
|
|
@ -15,7 +15,7 @@ final class PhabricatorSearchAbstractDocument {
|
|||
|
||||
public static function getSupportedTypes() {
|
||||
return array(
|
||||
PhabricatorPHIDConstants::PHID_TYPE_DREV => 'Differential Revisions',
|
||||
DifferentialPHIDTypeRevision::TYPECONST => 'Differential Revisions',
|
||||
PhabricatorPHIDConstants::PHID_TYPE_CMIT => 'Repository Commits',
|
||||
PhabricatorPHIDConstants::PHID_TYPE_TASK => 'Maniphest Tasks',
|
||||
PhabricatorPHIDConstants::PHID_TYPE_WIKI => 'Phriction Documents',
|
||||
|
|
|
@ -19,7 +19,7 @@ final class PhabricatorHovercardExample extends PhabricatorUIExample {
|
|||
|
||||
$diff_handle = $this->createBasicDummyHandle(
|
||||
"D123",
|
||||
PhabricatorPHIDConstants::PHID_TYPE_DREV,
|
||||
DifferentialPHIDTypeRevision::TYPECONST,
|
||||
"Introduce cooler Differential Revisions");
|
||||
|
||||
$panel = $this->createPanel("Differential Hovercard");
|
||||
|
|
|
@ -156,7 +156,6 @@ final class PhabricatorEdgeConfig extends PhabricatorEdgeConstants {
|
|||
static $class_map = array(
|
||||
PhabricatorPHIDConstants::PHID_TYPE_TASK => 'ManiphestTask',
|
||||
PhabricatorPHIDConstants::PHID_TYPE_CMIT => 'PhabricatorRepository',
|
||||
PhabricatorPHIDConstants::PHID_TYPE_DREV => 'DifferentialRevision',
|
||||
PhabricatorPHIDConstants::PHID_TYPE_FILE => 'PhabricatorFile',
|
||||
PhabricatorPHIDConstants::PHID_TYPE_USER => 'PhabricatorUser',
|
||||
PhabricatorPHIDConstants::PHID_TYPE_PROJ => 'PhabricatorProject',
|
||||
|
|
Loading…
Reference in a new issue