Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
26.32% |
5 / 19 |
|
71.43% |
5 / 7 |
CRAP | |
0.00% |
0 / 1 |
| StateService | |
26.32% |
5 / 19 |
|
71.43% |
5 / 7 |
59.41 | |
0.00% |
0 / 1 |
| getInitialStatus | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
| finish | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
| run | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
| pause | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
| terminate | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
| legacyTransition | |
0.00% |
0 / 9 |
|
0.00% |
0 / 1 |
30 | |||
| getDeliveriesStates | |
0.00% |
0 / 5 |
|
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) 2017 (original work) Open Assessment Technologies SA; |
| 19 | * |
| 20 | */ |
| 21 | |
| 22 | namespace oat\taoDelivery\model\execution; |
| 23 | |
| 24 | use oat\oatbox\user\User; |
| 25 | |
| 26 | /** |
| 27 | * Class StateService |
| 28 | * @package oat\taoDelivery |
| 29 | * @author Aleh Hutnikau, <hutnikau@1pt.com> |
| 30 | */ |
| 31 | class StateService extends AbstractStateService |
| 32 | { |
| 33 | /** |
| 34 | * (non-PHPdoc) |
| 35 | * @see \oat\taoDelivery\model\execution\AbstractStateService::getInitialStatus() |
| 36 | */ |
| 37 | public function getInitialStatus($deliveryId, User $user) |
| 38 | { |
| 39 | return DeliveryExecution::STATE_ACTIVE; |
| 40 | } |
| 41 | |
| 42 | /** |
| 43 | * @param DeliveryExecution $deliveryExecution |
| 44 | * @return bool |
| 45 | * @throws \common_exception_NotFound |
| 46 | */ |
| 47 | public function finish(DeliveryExecution $deliveryExecution) |
| 48 | { |
| 49 | return $this->setState($deliveryExecution, DeliveryExecution::STATE_FINISHED); |
| 50 | } |
| 51 | |
| 52 | /** |
| 53 | * @param DeliveryExecution $deliveryExecution |
| 54 | * @return bool |
| 55 | */ |
| 56 | public function run(DeliveryExecution $deliveryExecution) |
| 57 | { |
| 58 | return $this->setState($deliveryExecution, DeliveryExecution::STATE_ACTIVE); |
| 59 | } |
| 60 | |
| 61 | /** |
| 62 | * @param DeliveryExecution $deliveryExecution |
| 63 | * @return bool |
| 64 | * @throws \common_exception_NotFound |
| 65 | */ |
| 66 | public function pause(DeliveryExecution $deliveryExecution) |
| 67 | { |
| 68 | return $this->setState($deliveryExecution, DeliveryExecution::STATE_PAUSED); |
| 69 | } |
| 70 | |
| 71 | /** |
| 72 | * Terminate a delivery execution with an optional reason |
| 73 | * @param DeliveryExecution $deliveryExecution |
| 74 | * @return boolean |
| 75 | */ |
| 76 | public function terminate(DeliveryExecution $deliveryExecution) |
| 77 | { |
| 78 | return $this->setState($deliveryExecution, DeliveryExecution::STATE_TERMINATED); |
| 79 | } |
| 80 | |
| 81 | /** |
| 82 | * Legacy function to ensure all calls to setState use |
| 83 | * the correct transition instead |
| 84 | * |
| 85 | * @param DeliveryExecution $deliveryExecution |
| 86 | * @param string $state |
| 87 | * @return bool |
| 88 | * @throws \common_exception_NotFound |
| 89 | */ |
| 90 | public function legacyTransition(DeliveryExecution $deliveryExecution, $state) |
| 91 | { |
| 92 | switch ($state) { |
| 93 | case DeliveryExecution::STATE_FINISHED: |
| 94 | $result = $this->finish($deliveryExecution); |
| 95 | break; |
| 96 | case DeliveryExecution::STATE_ACTIVE: |
| 97 | $result = $this->run($deliveryExecution); |
| 98 | break; |
| 99 | case DeliveryExecution::STATE_PAUSED: |
| 100 | $result = $this->pause($deliveryExecution); |
| 101 | break; |
| 102 | default: |
| 103 | $this->logWarning('Unrecognised state ' . $state); |
| 104 | $result = $this->setState($deliveryExecution, $state); |
| 105 | } |
| 106 | return $result; |
| 107 | } |
| 108 | |
| 109 | /** |
| 110 | * @return array |
| 111 | */ |
| 112 | public function getDeliveriesStates() |
| 113 | { |
| 114 | return [ |
| 115 | DeliveryExecution::STATE_FINISHED, |
| 116 | DeliveryExecution::STATE_ACTIVE, |
| 117 | DeliveryExecution::STATE_PAUSED |
| 118 | ]; |
| 119 | } |
| 120 | } |