DatabaseBackups::create()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 6
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 4
c 1
b 0
f 0
nc 1
nop 2
dl 0
loc 6
rs 10
1
<?php
2
3
namespace AcquiaCloudApi\Endpoints;
4
5
use AcquiaCloudApi\Response\BackupResponse;
6
use AcquiaCloudApi\Response\BackupsResponse;
7
use AcquiaCloudApi\Response\OperationResponse;
8
use Psr\Http\Message\StreamInterface;
9
10
/**
11
 * Class DatabaseBackups
12
 *
13
 * @package AcquiaCloudApi\CloudApi
14
 */
15
class DatabaseBackups extends CloudApiBase
16
{
17
    /**
18
     * Backup a database.
19
     */
20
    public function create(string $environmentUuid, string $dbName): OperationResponse
21
    {
22
        return new OperationResponse(
23
            $this->client->request(
24
                'post',
25
                "/environments/$environmentUuid/databases/$dbName/backups"
26
            )
27
        );
28
    }
29
30
    /**
31
     * Shows all database backups in an environment.
32
     *
33
     * @return BackupsResponse<BackupResponse>
34
     */
35
    public function getAll(string $environmentUuid, string $dbName): BackupsResponse
36
    {
37
        return new BackupsResponse(
38
            $this->client->request(
39
                'get',
40
                "/environments/$environmentUuid/databases/$dbName/backups"
41
            )
42
        );
43
    }
44
45
    /**
46
     * Gets information about a database backup.
47
     */
48
    public function get(string $environmentUuid, string $dbName, int $backupId): BackupResponse
49
    {
50
        return new BackupResponse(
51
            $this->client->request(
52
                'get',
53
                "/environments/$environmentUuid/databases/$dbName/backups/$backupId"
54
            )
55
        );
56
    }
57
58
    /**
59
     * Restores a database backup to a database in an environment.
60
     */
61
    public function restore(string $environmentUuid, string $dbName, int $backupId): OperationResponse
62
    {
63
        return new OperationResponse(
64
            $this->client->request(
65
                'post',
66
                "/environments/$environmentUuid/databases/$dbName/backups/$backupId/actions/restore"
67
            )
68
        );
69
    }
70
71
    /**
72
     * Downloads a database backup.
73
     */
74
    public function download(string $environmentUuid, string $dbName, int $backupId): StreamInterface
75
    {
76
        return $this->client->stream(
77
            'get',
78
            "/environments/$environmentUuid/databases/$dbName/backups/$backupId/actions/download"
79
        );
80
    }
81
82
    /**
83
     * Deletes a database backup.
84
     */
85
    public function delete(string $environmentUuid, string $dbName, int $backupId): OperationResponse
86
    {
87
        return new OperationResponse(
88
            $this->client->request(
89
                'delete',
90
                "/environments/$environmentUuid/databases/$dbName/backups/$backupId"
91
            )
92
        );
93
    }
94
}
95