1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace AcquiaCloudApi\Endpoints; |
4
|
|
|
|
5
|
|
|
use AcquiaCloudApi\Response\DatabaseNameResponse; |
6
|
|
|
use AcquiaCloudApi\Response\DatabaseNamesResponse; |
7
|
|
|
use AcquiaCloudApi\Response\DatabasesResponse; |
8
|
|
|
use AcquiaCloudApi\Response\OperationResponse; |
9
|
|
|
|
10
|
|
|
/** |
11
|
|
|
* Class Databases |
12
|
|
|
* |
13
|
|
|
* @package AcquiaCloudApi\CloudApi |
14
|
|
|
*/ |
15
|
|
|
class Databases extends CloudApiBase |
16
|
|
|
{ |
17
|
|
|
/** |
18
|
|
|
* Shows all databases in an application. |
19
|
|
|
* |
20
|
|
|
* |
21
|
|
|
* @return DatabaseNamesResponse<DatabaseNameResponse> |
22
|
|
|
*/ |
23
|
|
|
public function getNames(string $applicationUuid): DatabaseNamesResponse |
24
|
|
|
{ |
25
|
|
|
return new DatabaseNamesResponse( |
26
|
|
|
$this->client->request( |
27
|
|
|
'get', |
28
|
|
|
"/applications/$applicationUuid/databases" |
29
|
|
|
) |
30
|
|
|
); |
31
|
|
|
} |
32
|
|
|
|
33
|
|
|
/** |
34
|
|
|
* Shows all databases in an environment. |
35
|
|
|
*/ |
36
|
|
|
public function getAll(string $environmentUuid): DatabasesResponse |
37
|
|
|
{ |
38
|
|
|
return new DatabasesResponse( |
39
|
|
|
$this->client->request( |
40
|
|
|
'get', |
41
|
|
|
"/environments/$environmentUuid/databases" |
42
|
|
|
) |
43
|
|
|
); |
44
|
|
|
} |
45
|
|
|
|
46
|
|
|
/** |
47
|
|
|
* Create a new database. |
48
|
|
|
* |
49
|
|
|
* |
50
|
|
|
*/ |
51
|
|
|
public function create(string $applicationUuid, string $name): OperationResponse |
52
|
|
|
{ |
53
|
|
|
$options = [ |
54
|
|
|
'json' => [ |
55
|
|
|
'name' => $name, |
56
|
|
|
], |
57
|
|
|
]; |
58
|
|
|
|
59
|
|
|
return new OperationResponse( |
60
|
|
|
$this->client->request('post', "/applications/$applicationUuid/databases", $options) |
61
|
|
|
); |
62
|
|
|
} |
63
|
|
|
|
64
|
|
|
/** |
65
|
|
|
* Delete a database. |
66
|
|
|
* |
67
|
|
|
* |
68
|
|
|
*/ |
69
|
|
|
public function delete(string $applicationUuid, string $name): OperationResponse |
70
|
|
|
{ |
71
|
|
|
return new OperationResponse( |
72
|
|
|
$this->client->request('delete', "/applications/$applicationUuid/databases/$name") |
73
|
|
|
); |
74
|
|
|
} |
75
|
|
|
|
76
|
|
|
/** |
77
|
|
|
* Erases (truncates) a database. |
78
|
|
|
* |
79
|
|
|
* This action will delete all tables of the database in ALL environments |
80
|
|
|
* within this application. |
81
|
|
|
* |
82
|
|
|
* |
83
|
|
|
*/ |
84
|
|
|
public function truncate(string $applicationUuid, string $name): OperationResponse |
85
|
|
|
{ |
86
|
|
|
return new OperationResponse( |
87
|
|
|
$this->client->request( |
88
|
|
|
'post', |
89
|
|
|
"/applications/$applicationUuid/databases/$name/actions/erase" |
90
|
|
|
) |
91
|
|
|
); |
92
|
|
|
} |
93
|
|
|
|
94
|
|
|
/** |
95
|
|
|
* Copies a database from an environment to an environment. |
96
|
|
|
* |
97
|
|
|
* |
98
|
|
|
*/ |
99
|
|
|
public function copy(string $environmentFromUuid, string $dbName, string $environmentToUuid): OperationResponse |
100
|
|
|
{ |
101
|
|
|
$options = [ |
102
|
|
|
'json' => [ |
103
|
|
|
'name' => $dbName, |
104
|
|
|
'source' => $environmentFromUuid, |
105
|
|
|
], |
106
|
|
|
]; |
107
|
|
|
|
108
|
|
|
return new OperationResponse( |
109
|
|
|
$this->client->request('post', "/environments/$environmentToUuid/databases", $options) |
110
|
|
|
); |
111
|
|
|
} |
112
|
|
|
} |
113
|
|
|
|