Beispiel #1
0
 /**
  * Create non existing view
  *
  * @return void
  * @throws \Doctrine\CouchDB\JsonDecodeException
  * @throws \Exception
  */
 public function createDesignDocument()
 {
     if (!$this->doc) {
         throw new \Exception("No DesignDocument Class is connected to this view query, cannot create the design document with its corresponding view automatically!");
     }
     $data = $this->doc->getData();
     if ($data === null) {
         throw \Doctrine\CouchDB\JsonDecodeException::fromLastJsonError();
     }
     $data['_id'] = '_design/' . $this->designDocumentName;
     $response = $this->client->request("PUT", sprintf("/%s/_design/%s", $this->databaseName, $this->designDocumentName), json_encode($data));
 }
Beispiel #2
0
 /**
  * Create or update a design document from the given in memory definition.
  *
  * @param string $designDocName
  * @param DesignDocument $designDoc
  * @return HTTP\Response
  */
 public function createDesignDocument($designDocName, DesignDocument $designDoc)
 {
     $data = $designDoc->getData();
     $data['_id'] = '_design/' . $designDocName;
     $documentPath = '/' . $this->databaseName . '/' . $data['_id'];
     $response = $this->httpClient->request('GET', $documentPath);
     if ($response->status == 200) {
         $docData = $response->body;
         $data['_rev'] = $docData['_rev'];
     }
     return $this->httpClient->request("PUT", sprintf("/%s/_design/%s", $this->databaseName, $designDocName), json_encode($data));
 }