1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace AcquiaCloudApi\Endpoints; |
4
|
|
|
|
5
|
|
|
use AcquiaCloudApi\Response\CronResponse; |
6
|
|
|
use AcquiaCloudApi\Response\CronsResponse; |
7
|
|
|
use AcquiaCloudApi\Response\OperationResponse; |
8
|
|
|
|
9
|
|
|
/** |
10
|
|
|
* Class Crons |
11
|
|
|
* |
12
|
|
|
* @package AcquiaCloudApi\CloudApi |
13
|
|
|
*/ |
14
|
|
|
class Crons extends CloudApiBase |
15
|
|
|
{ |
16
|
|
|
/** |
17
|
|
|
* Show all cron tasks for an environment. |
18
|
|
|
* |
19
|
|
|
* @param string $environmentUuid The environment ID |
20
|
|
|
* @return CronsResponse<CronResponse> |
21
|
|
|
*/ |
22
|
|
|
public function getAll(string $environmentUuid): CronsResponse |
23
|
|
|
{ |
24
|
|
|
return new CronsResponse( |
25
|
|
|
$this->client->request( |
26
|
|
|
'get', |
27
|
|
|
"/environments/$environmentUuid/crons" |
28
|
|
|
) |
29
|
|
|
); |
30
|
|
|
} |
31
|
|
|
|
32
|
|
|
/** |
33
|
|
|
* Get information about a cron task. |
34
|
|
|
* |
35
|
|
|
* @param string $environmentUuid The environment ID |
36
|
|
|
*/ |
37
|
|
|
public function get(string $environmentUuid, string $cronId): CronResponse |
38
|
|
|
{ |
39
|
|
|
return new CronResponse( |
40
|
|
|
$this->client->request( |
41
|
|
|
'get', |
42
|
|
|
"/environments/$environmentUuid/crons/$cronId" |
43
|
|
|
) |
44
|
|
|
); |
45
|
|
|
} |
46
|
|
|
|
47
|
|
|
/** |
48
|
|
|
* Add a cron task. |
49
|
|
|
*/ |
50
|
|
|
public function create( |
51
|
|
|
string $environmentUuid, |
52
|
|
|
string $command, |
53
|
|
|
string $frequency, |
54
|
|
|
string $label, |
55
|
|
|
?string $serverId = null |
56
|
|
|
): OperationResponse { |
57
|
|
|
|
58
|
|
|
$options = [ |
59
|
|
|
'json' => [ |
60
|
|
|
'command' => $command, |
61
|
|
|
'frequency' => $frequency, |
62
|
|
|
'label' => $label, |
63
|
|
|
'server_id' => $serverId, |
64
|
|
|
], |
65
|
|
|
]; |
66
|
|
|
|
67
|
|
|
return new OperationResponse( |
68
|
|
|
$this->client->request('post', "/environments/$environmentUuid/crons", $options) |
69
|
|
|
); |
70
|
|
|
} |
71
|
|
|
|
72
|
|
|
/** |
73
|
|
|
* Update a cron task. |
74
|
|
|
*/ |
75
|
|
|
public function update( |
76
|
|
|
string $environmentUuid, |
77
|
|
|
string $cronId, |
78
|
|
|
string $command, |
79
|
|
|
string $frequency, |
80
|
|
|
string $label, |
81
|
|
|
?string $serverId = null |
82
|
|
|
): OperationResponse { |
83
|
|
|
|
84
|
|
|
$options = [ |
85
|
|
|
'json' => [ |
86
|
|
|
'command' => $command, |
87
|
|
|
'frequency' => $frequency, |
88
|
|
|
'label' => $label, |
89
|
|
|
], |
90
|
|
|
]; |
91
|
|
|
if ($serverId) { |
92
|
|
|
$options['json']['server_id'] = $serverId; |
93
|
|
|
} |
94
|
|
|
|
95
|
|
|
return new OperationResponse( |
96
|
|
|
$this->client->request('put', "/environments/$environmentUuid/crons/$cronId", $options) |
97
|
|
|
); |
98
|
|
|
} |
99
|
|
|
|
100
|
|
|
/** |
101
|
|
|
* Delete a cron task. |
102
|
|
|
*/ |
103
|
|
|
public function delete(string $environmentUuid, string $cronId): OperationResponse |
104
|
|
|
{ |
105
|
|
|
return new OperationResponse( |
106
|
|
|
$this->client->request('delete', "/environments/$environmentUuid/crons/$cronId") |
107
|
|
|
); |
108
|
|
|
} |
109
|
|
|
|
110
|
|
|
/** |
111
|
|
|
* Disable a cron task. |
112
|
|
|
*/ |
113
|
|
|
public function disable(string $environmentUuid, string $cronId): OperationResponse |
114
|
|
|
{ |
115
|
|
|
return new OperationResponse( |
116
|
|
|
$this->client->request( |
117
|
|
|
'post', |
118
|
|
|
"/environments/$environmentUuid/crons/$cronId/actions/disable" |
119
|
|
|
) |
120
|
|
|
); |
121
|
|
|
} |
122
|
|
|
|
123
|
|
|
/** |
124
|
|
|
* Enable a cron task. |
125
|
|
|
*/ |
126
|
|
|
public function enable(string $environmentUuid, string $cronId): OperationResponse |
127
|
|
|
{ |
128
|
|
|
return new OperationResponse( |
129
|
|
|
$this->client->request( |
130
|
|
|
'post', |
131
|
|
|
"/environments/$environmentUuid/crons/$cronId/actions/enable" |
132
|
|
|
) |
133
|
|
|
); |
134
|
|
|
} |
135
|
|
|
} |
136
|
|
|
|