1
0
Fork 0
mirror of https://we.phorge.it/source/phorge.git synced 2025-02-05 11:28:25 +01:00

Use Application PHIDs in Maniphest

Summary: Ref T2715. Switch Maniphest to the new stuff.

Test Plan: Used `phid.query`; `phid.lookup` to load objects.

Reviewers: btrahan

Reviewed By: btrahan

CC: aran

Maniphest Tasks: T2715

Differential Revision: https://secure.phabricator.com/D6516
This commit is contained in:
epriestley 2013-07-21 12:05:28 -07:00
parent 0e3cb3b393
commit 17ee71d896
18 changed files with 107 additions and 52 deletions

View file

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

View file

@ -684,6 +684,7 @@ phutil_register_library_map(array(
'ManiphestExcelFormat' => 'applications/maniphest/export/ManiphestExcelFormat.php',
'ManiphestExportController' => 'applications/maniphest/controller/ManiphestExportController.php',
'ManiphestHovercardEventListener' => 'applications/maniphest/event/ManiphestHovercardEventListener.php',
'ManiphestPHIDTypeTask' => 'applications/maniphest/phid/ManiphestPHIDTypeTask.php',
'ManiphestPeopleMenuEventListener' => 'applications/maniphest/event/ManiphestPeopleMenuEventListener.php',
'ManiphestRemarkupRule' => 'applications/maniphest/remarkup/ManiphestRemarkupRule.php',
'ManiphestReplyHandler' => 'applications/maniphest/mail/ManiphestReplyHandler.php',
@ -2636,6 +2637,7 @@ phutil_register_library_map(array(
'ManiphestExcelDefaultFormat' => 'ManiphestExcelFormat',
'ManiphestExportController' => 'ManiphestController',
'ManiphestHovercardEventListener' => 'PhutilEventListener',
'ManiphestPHIDTypeTask' => 'PhabricatorPHIDType',
'ManiphestPeopleMenuEventListener' => 'PhutilEventListener',
'ManiphestRemarkupRule' => 'PhabricatorRemarkupRuleObject',
'ManiphestReplyHandler' => 'PhabricatorMailReplyHandler',

View file

@ -75,11 +75,23 @@ final class ManiphestTaskQuery extends PhabricatorQuery {
return $this;
}
public function withIDs(array $ids) {
$this->ids = $ids;
return $this;
}
public function withPHIDs(array $phids) {
$this->taskPHIDs = $phids;
return $this;
}
// TODO: Deprecated in favor of `withIDs()`.
public function withTaskIDs(array $ids) {
$this->taskIDs = $ids;
return $this;
}
// TODO: Deprecated in favor of `withPHIDs()`.
public function withTaskPHIDs(array $phids) {
$this->taskPHIDs = $phids;
return $this;

View file

@ -101,7 +101,7 @@ final class ManiphestEdgeEventListener extends PhutilEventListener {
$add_edges = $event->getValue('add');
$rem_edges = $event->getValue('rem');
$type_task = PhabricatorPHIDConstants::PHID_TYPE_TASK;
$type_task = ManiphestPHIDTypeTask::TYPECONST;
$all_edges = array_merge($add_edges, $rem_edges);
$all_edges = $this->filterEdgesBySourceType($all_edges, $type_task);

View file

@ -0,0 +1,78 @@
<?php
final class ManiphestPHIDTypeTask extends PhabricatorPHIDType {
const TYPECONST = 'TASK';
public function getTypeConstant() {
return self::TYPECONST;
}
public function getTypeName() {
return pht('Task');
}
public function newObject() {
return new ManiphestTask();
}
public function loadObjects(
PhabricatorObjectQuery $query,
array $phids) {
return id(new ManiphestTaskQuery())
->setViewer($query->getViewer())
->withPHIDs($phids)
->execute();
}
public function loadHandles(
PhabricatorHandleQuery $query,
array $handles,
array $objects) {
foreach ($handles as $phid => $handle) {
$task = $objects[$phid];
$id = $task->getID();
$title = $task->getTitle();
$handle->setName("T{$id}");
$handle->setFullName("T{$id}: {$title}");
$handle->setURI("/T{$id}");
if ($task->getStatus() != ManiphestTaskStatus::STATUS_OPEN) {
$handle->setStatus(PhabricatorObjectHandleStatus::STATUS_CLOSED);
}
}
}
public function canLoadNamedObject($name) {
return preg_match('/^T\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 ManiphestTaskQuery())
->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 ManiphestSearchIndexer
$doc = new PhabricatorSearchAbstractDocument();
$doc->setPHID($task->getPHID());
$doc->setDocumentType(PhabricatorPHIDConstants::PHID_TYPE_TASK);
$doc->setDocumentType(ManiphestPHIDTypeTask::TYPECONST);
$doc->setDocumentTitle($task->getTitle());
$doc->setDocumentCreated($task->getDateCreated());
$doc->setDocumentModified($task->getDateModified());
@ -34,7 +34,7 @@ final class ManiphestSearchIndexer
$doc->addRelationship(
PhabricatorSearchRelationship::RELATIONSHIP_OPEN,
$task->getPHID(),
PhabricatorPHIDConstants::PHID_TYPE_TASK,
ManiphestPHIDTypeTask::TYPECONST,
time());
}

View file

@ -65,8 +65,7 @@ final class ManiphestTask extends ManiphestDAO
}
public function generatePHID() {
return PhabricatorPHID::generateNewPHID(
PhabricatorPHIDConstants::PHID_TYPE_TASK);
return PhabricatorPHID::generateNewPHID(ManiphestPHIDTypeTask::TYPECONST);
}
public function getCCPHIDs() {

View file

@ -483,7 +483,7 @@ final class ManiphestTransactionDetailView extends ManiphestView {
foreach (array(
DifferentialPHIDTypeRevision::TYPECONST,
PhabricatorPHIDConstants::PHID_TYPE_TASK,
ManiphestPHIDTypeTask::TYPECONST,
PhabricatorPHIDConstants::PHID_TYPE_FILE) as $attach_type) {
$old = array_keys(idx($old_raw, $attach_type, array()));
$new = array_keys(idx($new_raw, $attach_type, array()));
@ -654,7 +654,7 @@ final class ManiphestTransactionDetailView extends ManiphestView {
return pht('Differential Revision(s)', $count);
case PhabricatorPHIDConstants::PHID_TYPE_FILE:
return pht('file(s)', $count);
case PhabricatorPHIDConstants::PHID_TYPE_TASK:
case ManiphestPHIDTypeTask::TYPECONST:
return pht('Maniphest Task(s)', $count);
}
}

View file

@ -109,7 +109,6 @@ final class PhabricatorObjectHandle
static $map = array(
PhabricatorPHIDConstants::PHID_TYPE_USER => 'User',
PhabricatorPHIDConstants::PHID_TYPE_TASK => 'Task',
PhabricatorPHIDConstants::PHID_TYPE_WIKI => 'Phriction Document',
PhabricatorPHIDConstants::PHID_TYPE_MCRO => 'Image Macro',
PhabricatorPHIDConstants::PHID_TYPE_MOCK => 'Pholio Mock',

View file

@ -3,7 +3,6 @@
final class PhabricatorPHIDConstants {
const PHID_TYPE_USER = 'USER';
const PHID_TYPE_TASK = 'TASK';
const PHID_TYPE_FILE = 'FILE';
const PHID_TYPE_PROJ = 'PROJ';
const PHID_TYPE_UNKNOWN = '????';

View file

@ -56,15 +56,6 @@ final class PhabricatorObjectHandleData {
$phids);
return mpull($users, null, 'getPHID');
case PhabricatorPHIDConstants::PHID_TYPE_TASK:
// TODO: Update this to ManiphestTaskQuery, //especially// after we have
// policy-awareness
$task_dao = new ManiphestTask();
$tasks = $task_dao->loadAllWhere(
'phid IN (%Ls)',
$phids);
return mpull($tasks, null, 'getPHID');
case PhabricatorPHIDConstants::PHID_TYPE_CONF:
$config_dao = new PhabricatorConfigEntry();
$entries = $config_dao->loadAllWhere(
@ -318,28 +309,6 @@ final class PhabricatorObjectHandleData {
}
break;
case PhabricatorPHIDConstants::PHID_TYPE_TASK:
foreach ($phids as $phid) {
$handle = new PhabricatorObjectHandle();
$handle->setPHID($phid);
$handle->setType($type);
if (empty($objects[$phid])) {
$handle->setName('Unknown Task');
} else {
$task = $objects[$phid];
$handle->setName('T'.$task->getID());
$handle->setURI('/T'.$task->getID());
$handle->setFullName('T'.$task->getID().': '.$task->getTitle());
$handle->setComplete(true);
if ($task->getStatus() != ManiphestTaskStatus::STATUS_OPEN) {
$closed = PhabricatorObjectHandleStatus::STATUS_CLOSED;
$handle->setStatus($closed);
}
}
$handles[$phid] = $handle;
}
break;
case PhabricatorPHIDConstants::PHID_TYPE_CONF:
foreach ($phids as $phid) {
$handle = new PhabricatorObjectHandle();

View file

@ -44,9 +44,7 @@ final class PhabricatorPHID {
return $name;
}
if (preg_match('/^t(\d+)$/i', $name, $match)) {
$object = id(new ManiphestTask())->load($match[1]);
} else if (preg_match('/^m(\d+)$/i', $name, $match)) {
if (preg_match('/^m(\d+)$/i', $name, $match)) {
$objects = id(new PholioMockQuery())
->setViewer($viewer)
->withIDs(array($match[1]))

View file

@ -202,7 +202,7 @@ final class PhabricatorSearchAttachController
$noun = 'Revisions';
$selected = 'created';
break;
case PhabricatorPHIDConstants::PHID_TYPE_TASK:
case ManiphestPHIDTypeTask::TYPECONST:
$noun = 'Tasks';
$selected = 'assigned';
break;
@ -270,7 +270,7 @@ final class PhabricatorSearchAttachController
private function getEdgeType($src_type, $dst_type) {
$t_cmit = PhabricatorRepositoryPHIDTypeCommit::TYPECONST;
$t_task = PhabricatorPHIDConstants::PHID_TYPE_TASK;
$t_task = ManiphestPHIDTypeTask::TYPECONST;
$t_drev = DifferentialPHIDTypeRevision::TYPECONST;
$t_mock = PhabricatorPHIDConstants::PHID_TYPE_MOCK;

View file

@ -53,7 +53,7 @@ final class PhabricatorSearchController
$query->setParameter('open', 1);
$query->setParameter(
'type',
PhabricatorPHIDConstants::PHID_TYPE_TASK);
ManiphestPHIDTypeTask::TYPECONST);
break;
case PhabricatorSearchScope::SCOPE_WIKI:
$query->setParameter(

View file

@ -67,7 +67,7 @@ final class PhabricatorSearchSelectController
$pattern = null;
switch ($this->type) {
case PhabricatorPHIDConstants::PHID_TYPE_TASK:
case ManiphestPHIDTypeTask::TYPECONST:
$pattern = '/\bT(\d+)\b/i';
break;
case DifferentialPHIDTypeRevision::TYPECONST:
@ -99,7 +99,7 @@ final class PhabricatorSearchSelectController
'id IN (%Ld)',
$object_ids);
break;
case PhabricatorPHIDConstants::PHID_TYPE_TASK:
case ManiphestPHIDTypeTask::TYPECONST:
$objects = id(new ManiphestTask())->loadAllWhere(
'id IN (%Ld)',
$object_ids);

View file

@ -17,7 +17,7 @@ final class PhabricatorSearchAbstractDocument {
return array(
DifferentialPHIDTypeRevision::TYPECONST => 'Differential Revisions',
PhabricatorRepositoryPHIDTypeCommit::TYPECONST => 'Repository Commits',
PhabricatorPHIDConstants::PHID_TYPE_TASK => 'Maniphest Tasks',
ManiphestPHIDTypeTask::TYPECONST => 'Maniphest Tasks',
PhabricatorPHIDConstants::PHID_TYPE_WIKI => 'Phriction Documents',
PhabricatorPHIDConstants::PHID_TYPE_USER => 'Phabricator Users',
PhabricatorPHIDConstants::PHID_TYPE_QUES => 'Ponder Questions',

View file

@ -33,7 +33,7 @@ final class PhabricatorHovercardExample extends PhabricatorUIExample {
$task_handle = $this->createBasicDummyHandle(
"T123",
PhabricatorPHIDConstants::PHID_TYPE_TASK,
ManiphestPHIDTypeTask::TYPECONST,
"Improve Mobile Experience for Phabricator");
$tag = id(new PhabricatorTagView())

View file

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