Skip to content

Commit

Permalink
Merge branch 'release-16.0.1'
Browse files Browse the repository at this point in the history
  • Loading branch information
github-actions committed Dec 5, 2024
2 parents 96af971 + bea83b8 commit bed756c
Show file tree
Hide file tree
Showing 2 changed files with 77 additions and 0 deletions.
18 changes: 18 additions & 0 deletions common/oatbox/filesystem/FileSystemService.php
Original file line number Diff line number Diff line change
Expand Up @@ -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'] : [];

Expand All @@ -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;
}
}
59 changes: 59 additions & 0 deletions migrations/Version202412031536512348_generis.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
<?php

declare(strict_types=1);

namespace oat\generis\migrations;

use Doctrine\DBAL\Schema\Schema;
use oat\oatbox\filesystem\FileSystemService;
use oat\tao\scripts\tools\migrations\AbstractMigration;

final class Version202412031536512348_generis extends AbstractMigration
{
public function getDescription(): string
{
return 'Update filesystem configuration';
}

public function up(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']['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);
}
}

0 comments on commit bed756c

Please sign in to comment.