Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for downloading a DB Backup via the API #37

Closed
typhonius opened this issue Jan 6, 2020 · 3 comments
Closed

Add support for downloading a DB Backup via the API #37

typhonius opened this issue Jan 6, 2020 · 3 comments

Comments

@typhonius
Copy link
Owner

https://cloudapi-docs.acquia.com/#/Environments/getEnvironmentsDatabaseDownloadBackup

@typhonius
Copy link
Owner Author

typhonius commented Jan 6, 2020

We can either pass this directly back as a Guzzle Stream object, or convert it to a string. To do the latter, we will have to rewind() and then getContents() the Stream response object.

I think I have a small preference to pass back a string rather than an object, although really we should implement the method consumers of the SDK would expect.

@typhonius
Copy link
Owner Author

Mock code:

DatabaseBackups.php

    public function download($environmentUuid, $dbName, $backupId)
    {
        return $this->client->requestStream(
            'get',
            "/environments/${environmentUuid}/databases/${dbName}/backups/${backupId}/actions/download"
        );
    }

Client.php

    public function requestStream(string $verb, string $path, array $options = [])
    {
        $response = $this->makeRequest($verb, $path, $options);

        try {
            $stream = $this->processResponse($response);
            $stream->rewind();
            return $stream->getContents();
        } catch (ApiErrorException $e) {
            exit($e->getErrorType() . ' error: ' .  $e->getMessage());
        }
    }

@typhonius
Copy link
Owner Author

Looking at what has been done with drush aliases and log downloads, my initial thought was incorrect and I should be passing the StreamInterface object back for consumers to work with.

This is the approach taken in #40

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant