1
0
Fork 0
mirror of https://we.phorge.it/source/phorge.git synced 2025-02-10 22:08:32 +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(); $id = $task->getID();
echo "Task {$id}: "; echo "Task {$id}: ";
$deps = $task->getAttachedPHIDs(PhabricatorPHIDConstants::PHID_TYPE_TASK); $deps = $task->getAttachedPHIDs(ManiphestPHIDTypeTask::TYPECONST);
if (!$deps) { if (!$deps) {
echo "-\n"; echo "-\n";
continue; continue;

View file

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

View file

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

View file

@ -101,7 +101,7 @@ final class ManiphestEdgeEventListener extends PhutilEventListener {
$add_edges = $event->getValue('add'); $add_edges = $event->getValue('add');
$rem_edges = $event->getValue('rem'); $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 = array_merge($add_edges, $rem_edges);
$all_edges = $this->filterEdgesBySourceType($all_edges, $type_task); $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 = new PhabricatorSearchAbstractDocument();
$doc->setPHID($task->getPHID()); $doc->setPHID($task->getPHID());
$doc->setDocumentType(PhabricatorPHIDConstants::PHID_TYPE_TASK); $doc->setDocumentType(ManiphestPHIDTypeTask::TYPECONST);
$doc->setDocumentTitle($task->getTitle()); $doc->setDocumentTitle($task->getTitle());
$doc->setDocumentCreated($task->getDateCreated()); $doc->setDocumentCreated($task->getDateCreated());
$doc->setDocumentModified($task->getDateModified()); $doc->setDocumentModified($task->getDateModified());
@ -34,7 +34,7 @@ final class ManiphestSearchIndexer
$doc->addRelationship( $doc->addRelationship(
PhabricatorSearchRelationship::RELATIONSHIP_OPEN, PhabricatorSearchRelationship::RELATIONSHIP_OPEN,
$task->getPHID(), $task->getPHID(),
PhabricatorPHIDConstants::PHID_TYPE_TASK, ManiphestPHIDTypeTask::TYPECONST,
time()); time());
} }

View file

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

View file

@ -483,7 +483,7 @@ final class ManiphestTransactionDetailView extends ManiphestView {
foreach (array( foreach (array(
DifferentialPHIDTypeRevision::TYPECONST, DifferentialPHIDTypeRevision::TYPECONST,
PhabricatorPHIDConstants::PHID_TYPE_TASK, ManiphestPHIDTypeTask::TYPECONST,
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()));
$new = array_keys(idx($new_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); 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);
case PhabricatorPHIDConstants::PHID_TYPE_TASK: case ManiphestPHIDTypeTask::TYPECONST:
return pht('Maniphest Task(s)', $count); return pht('Maniphest Task(s)', $count);
} }
} }

View file

@ -109,7 +109,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_WIKI => 'Phriction Document', PhabricatorPHIDConstants::PHID_TYPE_WIKI => 'Phriction Document',
PhabricatorPHIDConstants::PHID_TYPE_MCRO => 'Image Macro', PhabricatorPHIDConstants::PHID_TYPE_MCRO => 'Image Macro',
PhabricatorPHIDConstants::PHID_TYPE_MOCK => 'Pholio Mock', PhabricatorPHIDConstants::PHID_TYPE_MOCK => 'Pholio Mock',

View file

@ -3,7 +3,6 @@
final class PhabricatorPHIDConstants { final class PhabricatorPHIDConstants {
const PHID_TYPE_USER = 'USER'; const PHID_TYPE_USER = 'USER';
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';
const PHID_TYPE_UNKNOWN = '????'; const PHID_TYPE_UNKNOWN = '????';

View file

@ -56,15 +56,6 @@ final class PhabricatorObjectHandleData {
$phids); $phids);
return mpull($users, null, 'getPHID'); 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: case PhabricatorPHIDConstants::PHID_TYPE_CONF:
$config_dao = new PhabricatorConfigEntry(); $config_dao = new PhabricatorConfigEntry();
$entries = $config_dao->loadAllWhere( $entries = $config_dao->loadAllWhere(
@ -318,28 +309,6 @@ final class PhabricatorObjectHandleData {
} }
break; 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: case PhabricatorPHIDConstants::PHID_TYPE_CONF:
foreach ($phids as $phid) { foreach ($phids as $phid) {
$handle = new PhabricatorObjectHandle(); $handle = new PhabricatorObjectHandle();

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

@ -154,7 +154,6 @@ final class PhabricatorEdgeConfig extends PhabricatorEdgeConstants {
} }
static $class_map = array( static $class_map = array(
PhabricatorPHIDConstants::PHID_TYPE_TASK => 'ManiphestTask',
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',