Skip to content
This repository has been archived by the owner on Feb 5, 2024. It is now read-only.

Bug: using createDesignDocument to update a view document #4

Closed
Steffen-99 opened this issue Aug 30, 2012 · 0 comments
Closed

Bug: using createDesignDocument to update a view document #4

Steffen-99 opened this issue Aug 30, 2012 · 0 comments

Comments

@Steffen-99
Copy link

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)
    );
}
robsonvn added a commit that referenced this issue Apr 30, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants