importFactory = $importFactory; $this->resourceFactory = $resourceFactory; $this->configurationManager = $configurationManager; $this->extbasePersistenceSession = $extbasePersistenceSession; } public function createFromArray(array $configuration): Import { $result = array_map('strval', $configuration); $result['uid'] = $this->getUniqueUid(); $result['files_folder'] = $this->migrateFileFolder($result['files_folder'] ?? ''); $result['region'] = $result['region_uid']; unset($result['region_uid']); $result = $this->addCategorySettings($result); return $this->importFactory->create($result); } private function getUniqueUid(): string { do { // Only temporary solution as long as legacy exists. // Cool solution would be to fetch highest uid + 100, but that's to much for now. // Also this will vanish in future. $uid = (string) random_int(999, PHP_INT_MAX); } while ($this->extbasePersistenceSession->hasIdentifier($uid, Import::class)); return $uid; } private function migrateFileFolder(string $fileFolder): string { $storage = $this->resourceFactory->getDefaultStorage(); if ($storage === null) { throw new \Exception('No default storage defined. Cancel import.', 1643290642); } $uid = $storage->getUid(); return $uid . ':/' . trim($fileFolder, '/') . '/'; } private function addCategorySettings(array $result): array { $settings = $this->configurationManager->getConfiguration( ConfigurationManager::CONFIGURATION_TYPE_SETTINGS, 'Events', 'Pi1' ); $result['categories_pid'] = $settings['destinationData']['categoriesPid'] ?? ''; $result['category_parent'] = $settings['destinationData']['categoryParentUid'] ?? ''; return $result; } }