Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
0.00% |
0 / 23 |
|
0.00% |
0 / 3 |
CRAP | |
0.00% |
0 / 1 |
| LegacyTextReaderItemUpdate | |
0.00% |
0 / 23 |
|
0.00% |
0 / 3 |
42 | |
0.00% |
0 / 1 |
| __construct | |
0.00% |
0 / 2 |
|
0.00% |
0 / 1 |
2 | |||
| updateAllItems | |
0.00% |
0 / 20 |
|
0.00% |
0 / 1 |
20 | |||
| getItemResources | |
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) 2022-2023 (original work) Open Assessment Technologies SA; |
| 19 | */ |
| 20 | |
| 21 | declare(strict_types=1); |
| 22 | |
| 23 | namespace oat\pciSamples\model\LegacyPciHelper; |
| 24 | |
| 25 | use Exception; |
| 26 | use oat\generis\model\OntologyAwareTrait; |
| 27 | use oat\oatbox\reporting\Report; |
| 28 | use oat\pciSamples\model\LegacyPciHelper\Task\UpgradeTextReaderInteractionTask; |
| 29 | use oat\tao\model\TaoOntology; |
| 30 | use oat\tao\model\taskQueue\QueueDispatcherInterface; |
| 31 | use taoItems_models_classes_ItemsService; |
| 32 | |
| 33 | class LegacyTextReaderItemUpdate |
| 34 | { |
| 35 | use OntologyAwareTrait; |
| 36 | |
| 37 | private taoItems_models_classes_ItemsService $itemsService; |
| 38 | private QueueDispatcherInterface $queueDispatcher; |
| 39 | |
| 40 | public function __construct( |
| 41 | taoItems_models_classes_ItemsService $itemsService, |
| 42 | QueueDispatcherInterface $queueDispatcher |
| 43 | ) { |
| 44 | $this->itemsService = $itemsService; |
| 45 | $this->queueDispatcher = $queueDispatcher; |
| 46 | } |
| 47 | |
| 48 | public function updateAllItems(Report $report, ?string $queueName, bool $skipWithoutImages = true): void |
| 49 | { |
| 50 | foreach ($this->getItemResources() as $itemResource) { |
| 51 | try { |
| 52 | $this->queueDispatcher->linkTaskToQueue( |
| 53 | UpgradeTextReaderInteractionTask::class, |
| 54 | $queueName ?: $this->queueDispatcher->getDefaultQueue()->getName() |
| 55 | ); |
| 56 | |
| 57 | $this->queueDispatcher->createTask( |
| 58 | new UpgradeTextReaderInteractionTask(), |
| 59 | [ |
| 60 | 'itemUri' => $itemResource->getUri(), |
| 61 | 'skipItemsWithoutImages' => $skipWithoutImages |
| 62 | ], |
| 63 | sprintf("TextReaderUpgradeForItem-%s", $itemResource->getUri()) |
| 64 | ); |
| 65 | } catch (Exception $exception) { |
| 66 | $report->add(Report::createError( |
| 67 | sprintf( |
| 68 | "Item failed on task creation with this message: %s", |
| 69 | $exception->getMessage() |
| 70 | ) |
| 71 | )); |
| 72 | } |
| 73 | } |
| 74 | } |
| 75 | |
| 76 | private function getItemResources(): array |
| 77 | { |
| 78 | return $this->itemsService->getClass(TaoOntology::CLASS_URI_ITEM)->getInstances(true); |
| 79 | } |
| 80 | } |