persistArchive($params['deliveryId'], $params); } /** * @throws common_exception_Error * @throws common_exception_NotFound */ private function getDataStoreFilesystem(): FileSystem { return $this->getFileSystemManager()->getFileSystem(self::DATA_STORE); } private function getFolderName(string $deliveryId): string { return tao_helpers_Uri::encode($deliveryId); } /** * @throws Throwable * @throws common_Exception * @throws common_exception_Error * @throws common_exception_NotFound */ private function persistArchive(string $deliveryId, array $params): void { /** @var FileHelperService $tempDir */ $tempDir = $this->getServiceLocator()->get(FileHelperService::class); $folder = $tempDir->createTempDir(); try { $this->getTestExporter()->export( [ 'filename' => self::PACKAGE_FILENAME, 'instances' => $params['testUri'], 'uri' => $params['testUri'] ], $folder ); $this->moveExportedZipTest($folder, $deliveryId, $params); } finally { $tempDir->removeDirectory($folder); } } /** * @throws common_exception_Error * @throws common_exception_NotFound */ private function moveExportedZipTest(string $folder, string $deliveryId, array $params): void { $zipFiles = glob( sprintf('%s%s*%s', $folder, self::PACKAGE_FILENAME, self::ZIP_EXTENSION) ); if (!empty($zipFiles)) { foreach ($zipFiles as $zipFile) { $zipFileName = $this->getZipFileName($deliveryId); $this->getProcessDataService()->process($zipFile, $params); $contents = file_get_contents($zipFile); if ($this->getDataStoreFilesystem()->has($zipFileName)) { $this->getDataStoreFilesystem()->update( $zipFileName, $contents ); } else { $this->getDataStoreFilesystem()->write( $zipFileName, $contents ); } } } } private function getTestExporter(): ExporterInterface { $exporter = $this->getOption(self::OPTION_EXPORTER_SERVICE); if ($exporter) { return $exporter; } return new taoQtiTest_models_classes_export_TestExport22(); } private function getFileSystemManager(): FileSystemService { return $this->getServiceLocator()->get(FileSystemService::SERVICE_ID); } private function getProcessDataService(): ProcessDataService { return $this->getServiceLocator()->get(ProcessDataService::class); } private function getZipFileName(string $deliveryId): string { return sprintf( '%s%s%s%s', $this->getFolderName($deliveryId), DIRECTORY_SEPARATOR, self::PACKAGE_FILENAME, self::ZIP_EXTENSION ); } }