public static function indexQuestion(PonderQuestion $question)
 {
     // note: we assume someone's already called attachrelated on $question
     $doc = new PhabricatorSearchAbstractDocument();
     $doc->setPHID($question->getPHID());
     $doc->setDocumentType(PhabricatorPHIDConstants::PHID_TYPE_QUES);
     $doc->setDocumentTitle($question->getTitle());
     $doc->setDocumentCreated($question->getDateCreated());
     $doc->setDocumentModified($question->getDateModified());
     $doc->addField(PhabricatorSearchField::FIELD_BODY, $question->getContent());
     $doc->addRelationship(PhabricatorSearchRelationship::RELATIONSHIP_AUTHOR, $question->getAuthorPHID(), PhabricatorPHIDConstants::PHID_TYPE_USER, $question->getDateCreated());
     $comments = $question->getComments();
     foreach ($comments as $curcomment) {
         $doc->addField(PhabricatorSearchField::FIELD_COMMENT, $curcomment->getContent());
     }
     $answers = $question->getAnswers();
     foreach ($answers as $curanswer) {
         if (strlen($curanswer->getContent())) {
             $doc->addField(PhabricatorSearchField::FIELD_COMMENT, $curanswer->getContent());
         }
         $answer_comments = $curanswer->getComments();
         foreach ($answer_comments as $curcomment) {
             $doc->addField(PhabricatorSearchField::FIELD_COMMENT, $curcomment->getContent());
         }
     }
     self::reindexAbstractDocument($doc);
 }
 public static function indexCommit(PhabricatorRepositoryCommit $commit)
 {
     $commit_data = id(new PhabricatorRepositoryCommitData())->loadOneWhere('commitID = %d', $commit->getID());
     $date_created = $commit->getEpoch();
     $commit_message = $commit_data->getCommitMessage();
     $author_phid = $commit_data->getCommitDetail('authorPHID');
     $repository = id(new PhabricatorRepository())->loadOneWhere('id = %d', $commit->getRepositoryID());
     if (!$repository) {
         return;
     }
     $title = 'r' . $repository->getCallsign() . $commit->getCommitIdentifier() . " " . $commit_data->getSummary();
     $doc = new PhabricatorSearchAbstractDocument();
     $doc->setPHID($commit->getPHID());
     $doc->setDocumentType(PhabricatorPHIDConstants::PHID_TYPE_CMIT);
     $doc->setDocumentCreated($date_created);
     $doc->setDocumentModified($date_created);
     $doc->setDocumentTitle($title);
     $doc->addField(PhabricatorSearchField::FIELD_BODY, $commit_message);
     if ($author_phid) {
         $doc->addRelationship(PhabricatorSearchRelationship::RELATIONSHIP_AUTHOR, $author_phid, PhabricatorPHIDConstants::PHID_TYPE_USER, $date_created);
     }
     $doc->addRelationship(PhabricatorSearchRelationship::RELATIONSHIP_REPOSITORY, $repository->getPHID(), PhabricatorPHIDConstants::PHID_TYPE_REPO, $date_created);
     $comments = id(new PhabricatorAuditComment())->loadAllWhere('targetPHID = %s', $commit->getPHID());
     foreach ($comments as $comment) {
         if (strlen($comment->getContent())) {
             $doc->addField(PhabricatorSearchField::FIELD_COMMENT, $comment->getContent());
         }
     }
     self::reindexAbstractDocument($doc);
 }
 protected function buildAbstractDocument(PhabricatorSearchAbstractDocument $document, $object)
 {
     $book = $object;
     $document->setDocumentTitle($book->getTitle());
     $document->addField(PhabricatorSearchDocumentFieldType::FIELD_BODY, $book->getPreface());
     $document->addRelationship(PhabricatorSearchRelationship::RELATIONSHIP_REPOSITORY, $book->getRepositoryPHID(), PhabricatorRepositoryRepositoryPHIDType::TYPECONST, $book->getDateCreated());
 }
 protected function buildAbstractDocument(PhabricatorSearchAbstractDocument $document, $object)
 {
     $mock = $object;
     $document->setDocumentTitle($mock->getName());
     $document->addField(PhabricatorSearchDocumentFieldType::FIELD_BODY, $mock->getDescription());
     $document->addRelationship(PhabricatorSearchRelationship::RELATIONSHIP_AUTHOR, $mock->getAuthorPHID(), PhabricatorPeopleUserPHIDType::TYPECONST, $mock->getDateCreated());
 }
 protected function buildAbstractDocument(PhabricatorSearchAbstractDocument $document, $object)
 {
     $credential = $object;
     $document->setDocumentTitle($credential->getName());
     $document->addField(PhabricatorSearchDocumentFieldType::FIELD_BODY, $credential->getDescription());
     $document->addRelationship($credential->getIsDestroyed() ? PhabricatorSearchRelationship::RELATIONSHIP_CLOSED : PhabricatorSearchRelationship::RELATIONSHIP_OPEN, $credential->getPHID(), PassphraseCredentialPHIDType::TYPECONST, PhabricatorTime::getNow());
 }
 protected function buildAbstractDocumentByPHID($phid)
 {
     $task = $this->loadDocumentByPHID($phid);
     $doc = new PhabricatorSearchAbstractDocument();
     $doc->setPHID($task->getPHID());
     $doc->setDocumentType(ManiphestTaskPHIDType::TYPECONST);
     $doc->setDocumentTitle($task->getTitle());
     $doc->setDocumentCreated($task->getDateCreated());
     $doc->setDocumentModified($task->getDateModified());
     $doc->addField(PhabricatorSearchField::FIELD_BODY, $task->getDescription());
     $doc->addRelationship(PhabricatorSearchRelationship::RELATIONSHIP_AUTHOR, $task->getAuthorPHID(), PhabricatorPeopleUserPHIDType::TYPECONST, $task->getDateCreated());
     $doc->addRelationship($task->isClosed() ? PhabricatorSearchRelationship::RELATIONSHIP_CLOSED : PhabricatorSearchRelationship::RELATIONSHIP_OPEN, $task->getPHID(), ManiphestTaskPHIDType::TYPECONST, time());
     $this->indexTransactions($doc, new ManiphestTransactionQuery(), array($phid));
     foreach ($task->getProjectPHIDs() as $phid) {
         $doc->addRelationship(PhabricatorSearchRelationship::RELATIONSHIP_PROJECT, $phid, PhabricatorProjectProjectPHIDType::TYPECONST, $task->getDateModified());
         // Bogus.
     }
     $owner = $task->getOwnerPHID();
     if ($owner) {
         $doc->addRelationship(PhabricatorSearchRelationship::RELATIONSHIP_OWNER, $owner, PhabricatorPeopleUserPHIDType::TYPECONST, time());
     } else {
         $doc->addRelationship(PhabricatorSearchRelationship::RELATIONSHIP_UNOWNED, $task->getPHID(), PhabricatorPHIDConstants::PHID_TYPE_VOID, $task->getDateCreated());
     }
     // We need to load handles here since non-users may subscribe (mailing
     // lists, e.g.)
     $ccs = $task->getCCPHIDs();
     $handles = id(new PhabricatorHandleQuery())->setViewer(PhabricatorUser::getOmnipotentUser())->withPHIDs($ccs)->execute();
     foreach ($ccs as $cc) {
         $doc->addRelationship(PhabricatorSearchRelationship::RELATIONSHIP_SUBSCRIBER, $handles[$cc]->getPHID(), $handles[$cc]->getType(), time());
     }
     return $doc;
 }
 protected function buildAbstractDocumentByPHID($phid)
 {
     $commit = $this->loadDocumentByPHID($phid);
     $commit_data = id(new PhabricatorRepositoryCommitData())->loadOneWhere('commitID = %d', $commit->getID());
     $date_created = $commit->getEpoch();
     $commit_message = $commit_data->getCommitMessage();
     $author_phid = $commit_data->getCommitDetail('authorPHID');
     $repository = id(new PhabricatorRepositoryQuery())->setViewer($this->getViewer())->withIDs(array($commit->getRepositoryID()))->executeOne();
     if (!$repository) {
         throw new Exception(pht('No such repository!'));
     }
     $title = 'r' . $repository->getCallsign() . $commit->getCommitIdentifier() . ' ' . $commit_data->getSummary();
     $doc = new PhabricatorSearchAbstractDocument();
     $doc->setPHID($commit->getPHID());
     $doc->setDocumentType(PhabricatorRepositoryCommitPHIDType::TYPECONST);
     $doc->setDocumentCreated($date_created);
     $doc->setDocumentModified($date_created);
     $doc->setDocumentTitle($title);
     $doc->addField(PhabricatorSearchDocumentFieldType::FIELD_BODY, $commit_message);
     if ($author_phid) {
         $doc->addRelationship(PhabricatorSearchRelationship::RELATIONSHIP_AUTHOR, $author_phid, PhabricatorPeopleUserPHIDType::TYPECONST, $date_created);
     }
     $doc->addRelationship(PhabricatorSearchRelationship::RELATIONSHIP_REPOSITORY, $repository->getPHID(), PhabricatorRepositoryRepositoryPHIDType::TYPECONST, $date_created);
     $this->indexTransactions($doc, new PhabricatorAuditTransactionQuery(), array($commit->getPHID()));
     return $doc;
 }
 protected function buildAbstractDocument(PhabricatorSearchAbstractDocument $document, $object)
 {
     $blog = $object;
     $document->setDocumentTitle($blog->getName());
     $document->addField(PhabricatorSearchDocumentFieldType::FIELD_BODY, $blog->getDescription());
     $document->addRelationship($blog->isArchived() ? PhabricatorSearchRelationship::RELATIONSHIP_CLOSED : PhabricatorSearchRelationship::RELATIONSHIP_OPEN, $blog->getPHID(), PhabricatorPhameBlogPHIDType::TYPECONST, PhabricatorTime::getNow());
 }
 public static function indexRevision(DifferentialRevision $rev)
 {
     $doc = new PhabricatorSearchAbstractDocument();
     $doc->setPHID($rev->getPHID());
     $doc->setDocumentType(PhabricatorPHIDConstants::PHID_TYPE_DREV);
     $doc->setDocumentTitle($rev->getTitle());
     $doc->setDocumentCreated($rev->getDateCreated());
     $doc->setDocumentModified($rev->getDateModified());
     $doc->addField(PhabricatorSearchField::FIELD_BODY, $rev->getSummary());
     $doc->addField(PhabricatorSearchField::FIELD_TEST_PLAN, $rev->getTestPlan());
     $doc->addRelationship(PhabricatorSearchRelationship::RELATIONSHIP_AUTHOR, $rev->getAuthorPHID(), PhabricatorPHIDConstants::PHID_TYPE_USER, $rev->getDateCreated());
     if ($rev->getStatus() != ArcanistDifferentialRevisionStatus::CLOSED && $rev->getStatus() != ArcanistDifferentialRevisionStatus::ABANDONED) {
         $doc->addRelationship(PhabricatorSearchRelationship::RELATIONSHIP_OPEN, $rev->getPHID(), PhabricatorPHIDConstants::PHID_TYPE_DREV, time());
     }
     $comments = id(new DifferentialComment())->loadAllWhere('revisionID = %d', $rev->getID());
     $inlines = id(new DifferentialInlineComment())->loadAllWhere('revisionID = %d AND commentID IS NOT NULL', $rev->getID());
     $touches = array();
     foreach (array_merge($comments, $inlines) as $comment) {
         if (strlen($comment->getContent())) {
             $doc->addField(PhabricatorSearchField::FIELD_COMMENT, $comment->getContent());
         }
         $author = $comment->getAuthorPHID();
         $touches[$author] = $comment->getDateCreated();
     }
     foreach ($touches as $touch => $time) {
         $doc->addRelationship(PhabricatorSearchRelationship::RELATIONSHIP_TOUCH, $touch, PhabricatorPHIDConstants::PHID_TYPE_USER, $time);
     }
     $rev->loadRelationships();
     // If a revision needs review, the owners are the reviewers. Otherwise, the
     // owner is the author (e.g., accepted, rejected, closed).
     if ($rev->getStatus() == ArcanistDifferentialRevisionStatus::NEEDS_REVIEW) {
         foreach ($rev->getReviewers() as $phid) {
             $doc->addRelationship(PhabricatorSearchRelationship::RELATIONSHIP_OWNER, $phid, PhabricatorPHIDConstants::PHID_TYPE_USER, $rev->getDateModified());
             // Bogus timestamp.
         }
     } else {
         $doc->addRelationship(PhabricatorSearchRelationship::RELATIONSHIP_OWNER, $rev->getAuthorPHID(), PhabricatorPHIDConstants::PHID_TYPE_USER, $rev->getDateCreated());
     }
     $ccphids = $rev->getCCPHIDs();
     $handles = id(new PhabricatorObjectHandleData($ccphids))->loadHandles();
     foreach ($handles as $phid => $handle) {
         $doc->addRelationship(PhabricatorSearchRelationship::RELATIONSHIP_SUBSCRIBER, $phid, $handle->getType(), $rev->getDateModified());
         // Bogus timestamp.
     }
     self::reindexAbstractDocument($doc);
 }
 protected function buildAbstractDocument(PhabricatorSearchAbstractDocument $document, $object)
 {
     $post = $object;
     $document->setDocumentTitle($post->getTitle());
     $document->addField(PhabricatorSearchDocumentFieldType::FIELD_BODY, $post->getBody());
     $document->addRelationship(PhabricatorSearchRelationship::RELATIONSHIP_AUTHOR, $post->getBloggerPHID(), PhabricatorPeopleUserPHIDType::TYPECONST, $post->getDateCreated());
     $document->addRelationship($post->isArchived() ? PhabricatorSearchRelationship::RELATIONSHIP_CLOSED : PhabricatorSearchRelationship::RELATIONSHIP_OPEN, $post->getPHID(), PhabricatorPhamePostPHIDType::TYPECONST, PhabricatorTime::getNow());
 }
 protected function buildAbstractDocument(PhabricatorSearchAbstractDocument $document, $object)
 {
     $event = $object;
     $document->setDocumentTitle($event->getName());
     $document->addField(PhabricatorSearchDocumentFieldType::FIELD_BODY, $event->getDescription());
     $document->addRelationship(PhabricatorSearchRelationship::RELATIONSHIP_AUTHOR, $event->getHostPHID(), PhabricatorPeopleUserPHIDType::TYPECONST, $event->getDateCreated());
     $document->addRelationship(PhabricatorSearchRelationship::RELATIONSHIP_OWNER, $event->getHostPHID(), PhabricatorPeopleUserPHIDType::TYPECONST, $event->getDateCreated());
     $document->addRelationship($event->getIsCancelled() ? PhabricatorSearchRelationship::RELATIONSHIP_CLOSED : PhabricatorSearchRelationship::RELATIONSHIP_OPEN, $event->getPHID(), PhabricatorCalendarEventPHIDType::TYPECONST, PhabricatorTime::getNow());
 }
 protected function buildAbstractDocument(PhabricatorSearchAbstractDocument $document, $object)
 {
     $atom = $object;
     $book = $atom->getBook();
     $document->setDocumentTitle($atom->getTitle())->setDocumentCreated($book->getDateCreated())->setDocumentModified($book->getDateModified());
     $document->addField(PhabricatorSearchDocumentFieldType::FIELD_BODY, $atom->getSummary());
     $document->addRelationship(PhabricatorSearchRelationship::RELATIONSHIP_BOOK, $atom->getBookPHID(), DivinerBookPHIDType::TYPECONST, PhabricatorTime::getNow());
     $document->addRelationship(PhabricatorSearchRelationship::RELATIONSHIP_REPOSITORY, $atom->getRepositoryPHID(), PhabricatorRepositoryRepositoryPHIDType::TYPECONST, PhabricatorTime::getNow());
     $document->addRelationship($atom->getGraphHash() ? PhabricatorSearchRelationship::RELATIONSHIP_CLOSED : PhabricatorSearchRelationship::RELATIONSHIP_OPEN, $atom->getBookPHID(), DivinerBookPHIDType::TYPECONST, PhabricatorTime::getNow());
 }
 protected function indexTransactions(PhabricatorSearchAbstractDocument $doc, PhabricatorApplicationTransactionQuery $query, array $phids)
 {
     $xactions = id(clone $query)->setViewer($this->getViewer())->withObjectPHIDs($phids)->execute();
     foreach ($xactions as $xaction) {
         if (!$xaction->hasComment()) {
             continue;
         }
         $comment = $xaction->getComment();
         $doc->addField(PhabricatorSearchField::FIELD_COMMENT, $comment->getContent());
     }
 }
 public static function indexQuestion(PonderQuestion $question)
 {
     $doc = new PhabricatorSearchAbstractDocument();
     $doc->setPHID($question->getPHID());
     $doc->setDocumentType(PhabricatorPHIDConstants::PHID_TYPE_QUES);
     $doc->setDocumentTitle($question->getTitle());
     $doc->setDocumentCreated($question->getDateCreated());
     $doc->setDocumentModified($question->getDateModified());
     $doc->addField(PhabricatorSearchField::FIELD_BODY, $question->getContent());
     $doc->addRelationship(PhabricatorSearchRelationship::RELATIONSHIP_AUTHOR, $question->getAuthorPHID(), PhabricatorPHIDConstants::PHID_TYPE_USER, $question->getDateCreated());
     $answers = $question->getAnswers();
     $touches = array();
     foreach ($answers as $comment) {
         if (strlen($comment->getContent())) {
             $doc->addField(PhabricatorSearchField::FIELD_COMMENT, $comment->getContent());
         }
         $author = $comment->getAuthorPHID();
         $touches[$author] = $comment->getDateCreated();
     }
     self::reindexAbstractDocument($doc);
 }
 protected function buildAbstractDocument(PhabricatorSearchAbstractDocument $document, $object)
 {
     $wiki = id(new PhrictionDocumentQuery())->setViewer($this->getViewer())->withPHIDs(array($document->getPHID()))->needContent(true)->executeOne();
     $content = $wiki->getContent();
     $document->setDocumentTitle($content->getTitle());
     // TODO: These are not quite correct, but we don't currently store the
     // proper dates in a way that's easy to get to.
     $document->setDocumentCreated($content->getDateCreated())->setDocumentModified($content->getDateModified());
     $document->addField(PhabricatorSearchDocumentFieldType::FIELD_BODY, $content->getContent());
     $document->addRelationship(PhabricatorSearchRelationship::RELATIONSHIP_AUTHOR, $content->getAuthorPHID(), PhabricatorPeopleUserPHIDType::TYPECONST, $content->getDateCreated());
     $document->addRelationship($wiki->getStatus() == PhrictionDocumentStatus::STATUS_EXISTS ? PhabricatorSearchRelationship::RELATIONSHIP_OPEN : PhabricatorSearchRelationship::RELATIONSHIP_CLOSED, $wiki->getPHID(), PhrictionDocumentPHIDType::TYPECONST, PhabricatorTime::getNow());
 }
 protected function buildAbstractDocumentByPHID($phid)
 {
     $credential = $this->loadDocumentByPHID($phid);
     $doc = new PhabricatorSearchAbstractDocument();
     $doc->setPHID($credential->getPHID());
     $doc->setDocumentType(PassphraseCredentialPHIDType::TYPECONST);
     $doc->setDocumentTitle($credential->getName());
     $doc->setDocumentCreated($credential->getDateCreated());
     $doc->setDocumentModified($credential->getDateModified());
     $doc->addField(PhabricatorSearchDocumentFieldType::FIELD_BODY, $credential->getDescription());
     $doc->addRelationship($credential->getIsDestroyed() ? PhabricatorSearchRelationship::RELATIONSHIP_CLOSED : PhabricatorSearchRelationship::RELATIONSHIP_OPEN, $credential->getPHID(), PassphraseCredentialPHIDType::TYPECONST, time());
     $this->indexTransactions($doc, new PassphraseCredentialTransactionQuery(), array($phid));
     return $doc;
 }
 protected function buildAbstractDocument(PhabricatorSearchAbstractDocument $document, $object)
 {
     $task = $object;
     $document->setDocumentTitle($task->getTitle());
     $document->addField(PhabricatorSearchDocumentFieldType::FIELD_BODY, $task->getDescription());
     $document->addRelationship(PhabricatorSearchRelationship::RELATIONSHIP_AUTHOR, $task->getAuthorPHID(), PhabricatorPeopleUserPHIDType::TYPECONST, $task->getDateCreated());
     $document->addRelationship($task->isClosed() ? PhabricatorSearchRelationship::RELATIONSHIP_CLOSED : PhabricatorSearchRelationship::RELATIONSHIP_OPEN, $task->getPHID(), ManiphestTaskPHIDType::TYPECONST, PhabricatorTime::getNow());
     $owner = $task->getOwnerPHID();
     if ($owner) {
         $document->addRelationship(PhabricatorSearchRelationship::RELATIONSHIP_OWNER, $owner, PhabricatorPeopleUserPHIDType::TYPECONST, time());
     } else {
         $document->addRelationship(PhabricatorSearchRelationship::RELATIONSHIP_UNOWNED, $task->getPHID(), PhabricatorPHIDConstants::PHID_TYPE_VOID, $task->getDateCreated());
     }
 }
 public static function indexDocument(PhrictionDocument $document)
 {
     $content = $document->getContent();
     $doc = new PhabricatorSearchAbstractDocument();
     $doc->setPHID($document->getPHID());
     $doc->setDocumentType(PhabricatorPHIDConstants::PHID_TYPE_WIKI);
     $doc->setDocumentTitle($content->getTitle());
     // TODO: This isn't precisely correct, denormalize into the Document table?
     $doc->setDocumentCreated($content->getDateCreated());
     $doc->setDocumentModified($content->getDateModified());
     $doc->addField(PhabricatorSearchField::FIELD_BODY, $content->getContent());
     $doc->addRelationship(PhabricatorSearchRelationship::RELATIONSHIP_AUTHOR, $content->getAuthorPHID(), PhabricatorPHIDConstants::PHID_TYPE_USER, $content->getDateCreated());
     self::reindexAbstractDocument($doc);
 }
 public function indexFulltextObject($object, PhabricatorSearchAbstractDocument $document)
 {
     $query = PhabricatorApplicationTransactionQuery::newQueryForObject($object);
     if (!$query) {
         return;
     }
     $xactions = $query->setViewer($this->getViewer())->withObjectPHIDs(array($object->getPHID()))->needComments(true)->execute();
     foreach ($xactions as $xaction) {
         if (!$xaction->hasComment()) {
             continue;
         }
         $comment = $xaction->getComment();
         $document->addField(PhabricatorSearchDocumentFieldType::FIELD_COMMENT, $comment->getContent());
     }
 }
 protected function buildAbstractDocument(PhabricatorSearchAbstractDocument $document, $object)
 {
     $commit = id(new DiffusionCommitQuery())->setViewer($this->getViewer())->withPHIDs(array($object->getPHID()))->needCommitData(true)->executeOne();
     $repository = $commit->getRepository();
     $commit_data = $commit->getCommitData();
     $date_created = $commit->getEpoch();
     $commit_message = $commit_data->getCommitMessage();
     $author_phid = $commit_data->getCommitDetail('authorPHID');
     $title = 'r' . $repository->getCallsign() . $commit->getCommitIdentifier() . ' ' . $commit_data->getSummary();
     $document->setDocumentCreated($date_created)->setDocumentModified($date_created)->setDocumentTitle($title);
     $document->addField(PhabricatorSearchDocumentFieldType::FIELD_BODY, $commit_message);
     if ($author_phid) {
         $document->addRelationship(PhabricatorSearchRelationship::RELATIONSHIP_AUTHOR, $author_phid, PhabricatorPeopleUserPHIDType::TYPECONST, $date_created);
     }
     $document->addRelationship(PhabricatorSearchRelationship::RELATIONSHIP_REPOSITORY, $repository->getPHID(), PhabricatorRepositoryRepositoryPHIDType::TYPECONST, $date_created);
 }
 protected function buildAbstractDocumentByPHID($phid)
 {
     $event = $this->loadDocumentByPHID($phid);
     $doc = new PhabricatorSearchAbstractDocument();
     $doc->setPHID($event->getPHID());
     $doc->setDocumentType(PhabricatorCalendarEventPHIDType::TYPECONST);
     $doc->setDocumentTitle($event->getName());
     $doc->setDocumentCreated($event->getDateCreated());
     $doc->setDocumentModified($event->getDateModified());
     $doc->addField(PhabricatorSearchDocumentFieldType::FIELD_BODY, $event->getDescription());
     $doc->addRelationship(PhabricatorSearchRelationship::RELATIONSHIP_AUTHOR, $event->getUserPHID(), PhabricatorPeopleUserPHIDType::TYPECONST, $event->getDateCreated());
     $doc->addRelationship(PhabricatorSearchRelationship::RELATIONSHIP_OWNER, $event->getUserPHID(), PhabricatorPeopleUserPHIDType::TYPECONST, $event->getDateCreated());
     $doc->addRelationship($event->getIsCancelled() ? PhabricatorSearchRelationship::RELATIONSHIP_CLOSED : PhabricatorSearchRelationship::RELATIONSHIP_OPEN, $event->getPHID(), PhabricatorCalendarEventPHIDType::TYPECONST, time());
     $this->indexTransactions($doc, new PhabricatorCalendarEventTransactionQuery(), array($phid));
     return $doc;
 }
 protected function buildAbstractDocumentByPHID($phid)
 {
     $document = $this->loadDocumentByPHID($phid);
     $content = id(new PhrictionContent())->load($document->getContentID());
     $document->attachContent($content);
     $content = $document->getContent();
     $doc = new PhabricatorSearchAbstractDocument();
     $doc->setPHID($document->getPHID());
     $doc->setDocumentType(PhrictionDocumentPHIDType::TYPECONST);
     $doc->setDocumentTitle($content->getTitle());
     // TODO: This isn't precisely correct, denormalize into the Document table?
     $doc->setDocumentCreated($content->getDateCreated());
     $doc->setDocumentModified($content->getDateModified());
     $doc->addField(PhabricatorSearchField::FIELD_BODY, $content->getContent());
     $doc->addRelationship(PhabricatorSearchRelationship::RELATIONSHIP_AUTHOR, $content->getAuthorPHID(), PhabricatorPeopleUserPHIDType::TYPECONST, $content->getDateCreated());
     $doc->addRelationship($document->getStatus() == PhrictionDocumentStatus::STATUS_EXISTS ? PhabricatorSearchRelationship::RELATIONSHIP_OPEN : PhabricatorSearchRelationship::RELATIONSHIP_CLOSED, $document->getPHID(), PhrictionDocumentPHIDType::TYPECONST, time());
     return $doc;
 }
 protected function buildAbstractDocumentByPHID($phid)
 {
     $task = $this->loadDocumentByPHID($phid);
     $doc = new PhabricatorSearchAbstractDocument();
     $doc->setPHID($task->getPHID());
     $doc->setDocumentType(ManiphestTaskPHIDType::TYPECONST);
     $doc->setDocumentTitle($task->getTitle());
     $doc->setDocumentCreated($task->getDateCreated());
     $doc->setDocumentModified($task->getDateModified());
     $doc->addField(PhabricatorSearchDocumentFieldType::FIELD_BODY, $task->getDescription());
     $doc->addRelationship(PhabricatorSearchRelationship::RELATIONSHIP_AUTHOR, $task->getAuthorPHID(), PhabricatorPeopleUserPHIDType::TYPECONST, $task->getDateCreated());
     $doc->addRelationship($task->isClosed() ? PhabricatorSearchRelationship::RELATIONSHIP_CLOSED : PhabricatorSearchRelationship::RELATIONSHIP_OPEN, $task->getPHID(), ManiphestTaskPHIDType::TYPECONST, time());
     $this->indexTransactions($doc, new ManiphestTransactionQuery(), array($phid));
     $owner = $task->getOwnerPHID();
     if ($owner) {
         $doc->addRelationship(PhabricatorSearchRelationship::RELATIONSHIP_OWNER, $owner, PhabricatorPeopleUserPHIDType::TYPECONST, time());
     } else {
         $doc->addRelationship(PhabricatorSearchRelationship::RELATIONSHIP_UNOWNED, $task->getPHID(), PhabricatorPHIDConstants::PHID_TYPE_VOID, $task->getDateCreated());
     }
     return $doc;
 }
 public function reconstructDocument($phid)
 {
     $type = phid_get_type($phid);
     $response = $this->executeRequest("/phabricator/{$type}/{$phid}", array());
     if (empty($response['exists'])) {
         return null;
     }
     $hit = $response['_source'];
     $doc = new PhabricatorSearchAbstractDocument();
     $doc->setPHID($phid);
     $doc->setDocumentType($response['_type']);
     $doc->setDocumentTitle($hit['title']);
     $doc->setDocumentCreated($hit['dateCreated']);
     $doc->setDocumentModified($hit['_timestamp']);
     foreach ($hit['field'] as $fdef) {
         $doc->addField($fdef['type'], $fdef['corpus'], $fdef['aux']);
     }
     foreach ($hit['relationship'] as $rtype => $rships) {
         foreach ($rships as $rship) {
             $doc->addRelationship($rtype, $rship['phid'], $rship['phidType'], $rship['when']);
         }
     }
     return $doc;
 }
 public function updateAbstractDocument(PhabricatorSearchAbstractDocument $document)
 {
     if (strlen($this->getValue())) {
         $document->addField('plan', $this->getValue());
     }
 }
 public static function indexTask(ManiphestTask $task)
 {
     $doc = new PhabricatorSearchAbstractDocument();
     $doc->setPHID($task->getPHID());
     $doc->setDocumentType(PhabricatorPHIDConstants::PHID_TYPE_TASK);
     $doc->setDocumentTitle($task->getTitle());
     $doc->setDocumentCreated($task->getDateCreated());
     $doc->setDocumentModified($task->getDateModified());
     $doc->addField(PhabricatorSearchField::FIELD_BODY, $task->getDescription());
     $doc->addRelationship(PhabricatorSearchRelationship::RELATIONSHIP_AUTHOR, $task->getAuthorPHID(), PhabricatorPHIDConstants::PHID_TYPE_USER, $task->getDateCreated());
     if ($task->getStatus() == ManiphestTaskStatus::STATUS_OPEN) {
         $doc->addRelationship(PhabricatorSearchRelationship::RELATIONSHIP_OPEN, $task->getPHID(), PhabricatorPHIDConstants::PHID_TYPE_TASK, 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;
         }
     }
     foreach ($task->getProjectPHIDs() as $phid) {
         $doc->addRelationship(PhabricatorSearchRelationship::RELATIONSHIP_PROJECT, $phid, PhabricatorPHIDConstants::PHID_TYPE_PROJ, $task->getDateModified());
         // Bogus.
     }
     if ($owner && $owner->getNewValue()) {
         $doc->addRelationship(PhabricatorSearchRelationship::RELATIONSHIP_OWNER, $owner->getNewValue(), PhabricatorPHIDConstants::PHID_TYPE_USER, $owner->getDateCreated());
     } else {
         $doc->addRelationship(PhabricatorSearchRelationship::RELATIONSHIP_OWNER, ManiphestTaskOwner::OWNER_UP_FOR_GRABS, PhabricatorPHIDConstants::PHID_TYPE_MAGIC, $owner ? $owner->getDateCreated() : $task->getDateCreated());
     }
     foreach ($touches as $touch => $time) {
         $doc->addRelationship(PhabricatorSearchRelationship::RELATIONSHIP_TOUCH, $touch, PhabricatorPHIDConstants::PHID_TYPE_USER, $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);
     }
     self::reindexAbstractDocument($doc);
 }
 public function updateAbstractDocument(PhabricatorSearchAbstractDocument $document)
 {
     $field_key = $this->getFieldConfigValue('fulltext');
     // If the caller or configuration didn't specify a valid field key,
     // generate one automatically from the field index.
     if (!is_string($field_key) || strlen($field_key) != 4) {
         $field_key = '!' . substr($this->getFieldIndex(), 0, 3);
     }
     $field_value = $this->getFieldValue();
     if (strlen($field_value)) {
         $document->addField($field_key, $field_value);
     }
 }