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