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:
epriestley
2013-07-21 08:11:37 -07:00
parent 5ca419174a
commit 1fb39a20d3
18 changed files with 104 additions and 55 deletions

View File

@@ -8,7 +8,7 @@ foreach (new LiskMigrationIterator($table) as $rev) {
$id = $rev->getID(); $id = $rev->getID();
echo "Revision {$id}: "; echo "Revision {$id}: ";
$deps = $rev->getAttachedPHIDs(PhabricatorPHIDConstants::PHID_TYPE_DREV); $deps = $rev->getAttachedPHIDs(DifferentialPHIDTypeRevision::TYPECONST);
if (!$deps) { if (!$deps) {
echo "-\n"; echo "-\n";
continue; continue;

View File

@@ -8,7 +8,7 @@ foreach (new LiskMigrationIterator($table) as $task) {
$id = $task->getID(); $id = $task->getID();
echo "Task {$id}: "; echo "Task {$id}: ";
$revs = $task->getAttachedPHIDs(PhabricatorPHIDConstants::PHID_TYPE_DREV); $revs = $task->getAttachedPHIDs(DifferentialPHIDTypeRevision::TYPECONST);
if (!$revs) { if (!$revs) {
echo "-\n"; echo "-\n";
continue; continue;

View File

@@ -383,6 +383,7 @@ phutil_register_library_map(array(
'DifferentialMailPhase' => 'applications/differential/constants/DifferentialMailPhase.php', 'DifferentialMailPhase' => 'applications/differential/constants/DifferentialMailPhase.php',
'DifferentialManiphestTasksFieldSpecification' => 'applications/differential/field/specification/DifferentialManiphestTasksFieldSpecification.php', 'DifferentialManiphestTasksFieldSpecification' => 'applications/differential/field/specification/DifferentialManiphestTasksFieldSpecification.php',
'DifferentialNewDiffMail' => 'applications/differential/mail/DifferentialNewDiffMail.php', 'DifferentialNewDiffMail' => 'applications/differential/mail/DifferentialNewDiffMail.php',
'DifferentialPHIDTypeRevision' => 'applications/differential/phid/DifferentialPHIDTypeRevision.php',
'DifferentialParseRenderTestCase' => 'applications/differential/__tests__/DifferentialParseRenderTestCase.php', 'DifferentialParseRenderTestCase' => 'applications/differential/__tests__/DifferentialParseRenderTestCase.php',
'DifferentialPathFieldSpecification' => 'applications/differential/field/specification/DifferentialPathFieldSpecification.php', 'DifferentialPathFieldSpecification' => 'applications/differential/field/specification/DifferentialPathFieldSpecification.php',
'DifferentialPeopleMenuEventListener' => 'applications/differential/events/DifferentialPeopleMenuEventListener.php', 'DifferentialPeopleMenuEventListener' => 'applications/differential/events/DifferentialPeopleMenuEventListener.php',
@@ -2340,6 +2341,7 @@ phutil_register_library_map(array(
'DifferentialMail' => 'PhabricatorMail', 'DifferentialMail' => 'PhabricatorMail',
'DifferentialManiphestTasksFieldSpecification' => 'DifferentialFieldSpecification', 'DifferentialManiphestTasksFieldSpecification' => 'DifferentialFieldSpecification',
'DifferentialNewDiffMail' => 'DifferentialReviewRequestMail', 'DifferentialNewDiffMail' => 'DifferentialReviewRequestMail',
'DifferentialPHIDTypeRevision' => 'PhabricatorPHIDType',
'DifferentialParseRenderTestCase' => 'PhabricatorTestCase', 'DifferentialParseRenderTestCase' => 'PhabricatorTestCase',
'DifferentialPathFieldSpecification' => 'DifferentialFieldSpecification', 'DifferentialPathFieldSpecification' => 'DifferentialFieldSpecification',
'DifferentialPeopleMenuEventListener' => 'PhutilEventListener', 'DifferentialPeopleMenuEventListener' => 'PhutilEventListener',

View File

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

View File

@@ -15,7 +15,7 @@ final class DifferentialSearchIndexer
$doc = new PhabricatorSearchAbstractDocument(); $doc = new PhabricatorSearchAbstractDocument();
$doc->setPHID($rev->getPHID()); $doc->setPHID($rev->getPHID());
$doc->setDocumentType(PhabricatorPHIDConstants::PHID_TYPE_DREV); $doc->setDocumentType(DifferentialPHIDTypeRevision::TYPECONST);
$doc->setDocumentTitle($rev->getTitle()); $doc->setDocumentTitle($rev->getTitle());
$doc->setDocumentCreated($rev->getDateCreated()); $doc->setDocumentCreated($rev->getDateCreated());
$doc->setDocumentModified($rev->getDateModified()); $doc->setDocumentModified($rev->getDateModified());
@@ -49,7 +49,7 @@ final class DifferentialSearchIndexer
$doc->addRelationship( $doc->addRelationship(
PhabricatorSearchRelationship::RELATIONSHIP_OPEN, PhabricatorSearchRelationship::RELATIONSHIP_OPEN,
$rev->getPHID(), $rev->getPHID(),
PhabricatorPHIDConstants::PHID_TYPE_DREV, DifferentialPHIDTypeRevision::TYPECONST,
time()); time());
} }

View File

@@ -138,7 +138,7 @@ final class DifferentialRevision extends DifferentialDAO
public function generatePHID() { public function generatePHID() {
return PhabricatorPHID::generateNewPHID( return PhabricatorPHID::generateNewPHID(
PhabricatorPHIDConstants::PHID_TYPE_DREV); DifferentialPHIDTypeRevision::TYPECONST);
} }
public function loadDiffs() { public function loadDiffs() {

View File

@@ -7,7 +7,7 @@ final class DifferentialTransaction extends PhabricatorApplicationTransaction {
} }
public function getApplicationTransactionType() { public function getApplicationTransactionType() {
return PhabricatorPHIDConstants::PHID_TYPE_DREV; return DifferentialPHIDTypeRevision::TYPECONST;
} }
public function getApplicationTransactionCommentObject() { public function getApplicationTransactionCommentObject() {

View File

@@ -241,7 +241,7 @@ final class ManiphestTransactionDetailView extends ManiphestView {
$new_raw = nonempty($new, array()); $new_raw = nonempty($new, array());
$attach_types = array( $attach_types = array(
PhabricatorPHIDConstants::PHID_TYPE_DREV, DifferentialPHIDTypeRevision::TYPECONST,
PhabricatorPHIDConstants::PHID_TYPE_FILE, PhabricatorPHIDConstants::PHID_TYPE_FILE,
); );
@@ -265,7 +265,7 @@ final class ManiphestTransactionDetailView extends ManiphestView {
$links = implode("\n", $links); $links = implode("\n", $links);
switch ($attach_type) { switch ($attach_type) {
case PhabricatorPHIDConstants::PHID_TYPE_DREV: case DifferentialPHIDTypeRevision::TYPECONST:
$title = 'ATTACHED REVISIONS'; $title = 'ATTACHED REVISIONS';
break; break;
case PhabricatorPHIDConstants::PHID_TYPE_FILE: case PhabricatorPHIDConstants::PHID_TYPE_FILE:
@@ -482,7 +482,7 @@ final class ManiphestTransactionDetailView extends ManiphestView {
$new_raw = nonempty($new, array()); $new_raw = nonempty($new, array());
foreach (array( foreach (array(
PhabricatorPHIDConstants::PHID_TYPE_DREV, DifferentialPHIDTypeRevision::TYPECONST,
PhabricatorPHIDConstants::PHID_TYPE_TASK, PhabricatorPHIDConstants::PHID_TYPE_TASK,
PhabricatorPHIDConstants::PHID_TYPE_FILE) as $attach_type) { PhabricatorPHIDConstants::PHID_TYPE_FILE) as $attach_type) {
$old = array_keys(idx($old_raw, $attach_type, array())); $old = array_keys(idx($old_raw, $attach_type, array()));
@@ -650,7 +650,7 @@ final class ManiphestTransactionDetailView extends ManiphestView {
*/ */
private function getAttachName($attach_type, $count) { private function getAttachName($attach_type, $count) {
switch ($attach_type) { switch ($attach_type) {
case PhabricatorPHIDConstants::PHID_TYPE_DREV: case DifferentialPHIDTypeRevision::TYPECONST:
return pht('Differential Revision(s)', $count); return pht('Differential Revision(s)', $count);
case PhabricatorPHIDConstants::PHID_TYPE_FILE: case PhabricatorPHIDConstants::PHID_TYPE_FILE:
return pht('file(s)', $count); return pht('file(s)', $count);

View File

@@ -110,7 +110,6 @@ final class PhabricatorObjectHandle
static $map = array( static $map = array(
PhabricatorPHIDConstants::PHID_TYPE_USER => 'User', PhabricatorPHIDConstants::PHID_TYPE_USER => 'User',
PhabricatorPHIDConstants::PHID_TYPE_TASK => 'Task', PhabricatorPHIDConstants::PHID_TYPE_TASK => 'Task',
PhabricatorPHIDConstants::PHID_TYPE_DREV => 'Revision',
PhabricatorPHIDConstants::PHID_TYPE_CMIT => 'Commit', PhabricatorPHIDConstants::PHID_TYPE_CMIT => 'Commit',
PhabricatorPHIDConstants::PHID_TYPE_WIKI => 'Phriction Document', PhabricatorPHIDConstants::PHID_TYPE_WIKI => 'Phriction Document',
PhabricatorPHIDConstants::PHID_TYPE_MCRO => 'Image Macro', PhabricatorPHIDConstants::PHID_TYPE_MCRO => 'Image Macro',

View File

@@ -4,7 +4,6 @@ final class PhabricatorPHIDConstants {
const PHID_TYPE_USER = 'USER'; const PHID_TYPE_USER = 'USER';
const PHID_TYPE_MLST = 'MLST'; const PHID_TYPE_MLST = 'MLST';
const PHID_TYPE_DREV = 'DREV';
const PHID_TYPE_TASK = 'TASK'; const PHID_TYPE_TASK = 'TASK';
const PHID_TYPE_FILE = 'FILE'; const PHID_TYPE_FILE = 'FILE';
const PHID_TYPE_PROJ = 'PROJ'; const PHID_TYPE_PROJ = 'PROJ';

View File

@@ -115,13 +115,6 @@ final class PhabricatorObjectHandleData {
$lists = $object->loadAllWhere('phid IN (%Ls)', $phids); $lists = $object->loadAllWhere('phid IN (%Ls)', $phids);
return mpull($lists, null, 'getPHID'); 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: case PhabricatorPHIDConstants::PHID_TYPE_WIKI:
// TODO: Update this to PhrictionDocumentQuery, already pre-package // TODO: Update this to PhrictionDocumentQuery, already pre-package
// content DAO // content DAO
@@ -355,32 +348,6 @@ final class PhabricatorObjectHandleData {
} }
break; 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: case PhabricatorPHIDConstants::PHID_TYPE_CMIT:
foreach ($phids as $phid) { foreach ($phids as $phid) {
$handle = new PhabricatorObjectHandle(); $handle = new PhabricatorObjectHandle();

View File

@@ -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)) { } else if (preg_match('/^t(\d+)$/i', $name, $match)) {
$object = id(new ManiphestTask())->load($match[1]); $object = id(new ManiphestTask())->load($match[1]);
} else if (preg_match('/^m(\d+)$/i', $name, $match)) { } else if (preg_match('/^m(\d+)$/i', $name, $match)) {

View File

@@ -198,7 +198,7 @@ final class PhabricatorSearchAttachController
private function getStrings() { private function getStrings() {
switch ($this->type) { switch ($this->type) {
case PhabricatorPHIDConstants::PHID_TYPE_DREV: case DifferentialPHIDTypeRevision::TYPECONST:
$noun = 'Revisions'; $noun = 'Revisions';
$selected = 'created'; $selected = 'created';
break; break;
@@ -271,7 +271,7 @@ final class PhabricatorSearchAttachController
private function getEdgeType($src_type, $dst_type) { private function getEdgeType($src_type, $dst_type) {
$t_cmit = PhabricatorPHIDConstants::PHID_TYPE_CMIT; $t_cmit = PhabricatorPHIDConstants::PHID_TYPE_CMIT;
$t_task = PhabricatorPHIDConstants::PHID_TYPE_TASK; $t_task = PhabricatorPHIDConstants::PHID_TYPE_TASK;
$t_drev = PhabricatorPHIDConstants::PHID_TYPE_DREV; $t_drev = DifferentialPHIDTypeRevision::TYPECONST;
$t_mock = PhabricatorPHIDConstants::PHID_TYPE_MOCK; $t_mock = PhabricatorPHIDConstants::PHID_TYPE_MOCK;
$map = array( $map = array(

View File

@@ -47,7 +47,7 @@ final class PhabricatorSearchController
$query->setParameter('open', 1); $query->setParameter('open', 1);
$query->setParameter( $query->setParameter(
'type', 'type',
PhabricatorPHIDConstants::PHID_TYPE_DREV); DifferentialPHIDTypeRevision::TYPECONST);
break; break;
case PhabricatorSearchScope::SCOPE_OPEN_TASKS: case PhabricatorSearchScope::SCOPE_OPEN_TASKS:
$query->setParameter('open', 1); $query->setParameter('open', 1);

View File

@@ -70,7 +70,7 @@ final class PhabricatorSearchSelectController
case PhabricatorPHIDConstants::PHID_TYPE_TASK: case PhabricatorPHIDConstants::PHID_TYPE_TASK:
$pattern = '/\bT(\d+)\b/i'; $pattern = '/\bT(\d+)\b/i';
break; break;
case PhabricatorPHIDConstants::PHID_TYPE_DREV: case DifferentialPHIDTypeRevision::TYPECONST:
$pattern = '/\bD(\d+)\b/i'; $pattern = '/\bD(\d+)\b/i';
break; break;
case PhabricatorPHIDConstants::PHID_TYPE_MOCK: case PhabricatorPHIDConstants::PHID_TYPE_MOCK:
@@ -94,7 +94,7 @@ final class PhabricatorSearchSelectController
} }
switch ($this->type) { switch ($this->type) {
case PhabricatorPHIDConstants::PHID_TYPE_DREV: case DifferentialPHIDTypeRevision::TYPECONST:
$objects = id(new DifferentialRevision())->loadAllWhere( $objects = id(new DifferentialRevision())->loadAllWhere(
'id IN (%Ld)', 'id IN (%Ld)',
$object_ids); $object_ids);

View File

@@ -15,7 +15,7 @@ final class PhabricatorSearchAbstractDocument {
public static function getSupportedTypes() { public static function getSupportedTypes() {
return array( return array(
PhabricatorPHIDConstants::PHID_TYPE_DREV => 'Differential Revisions', DifferentialPHIDTypeRevision::TYPECONST => 'Differential Revisions',
PhabricatorPHIDConstants::PHID_TYPE_CMIT => 'Repository Commits', PhabricatorPHIDConstants::PHID_TYPE_CMIT => 'Repository Commits',
PhabricatorPHIDConstants::PHID_TYPE_TASK => 'Maniphest Tasks', PhabricatorPHIDConstants::PHID_TYPE_TASK => 'Maniphest Tasks',
PhabricatorPHIDConstants::PHID_TYPE_WIKI => 'Phriction Documents', PhabricatorPHIDConstants::PHID_TYPE_WIKI => 'Phriction Documents',

View File

@@ -19,7 +19,7 @@ final class PhabricatorHovercardExample extends PhabricatorUIExample {
$diff_handle = $this->createBasicDummyHandle( $diff_handle = $this->createBasicDummyHandle(
"D123", "D123",
PhabricatorPHIDConstants::PHID_TYPE_DREV, DifferentialPHIDTypeRevision::TYPECONST,
"Introduce cooler Differential Revisions"); "Introduce cooler Differential Revisions");
$panel = $this->createPanel("Differential Hovercard"); $panel = $this->createPanel("Differential Hovercard");

View File

@@ -156,7 +156,6 @@ final class PhabricatorEdgeConfig extends PhabricatorEdgeConstants {
static $class_map = array( static $class_map = array(
PhabricatorPHIDConstants::PHID_TYPE_TASK => 'ManiphestTask', PhabricatorPHIDConstants::PHID_TYPE_TASK => 'ManiphestTask',
PhabricatorPHIDConstants::PHID_TYPE_CMIT => 'PhabricatorRepository', PhabricatorPHIDConstants::PHID_TYPE_CMIT => 'PhabricatorRepository',
PhabricatorPHIDConstants::PHID_TYPE_DREV => 'DifferentialRevision',
PhabricatorPHIDConstants::PHID_TYPE_FILE => 'PhabricatorFile', PhabricatorPHIDConstants::PHID_TYPE_FILE => 'PhabricatorFile',
PhabricatorPHIDConstants::PHID_TYPE_USER => 'PhabricatorUser', PhabricatorPHIDConstants::PHID_TYPE_USER => 'PhabricatorUser',
PhabricatorPHIDConstants::PHID_TYPE_PROJ => 'PhabricatorProject', PhabricatorPHIDConstants::PHID_TYPE_PROJ => 'PhabricatorProject',