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 indexProjects(PhabricatorSearchAbstractDocument $doc, PhabricatorProjectInterface $object)
 {
     $project_phids = PhabricatorEdgeQuery::loadDestinationPHIDs($object->getPHID(), PhabricatorProjectObjectHasProjectEdgeType::EDGECONST);
     if ($project_phids) {
         foreach ($project_phids as $project_phid) {
             $doc->addRelationship(PhabricatorSearchRelationship::RELATIONSHIP_PROJECT, $project_phid, PhabricatorProjectProjectPHIDType::TYPECONST, $doc->getDocumentModified());
             // Bogus timestamp.
         }
     }
 }
 public function indexFulltextObject($object, PhabricatorSearchAbstractDocument $document)
 {
     $project_phids = PhabricatorEdgeQuery::loadDestinationPHIDs($object->getPHID(), PhabricatorProjectObjectHasProjectEdgeType::EDGECONST);
     if (!$project_phids) {
         return;
     }
     foreach ($project_phids as $project_phid) {
         $document->addRelationship(PhabricatorSearchRelationship::RELATIONSHIP_PROJECT, $project_phid, PhabricatorProjectProjectPHIDType::TYPECONST, $document->getDocumentModified());
         // Bogus timestamp.
     }
 }
 public function indexFulltextObject($object, PhabricatorSearchAbstractDocument $document)
 {
     $subscriber_phids = PhabricatorSubscribersQuery::loadSubscribersForPHID($object->getPHID());
     if (!$subscriber_phids) {
         return;
     }
     $handles = id(new PhabricatorHandleQuery())->setViewer($this->getViewer())->withPHIDs($subscriber_phids)->execute();
     foreach ($handles as $phid => $handle) {
         $document->addRelationship(PhabricatorSearchRelationship::RELATIONSHIP_SUBSCRIBER, $phid, $handle->getType(), $document->getDocumentModified());
         // Bogus timestamp.
     }
 }
 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');
 }