2011-02-15 00:34:20 +01:00
|
|
|
<?php
|
|
|
|
|
2011-09-14 17:02:31 +02:00
|
|
|
/**
|
|
|
|
* @group search
|
|
|
|
*/
|
2012-03-14 00:21:04 +01:00
|
|
|
final class PhabricatorSearchManiphestIndexer
|
2011-02-15 00:34:20 +01:00
|
|
|
extends PhabricatorSearchDocumentIndexer {
|
|
|
|
|
|
|
|
public static function indexTask(ManiphestTask $task) {
|
|
|
|
$doc = new PhabricatorSearchAbstractDocument();
|
|
|
|
$doc->setPHID($task->getPHID());
|
2011-03-03 03:58:21 +01:00
|
|
|
$doc->setDocumentType(PhabricatorPHIDConstants::PHID_TYPE_TASK);
|
2011-02-15 00:34:20 +01:00
|
|
|
$doc->setDocumentTitle($task->getTitle());
|
|
|
|
$doc->setDocumentCreated($task->getDateCreated());
|
|
|
|
$doc->setDocumentModified($task->getDateModified());
|
|
|
|
|
|
|
|
$doc->addField(
|
|
|
|
PhabricatorSearchField::FIELD_BODY,
|
|
|
|
$task->getDescription());
|
|
|
|
|
|
|
|
$doc->addRelationship(
|
|
|
|
PhabricatorSearchRelationship::RELATIONSHIP_AUTHOR,
|
2011-02-19 02:16:00 +01:00
|
|
|
$task->getAuthorPHID(),
|
2011-03-03 03:58:21 +01:00
|
|
|
PhabricatorPHIDConstants::PHID_TYPE_USER,
|
2011-02-19 02:16:00 +01:00
|
|
|
$task->getDateCreated());
|
|
|
|
|
|
|
|
if ($task->getStatus() == ManiphestTaskStatus::STATUS_OPEN) {
|
|
|
|
$doc->addRelationship(
|
|
|
|
PhabricatorSearchRelationship::RELATIONSHIP_OPEN,
|
|
|
|
$task->getPHID(),
|
2011-03-03 03:58:21 +01:00
|
|
|
PhabricatorPHIDConstants::PHID_TYPE_TASK,
|
2011-02-19 02:16:00 +01:00
|
|
|
time());
|
|
|
|
}
|
|
|
|
|
|
|
|
$transactions = id(new ManiphestTransaction())->loadAllWhere(
|
|
|
|
'taskID = %d',
|
|
|
|
$task->getID());
|
|
|
|
|
|
|
|
$current_ccs = $task->getCCPHIDs();
|
|
|
|
$touches = array();
|
|
|
|
$owner = null;
|
|
|
|
$ccs = array();
|
|
|
|
foreach ($transactions as $transaction) {
|
|
|
|
if ($transaction->hasComments()) {
|
|
|
|
$doc->addField(
|
|
|
|
PhabricatorSearchField::FIELD_COMMENT,
|
|
|
|
$transaction->getComments());
|
|
|
|
}
|
|
|
|
|
|
|
|
$author = $transaction->getAuthorPHID();
|
|
|
|
|
|
|
|
// Record the most recent time they touched this object.
|
|
|
|
$touches[$author] = $transaction->getDateCreated();
|
|
|
|
|
|
|
|
switch ($transaction->getTransactionType()) {
|
|
|
|
case ManiphestTransactionType::TYPE_OWNER:
|
|
|
|
$owner = $transaction;
|
|
|
|
break;
|
|
|
|
case ManiphestTransactionType::TYPE_CCS:
|
|
|
|
// For users who are still CC'd, record the first time they were
|
|
|
|
// added to CC.
|
|
|
|
foreach ($transaction->getNewValue() as $added_cc) {
|
|
|
|
if (in_array($added_cc, $current_ccs)) {
|
|
|
|
if (empty($ccs[$added_cc])) {
|
|
|
|
$ccs[$added_cc] = $transaction->getDateCreated();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-02-21 05:37:50 +01:00
|
|
|
foreach ($task->getProjectPHIDs() as $phid) {
|
|
|
|
$doc->addRelationship(
|
|
|
|
PhabricatorSearchRelationship::RELATIONSHIP_PROJECT,
|
|
|
|
$phid,
|
2011-03-03 03:58:21 +01:00
|
|
|
PhabricatorPHIDConstants::PHID_TYPE_PROJ,
|
2011-02-21 05:37:50 +01:00
|
|
|
$task->getDateModified()); // Bogus.
|
|
|
|
}
|
|
|
|
|
2011-02-19 02:16:00 +01:00
|
|
|
if ($owner && $owner->getNewValue()) {
|
|
|
|
$doc->addRelationship(
|
|
|
|
PhabricatorSearchRelationship::RELATIONSHIP_OWNER,
|
|
|
|
$owner->getNewValue(),
|
2011-03-03 03:58:21 +01:00
|
|
|
PhabricatorPHIDConstants::PHID_TYPE_USER,
|
2011-02-19 02:16:00 +01:00
|
|
|
$owner->getDateCreated());
|
2011-02-21 05:37:50 +01:00
|
|
|
} else {
|
|
|
|
$doc->addRelationship(
|
|
|
|
PhabricatorSearchRelationship::RELATIONSHIP_OWNER,
|
2011-05-28 23:13:12 +02:00
|
|
|
ManiphestTaskOwner::OWNER_UP_FOR_GRABS,
|
2011-03-03 03:58:21 +01:00
|
|
|
PhabricatorPHIDConstants::PHID_TYPE_MAGIC,
|
2011-02-21 05:37:50 +01:00
|
|
|
$owner
|
|
|
|
? $owner->getDateCreated()
|
|
|
|
: $task->getDateCreated());
|
2011-02-19 02:16:00 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
foreach ($touches as $touch => $time) {
|
|
|
|
$doc->addRelationship(
|
|
|
|
PhabricatorSearchRelationship::RELATIONSHIP_TOUCH,
|
|
|
|
$touch,
|
2011-03-03 03:58:21 +01:00
|
|
|
PhabricatorPHIDConstants::PHID_TYPE_USER,
|
2011-02-19 02:16:00 +01:00
|
|
|
$time);
|
|
|
|
}
|
|
|
|
|
|
|
|
// We need to load handles here since non-users may subscribe (mailing
|
|
|
|
// lists, e.g.)
|
|
|
|
$handles = id(new PhabricatorObjectHandleData(array_keys($ccs)))
|
|
|
|
->loadHandles();
|
|
|
|
foreach ($ccs as $cc => $time) {
|
|
|
|
$doc->addRelationship(
|
|
|
|
PhabricatorSearchRelationship::RELATIONSHIP_SUBSCRIBER,
|
|
|
|
$handles[$cc]->getPHID(),
|
|
|
|
$handles[$cc]->getType(),
|
|
|
|
$time);
|
|
|
|
}
|
2011-02-15 00:34:20 +01:00
|
|
|
|
2011-08-08 00:14:23 +02:00
|
|
|
self::reindexAbstractDocument($doc);
|
2011-02-15 00:34:20 +01:00
|
|
|
}
|
|
|
|
}
|