1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace AcquiaCloudApi\Endpoints; |
4
|
|
|
|
5
|
|
|
use AcquiaCloudApi\Connector\ClientInterface; |
6
|
|
|
use AcquiaCloudApi\Response\EnvironmentResponse; |
7
|
|
|
use AcquiaCloudApi\Response\EnvironmentsResponse; |
8
|
|
|
use AcquiaCloudApi\Response\DatabasesResponse; |
9
|
|
|
use AcquiaCloudApi\Response\CronsResponse; |
10
|
|
|
use AcquiaCloudApi\Response\CronResponse; |
11
|
|
|
use AcquiaCloudApi\Response\BackupsResponse; |
12
|
|
|
use AcquiaCloudApi\Response\BackupResponse; |
13
|
|
|
use AcquiaCloudApi\Response\DomainsResponse; |
14
|
|
|
use AcquiaCloudApi\Response\DomainResponse; |
15
|
|
|
use AcquiaCloudApi\Response\InsightsResponse; |
16
|
|
|
use AcquiaCloudApi\Response\ServersResponse; |
17
|
|
|
use AcquiaCloudApi\Response\OperationResponse; |
18
|
|
|
|
19
|
|
|
/** |
20
|
|
|
* Class Client |
21
|
|
|
* @package AcquiaCloudApi\CloudApi |
22
|
|
|
*/ |
23
|
|
|
class Environment implements CloudApi |
24
|
|
|
{ |
25
|
|
|
|
26
|
|
|
/** |
27
|
|
|
* Client constructor. |
28
|
|
|
* |
29
|
|
|
* @param ConnectorInterface $connector |
|
|
|
|
30
|
|
|
*/ |
31
|
|
|
public function __construct(ClientInterface $client) |
32
|
|
|
{ |
33
|
|
|
$this->client = $client; |
|
|
|
|
34
|
|
|
} |
35
|
|
|
|
36
|
|
|
/** |
37
|
|
|
* Shows all databases in an environment. |
38
|
|
|
* |
39
|
|
|
* @param string $environmentUuid |
40
|
|
|
* @return DatabasesResponse |
41
|
|
|
*/ |
42
|
|
|
public function getDatabases($environmentUuid) |
43
|
|
|
{ |
44
|
|
|
return new DatabasesResponse( |
45
|
|
|
$this->client->request( |
|
|
|
|
46
|
|
|
'get', |
47
|
|
|
"/environments/${environmentUuid}/databases" |
48
|
|
|
) |
49
|
|
|
); |
50
|
|
|
} |
51
|
|
|
|
52
|
|
|
/** |
53
|
|
|
* Copies a database from an environment to an environment. |
54
|
|
|
* |
55
|
|
|
* @param string $environmentFromUuid |
56
|
|
|
* @param string $dbName |
57
|
|
|
* @param string $environmentToUuid |
58
|
|
|
* @return OperationResponse |
59
|
|
|
*/ |
60
|
|
|
public function databaseCopy($environmentFromUuid, $dbName, $environmentToUuid) |
61
|
|
|
{ |
62
|
|
|
$options = [ |
63
|
|
|
'form_params' => [ |
64
|
|
|
'name' => $dbName, |
65
|
|
|
'source' => $environmentFromUuid, |
66
|
|
|
], |
67
|
|
|
]; |
68
|
|
|
|
69
|
|
|
return new OperationResponse( |
70
|
|
|
$this->client->request('post', "/environments/${environmentToUuid}/databases", $options) |
|
|
|
|
71
|
|
|
); |
72
|
|
|
} |
73
|
|
|
|
74
|
|
|
/** |
75
|
|
|
* Backup a database. |
76
|
|
|
* |
77
|
|
|
* @param string $environmentUuid |
78
|
|
|
* @param string $dbName |
79
|
|
|
* @return OperationResponse |
80
|
|
|
*/ |
81
|
|
|
public function createDatabaseBackup($environmentUuid, $dbName) |
82
|
|
|
{ |
83
|
|
|
return new OperationResponse( |
84
|
|
|
$this->client->request( |
|
|
|
|
85
|
|
|
'post', |
86
|
|
|
"/environments/${environmentUuid}/databases/${dbName}/backups" |
87
|
|
|
) |
88
|
|
|
); |
89
|
|
|
} |
90
|
|
|
|
91
|
|
|
/** |
92
|
|
|
* Shows all database backups in an environment. |
93
|
|
|
* |
94
|
|
|
* @param string $environmentUuid |
95
|
|
|
* @param string $dbName |
96
|
|
|
* @return BackupsResponse |
97
|
|
|
*/ |
98
|
|
|
public function getDatabaseBackups($environmentUuid, $dbName) |
99
|
|
|
{ |
100
|
|
|
return new BackupsResponse( |
101
|
|
|
$this->client->request( |
|
|
|
|
102
|
|
|
'get', |
103
|
|
|
"/environments/${environmentUuid}/databases/${dbName}/backups" |
104
|
|
|
) |
105
|
|
|
); |
106
|
|
|
} |
107
|
|
|
|
108
|
|
|
/** |
109
|
|
|
* Gets information about a database backup. |
110
|
|
|
* |
111
|
|
|
* @param string $environmentUuid |
112
|
|
|
* @param string $dbName |
113
|
|
|
* @param int $backupId |
114
|
|
|
* @return BackupResponse |
115
|
|
|
*/ |
116
|
|
|
public function getDatabaseBackup($environmentUuid, $dbName, $backupId) |
117
|
|
|
{ |
118
|
|
|
return new BackupResponse( |
119
|
|
|
$this->client->request( |
|
|
|
|
120
|
|
|
'get', |
121
|
|
|
"/environments/${environmentUuid}/databases/${dbName}/backups/${backupId}" |
122
|
|
|
) |
123
|
|
|
); |
124
|
|
|
} |
125
|
|
|
|
126
|
|
|
/** |
127
|
|
|
* Restores a database backup to a database in an environment. |
128
|
|
|
* |
129
|
|
|
* @param string $environmentUuid |
130
|
|
|
* @param string $dbName |
131
|
|
|
* @param int $backupId |
132
|
|
|
* @return OperationResponse |
133
|
|
|
*/ |
134
|
|
|
public function restoreDatabaseBackup($environmentUuid, $dbName, $backupId) |
135
|
|
|
{ |
136
|
|
|
return new OperationResponse( |
137
|
|
|
$this->client->request( |
|
|
|
|
138
|
|
|
'post', |
139
|
|
|
"/environments/${environmentUuid}/databases/${dbName}/backups/${backupId}/actions/restore" |
140
|
|
|
) |
141
|
|
|
); |
142
|
|
|
} |
143
|
|
|
|
144
|
|
|
/** |
145
|
|
|
* Copies files from an environment to another environment. |
146
|
|
|
* |
147
|
|
|
* @param string $environmentUuidFrom |
148
|
|
|
* @param string $environmentUuidTo |
149
|
|
|
* @return OperationResponse |
150
|
|
|
*/ |
151
|
|
|
public function copyFiles($environmentUuidFrom, $environmentUuidTo) |
152
|
|
|
{ |
153
|
|
|
$options = [ |
154
|
|
|
'form_params' => [ |
155
|
|
|
'source' => $environmentUuidFrom, |
156
|
|
|
], |
157
|
|
|
]; |
158
|
|
|
|
159
|
|
|
return new OperationResponse( |
160
|
|
|
$this->client->request('post', "/environments/${environmentUuidTo}/files", $options) |
|
|
|
|
161
|
|
|
); |
162
|
|
|
} |
163
|
|
|
|
164
|
|
|
/** |
165
|
|
|
* Deploys a code branch/tag to an environment. |
166
|
|
|
* |
167
|
|
|
* @param string $environmentUuid |
168
|
|
|
* @param string $branch |
169
|
|
|
* @return OperationResponse |
170
|
|
|
*/ |
171
|
|
|
public function switchCode($environmentUuid, $branch) |
172
|
|
|
{ |
173
|
|
|
|
174
|
|
|
$options = [ |
175
|
|
|
'form_params' => [ |
176
|
|
|
'branch' => $branch, |
177
|
|
|
], |
178
|
|
|
]; |
179
|
|
|
|
180
|
|
|
return new OperationResponse( |
181
|
|
|
$this->client->request( |
|
|
|
|
182
|
|
|
'post', |
183
|
|
|
"/environments/${environmentUuid}/code/actions/switch", |
184
|
|
|
$options |
185
|
|
|
) |
186
|
|
|
); |
187
|
|
|
} |
188
|
|
|
|
189
|
|
|
/** |
190
|
|
|
* Deploys code from one environment to another environment. |
191
|
|
|
* |
192
|
|
|
* @param string $environmentFromUuid |
193
|
|
|
* @param string $environmentToUuid |
194
|
|
|
* @param string $commitMessage |
195
|
|
|
*/ |
196
|
|
|
public function deployCode($environmentFromUuid, $environmentToUuid, $commitMessage = null) |
197
|
|
|
{ |
198
|
|
|
|
199
|
|
|
$options = [ |
200
|
|
|
'form_params' => [ |
201
|
|
|
'source' => $environmentFromUuid, |
202
|
|
|
'message' => $commitMessage, |
203
|
|
|
], |
204
|
|
|
]; |
205
|
|
|
|
206
|
|
|
return new OperationResponse( |
207
|
|
|
$this->client->request( |
|
|
|
|
208
|
|
|
'post', |
209
|
|
|
"/environments/${environmentToUuid}/code", |
210
|
|
|
$options |
211
|
|
|
) |
212
|
|
|
); |
213
|
|
|
} |
214
|
|
|
|
215
|
|
|
/** |
216
|
|
|
* Shows all domains on an environment. |
217
|
|
|
* |
218
|
|
|
* @param string $environmentUuid |
219
|
|
|
* @return DomainsResponse |
220
|
|
|
*/ |
221
|
|
|
public function getDomains($environmentUuid) |
222
|
|
|
{ |
223
|
|
|
return new DomainsResponse( |
224
|
|
|
$this->client->request( |
|
|
|
|
225
|
|
|
'get', |
226
|
|
|
"/environments/${environmentUuid}/domains" |
227
|
|
|
) |
228
|
|
|
); |
229
|
|
|
} |
230
|
|
|
|
231
|
|
|
/** |
232
|
|
|
* Return details about a domain. |
233
|
|
|
* |
234
|
|
|
* @param string $environmentUuid |
235
|
|
|
* @param string $domain |
236
|
|
|
* @return DomainResponse |
237
|
|
|
*/ |
238
|
|
|
public function getDomain($environmentUuid, $domain) |
239
|
|
|
{ |
240
|
|
|
return new DomainResponse( |
241
|
|
|
$this->client->request( |
|
|
|
|
242
|
|
|
'get', |
243
|
|
|
"/environments/${environmentUuid}/domains/${domain}" |
244
|
|
|
) |
245
|
|
|
); |
246
|
|
|
} |
247
|
|
|
|
248
|
|
|
/** |
249
|
|
|
* Adds a domain to an environment. |
250
|
|
|
* |
251
|
|
|
* @param string $environmentUuid |
252
|
|
|
* @param string $hostname |
253
|
|
|
* @return OperationResponse |
254
|
|
|
*/ |
255
|
|
|
public function createDomain($environmentUuid, $hostname) |
256
|
|
|
{ |
257
|
|
|
|
258
|
|
|
$options = [ |
259
|
|
|
'form_params' => [ |
260
|
|
|
'hostname' => $hostname, |
261
|
|
|
], |
262
|
|
|
]; |
263
|
|
|
|
264
|
|
|
return new OperationResponse( |
265
|
|
|
$this->client->request('post', "/environments/${environmentUuid}/domains", $options) |
|
|
|
|
266
|
|
|
); |
267
|
|
|
} |
268
|
|
|
|
269
|
|
|
/** |
270
|
|
|
* Deletes a domain from an environment. |
271
|
|
|
* |
272
|
|
|
* @param string $environmentUuid |
273
|
|
|
* @param string $domain |
274
|
|
|
* @return OperationResponse |
275
|
|
|
*/ |
276
|
|
|
public function deleteDomain($environmentUuid, $domain) |
277
|
|
|
{ |
278
|
|
|
return new OperationResponse( |
279
|
|
|
$this->client->request('delete', "/environments/${environmentUuid}/domains/${domain}") |
|
|
|
|
280
|
|
|
); |
281
|
|
|
} |
282
|
|
|
|
283
|
|
|
/** |
284
|
|
|
* Purges varnish for selected domains in an environment. |
285
|
|
|
* |
286
|
|
|
* @param string $environmentUuid |
287
|
|
|
* @param array $domains |
288
|
|
|
* @return OperationResponse |
289
|
|
|
*/ |
290
|
|
|
public function purgeVarnishCache($environmentUuid, array $domains) |
291
|
|
|
{ |
292
|
|
|
|
293
|
|
|
$options = [ |
294
|
|
|
'form_params' => [ |
295
|
|
|
'domains' => $domains, |
296
|
|
|
], |
297
|
|
|
]; |
298
|
|
|
|
299
|
|
|
return new OperationResponse( |
300
|
|
|
$this->client->request( |
|
|
|
|
301
|
|
|
'post', |
302
|
|
|
"/environments/${environmentUuid}/domains/actions/clear-varnish", |
303
|
|
|
$options |
304
|
|
|
) |
305
|
|
|
); |
306
|
|
|
} |
307
|
|
|
|
308
|
|
|
/** |
309
|
|
|
* Gets information about an environment. |
310
|
|
|
* |
311
|
|
|
* @param string $environmentUuid |
312
|
|
|
* @return EnvironmentResponse |
313
|
|
|
*/ |
314
|
|
|
public function getEnvironment($environmentUuid) |
315
|
|
|
{ |
316
|
|
|
return new EnvironmentResponse( |
317
|
|
|
$this->client->request( |
|
|
|
|
318
|
|
|
'get', |
319
|
|
|
"/environments/${environmentUuid}" |
320
|
|
|
) |
321
|
|
|
); |
322
|
|
|
} |
323
|
|
|
|
324
|
|
|
/** |
325
|
|
|
* Modifies configuration settings for an environment. |
326
|
|
|
* |
327
|
|
|
* @param string $environmentUuid |
328
|
|
|
* @param array $config |
329
|
|
|
* @return OperationResponse |
330
|
|
|
*/ |
331
|
|
|
public function modifyEnvironment($environmentUuid, array $config) |
332
|
|
|
{ |
333
|
|
|
|
334
|
|
|
$options = [ |
335
|
|
|
'form_params' => $config, |
336
|
|
|
]; |
337
|
|
|
|
338
|
|
|
return new OperationResponse( |
339
|
|
|
$this->client->request( |
|
|
|
|
340
|
|
|
'put', |
341
|
|
|
"/environments/${environmentUuid}", |
342
|
|
|
$options |
343
|
|
|
) |
344
|
|
|
); |
345
|
|
|
} |
346
|
|
|
|
347
|
|
|
/** |
348
|
|
|
* Renames an environment. |
349
|
|
|
* |
350
|
|
|
* @param string $environmentUuid |
351
|
|
|
* @param string $label |
352
|
|
|
* @return OperationResponse |
353
|
|
|
*/ |
354
|
|
|
public function renameEnvironment($environmentUuid, $label) |
355
|
|
|
{ |
356
|
|
|
|
357
|
|
|
$options = [ |
358
|
|
|
'form_params' => [ |
359
|
|
|
'label' => $label, |
360
|
|
|
], |
361
|
|
|
]; |
362
|
|
|
|
363
|
|
|
return new OperationResponse( |
364
|
|
|
$this->client->request( |
|
|
|
|
365
|
|
|
'post', |
366
|
|
|
"/environments/${environmentUuid}/actions/change-label", |
367
|
|
|
$options |
368
|
|
|
) |
369
|
|
|
); |
370
|
|
|
} |
371
|
|
|
|
372
|
|
|
/** |
373
|
|
|
* Show all servers associated with an environment. |
374
|
|
|
* |
375
|
|
|
* @param string $environmentUuid |
376
|
|
|
* @return ServersResponse |
377
|
|
|
*/ |
378
|
|
|
public function getServers($environmentUuid) |
379
|
|
|
{ |
380
|
|
|
return new ServersResponse( |
381
|
|
|
$this->client->request( |
|
|
|
|
382
|
|
|
'get', |
383
|
|
|
"/environments/${environmentUuid}/servers" |
384
|
|
|
) |
385
|
|
|
); |
386
|
|
|
} |
387
|
|
|
|
388
|
|
|
/** |
389
|
|
|
* Enable livedev mode for an environment. |
390
|
|
|
* |
391
|
|
|
* @param string $environmentUuid |
392
|
|
|
* @return OperationResponse |
393
|
|
|
*/ |
394
|
|
|
public function enableLiveDev($environmentUuid) |
395
|
|
|
{ |
396
|
|
|
return new OperationResponse( |
397
|
|
|
$this->client->request('post', "/environments/${environmentUuid}/livedev/actions/enable") |
|
|
|
|
398
|
|
|
); |
399
|
|
|
} |
400
|
|
|
|
401
|
|
|
/** |
402
|
|
|
* Disable livedev mode for an environment. |
403
|
|
|
* |
404
|
|
|
* @param string $environmentUuid |
405
|
|
|
* @return OperationResponse |
406
|
|
|
*/ |
407
|
|
|
public function disableLiveDev($environmentUuid) |
408
|
|
|
{ |
409
|
|
|
|
410
|
|
|
$options = [ |
411
|
|
|
'form_params' => [ |
412
|
|
|
'discard' => 1, |
413
|
|
|
], |
414
|
|
|
]; |
415
|
|
|
|
416
|
|
|
return new OperationResponse( |
417
|
|
|
$this->client->request( |
|
|
|
|
418
|
|
|
'post', |
419
|
|
|
"/environments/${environmentUuid}/livedev/actions/disable", |
420
|
|
|
$options |
421
|
|
|
) |
422
|
|
|
); |
423
|
|
|
} |
424
|
|
|
|
425
|
|
|
/** |
426
|
|
|
* Enable production mode for an environment. |
427
|
|
|
* |
428
|
|
|
* @param string $environmentUuid |
429
|
|
|
* @return OperationResponse |
430
|
|
|
*/ |
431
|
|
|
public function enableProductionMode($environmentUuid) |
432
|
|
|
{ |
433
|
|
|
return new OperationResponse( |
434
|
|
|
$this->client->request( |
|
|
|
|
435
|
|
|
'post', |
436
|
|
|
"/environments/${environmentUuid}/production-mode/actions/enable" |
437
|
|
|
) |
438
|
|
|
); |
439
|
|
|
} |
440
|
|
|
|
441
|
|
|
/** |
442
|
|
|
* Disable production mode for an environment. |
443
|
|
|
* |
444
|
|
|
* @param string $environmentUuid |
445
|
|
|
* @return OperationResponse |
446
|
|
|
*/ |
447
|
|
|
public function disableProductionMode($environmentUuid) |
448
|
|
|
{ |
449
|
|
|
return new OperationResponse( |
450
|
|
|
$this->client->request( |
|
|
|
|
451
|
|
|
'post', |
452
|
|
|
"/environments/${environmentUuid}/production-mode/actions/disable" |
453
|
|
|
) |
454
|
|
|
); |
455
|
|
|
} |
456
|
|
|
|
457
|
|
|
/** |
458
|
|
|
* Show all cron tasks for an environment. |
459
|
|
|
* |
460
|
|
|
* @param string $environmentUuid The environment ID |
461
|
|
|
* @return CronsResponse |
462
|
|
|
*/ |
463
|
|
|
public function getCrons($environmentUuid) |
464
|
|
|
{ |
465
|
|
|
return new CronsResponse( |
466
|
|
|
$this->client->request( |
|
|
|
|
467
|
|
|
'get', |
468
|
|
|
"/environments/${environmentUuid}/crons" |
469
|
|
|
) |
470
|
|
|
); |
471
|
|
|
} |
472
|
|
|
|
473
|
|
|
/** |
474
|
|
|
* Get information about a cron task. |
475
|
|
|
* |
476
|
|
|
* @param string $environmentUuid The environment ID |
477
|
|
|
* @param int $cronId |
478
|
|
|
* @return CronResponse |
479
|
|
|
*/ |
480
|
|
|
public function getCron($environmentUuid, $cronId) |
481
|
|
|
{ |
482
|
|
|
return new CronResponse( |
483
|
|
|
$this->client->request( |
|
|
|
|
484
|
|
|
'get', |
485
|
|
|
"/environments/${environmentUuid}/crons/${cronId}" |
486
|
|
|
) |
487
|
|
|
); |
488
|
|
|
} |
489
|
|
|
|
490
|
|
|
/** |
491
|
|
|
* Add a cron task. |
492
|
|
|
* |
493
|
|
|
* @param string $environmentUuid |
494
|
|
|
* @param string $command |
495
|
|
|
* @param string $frequency |
496
|
|
|
* @param string $label |
497
|
|
|
* @return OperationResponse |
498
|
|
|
*/ |
499
|
|
|
public function createCron($environmentUuid, $command, $frequency, $label) |
500
|
|
|
{ |
501
|
|
|
|
502
|
|
|
$options = [ |
503
|
|
|
'form_params' => [ |
504
|
|
|
'command' => $command, |
505
|
|
|
'frequency' => $frequency, |
506
|
|
|
'label' => $label, |
507
|
|
|
], |
508
|
|
|
]; |
509
|
|
|
|
510
|
|
|
return new OperationResponse( |
511
|
|
|
$this->client->request('post', "/environments/${environmentUuid}/crons", $options) |
|
|
|
|
512
|
|
|
); |
513
|
|
|
} |
514
|
|
|
|
515
|
|
|
/** |
516
|
|
|
* Delete a cron task. |
517
|
|
|
* |
518
|
|
|
* @param string $environmentUuid |
519
|
|
|
* @param int $cronId |
520
|
|
|
* @return OperationResponse |
521
|
|
|
*/ |
522
|
|
|
public function deleteCron($environmentUuid, $cronId) |
523
|
|
|
{ |
524
|
|
|
return new OperationResponse( |
525
|
|
|
$this->client->request('delete', "/environments/${environmentUuid}/crons/${cronId}") |
|
|
|
|
526
|
|
|
); |
527
|
|
|
} |
528
|
|
|
|
529
|
|
|
/** |
530
|
|
|
* Disable a cron task. |
531
|
|
|
* |
532
|
|
|
* @param string $environmentUuid |
533
|
|
|
* @param int $cronId |
534
|
|
|
* @return OperationResponse |
535
|
|
|
*/ |
536
|
|
|
public function disableCron($environmentUuid, $cronId) |
537
|
|
|
{ |
538
|
|
|
return new OperationResponse( |
539
|
|
|
$this->client->request( |
|
|
|
|
540
|
|
|
'post', |
541
|
|
|
"/environments/${environmentUuid}/crons/${cronId}/actions/disable" |
542
|
|
|
) |
543
|
|
|
); |
544
|
|
|
} |
545
|
|
|
|
546
|
|
|
/** |
547
|
|
|
* Enable a cron task. |
548
|
|
|
* |
549
|
|
|
* @param string $environmentUuid |
550
|
|
|
* @param int $cronId |
551
|
|
|
* @return OperationResponse |
552
|
|
|
*/ |
553
|
|
|
public function enableCron($environmentUuid, $cronId) |
554
|
|
|
{ |
555
|
|
|
return new OperationResponse( |
556
|
|
|
$this->client->request( |
|
|
|
|
557
|
|
|
'post', |
558
|
|
|
"/environments/${environmentUuid}/crons/${cronId}/actions/enable" |
559
|
|
|
) |
560
|
|
|
); |
561
|
|
|
} |
562
|
|
|
|
563
|
|
|
/** |
564
|
|
|
* Show insights data from a specific environment. |
565
|
|
|
* |
566
|
|
|
* @param string $environmentUuid |
567
|
|
|
* @return InsightsResponse |
568
|
|
|
*/ |
569
|
|
|
public function getInsights($environmentUuid) |
570
|
|
|
{ |
571
|
|
|
return new InsightsResponse( |
572
|
|
|
$this->client->request('get', "/environments/${environmentUuid}/insight") |
|
|
|
|
573
|
|
|
); |
574
|
|
|
} |
575
|
|
|
} |
576
|
|
|
|
The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g.
excluded_paths: ["lib/*"]
, you can move it to the dependency path list as follows:For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths