1 | <?php |
||
30 | class Task |
||
31 | { |
||
32 | /** |
||
33 | * @var int |
||
34 | */ |
||
35 | const STATUS_ENABLED = 1; |
||
36 | |||
37 | /** |
||
38 | * @var int |
||
39 | */ |
||
40 | const STATUS_DISABLED = 0; |
||
41 | |||
42 | /** |
||
43 | * @ORM\Id |
||
44 | * @ORM\GeneratedValue |
||
45 | * @ORM\Column(type="integer") |
||
46 | * |
||
47 | * @var int |
||
48 | */ |
||
49 | protected $id; |
||
50 | |||
51 | /** |
||
52 | * @ORM\Column(type="string", length=128) |
||
53 | * |
||
54 | * @var string |
||
55 | */ |
||
56 | protected $command = ''; |
||
57 | |||
58 | /** |
||
59 | * @ORM\Column(type="datetime", nullable=true) |
||
60 | * @Assert\DateTime() |
||
61 | * |
||
62 | * @var \DateTime|null |
||
63 | */ |
||
64 | protected $last_run; |
||
65 | |||
66 | /** |
||
67 | * @ORM\Column(type="datetime") |
||
68 | * @Assert\DateTime() |
||
69 | * |
||
70 | * @var \DateTime |
||
71 | */ |
||
72 | protected $next_run; |
||
73 | |||
74 | /** |
||
75 | * A date/time string |
||
76 | * |
||
77 | * Valid formats are explained in Date and Time Formats. |
||
78 | * |
||
79 | * @link http://www.php.net/manual/en/datetime.formats.php |
||
80 | * @ORM\Column(type="string", length=128, nullable=true) |
||
81 | * |
||
82 | * @var string |
||
83 | */ |
||
84 | protected $modify = ''; |
||
85 | |||
86 | /** |
||
87 | * @ORM\Column(type="integer") |
||
88 | * @Assert\Choice(callback = "getStatuses") |
||
89 | * |
||
90 | * @var int |
||
91 | */ |
||
92 | protected $status = self::STATUS_DISABLED; |
||
93 | |||
94 | 27 | public function __construct() |
|
95 | { |
||
96 | 27 | $this->next_run = new \DateTime(); |
|
97 | 27 | } |
|
98 | |||
99 | /** |
||
100 | * @param string $command |
||
101 | * |
||
102 | * @return Task |
||
103 | */ |
||
104 | 1 | public function setCommand($command) |
|
105 | { |
||
106 | 1 | $this->command = $command; |
|
107 | 1 | return $this; |
|
108 | } |
||
109 | |||
110 | /** |
||
111 | * @return string |
||
112 | */ |
||
113 | 1 | public function getCommand() |
|
114 | { |
||
115 | 1 | return $this->command; |
|
116 | } |
||
117 | |||
118 | /** |
||
119 | * @return int |
||
120 | */ |
||
121 | 1 | public function getId() |
|
125 | |||
126 | /** |
||
127 | * @param \DateTime $last_run |
||
128 | * |
||
129 | * @return Task |
||
130 | */ |
||
131 | 4 | public function setLastRun(\DateTime $last_run) |
|
136 | |||
137 | /** |
||
138 | * @return \DateTime|null |
||
139 | */ |
||
140 | 4 | public function getLastRun() |
|
144 | |||
145 | /** |
||
146 | * @param \DateTime $next_run |
||
147 | * |
||
148 | * @return Task |
||
149 | */ |
||
150 | 2 | public function setNextRun(\DateTime $next_run) |
|
155 | |||
156 | /** |
||
157 | * @return \DateTime |
||
158 | */ |
||
159 | 2 | public function getNextRun() |
|
163 | |||
164 | /** |
||
165 | * @param int $interval |
||
166 | * |
||
167 | * @return Task |
||
168 | */ |
||
169 | 3 | public function setInterval($interval) |
|
170 | { |
||
171 | 3 | if ($interval > 0) { |
|
172 | 1 | $this->setModify(sprintf('+%s second', (int)$interval)); |
|
173 | } |
||
174 | 3 | return $this; |
|
175 | } |
||
176 | |||
177 | /** |
||
178 | * @param string $modify |
||
179 | * |
||
180 | * @return Task |
||
181 | */ |
||
182 | 5 | public function setModify($modify) |
|
187 | |||
188 | /** |
||
189 | * @return string |
||
190 | */ |
||
191 | 9 | public function getModify() |
|
192 | { |
||
193 | 9 | return $this->modify; |
|
194 | } |
||
195 | |||
196 | /** |
||
197 | * @param int $status |
||
198 | * |
||
199 | * @return Task |
||
200 | */ |
||
201 | 4 | public function setStatus($status) |
|
202 | { |
||
203 | 4 | $this->status = $status; |
|
204 | 4 | return $this; |
|
205 | } |
||
206 | |||
207 | /** |
||
208 | * @return int |
||
209 | */ |
||
210 | 4 | public function getStatus() |
|
214 | |||
215 | /** |
||
216 | * @return int[] |
||
217 | */ |
||
218 | 1 | public static function getStatuses() |
|
225 | |||
226 | /** |
||
227 | * @param ExecutionContextInterface $context |
||
228 | */ |
||
229 | 2 | public function isModifyValid(ExecutionContextInterface $context) |
|
230 | { |
||
231 | 2 | if ($this->getModify() && strtotime($this->getModify()) === false) { |
|
238 | |||
239 | /** |
||
240 | * Update task after execution |
||
241 | */ |
||
242 | 3 | public function executed() |
|
262 | } |
||
263 |