Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
0.00% |
0 / 34 |
|
0.00% |
0 / 1 |
CRAP | |
0.00% |
0 / 1 |
| StateBackupRemovalTask | |
0.00% |
0 / 34 |
|
0.00% |
0 / 1 |
6 | |
0.00% |
0 / 1 |
| manipulateState | |
0.00% |
0 / 34 |
|
0.00% |
0 / 1 |
6 | |||
| 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 (original work) Open Assessment Technologies SA; |
| 19 | */ |
| 20 | |
| 21 | declare(strict_types=1); |
| 22 | |
| 23 | namespace oat\taoQtiTest\models\classes\tasks\QtiStateOffload; |
| 24 | |
| 25 | use Exception; |
| 26 | use oat\oatbox\reporting\Report; |
| 27 | use Psr\Container\ContainerExceptionInterface; |
| 28 | use Psr\Container\NotFoundExceptionInterface; |
| 29 | |
| 30 | class StateBackupRemovalTask extends AbstractQtiStateManipulationTask |
| 31 | { |
| 32 | /** |
| 33 | * @param string $userId |
| 34 | * @param string $callId |
| 35 | * @param string $stateLabel |
| 36 | * @return Report |
| 37 | * @throws ContainerExceptionInterface |
| 38 | * @throws NotFoundExceptionInterface |
| 39 | */ |
| 40 | protected function manipulateState(string $userId, string $callId, string $stateLabel): Report |
| 41 | { |
| 42 | try { |
| 43 | $this->getStateMigrationService()->removeBackup($userId, $callId); |
| 44 | |
| 45 | $this->getLogger()->info( |
| 46 | sprintf('%s state backup has been deleted', $stateLabel), |
| 47 | [ |
| 48 | 'userId' => $userId, |
| 49 | 'callId' => $callId, |
| 50 | 'stateType' => $stateLabel |
| 51 | ] |
| 52 | ); |
| 53 | return Report::createSuccess( |
| 54 | sprintf( |
| 55 | '[%s] - %s state backup was successfully removed for user %s', |
| 56 | $callId, |
| 57 | $stateLabel, |
| 58 | $userId |
| 59 | ) |
| 60 | ); |
| 61 | } catch (Exception $exception) { |
| 62 | $this->getLogger()->warning( |
| 63 | sprintf('Failed to delete backup %s state', $stateLabel), |
| 64 | [ |
| 65 | 'userId' => $userId, |
| 66 | 'callId' => $callId, |
| 67 | 'stateType' => $stateLabel |
| 68 | ] |
| 69 | ); |
| 70 | return Report::createError( |
| 71 | sprintf( |
| 72 | '[%s] - %s state backup removing failed for user %s', |
| 73 | $callId, |
| 74 | $stateLabel, |
| 75 | $userId |
| 76 | ) |
| 77 | ); |
| 78 | } |
| 79 | } |
| 80 | } |