public static function reindexAbstractDocument(PhabricatorSearchAbstractDocument $doc)
 {
     $phid = $doc->getPHID();
     if (!$phid) {
         throw new Exception("Document has no PHID!");
     }
     $store = new PhabricatorSearchDocument();
     $store->setPHID($doc->getPHID());
     $store->setDocumentType($doc->getDocumentType());
     $store->setDocumentTitle($doc->getDocumentTitle());
     $store->setDocumentCreated($doc->getDocumentCreated());
     $store->setDocumentModified($doc->getDocumentModified());
     $store->replace();
     $conn_w = $store->establishConnection('w');
     $field_dao = new PhabricatorSearchDocumentField();
     queryfx($conn_w, 'DELETE FROM %T WHERE phid = %s', $field_dao->getTableName(), $phid);
     foreach ($doc->getFieldData() as $field) {
         list($ftype, $corpus, $aux_phid) = $field;
         queryfx($conn_w, 'INSERT INTO %T (phid, phidType, field, auxPHID, corpus) ' . ' VALUES (%s, %s, %s, %ns, %s)', $field_dao->getTableName(), $phid, $doc->getDocumentType(), $ftype, $aux_phid, $corpus);
     }
     $sql = array();
     foreach ($doc->getRelationshipData() as $relationship) {
         list($rtype, $to_phid, $to_type, $time) = $relationship;
         $sql[] = qsprintf($conn_w, '(%s, %s, %s, %s, %d)', $phid, $to_phid, $rtype, $to_type, $time);
     }
     $rship_dao = new PhabricatorSearchDocumentRelationship();
     queryfx($conn_w, 'DELETE FROM %T WHERE phid = %s', $rship_dao->getTableName(), $phid);
     if ($sql) {
         queryfx($conn_w, 'INSERT INTO %T' . ' (phid, relatedPHID, relation, relatedType, relatedTime) ' . ' VALUES %Q', $rship_dao->getTableName(), implode(', ', $sql));
     }
 }
 protected function indexSubscribers(PhabricatorSearchAbstractDocument $doc)
 {
     $subscribers = PhabricatorSubscribersQuery::loadSubscribersForPHID($doc->getPHID());
     $handles = id(new PhabricatorHandleQuery())->setViewer($this->getViewer())->withPHIDs($subscribers)->execute();
     foreach ($handles as $phid => $handle) {
         $doc->addRelationship(PhabricatorSearchRelationship::RELATIONSHIP_SUBSCRIBER, $phid, $handle->getType(), $doc->getDocumentModified());
         // Bogus timestamp.
     }
 }
 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());
 }
 public function reindexAbstractDocument(PhabricatorSearchAbstractDocument $doc)
 {
     $type = $doc->getDocumentType();
     $phid = $doc->getPHID();
     $handle = PhabricatorObjectHandleData::loadOneHandle($phid);
     // URL is not used internally but it can be useful externally.
     $spec = array('title' => $doc->getDocumentTitle(), 'url' => PhabricatorEnv::getProductionURI($handle->getURI()), 'dateCreated' => $doc->getDocumentCreated(), '_timestamp' => $doc->getDocumentModified(), 'field' => array(), 'relationship' => array());
     foreach ($doc->getFieldData() as $field) {
         $spec['field'][] = array_combine(array('type', 'corpus', 'aux'), $field);
     }
     foreach ($doc->getRelationshipData() as $relationship) {
         list($rtype, $to_phid, $to_type, $time) = $relationship;
         $spec['relationship'][$rtype][] = array('phid' => $to_phid, 'phidType' => $to_type, 'when' => $time);
     }
     $this->executeRequest("/phabricator/{$type}/{$phid}/", $spec, $is_write = true);
 }
 public function reindexAbstractDocument(PhabricatorSearchAbstractDocument $doc)
 {
     $type = $doc->getDocumentType();
     $phid = $doc->getPHID();
     $handle = id(new PhabricatorHandleQuery())->setViewer(PhabricatorUser::getOmnipotentUser())->withPHIDs(array($phid))->executeOne();
     // URL is not used internally but it can be useful externally.
     $spec = array('title' => $doc->getDocumentTitle(), 'url' => PhabricatorEnv::getProductionURI($handle->getURI()), 'dateCreated' => $doc->getDocumentCreated(), '_timestamp' => $doc->getDocumentModified(), 'field' => array(), 'relationship' => array());
     foreach ($doc->getFieldData() as $field) {
         $spec['field'][] = array_combine(array('type', 'corpus', 'aux'), $field);
     }
     foreach ($doc->getRelationshipData() as $relationship) {
         list($rtype, $to_phid, $to_type, $time) = $relationship;
         $spec['relationship'][$rtype][] = array('phid' => $to_phid, 'phidType' => $to_type, 'when' => (int) $time);
     }
     $this->executeRequest("/{$type}/{$phid}/", $spec, 'PUT');
 }