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