1
|
|
|
<?php namespace Comodojo\Extender\Orm\Entities; |
2
|
|
|
|
3
|
|
|
use \Doctrine\ORM\Mapping as ORM; |
4
|
|
|
use \Comodojo\Extender\Traits\BaseEntityTrait; |
5
|
|
|
use \InvalidArgumentException; |
6
|
|
|
use \DateTime; |
7
|
|
|
|
8
|
|
|
/** |
9
|
|
|
* @package Comodojo Extender |
10
|
|
|
* @author Marco Giovinazzi <[email protected]> |
11
|
|
|
* @license MIT |
12
|
|
|
* |
13
|
|
|
* LICENSE: |
14
|
|
|
* |
15
|
|
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
16
|
|
|
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
17
|
|
|
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE |
18
|
|
|
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER |
19
|
|
|
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, |
20
|
|
|
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN |
21
|
|
|
* THE SOFTWARE. |
22
|
|
|
* |
23
|
|
|
* @ORM\Table(name="extender_worklog") |
24
|
|
|
* @ORM\Entity |
25
|
|
|
*/ |
26
|
|
|
class Worklog { |
27
|
|
|
|
28
|
|
|
const STATUS_RUNNING = 0; |
29
|
|
|
|
30
|
|
|
const STATUS_ERROR = 1; |
31
|
|
|
|
32
|
|
|
const STATUS_FINISHED = 2; |
33
|
|
|
|
34
|
|
|
const STATUS_ABORTED = 3; |
35
|
|
|
|
36
|
|
|
use BaseEntityTrait; |
37
|
|
|
|
38
|
|
|
/** |
39
|
|
|
* @var integer |
40
|
|
|
* |
41
|
|
|
* @ORM\Column(name="pid", type="integer", nullable=false) |
42
|
|
|
*/ |
43
|
|
|
protected $pid; |
44
|
|
|
|
45
|
|
|
/** |
46
|
|
|
* @var integer |
47
|
|
|
* |
48
|
|
|
* @ORM\ManyToOne(targetEntity="Schedule", cascade={"persist"}) |
49
|
|
|
* @ORM\JoinColumn(name="jid", nullable=true, referencedColumnName="id", onDelete="SET NULL") |
50
|
|
|
*/ |
51
|
|
|
protected $jid; |
52
|
|
|
|
53
|
|
|
/** |
54
|
|
|
* @var integer |
55
|
|
|
* |
56
|
|
|
* @ORM\Column(name="status", type="integer", nullable=false) |
57
|
|
|
*/ |
58
|
|
|
protected $status; |
59
|
|
|
|
60
|
|
|
/** |
61
|
|
|
* @var boolean |
62
|
|
|
* |
63
|
|
|
* @ORM\Column(name="success", type="boolean", nullable=true) |
64
|
|
|
*/ |
65
|
|
|
protected $success; |
66
|
|
|
|
67
|
|
|
/** |
68
|
|
|
* @var string |
69
|
|
|
* |
70
|
|
|
* @ORM\Column(name="result", type="text", length=65535, nullable=true) |
71
|
|
|
*/ |
72
|
|
|
protected $result; |
73
|
|
|
|
74
|
|
|
/** |
75
|
|
|
* @var datetime |
76
|
|
|
* |
77
|
|
|
* @ORM\Column(name="start", type="datetime", nullable=false) |
78
|
|
|
*/ |
79
|
|
|
protected $start_time; |
80
|
|
|
|
81
|
|
|
/** |
82
|
|
|
* @var datetime |
83
|
|
|
* |
84
|
|
|
* @ORM\Column(name="end", type="datetime", nullable=true) |
85
|
|
|
*/ |
86
|
|
|
protected $end_time; |
87
|
|
|
|
88
|
|
|
/** |
89
|
|
|
* Get worklog item's pid |
90
|
|
|
* |
91
|
|
|
* @return integer |
92
|
|
|
*/ |
93
|
|
|
public function getPid() { |
94
|
|
|
|
95
|
|
|
return $this->pid; |
96
|
|
|
|
97
|
|
|
} |
98
|
|
|
|
99
|
|
|
/** |
100
|
|
|
* Set worklog item's pid |
101
|
|
|
* |
102
|
|
|
* @param string $pid |
103
|
|
|
* @return Worklog |
104
|
|
|
*/ |
105
|
|
|
public function setPid($pid) { |
106
|
|
|
|
107
|
|
|
$this->pid = $pid; |
|
|
|
|
108
|
|
|
|
109
|
|
|
return $this; |
110
|
|
|
|
111
|
|
|
} |
112
|
|
|
|
113
|
|
|
/** |
114
|
|
|
* Get worklog item's jid |
115
|
|
|
* |
116
|
|
|
* @return integer |
117
|
|
|
*/ |
118
|
|
|
public function getJid() { |
119
|
|
|
|
120
|
|
|
return $this->jid; |
121
|
|
|
|
122
|
|
|
} |
123
|
|
|
|
124
|
|
|
/** |
125
|
|
|
* Set worklog item's jid |
126
|
|
|
* |
127
|
|
|
* @param string $jid |
128
|
|
|
* @return Worklog |
129
|
|
|
*/ |
130
|
|
|
public function setJid($jid) { |
131
|
|
|
|
132
|
|
|
$this->jid = $jid; |
|
|
|
|
133
|
|
|
|
134
|
|
|
return $this; |
135
|
|
|
|
136
|
|
|
} |
137
|
|
|
|
138
|
|
|
/** |
139
|
|
|
* Get current job status |
140
|
|
|
* |
141
|
|
|
* @return int |
142
|
|
|
*/ |
143
|
|
|
public function getStatus() { |
144
|
|
|
|
145
|
|
|
return $this->status; |
146
|
|
|
|
147
|
|
|
} |
148
|
|
|
|
149
|
|
|
/** |
150
|
|
|
* Set current job status |
151
|
|
|
* |
152
|
|
|
* @param string $name |
|
|
|
|
153
|
|
|
* @return Worklog |
154
|
|
|
*/ |
155
|
|
|
public function setStatus($status) { |
156
|
|
|
|
157
|
|
|
if ( !in_array($status, range(0, 3)) ) throw new InvalidArgumentException("Invalid status $status"); |
158
|
|
|
|
159
|
|
|
$this->status = $status; |
160
|
|
|
|
161
|
|
|
return $this; |
162
|
|
|
|
163
|
|
|
} |
164
|
|
|
|
165
|
|
|
/** |
166
|
|
|
* True if task is finished with success state |
167
|
|
|
* |
168
|
|
|
* @return bool |
169
|
|
|
*/ |
170
|
|
|
public function getSuccess() { |
171
|
|
|
|
172
|
|
|
return $this->success; |
173
|
|
|
|
174
|
|
|
} |
175
|
|
|
|
176
|
|
|
/** |
177
|
|
|
* Set task exit status |
178
|
|
|
* |
179
|
|
|
* @param bool $success |
180
|
|
|
* @return Worklog |
181
|
|
|
*/ |
182
|
|
|
public function setSuccess($success) { |
183
|
|
|
|
184
|
|
|
$success = DataFilter::filterBoolean($success); |
185
|
|
|
|
186
|
|
|
$this->success = $success; |
187
|
|
|
|
188
|
|
|
return $this; |
189
|
|
|
|
190
|
|
|
} |
191
|
|
|
|
192
|
|
|
/** |
193
|
|
|
* Get the task's result |
194
|
|
|
* |
195
|
|
|
* @return string |
196
|
|
|
*/ |
197
|
|
|
public function getResult() { |
198
|
|
|
|
199
|
|
|
return unserialize($this->result); |
200
|
|
|
|
201
|
|
|
} |
202
|
|
|
|
203
|
|
|
/** |
204
|
|
|
* Set the task's result |
205
|
|
|
* |
206
|
|
|
* @param string $result |
207
|
|
|
* @return Worklog |
208
|
|
|
*/ |
209
|
|
|
public function setResult($result) { |
210
|
|
|
|
211
|
|
|
$this->result = serialize($result); |
212
|
|
|
|
213
|
|
|
return $this; |
214
|
|
|
|
215
|
|
|
} |
216
|
|
|
|
217
|
|
|
/** |
218
|
|
|
* Get the task's start-time |
219
|
|
|
* |
220
|
|
|
* @return DateTime |
221
|
|
|
*/ |
222
|
|
|
public function getStartTime() { |
223
|
|
|
|
224
|
|
|
return $this->start_time; |
225
|
|
|
|
226
|
|
|
} |
227
|
|
|
|
228
|
|
|
/** |
229
|
|
|
* Set the task's start-time |
230
|
|
|
* |
231
|
|
|
* @param DateTime $datetime |
232
|
|
|
* @return Worklog |
233
|
|
|
*/ |
234
|
|
|
public function setStartTime(DateTime $datetime) { |
235
|
|
|
|
236
|
|
|
$this->start_time = $datetime; |
|
|
|
|
237
|
|
|
|
238
|
|
|
return $this; |
239
|
|
|
|
240
|
|
|
} |
241
|
|
|
|
242
|
|
|
/** |
243
|
|
|
* Get the task's end-time |
244
|
|
|
* |
245
|
|
|
* @return DateTime |
246
|
|
|
*/ |
247
|
|
|
public function getEndTime() { |
248
|
|
|
|
249
|
|
|
return $this->end_time; |
250
|
|
|
|
251
|
|
|
} |
252
|
|
|
|
253
|
|
|
/** |
254
|
|
|
* Set the task's end-time |
255
|
|
|
* |
256
|
|
|
* @param DateTime $datetime |
257
|
|
|
* @return Worklog |
258
|
|
|
*/ |
259
|
|
|
public function setEndTime(DateTime $datetime) { |
260
|
|
|
|
261
|
|
|
$this->end_time = $datetime; |
|
|
|
|
262
|
|
|
|
263
|
|
|
return $this; |
264
|
|
|
|
265
|
|
|
} |
266
|
|
|
|
267
|
|
|
} |
268
|
|
|
|
This check looks for assignments to scalar types that may be of the wrong type.
To ensure the code behaves as expected, it may be a good idea to add an explicit type cast.