Skip to content
This repository was archived by the owner on Feb 5, 2024. It is now read-only.
This repository was 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

Description

@Steffen-99

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions