Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
0.00% |
0 / 62 |
|
0.00% |
0 / 21 |
CRAP | |
0.00% |
0 / 1 |
| AbstractTask | |
0.00% |
0 / 62 |
|
0.00% |
0 / 21 |
1190 | |
0.00% |
0 / 1 |
| __construct | |
0.00% |
0 / 5 |
|
0.00% |
0 / 1 |
2 | |||
| getId | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
| setType | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
| getType | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
| setLabel | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
| getLabel | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
| setId | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
| getInvocable | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
| setInvocable | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
| getStatus | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
| setStatus | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
| getParameters | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
| setParameters | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
| getReport | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
| setReport | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
| getCreationDate | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
| setCreationDate | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
| getOwner | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
| setOwner | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
| jsonSerialize | |
0.00% |
0 / 14 |
|
0.00% |
0 / 1 |
12 | |||
| restore | |
0.00% |
0 / 25 |
|
0.00% |
0 / 1 |
156 | |||
| 1 | <?php |
| 2 | |
| 3 | /** |
| 4 | * This program is free software; you can redistribute it and/or |
| 5 | * modify it under the terms of the GNU General Public License |
| 6 | * as published by the Free Software Foundation; under version 2 |
| 7 | * of the License (non-upgradable). |
| 8 | * |
| 9 | * This program is distributed in the hope that it will be useful, |
| 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 12 | * GNU General Public License for more details. |
| 13 | * |
| 14 | * You should have received a copy of the GNU General Public License |
| 15 | * along with this program; if not, write to the Free Software |
| 16 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. |
| 17 | * |
| 18 | * Copyright (c) 2016-2017 (original work) Open Assessment Technologies SA (under the project TAO-PRODUCT); |
| 19 | * |
| 20 | */ |
| 21 | |
| 22 | namespace oat\oatbox\task; |
| 23 | |
| 24 | /** |
| 25 | * Class SyncTask |
| 26 | * |
| 27 | * Basic implementation of `Task` interface |
| 28 | * |
| 29 | * @package oat\oatbox\task\implementation |
| 30 | * @author Aleh Hutnikau, <huntikau@1pt.com> |
| 31 | * |
| 32 | * @deprecated since version 7.10.0, to be removed in 8.0. Use \oat\tao\model\taskQueue\Task\AbstractTask instead. |
| 33 | */ |
| 34 | abstract class AbstractTask implements Task, \JsonSerializable |
| 35 | { |
| 36 | /** |
| 37 | * @var string |
| 38 | */ |
| 39 | protected $id; |
| 40 | |
| 41 | /** |
| 42 | * @var string |
| 43 | */ |
| 44 | protected $label; |
| 45 | |
| 46 | /** |
| 47 | * @var |
| 48 | */ |
| 49 | protected $invocable; |
| 50 | |
| 51 | /** |
| 52 | * @var |
| 53 | */ |
| 54 | protected $status; |
| 55 | |
| 56 | /** |
| 57 | * @var array |
| 58 | */ |
| 59 | protected $params; |
| 60 | |
| 61 | /** |
| 62 | * @var string |
| 63 | */ |
| 64 | protected $type; |
| 65 | /** |
| 66 | * Task execution report |
| 67 | * @var null|array |
| 68 | */ |
| 69 | protected $report; |
| 70 | |
| 71 | protected $creationDate; |
| 72 | |
| 73 | protected $owner; |
| 74 | |
| 75 | /** |
| 76 | * SyncTask constructor. |
| 77 | * @param Action|string $invocable |
| 78 | * @param array $params |
| 79 | */ |
| 80 | public function __construct($invocable = null, $params = null) |
| 81 | { |
| 82 | $this->id = \common_Utils::getNewUri(); |
| 83 | $this->setOwner(\common_session_SessionManager::getSession()->getUser()->getIdentifier()); |
| 84 | $this->setInvocable($invocable); |
| 85 | $this->setParameters($params); |
| 86 | $this->setStatus(self::STATUS_CREATED); |
| 87 | } |
| 88 | |
| 89 | /** |
| 90 | * @return string |
| 91 | */ |
| 92 | public function getId() |
| 93 | { |
| 94 | return $this->id; |
| 95 | } |
| 96 | |
| 97 | public function setType($type) |
| 98 | { |
| 99 | $this->type = $type; |
| 100 | } |
| 101 | |
| 102 | public function getType() |
| 103 | { |
| 104 | return $this->type; |
| 105 | } |
| 106 | |
| 107 | /** |
| 108 | * @param string $label |
| 109 | */ |
| 110 | public function setLabel($label) |
| 111 | { |
| 112 | $this->label = $label; |
| 113 | } |
| 114 | |
| 115 | /** |
| 116 | * @return string |
| 117 | */ |
| 118 | public function getLabel() |
| 119 | { |
| 120 | return $this->label; |
| 121 | } |
| 122 | |
| 123 | /** |
| 124 | * @param string $id |
| 125 | * @return string |
| 126 | */ |
| 127 | public function setId($id) |
| 128 | { |
| 129 | $this->id = $id; |
| 130 | } |
| 131 | |
| 132 | /** |
| 133 | * @return Action|string |
| 134 | */ |
| 135 | public function getInvocable() |
| 136 | { |
| 137 | return $this->invocable; |
| 138 | } |
| 139 | |
| 140 | /** |
| 141 | * Set action to invoke |
| 142 | */ |
| 143 | public function setInvocable($invocable) |
| 144 | { |
| 145 | $this->invocable = $invocable; |
| 146 | } |
| 147 | |
| 148 | /** |
| 149 | * @return string |
| 150 | */ |
| 151 | public function getStatus() |
| 152 | { |
| 153 | return $this->status; |
| 154 | } |
| 155 | |
| 156 | /** |
| 157 | * @param string $status |
| 158 | */ |
| 159 | public function setStatus($status) |
| 160 | { |
| 161 | $this->status = $status; |
| 162 | } |
| 163 | |
| 164 | /** |
| 165 | * @return array |
| 166 | */ |
| 167 | public function getParameters() |
| 168 | { |
| 169 | return $this->params; |
| 170 | } |
| 171 | |
| 172 | /** |
| 173 | * @param array $params |
| 174 | */ |
| 175 | public function setParameters(array $params) |
| 176 | { |
| 177 | $this->params = $params; |
| 178 | } |
| 179 | |
| 180 | /** |
| 181 | * @return array|null |
| 182 | */ |
| 183 | public function getReport() |
| 184 | { |
| 185 | return $this->report; |
| 186 | } |
| 187 | |
| 188 | /** |
| 189 | * @param $report |
| 190 | */ |
| 191 | public function setReport($report) |
| 192 | { |
| 193 | $this->report = $report; |
| 194 | } |
| 195 | |
| 196 | /** |
| 197 | * @return mixed |
| 198 | */ |
| 199 | public function getCreationDate() |
| 200 | { |
| 201 | return $this->creationDate; |
| 202 | } |
| 203 | |
| 204 | /** |
| 205 | * @param mixed $creationDate |
| 206 | */ |
| 207 | public function setCreationDate($creationDate) |
| 208 | { |
| 209 | $this->creationDate = $creationDate; |
| 210 | } |
| 211 | |
| 212 | /** |
| 213 | * @return mixed |
| 214 | */ |
| 215 | public function getOwner() |
| 216 | { |
| 217 | return $this->owner; |
| 218 | } |
| 219 | |
| 220 | /** |
| 221 | * @param mixed $owner |
| 222 | */ |
| 223 | public function setOwner($owner) |
| 224 | { |
| 225 | $this->owner = $owner; |
| 226 | } |
| 227 | |
| 228 | // Serialization |
| 229 | |
| 230 | /** |
| 231 | * (non-PHPdoc) |
| 232 | * @see JsonSerializable::jsonSerialize() |
| 233 | */ |
| 234 | public function jsonSerialize() |
| 235 | { |
| 236 | $invocable = $this->getInvocable(); |
| 237 | if (is_object($invocable) && !$invocable instanceof \JsonSerializable) { |
| 238 | $invocable = get_class($invocable); |
| 239 | } |
| 240 | return [ |
| 241 | 'invocable' => $invocable, |
| 242 | 'params' => $this->getParameters(), |
| 243 | 'id' => $this->getId(), |
| 244 | 'status' => $this->getStatus(), |
| 245 | 'report' => $this->getReport(), |
| 246 | 'label' => $this->getLabel(), |
| 247 | 'type' => $this->getType(), |
| 248 | 'added' => $this->getCreationDate(), |
| 249 | 'owner' => $this->getOwner(), |
| 250 | ]; |
| 251 | } |
| 252 | |
| 253 | /** |
| 254 | * Restore a task |
| 255 | * |
| 256 | * @param array $data |
| 257 | * @return Task |
| 258 | */ |
| 259 | public static function restore(array $data) |
| 260 | { |
| 261 | if (!isset($data['invocable'], $data['params'])) { |
| 262 | return null; |
| 263 | } |
| 264 | /** |
| 265 | * @var $task Task |
| 266 | */ |
| 267 | $class = self::class; |
| 268 | $task = new $class(); |
| 269 | if (isset($data['report'])) { |
| 270 | $task->setReport($data['report']); |
| 271 | } |
| 272 | if (isset($data['status'])) { |
| 273 | $task->setStatus($data['status']); |
| 274 | } |
| 275 | if (isset($data['id'])) { |
| 276 | $task->setId($data['id']); |
| 277 | } |
| 278 | if (isset($data['added'])) { |
| 279 | $task->setCreationDate($data['added']); |
| 280 | } |
| 281 | if (isset($data['owner'])) { |
| 282 | $task->setOwner($data['owner']); |
| 283 | } |
| 284 | if (isset($data['label'])) { |
| 285 | $task->setLabel($data['label']); |
| 286 | } |
| 287 | if (isset($data['type'])) { |
| 288 | $task->setType($data['type']); |
| 289 | } |
| 290 | if (isset($data['added'])) { |
| 291 | $task->setType($data['added']); |
| 292 | } |
| 293 | if (isset($data['invocable'])) { |
| 294 | $task->setInvocable($data['invocable']); |
| 295 | } |
| 296 | if (isset($data['params'])) { |
| 297 | $task->setParameters($data['params']); |
| 298 | } |
| 299 | return $task; |
| 300 | } |
| 301 | } |