getServiceLocator()->get(QueueDispatcher::SERVICE_ID); $action = $this->getServiceLocator()->get(self::SERVICE_ID); $parameters = [ 'deliveryId' => $delivery->getUri(), 'from' => $from, 'to' => $to, ]; return $queueDispatcher->createTask( $action, $parameters, __( 'CSV irregularities export for delivery "%s" from %s to %s', $delivery->getLabel(), $this->getFormatedDateForFileName($from), $this->getFormatedDateForFileName($to) ) ); } public function __invoke($params) { $this->getServiceLocator() ->get(\common_ext_ExtensionsManager::SERVICE_ID) ->getExtensionById('taoResultServer'); if (!isset($params['deliveryId'])) { throw new \InvalidArgumentException('Delivery uri is missing for irregularity export'); } if (!isset($params['from'])) { throw new \InvalidArgumentException('From date is missing for irregularity export'); } if (!isset($params['to'])) { throw new \InvalidArgumentException('To date is missing for irregularity export'); } $delivery = $this->getResource($params['deliveryId']); $data = $this->getIrregularitiesTable($delivery, $params['from'], $params['to']); $exporter = new CsvExporter($data); $filePrefix = $this->saveStringToStorage($exporter->export(), $this->getFileName($delivery, $params)); return $filePrefix === false ? Report::createFailure(__('Unable to create irregularities export for %s', $delivery->getLabel())) : Report::createSuccess(__('Irregularities for "%s" successfully exported', $delivery->getLabel()), $filePrefix); } protected function getFileName(\core_kernel_classes_Resource $delivery, array $params) { return strtolower( 'irregularities_' .\tao_helpers_File::getSafeFileName($delivery->getLabel()).'_' .$this->getFormatedDateForFileName($params['from']).'_' .$this->getFormatedDateForFileName($params['to']).'_' .date('YmdHis') . rand(10, 99) //more unique name .'.csv' ); } /** * @param \core_kernel_classes_Resource $delivery * @param string $from * @param string $to * @return array */ abstract public function getIrregularitiesTable(\core_kernel_classes_Resource $delivery, $from = '', $to = ''); /** * @see FilesystemAwareTrait::getFileSystemService() */ protected function getFileSystemService() { return $this->getServiceLocator() ->get(FileSystemService::SERVICE_ID); } }