From bf3697b421300dc7949a1fe0dbf36305eac3b0ce Mon Sep 17 00:00:00 2001 From: Augustas Nedzinskas Date: Wed, 4 Dec 2024 10:07:31 +0100 Subject: [PATCH 1/5] fix: migration to update filesystem configuration --- .../Version202412031536512348_generis.php | 59 +++++++++++++++++++ 1 file changed, 59 insertions(+) create mode 100644 migrations/Version202412031536512348_generis.php diff --git a/migrations/Version202412031536512348_generis.php b/migrations/Version202412031536512348_generis.php new file mode 100644 index 000000000..b5a9a14eb --- /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 (isset($adapterConfig['options']['root'])) { + $updatedConfig[$adapterId]['options']['location'] = $adapterConfig[$adapterId]['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 (isset($adapterConfig['options']['location'])) { + $updatedConfig[$adapterId]['options']['root'] = $adapterConfig[$adapterId]['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); + } +} From 1e4e16994531fb09c9710779ba1a27babf8c225d Mon Sep 17 00:00:00 2001 From: Augustas Nedzinskas Date: Wed, 4 Dec 2024 11:03:08 +0100 Subject: [PATCH 2/5] fix: mistake in picking previous value --- migrations/Version202412031536512348_generis.php | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/migrations/Version202412031536512348_generis.php b/migrations/Version202412031536512348_generis.php index b5a9a14eb..5ae29171f 100644 --- a/migrations/Version202412031536512348_generis.php +++ b/migrations/Version202412031536512348_generis.php @@ -23,8 +23,8 @@ public function up(Schema $schema): void if ($adapterConfig['class'] === 'Local' || $adapterConfig['class'] === 'League\\Flysystem\\Local\\LocalFilesystemAdapter' ) { - if (isset($adapterConfig['options']['root'])) { - $updatedConfig[$adapterId]['options']['location'] = $adapterConfig[$adapterId]['options']['root']; + if (!empty($adapterConfig['options']['root'])) { + $updatedConfig[$adapterId]['options']['location'] = $adapterConfig['options']['root']; unset($updatedConfig[$adapterId]['options']['root']); } } elseif ($adapterConfig['class'] === 'League\\Flysystem\\Memory\\MemoryAdapter') { @@ -44,8 +44,8 @@ public function down(Schema $schema): void if ($adapterConfig['class'] === 'Local' || $adapterConfig['class'] === 'League\\Flysystem\\Local\\LocalFilesystemAdapter' ) { - if (isset($adapterConfig['options']['location'])) { - $updatedConfig[$adapterId]['options']['root'] = $adapterConfig[$adapterId]['options']['location']; + if (!empty($adapterConfig['options']['location'])) { + $updatedConfig[$adapterId]['options']['root'] = $adapterConfig['options']['location']; unset($updatedConfig[$adapterId]['options']['location']); } } elseif ($adapterConfig['class'] === 'League\\Flysystem\\InMemory\\InMemoryFilesystemAdapter') { From fb3a21fca4e0ee58745a4d16f382fa1ba4e9d7bf Mon Sep 17 00:00:00 2001 From: Augustas Nedzinskas Date: Thu, 5 Dec 2024 18:33:17 +0100 Subject: [PATCH 3/5] fix: handle flysystem upgrade --- common/oatbox/filesystem/FileSystemService.php | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/common/oatbox/filesystem/FileSystemService.php b/common/oatbox/filesystem/FileSystemService.php index 66dcebf24..227db4149 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,18 @@ 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; + } } From 927f4cc22fe6fbe73f93b26517664bd7b6daa2e1 Mon Sep 17 00:00:00 2001 From: Augustas Nedzinskas Date: Thu, 5 Dec 2024 18:53:32 +0100 Subject: [PATCH 4/5] chore: whitespace change for CI --- common/oatbox/filesystem/FileSystemService.php | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/common/oatbox/filesystem/FileSystemService.php b/common/oatbox/filesystem/FileSystemService.php index 227db4149..58f232366 100755 --- a/common/oatbox/filesystem/FileSystemService.php +++ b/common/oatbox/filesystem/FileSystemService.php @@ -267,7 +267,9 @@ protected function getFlysystemAdapter($id) private function handleFlysystemUpgrade(array $adapterConfig): array { - if ($adapterConfig['class'] === 'Local' || $adapterConfig['class'] === 'League\\Flysystem\\Local\\LocalFilesystemAdapter') { + 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']); From 6f93fa404fb281f4e340f82964693c25e686370a Mon Sep 17 00:00:00 2001 From: Augustas Nedzinskas Date: Thu, 5 Dec 2024 18:55:11 +0100 Subject: [PATCH 5/5] chore: whitespace change for CI --- common/oatbox/filesystem/FileSystemService.php | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/common/oatbox/filesystem/FileSystemService.php b/common/oatbox/filesystem/FileSystemService.php index 58f232366..8364f4e1b 100755 --- a/common/oatbox/filesystem/FileSystemService.php +++ b/common/oatbox/filesystem/FileSystemService.php @@ -267,7 +267,8 @@ protected function getFlysystemAdapter($id) private function handleFlysystemUpgrade(array $adapterConfig): array { - if ($adapterConfig['class'] === 'Local' + if ( + $adapterConfig['class'] === 'Local' || $adapterConfig['class'] === 'League\\Flysystem\\Local\\LocalFilesystemAdapter' ) { if (!empty($adapterConfig['options']['root'])) {