hasOption(static::OPTION_DELETE_DELIVERY_EXECUTION_DATA_SERVICES)) { throw new \common_exception_Error('Invalid Option provided: ' . static::OPTION_DELETE_DELIVERY_EXECUTION_DATA_SERVICES); } } /** * @param DeliveryExecutionDeleteRequest $request * @return bool * @throws \Exception */ public function execute(DeliveryExecutionDeleteRequest $request) { $this->report = common_report_Report::createInfo('Deleting Delivery Execution: ' . $request->getDeliveryExecution()->getIdentifier()); $shouldDelete = $this->deleteDeliveryExecutionData($request); if ($shouldDelete) { /** @var Service $executionService */ $executionService = $this->getServiceLocator()->get(ServiceProxy::SERVICE_ID); // at the end delete the delivery execution itself. $deleted = $executionService->deleteDeliveryExecutionData($request); if ($deleted) { $this->report->add(common_report_Report::createSuccess('Delivery Execution has been deleted.', $request->getDeliveryExecution()->getIdentifier())); } else { $this->report->add(common_report_Report::createInfo('Delivery Execution has NOT been deleted. DE id: ' . $request->getDeliveryExecution()->getIdentifier())); } return $deleted; } return false; } /** * @return common_report_Report */ public function getReport() { return $this->report; } /** * @param DeliveryExecutionDeleteRequest $request * @return bool * @throws \Exception */ protected function deleteDeliveryExecutionData(DeliveryExecutionDeleteRequest $request) { $services = $this->getDeliveryExecutionDeleteService(); foreach ($services as $service) { try { $deleted = $service->deleteDeliveryExecutionData($request); if ($deleted) { $this->report->add(common_report_Report::createSuccess( 'Delete execution Service: ' . get_class($service) . ' data has been deleted.', $request->getDeliveryExecution()->getIdentifier() )); } else { $this->report->add(common_report_Report::createInfo( 'Delete execution Service: ' . get_class($service) . ' data has nothing to delete' )); } } catch (\Exception $exception) { $this->report->add(common_report_Report::createFailure($exception->getMessage())); } } return true; } /** * @return DeliveryExecutionDelete[] * @throws \common_exception_Error */ private function getDeliveryExecutionDeleteService() { $services = []; $servicesStrings = $this->getOption(static::OPTION_DELETE_DELIVERY_EXECUTION_DATA_SERVICES); foreach ($servicesStrings as $serviceString) { $deleteService = $this->getServiceLocator()->get($serviceString); if (!$deleteService instanceof DeliveryExecutionDelete) { throw new \common_exception_Error('Invalid Delete Service provided: ' . $serviceString); } $services[] = $deleteService; } return $services; } }