Changeset View
Changeset View
Standalone View
Standalone View
src/applications/differential/search/DifferentialSearchIndexer.php
| <?php | <?php | ||||
| /** | |||||
| * @group differential | |||||
| */ | |||||
| final class DifferentialSearchIndexer | final class DifferentialSearchIndexer | ||||
| extends PhabricatorSearchDocumentIndexer { | extends PhabricatorSearchDocumentIndexer { | ||||
| public function getIndexableObject() { | public function getIndexableObject() { | ||||
| return new DifferentialRevision(); | return new DifferentialRevision(); | ||||
| } | } | ||||
| protected function loadDocumentByPHID($phid) { | |||||
| $object = id(new DifferentialRevisionQuery()) | |||||
| ->setViewer($this->getViewer()) | |||||
| ->withPHIDs(array($phid)) | |||||
| ->needReviewerStatus(true) | |||||
| ->executeOne(); | |||||
| if (!$object) { | |||||
| throw new Exception("Unable to load object by phid '{$phid}'!"); | |||||
| } | |||||
| return $object; | |||||
| } | |||||
| protected function buildAbstractDocumentByPHID($phid) { | protected function buildAbstractDocumentByPHID($phid) { | ||||
| $rev = $this->loadDocumentByPHID($phid); | $rev = $this->loadDocumentByPHID($phid); | ||||
| $doc = new PhabricatorSearchAbstractDocument(); | $doc = new PhabricatorSearchAbstractDocument(); | ||||
| $doc->setPHID($rev->getPHID()); | $doc->setPHID($rev->getPHID()); | ||||
| $doc->setDocumentType(DifferentialPHIDTypeRevision::TYPECONST); | $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()); | ||||
| $aux_fields = DifferentialFieldSelector::newSelector() | |||||
| ->getFieldSpecifications(); | |||||
| foreach ($aux_fields as $key => $aux_field) { | |||||
| $aux_field->setUser(PhabricatorUser::getOmnipotentUser()); | |||||
| if (!$aux_field->shouldAddToSearchIndex()) { | |||||
| unset($aux_fields[$key]); | |||||
| } | |||||
| } | |||||
| $aux_fields = DifferentialAuxiliaryField::loadFromStorage( | |||||
| $rev, | |||||
| $aux_fields); | |||||
| foreach ($aux_fields as $aux_field) { | |||||
| $doc->addField( | |||||
| $aux_field->getKeyForSearchIndex(), | |||||
| $aux_field->getValueForSearchIndex()); | |||||
| } | |||||
| $doc->addRelationship( | $doc->addRelationship( | ||||
| PhabricatorSearchRelationship::RELATIONSHIP_AUTHOR, | PhabricatorSearchRelationship::RELATIONSHIP_AUTHOR, | ||||
| $rev->getAuthorPHID(), | $rev->getAuthorPHID(), | ||||
| PhabricatorPeoplePHIDTypeUser::TYPECONST, | PhabricatorPeoplePHIDTypeUser::TYPECONST, | ||||
| $rev->getDateCreated()); | $rev->getDateCreated()); | ||||
| $doc->addRelationship( | $doc->addRelationship( | ||||
| $rev->isClosed() | $rev->isClosed() | ||||
| ? PhabricatorSearchRelationship::RELATIONSHIP_CLOSED | ? PhabricatorSearchRelationship::RELATIONSHIP_CLOSED | ||||
| : PhabricatorSearchRelationship::RELATIONSHIP_OPEN, | : PhabricatorSearchRelationship::RELATIONSHIP_OPEN, | ||||
| $rev->getPHID(), | $rev->getPHID(), | ||||
| DifferentialPHIDTypeRevision::TYPECONST, | DifferentialPHIDTypeRevision::TYPECONST, | ||||
| time()); | time()); | ||||
| $comments = id(new DifferentialCommentQuery()) | $this->indexTransactions( | ||||
| ->withRevisionPHIDs(array($rev->getPHID())) | $doc, | ||||
| ->execute(); | new DifferentialTransactionQuery(), | ||||
| array($rev->getPHID())); | |||||
| $inlines = id(new DifferentialInlineCommentQuery()) | |||||
| ->withRevisionIDs(array($rev->getID())) | |||||
| ->withNotDraft(true) | |||||
| ->execute(); | |||||
| foreach (array_merge($comments, $inlines) as $comment) { | |||||
| if (strlen($comment->getContent())) { | |||||
| $doc->addField( | |||||
| PhabricatorSearchField::FIELD_COMMENT, | |||||
| $comment->getContent()); | |||||
| } | |||||
| } | |||||
| $rev->loadRelationships(); | |||||
| // If a revision needs review, the owners are the reviewers. Otherwise, the | // If a revision needs review, the owners are the reviewers. Otherwise, the | ||||
| // owner is the author (e.g., accepted, rejected, closed). | // owner is the author (e.g., accepted, rejected, closed). | ||||
| if ($rev->getStatus() == ArcanistDifferentialRevisionStatus::NEEDS_REVIEW) { | if ($rev->getStatus() == ArcanistDifferentialRevisionStatus::NEEDS_REVIEW) { | ||||
| $reviewers = $rev->getReviewers(); | $reviewers = $rev->getReviewerStatus(); | ||||
| $reviewers = mpull($reviewers, 'getReviewerPHID', 'getReviewerPHID'); | |||||
| if ($reviewers) { | if ($reviewers) { | ||||
| foreach ($reviewers as $phid) { | foreach ($reviewers as $phid) { | ||||
| $doc->addRelationship( | $doc->addRelationship( | ||||
| PhabricatorSearchRelationship::RELATIONSHIP_OWNER, | PhabricatorSearchRelationship::RELATIONSHIP_OWNER, | ||||
| $phid, | $phid, | ||||
| PhabricatorPeoplePHIDTypeUser::TYPECONST, | PhabricatorPeoplePHIDTypeUser::TYPECONST, | ||||
| $rev->getDateModified()); // Bogus timestamp. | $rev->getDateModified()); // Bogus timestamp. | ||||
| } | } | ||||
| } else { | } else { | ||||
| $doc->addRelationship( | $doc->addRelationship( | ||||
| PhabricatorSearchRelationship::RELATIONSHIP_UNOWNED, | PhabricatorSearchRelationship::RELATIONSHIP_UNOWNED, | ||||
| $rev->getPHID(), | $rev->getPHID(), | ||||
| PhabricatorPeoplePHIDTypeUser::TYPECONST, | PhabricatorPeoplePHIDTypeUser::TYPECONST, | ||||
| $rev->getDateModified()); // Bogus timestamp. | $rev->getDateModified()); // Bogus timestamp. | ||||
| } | } | ||||
| } else { | } else { | ||||
| $doc->addRelationship( | $doc->addRelationship( | ||||
| PhabricatorSearchRelationship::RELATIONSHIP_OWNER, | PhabricatorSearchRelationship::RELATIONSHIP_OWNER, | ||||
| $rev->getAuthorPHID(), | $rev->getAuthorPHID(), | ||||
| PhabricatorPHIDConstants::PHID_TYPE_VOID, | PhabricatorPHIDConstants::PHID_TYPE_VOID, | ||||
| $rev->getDateCreated()); | $rev->getDateCreated()); | ||||
| } | } | ||||
| $ccphids = $rev->getCCPHIDs(); | |||||
| $handles = id(new PhabricatorHandleQuery()) | |||||
| ->setViewer(PhabricatorUser::getOmnipotentUser()) | |||||
| ->withPHIDs($ccphids) | |||||
| ->execute(); | |||||
| foreach ($handles as $phid => $handle) { | |||||
| $doc->addRelationship( | |||||
| PhabricatorSearchRelationship::RELATIONSHIP_SUBSCRIBER, | |||||
| $phid, | |||||
| $handle->getType(), | |||||
| $rev->getDateModified()); // Bogus timestamp. | |||||
| } | |||||
| return $doc; | return $doc; | ||||
| } | } | ||||
| } | } | ||||