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