[ 'prefix' => 'uri', 'required' => true, 'longPrefix' => self::OPTION_DELIVERY_URI, 'cast' => 'string', 'description' => 'Compiled delivery RDF resource URI.' ], self::OPTION_OUTPUT_TEST_FORMAT => [ 'prefix' => 'format', 'required' => false, 'defaultValue' => CompiledTestConverterFactory::COMPILED_TEST_FORMAT_XML, 'longPrefix' => self::OPTION_OUTPUT_TEST_FORMAT, 'description' => 'Output format for compiled test data file.', ], self::OPTION_OUTPUT_FILEPATH => [ 'prefix' => 'out', 'longPrefix' => self::OPTION_OUTPUT_FILEPATH, 'required' => true, 'description' => 'Filepath for compiled assembly package.', ], ]; } /** * @return string */ protected function provideDescription() { return 'Export compiled delivery assembly package with possibility to convert compiled test file into one of supported formats.'; } /** * @return array */ protected function provideUsage() { return [ 'prefix' => 'h', 'longPrefix' => 'help', 'description' => 'Prints a help statement' ]; } /** * @return Report * @throws common_exception_Error */ protected function run() { $this->report = Report::createInfo('Delivery assembly export started'); try { $deliveryUri = $this->getOption(self::OPTION_DELIVERY_URI); $delivery = $this->getResource($deliveryUri); if (!$delivery->exists()) { $this->report->add(Report::createFailure(__('Delivery \'%s\' not found', $deliveryUri))); return $this->report; } $outputCompiledTestFormat = $this->getOption(self::OPTION_OUTPUT_TEST_FORMAT); $outputFile = $this->getOption(self::OPTION_OUTPUT_FILEPATH); /** @var AssemblyExporterService $assemblyExporter */ $assemblyExporter = $this->getServiceLocator()->get(AssemblyExporterService::SERVICE_ID); $tmpFile = $assemblyExporter->exportCompiledDelivery($delivery, $outputCompiledTestFormat); tao_helpers_File::move($tmpFile, $outputFile); $this->report->add(Report::createSuccess(__('Exported %1$s to %2$s', $delivery->getLabel(), $outputFile))); } catch (Exception $e) { $this->report->add(Report::createFailure("Export failed: " . $e->getMessage())); } return $this->report; } }