Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
0.00% |
0 / 20 |
|
0.00% |
0 / 2 |
CRAP | |
0.00% |
0 / 1 |
| DeliveryDeleteTask | |
0.00% |
0 / 20 |
|
0.00% |
0 / 2 |
30 | |
0.00% |
0 / 1 |
| __invoke | |
0.00% |
0 / 19 |
|
0.00% |
0 / 1 |
20 | |||
| jsonSerialize | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
| 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) 2018 (original work) Open Assessment Technologies SA; |
| 19 | * |
| 20 | */ |
| 21 | |
| 22 | namespace oat\taoDeliveryRdf\model\Delete; |
| 23 | |
| 24 | use oat\oatbox\extension\AbstractAction; |
| 25 | use oat\tao\model\taskQueue\QueueDispatcher; |
| 26 | |
| 27 | class DeliveryDeleteTask extends AbstractAction implements \JsonSerializable |
| 28 | { |
| 29 | /** |
| 30 | * @param $params |
| 31 | * @return \common_report_Report |
| 32 | * @throws \Exception |
| 33 | */ |
| 34 | public function __invoke($params) |
| 35 | { |
| 36 | if (!isset($params['deliveryId'])) { |
| 37 | throw new \common_exception_MissingParameter('Missing parameter `deliveryId` in ' . static::class); |
| 38 | } |
| 39 | /** @var QueueDispatcher $queueDispatcher */ |
| 40 | $queueDispatcher = $this->getServiceManager()->get(QueueDispatcher::SERVICE_ID); |
| 41 | |
| 42 | $report = \common_report_Report::createInfo('Deleting delivery: ' . $params['deliveryId']); |
| 43 | try { |
| 44 | /** @var DeliveryDeleteService $deleteDeliveryService */ |
| 45 | $deleteDeliveryService = $this->getServiceLocator()->get(DeliveryDeleteService::SERVICE_ID); |
| 46 | $request = new DeliveryDeleteRequest($params['deliveryId']); |
| 47 | $deleteDeliveryService->execute($request, true); |
| 48 | $delivery = $request->getDeliveryResource(); |
| 49 | if ($deleteDeliveryService->hasDeliveryExecutions($delivery)) { |
| 50 | $queueDispatcher->createTask( |
| 51 | $this, |
| 52 | $params, |
| 53 | __('Continue deleting of delivery "%s".', $delivery->getLabel()) |
| 54 | ); |
| 55 | $this->logInfo('Queued task to continue delete delivery ' . $delivery->getLabel()); |
| 56 | } |
| 57 | |
| 58 | $report->add($deleteDeliveryService->getReport()); |
| 59 | } catch (\Exception $exception) { |
| 60 | $report->add(\common_report_Report::createFailure($exception->getMessage())); |
| 61 | } |
| 62 | |
| 63 | return $report; |
| 64 | } |
| 65 | |
| 66 | /** |
| 67 | * @return mixed|string |
| 68 | */ |
| 69 | public function jsonSerialize() |
| 70 | { |
| 71 | return __CLASS__; |
| 72 | } |
| 73 | } |