[ Index ]

PHP Cross Reference of Phabricator

title

Body

[close]

/src/applications/differential/search/ -> DifferentialSearchIndexer.php (source)

   1  <?php
   2  
   3  final class DifferentialSearchIndexer
   4    extends PhabricatorSearchDocumentIndexer {
   5  
   6    public function getIndexableObject() {
   7      return new DifferentialRevision();
   8    }
   9  
  10    protected function loadDocumentByPHID($phid) {
  11      $object = id(new DifferentialRevisionQuery())
  12        ->setViewer($this->getViewer())
  13        ->withPHIDs(array($phid))
  14        ->needReviewerStatus(true)
  15        ->executeOne();
  16      if (!$object) {
  17        throw new Exception("Unable to load object by phid '{$phid}'!");
  18      }
  19      return $object;
  20    }
  21  
  22    protected function buildAbstractDocumentByPHID($phid) {
  23      $rev = $this->loadDocumentByPHID($phid);
  24  
  25      $doc = new PhabricatorSearchAbstractDocument();
  26      $doc->setPHID($rev->getPHID());
  27      $doc->setDocumentType(DifferentialRevisionPHIDType::TYPECONST);
  28      $doc->setDocumentTitle($rev->getTitle());
  29      $doc->setDocumentCreated($rev->getDateCreated());
  30      $doc->setDocumentModified($rev->getDateModified());
  31  
  32      $doc->addRelationship(
  33        PhabricatorSearchRelationship::RELATIONSHIP_AUTHOR,
  34        $rev->getAuthorPHID(),
  35        PhabricatorPeopleUserPHIDType::TYPECONST,
  36        $rev->getDateCreated());
  37  
  38      $doc->addRelationship(
  39        $rev->isClosed()
  40          ? PhabricatorSearchRelationship::RELATIONSHIP_CLOSED
  41          : PhabricatorSearchRelationship::RELATIONSHIP_OPEN,
  42        $rev->getPHID(),
  43        DifferentialRevisionPHIDType::TYPECONST,
  44        time());
  45  
  46      $this->indexTransactions(
  47        $doc,
  48        new DifferentialTransactionQuery(),
  49        array($rev->getPHID()));
  50  
  51      // If a revision needs review, the owners are the reviewers. Otherwise, the
  52      // owner is the author (e.g., accepted, rejected, closed).
  53      if ($rev->getStatus() == ArcanistDifferentialRevisionStatus::NEEDS_REVIEW) {
  54        $reviewers = $rev->getReviewerStatus();
  55        $reviewers = mpull($reviewers, 'getReviewerPHID', 'getReviewerPHID');
  56        if ($reviewers) {
  57          foreach ($reviewers as $phid) {
  58            $doc->addRelationship(
  59              PhabricatorSearchRelationship::RELATIONSHIP_OWNER,
  60              $phid,
  61              PhabricatorPeopleUserPHIDType::TYPECONST,
  62              $rev->getDateModified()); // Bogus timestamp.
  63          }
  64        } else {
  65          $doc->addRelationship(
  66            PhabricatorSearchRelationship::RELATIONSHIP_UNOWNED,
  67            $rev->getPHID(),
  68            PhabricatorPeopleUserPHIDType::TYPECONST,
  69            $rev->getDateModified()); // Bogus timestamp.
  70        }
  71      } else {
  72        $doc->addRelationship(
  73          PhabricatorSearchRelationship::RELATIONSHIP_OWNER,
  74          $rev->getAuthorPHID(),
  75          PhabricatorPHIDConstants::PHID_TYPE_VOID,
  76          $rev->getDateCreated());
  77      }
  78  
  79      return $doc;
  80    }
  81  }


Generated: Sun Nov 30 09:20:46 2014 Cross-referenced by PHPXref 0.7.1