diff --git a/common/oatbox/filesystem/FileSystemService.php b/common/oatbox/filesystem/FileSystemService.php index 66dcebf24..8364f4e1b 100755 --- a/common/oatbox/filesystem/FileSystemService.php +++ b/common/oatbox/filesystem/FileSystemService.php @@ -241,6 +241,7 @@ protected function getFlysystemAdapter($id) while (is_string($adapterConfig)) { $adapterConfig = $fsConfig[$adapterConfig]; } + $adapterConfig = $this->handleFlysystemUpgrade($adapterConfig); $class = $adapterConfig['class']; $options = isset($adapterConfig['options']) ? $adapterConfig['options'] : []; @@ -263,4 +264,21 @@ protected function getFlysystemAdapter($id) } return $adapter; } + + private function handleFlysystemUpgrade(array $adapterConfig): array + { + if ( + $adapterConfig['class'] === 'Local' + || $adapterConfig['class'] === 'League\\Flysystem\\Local\\LocalFilesystemAdapter' + ) { + if (!empty($adapterConfig['options']['root'])) { + $adapterConfig['options']['location'] = $adapterConfig['options']['root']; + unset($adapterConfig['options']['root']); + } + } elseif ($adapterConfig['class'] === 'League\\Flysystem\\Memory\\MemoryAdapter') { + $adapterConfig['class'] = 'League\\Flysystem\\InMemory\\InMemoryFilesystemAdapter'; + } + + return $adapterConfig; + } } diff --git a/migrations/Version202412031536512348_generis.php b/migrations/Version202412031536512348_generis.php new file mode 100644 index 000000000..5ae29171f --- /dev/null +++ b/migrations/Version202412031536512348_generis.php @@ -0,0 +1,59 @@ +getServiceLocator()->get(FileSystemService::SERVICE_ID); + $config = $updatedConfig = $filesystemService->getOption(FileSystemService::OPTION_ADAPTERS); + foreach ($config as $adapterId => $adapterConfig) { + if ($adapterConfig['class'] === 'Local' + || $adapterConfig['class'] === 'League\\Flysystem\\Local\\LocalFilesystemAdapter' + ) { + if (!empty($adapterConfig['options']['root'])) { + $updatedConfig[$adapterId]['options']['location'] = $adapterConfig['options']['root']; + unset($updatedConfig[$adapterId]['options']['root']); + } + } elseif ($adapterConfig['class'] === 'League\\Flysystem\\Memory\\MemoryAdapter') { + $updatedConfig[$adapterId]['class'] = 'League\\Flysystem\\InMemory\\InMemoryFilesystemAdapter'; + } + } + + $filesystemService->setOption(FileSystemService::OPTION_ADAPTERS, $updatedConfig); + $this->registerService(FileSystemService::SERVICE_ID, $filesystemService); + } + + public function down(Schema $schema): void + { + $filesystemService = $this->getServiceLocator()->get(FileSystemService::SERVICE_ID); + $config = $updatedConfig = $filesystemService->getOption(FileSystemService::OPTION_ADAPTERS); + foreach ($config as $adapterId => $adapterConfig) { + if ($adapterConfig['class'] === 'Local' + || $adapterConfig['class'] === 'League\\Flysystem\\Local\\LocalFilesystemAdapter' + ) { + if (!empty($adapterConfig['options']['location'])) { + $updatedConfig[$adapterId]['options']['root'] = $adapterConfig['options']['location']; + unset($updatedConfig[$adapterId]['options']['location']); + } + } elseif ($adapterConfig['class'] === 'League\\Flysystem\\InMemory\\InMemoryFilesystemAdapter') { + $updatedConfig[$adapterId]['class'] = 'League\\Flysystem\\Memory\\MemoryAdapter'; + } + } + + $filesystemService->setOption(FileSystemService::OPTION_ADAPTERS, $updatedConfig); + $this->registerService(FileSystemService::SERVICE_ID, $filesystemService); + } +}