doctrine / couchdb-client

CouchDB Client library
MIT License
122 stars 68 forks source link

Bug: using createDesignDocument to update a view document #4

Closed Steffen-99 closed 11 years ago

Steffen-99 commented 12 years ago

If you using createDesignDocument to create a view document they already exists, the function createDesignDocument will check if exists with $this->findDocument($data['_id']);

But in this function findDocument will force urlencode over this "id" => '_design/' . $designDocName; Then the "/" will changed to the URL code"%2F".

I have temporary Fixed it at function "findDocument" on our project with additional parameter to disable urlencoding temporary. Please fix it on next release!

/* * Find a document by ID and return the HTTP response. * @param string $id * @return Response */ public function findDocument($id, $disableURLEncode=false) { if ( $disableURLEncode === false ){ $id = urlencode($id); } $documentPath = '/' . $this->databaseName . '/' . $id; return $this->httpClient->request( 'GET', $documentPath ); }

.........

/* * 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;

    $response = $this->findDocument($data['_id'], true);
    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)
    );
}