*/ class StateService extends AbstractStateService { /** * (non-PHPdoc) * @see \oat\taoDelivery\model\execution\AbstractStateService::getInitialStatus() */ public function getInitialStatus($deliveryId, User $user) { return DeliveryExecution::STATE_ACTIVE; } /** * @param DeliveryExecution $deliveryExecution * @return bool * @throws \common_exception_NotFound */ public function finish(DeliveryExecution $deliveryExecution) { return $this->setState($deliveryExecution, DeliveryExecution::STATE_FINISHED); } /** * @param DeliveryExecution $deliveryExecution * @return bool */ public function run(DeliveryExecution $deliveryExecution) { return $this->setState($deliveryExecution, DeliveryExecution::STATE_ACTIVE); } /** * @param DeliveryExecution $deliveryExecution * @return bool * @throws \common_exception_NotFound */ public function pause(DeliveryExecution $deliveryExecution) { return $this->setState($deliveryExecution, DeliveryExecution::STATE_PAUSED); } /** * Terminate a delivery execution with an optional reason * @param DeliveryExecution $deliveryExecution * @return boolean */ public function terminate(DeliveryExecution $deliveryExecution) { return $this->setState($deliveryExecution, DeliveryExecution::STATE_TERMINATED); } /** * Legacy function to ensure all calls to setState use * the correct transition instead * * @param DeliveryExecution $deliveryExecution * @param string $state * @return bool * @throws \common_exception_NotFound */ public function legacyTransition(DeliveryExecution $deliveryExecution, $state) { switch ($state) { case DeliveryExecution::STATE_FINISHED: $result = $this->finish($deliveryExecution); break; case DeliveryExecution::STATE_ACTIVE: $result = $this->run($deliveryExecution); break; case DeliveryExecution::STATE_PAUSED: $result = $this->pause($deliveryExecution); break; default: $this->logWarning('Unrecognised state ' . $state); $result = $this->setState($deliveryExecution, $state); } return $result; } /** * @return array */ public function getDeliveriesStates() { return [ DeliveryExecution::STATE_FINISHED, DeliveryExecution::STATE_ACTIVE, DeliveryExecution::STATE_PAUSED ]; } }