/** * Create a CouchDB-Lucene Query. * * @param string $designDocName * @param string $viewName * @return View\ODMLuceneQuery */ public function createLuceneQuery($designDocName, $viewName) { $luceneHandlerName = $this->config->getLuceneHandlerName(); $designDoc = $this->config->getDesignDocument($designDocName); if ($designDoc) { $designDoc = new $designDoc['className']($designDoc['options']); } $query = new ODMLuceneQuery($this->couchDBClient->getHttpClient(), $this->couchDBClient->getDatabase(), $luceneHandlerName, $designDocName, $viewName, $designDoc); $query->setDocumentManager($this); return $query; }
/** * @return array * @throws HTTPException * @throws \Exception */ public function getReplicationLog() { $sourceLog = null; $targetLog = null; $replicationDocId = '_local' . '/' . $this->task->getRepId(); $sourceResponse = $this->source->findDocument($replicationDocId); $targetResponse = $this->target->findDocument($replicationDocId); if ($sourceResponse->status == 200) { $sourceLog = $sourceResponse->body; } elseif ($sourceResponse->status != 404) { throw HTTPException::fromResponse('/' . $this->source->getDatabase() . '/' . $replicationDocId, $sourceResponse); } if ($targetResponse->status == 200) { $targetLog = $targetResponse->body; } elseif ($targetResponse->status != 404) { throw HTTPException::fromResponse('/' . $this->target->getDatabase() . '/' . $replicationDocId, $targetResponse); } return array($sourceLog, $targetLog); }
/** * Transfer missing revisions to the target. The Content-Type of response * from the source should be multipart/mixed. * * @param string $docId * @param array $missingRevs * @param CouchDBClient $target * @return array|HTTP\ErrorResponse|string * @throws HTTPException */ public function transferChangedDocuments($docId, $missingRevs, CouchDBClient $target) { $path = '/' . $this->getDatabase() . '/' . $docId; $params = array('revs' => true, 'latest' => true, 'open_revs' => json_encode($missingRevs)); $query = http_build_query($params); $path .= '?' . $query; $targetPath = '/' . $target->getDatabase() . '/' . $docId . '?new_edits=false'; $mutltipartHandler = new MultipartParserAndSender($this->getHttpClient(), $target->getHttpClient()); return $mutltipartHandler->request('GET', $path, $targetPath, null, array('Accept' => 'multipart/mixed')); }
/** * @param \Doctrine\CouchDB\CouchDBClient $client * @param string $database * @param bool $createIfNotFound * * @return bool Returns TRUE ONLY when the database existed before the call. * @throws \Doctrine\CouchDB\HTTP\HTTPException */ public static function databaseExists($client, $database = null, $createIfNotFound = true) { try { return $client->getDatabaseInfo($database ?: $client->getDatabase()); } catch (\Doctrine\CouchDB\HTTP\HTTPException $_ex) { if (static::NotFound != $_ex->getCode()) { throw $_ex; } if (true === $createIfNotFound) { $client->createDatabase($database ?: $client->getDatabase()); } } return false; }