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
|
|
|
* @return DatabaseNamesResponse<DatabaseNameResponse> |
21
|
|
|
*/ |
22
|
|
|
public function getNames(string $applicationUuid): DatabaseNamesResponse |
23
|
|
|
{ |
24
|
|
|
return new DatabaseNamesResponse( |
25
|
|
|
$this->client->request( |
26
|
|
|
'get', |
27
|
|
|
"/applications/$applicationUuid/databases" |
28
|
|
|
) |
29
|
|
|
); |
30
|
|
|
} |
31
|
|
|
|
32
|
|
|
/** |
33
|
|
|
* Shows all databases in an environment. |
34
|
|
|
*/ |
35
|
|
|
public function getAll(string $environmentUuid): DatabasesResponse |
36
|
|
|
{ |
37
|
|
|
return new DatabasesResponse( |
38
|
|
|
$this->client->request( |
39
|
|
|
'get', |
40
|
|
|
"/environments/$environmentUuid/databases" |
41
|
|
|
) |
42
|
|
|
); |
43
|
|
|
} |
44
|
|
|
|
45
|
|
|
/** |
46
|
|
|
* Create a new database. |
47
|
|
|
*/ |
48
|
|
|
public function create(string $applicationUuid, string $name): OperationResponse |
49
|
|
|
{ |
50
|
|
|
$options = [ |
51
|
|
|
'json' => [ |
52
|
|
|
'name' => $name, |
53
|
|
|
], |
54
|
|
|
]; |
55
|
|
|
|
56
|
|
|
return new OperationResponse( |
57
|
|
|
$this->client->request('post', "/applications/$applicationUuid/databases", $options) |
58
|
|
|
); |
59
|
|
|
} |
60
|
|
|
|
61
|
|
|
/** |
62
|
|
|
* Delete a database. |
63
|
|
|
*/ |
64
|
|
|
public function delete(string $applicationUuid, string $name): OperationResponse |
65
|
|
|
{ |
66
|
|
|
return new OperationResponse( |
67
|
|
|
$this->client->request('delete', "/applications/$applicationUuid/databases/$name") |
68
|
|
|
); |
69
|
|
|
} |
70
|
|
|
|
71
|
|
|
/** |
72
|
|
|
* Erases (truncates) a database. |
73
|
|
|
* |
74
|
|
|
* This action will delete all tables of the database in ALL environments |
75
|
|
|
* within this application. |
76
|
|
|
*/ |
77
|
|
|
public function truncate(string $applicationUuid, string $name): OperationResponse |
78
|
|
|
{ |
79
|
|
|
return new OperationResponse( |
80
|
|
|
$this->client->request( |
81
|
|
|
'post', |
82
|
|
|
"/applications/$applicationUuid/databases/$name/actions/erase" |
83
|
|
|
) |
84
|
|
|
); |
85
|
|
|
} |
86
|
|
|
|
87
|
|
|
/** |
88
|
|
|
* Copies a database from an environment to an environment. |
89
|
|
|
*/ |
90
|
|
|
public function copy(string $environmentFromUuid, string $dbName, string $environmentToUuid): OperationResponse |
91
|
|
|
{ |
92
|
|
|
$options = [ |
93
|
|
|
'json' => [ |
94
|
|
|
'name' => $dbName, |
95
|
|
|
'source' => $environmentFromUuid, |
96
|
|
|
], |
97
|
|
|
]; |
98
|
|
|
|
99
|
|
|
return new OperationResponse( |
100
|
|
|
$this->client->request('post', "/environments/$environmentToUuid/databases", $options) |
101
|
|
|
); |
102
|
|
|
} |
103
|
|
|
} |
104
|
|
|
|