Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
0.00% |
0 / 32 |
|
0.00% |
0 / 4 |
CRAP | |
0.00% |
0 / 1 |
| AbstractMigrationTask | |
0.00% |
0 / 32 |
|
0.00% |
0 / 4 |
30 | |
0.00% |
0 / 1 |
| __invoke | |
0.00% |
0 / 14 |
|
0.00% |
0 / 1 |
6 | |||
| getUnitProcessor | n/a |
0 / 0 |
n/a |
0 / 0 |
0 | |||||
| getResultSearcher | n/a |
0 / 0 |
n/a |
0 / 0 |
0 | |||||
| getSpawnMigrationConfigService | n/a |
0 / 0 |
n/a |
0 / 0 |
0 | |||||
| getResultFilterFactory | n/a |
0 / 0 |
n/a |
0 / 0 |
0 | |||||
| getMigrationConfigFactory | n/a |
0 / 0 |
n/a |
0 / 0 |
0 | |||||
| respawnTask | |
0.00% |
0 / 16 |
|
0.00% |
0 / 1 |
2 | |||
| getQueueMigrationService | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
| getQueueDispatcher | |
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) 2020 (original work) Open Assessment Technologies SA; |
| 19 | */ |
| 20 | |
| 21 | declare(strict_types=1); |
| 22 | |
| 23 | namespace oat\tao\model\task\migration; |
| 24 | |
| 25 | use common_exception_MissingParameter; |
| 26 | use common_report_Report; |
| 27 | use oat\generis\model\OntologyAwareTrait; |
| 28 | use oat\oatbox\action\Action; |
| 29 | use oat\oatbox\log\LoggerAwareTrait; |
| 30 | use oat\tao\model\task\migration\service\MigrationConfigFactoryInterface; |
| 31 | use oat\tao\model\task\migration\service\QueueMigrationService; |
| 32 | use oat\tao\model\task\migration\service\ResultFilterFactoryInterface; |
| 33 | use oat\tao\model\task\migration\service\ResultSearcherInterface; |
| 34 | use oat\tao\model\task\migration\service\ResultUnitProcessorInterface; |
| 35 | use oat\tao\model\task\migration\service\SpawnMigrationConfigServiceInterface; |
| 36 | use oat\tao\model\taskQueue\QueueDispatcherInterface; |
| 37 | use oat\tao\model\taskQueue\Task\CallbackTaskInterface; |
| 38 | use oat\tao\model\taskQueue\Task\TaskAwareInterface; |
| 39 | use oat\tao\model\taskQueue\Task\TaskAwareTrait; |
| 40 | use Zend\ServiceManager\ServiceLocatorAwareInterface; |
| 41 | use Zend\ServiceManager\ServiceLocatorAwareTrait; |
| 42 | |
| 43 | abstract class AbstractMigrationTask implements Action, ServiceLocatorAwareInterface, TaskAwareInterface |
| 44 | { |
| 45 | use ServiceLocatorAwareTrait; |
| 46 | use OntologyAwareTrait; |
| 47 | use TaskAwareTrait; |
| 48 | use LoggerAwareTrait; |
| 49 | |
| 50 | /** @var int */ |
| 51 | private $affected; |
| 52 | |
| 53 | /** @var int */ |
| 54 | private $pickSize; |
| 55 | |
| 56 | /** @var common_report_Report */ |
| 57 | private $errorReport; |
| 58 | |
| 59 | /** |
| 60 | * @param $params |
| 61 | * @throws common_exception_MissingParameter |
| 62 | * @return common_report_Report |
| 63 | */ |
| 64 | public function __invoke($params) |
| 65 | { |
| 66 | $report = common_report_Report::createInfo('Statement Migration Task'); |
| 67 | |
| 68 | $migrationConfig = $this->getMigrationConfigFactory()->create($params); |
| 69 | $resultFilter = $this->getResultFilterFactory()->create($migrationConfig); |
| 70 | |
| 71 | $respawnTaskConfig = $this->getQueueMigrationService()->migrate( |
| 72 | $migrationConfig, |
| 73 | $this->getUnitProcessor(), |
| 74 | $this->getResultSearcher(), |
| 75 | $resultFilter, |
| 76 | $this->getSpawnMigrationConfigService(), |
| 77 | $report |
| 78 | ); |
| 79 | |
| 80 | if ($respawnTaskConfig instanceof MigrationConfig) { |
| 81 | $this->respawnTask($respawnTaskConfig); |
| 82 | } |
| 83 | |
| 84 | return $report; |
| 85 | } |
| 86 | |
| 87 | abstract protected function getUnitProcessor(): ResultUnitProcessorInterface; |
| 88 | |
| 89 | abstract protected function getResultSearcher(): ResultSearcherInterface; |
| 90 | |
| 91 | abstract protected function getSpawnMigrationConfigService(): SpawnMigrationConfigServiceInterface; |
| 92 | |
| 93 | abstract protected function getResultFilterFactory(): ResultFilterFactoryInterface; |
| 94 | |
| 95 | abstract protected function getMigrationConfigFactory(): MigrationConfigFactoryInterface; |
| 96 | |
| 97 | private function respawnTask(MigrationConfig $config): CallbackTaskInterface |
| 98 | { |
| 99 | return $this->getQueueDispatcher()->createTask( |
| 100 | new static(), |
| 101 | array_merge( |
| 102 | $config->getCustomParameters(), |
| 103 | [ |
| 104 | 'chunkSize' => $config->getChunkSize(), |
| 105 | 'pickSize' => $config->getPickSize(), |
| 106 | 'repeat' => $config->isProcessAll(), |
| 107 | ] |
| 108 | ), |
| 109 | sprintf( |
| 110 | 'Unit processing by %s with chunk size of %s', |
| 111 | self::class, |
| 112 | $config->getChunkSize() |
| 113 | ) |
| 114 | ); |
| 115 | } |
| 116 | |
| 117 | private function getQueueMigrationService(): QueueMigrationService |
| 118 | { |
| 119 | return $this->getServiceLocator()->get(QueueMigrationService::class); |
| 120 | } |
| 121 | |
| 122 | private function getQueueDispatcher(): QueueDispatcherInterface |
| 123 | { |
| 124 | return $this->getServiceLocator()->get(QueueDispatcherInterface::SERVICE_ID); |
| 125 | } |
| 126 | } |