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));
     }
 }
 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');
 }