diff --git a/composer.json b/composer.json index 0f1078b..6129b88 100644 --- a/composer.json +++ b/composer.json @@ -12,6 +12,9 @@ "dealerdirect/phpcodesniffer-composer-installer": "^0.7.0", "drupal/coder": "^8.3" }, + "conflict": { + "drupal/core": "<10.3" + }, "extra": { "patches": { "twistor/flysystem-stream-wrapper": { diff --git a/helfi_azure_fs.info.yml b/helfi_azure_fs.info.yml index 5439a21..187bb29 100644 --- a/helfi_azure_fs.info.yml +++ b/helfi_azure_fs.info.yml @@ -1,4 +1,4 @@ name: HELfi azure file system type: module package: Custom -core_version_requirement: ^9 || ^10 +core_version_requirement: ^9 || ^10 || ^11 diff --git a/helfi_azure_fs.module b/helfi_azure_fs.module index ce77556..b632016 100644 --- a/helfi_azure_fs.module +++ b/helfi_azure_fs.module @@ -8,7 +8,6 @@ declare(strict_types=1); use Drupal\Core\Entity\EntityTypeInterface; -use Drupal\Core\File\FileSystemInterface; use Drupal\file\FileInterface; /** @@ -16,7 +15,7 @@ use Drupal\file\FileInterface; */ function helfi_azure_fs_entity_field_storage_info_alter( &$fields, - EntityTypeInterface $entity_type + EntityTypeInterface $entity_type, ) : void { $config = Drupal::config('helfi_azure_fs.settings'); @@ -46,7 +45,7 @@ function helfi_azure_fs_file_presave(FileInterface $file) : void { $uri = $file->getFileUri(); $directory = $file_system->dirname($uri); $uri = $directory . '/' . $new_filename; - if ($new_uri = $file_system->move($file->getFileUri(), $uri, FileSystemInterface::EXISTS_RENAME)) { + if ($new_uri = $file_system->move($file->getFileUri(), $uri)) { $file->set('uri', $new_uri); $file->set('filename', $file_system->basename($new_uri)); } diff --git a/helfi_azure_fs.services.yml b/helfi_azure_fs.services.yml index c354d74..1ca267d 100644 --- a/helfi_azure_fs.services.yml +++ b/helfi_azure_fs.services.yml @@ -1,4 +1,7 @@ services: + _defaults: + autoconfigure: true + autowire: true azure_file_system: class: Drupal\helfi_azure_fs\AzureFileSystem decorates: file_system @@ -7,4 +10,5 @@ services: - '@azure_file_system.inner' - '@stream_wrapper_manager' - '@settings' - - '@logger.channel.file' + + Drupal\helfi_azure_fs\Routing\RouteSubscriber: ~ diff --git a/src/AzureBlobStorageAdapter.php b/src/AzureBlobStorageAdapter.php index d8f566e..abb0bb4 100644 --- a/src/AzureBlobStorageAdapter.php +++ b/src/AzureBlobStorageAdapter.php @@ -65,7 +65,7 @@ class AzureBlobStorageAdapter extends AbstractAdapter { public function __construct( protected BlobRestProxy $client, protected string $container, - ?string $prefix = NULL + ?string $prefix = NULL, ) { $this->setPathPrefix($prefix); } diff --git a/src/AzureFileSystem.php b/src/AzureFileSystem.php index fa8471e..668f800 100644 --- a/src/AzureFileSystem.php +++ b/src/AzureFileSystem.php @@ -8,7 +8,6 @@ use Drupal\Core\File\FileSystemInterface; use Drupal\Core\Site\Settings; use Drupal\Core\StreamWrapper\StreamWrapperManagerInterface; -use Psr\Log\LoggerInterface; /** * Provides Azure specific file system. @@ -38,18 +37,15 @@ final class AzureFileSystem extends FileSystem { * The stream wrapper manager. * @param \Drupal\Core\Site\Settings $settings * The settings. - * @param \Psr\Log\LoggerInterface $logger - * The logger. */ public function __construct( private FileSystemInterface $decorated, StreamWrapperManagerInterface $streamWrapperManager, Settings $settings, - LoggerInterface $logger, ) { $this->skipFsOperations = $settings::get('is_azure', FALSE); - parent::__construct($streamWrapperManager, $settings, $logger); + parent::__construct($streamWrapperManager, $settings); } /** @@ -69,7 +65,7 @@ public function mkdir( $uri, $mode = NULL, $recursive = FALSE, - $context = NULL + $context = NULL, ): bool { if (!$this->skipFsOperations) { return $this->decorated->mkdir($uri, $mode, $recursive, $context); diff --git a/src/Flysystem/Azure.php b/src/Flysystem/Azure.php index 24284e2..4cb6695 100644 --- a/src/Flysystem/Azure.php +++ b/src/Flysystem/Azure.php @@ -59,7 +59,7 @@ final class Azure implements FlysystemPluginInterface, ContainerFactoryPluginInt public function __construct( private array $configuration, private LoggerInterface $logger, - private FileUrlGeneratorInterface $fileUrlGenerator + private FileUrlGeneratorInterface $fileUrlGenerator, ) { } diff --git a/src/Routing/RouteSubscriber.php b/src/Routing/RouteSubscriber.php new file mode 100644 index 0000000..26672fa --- /dev/null +++ b/src/Routing/RouteSubscriber.php @@ -0,0 +1,44 @@ +configFactory->get('helfi_azure_fs.settings'); + + // Skip if blob storage is not in use. + if (!$config->get('use_blob_storage')) { + return; + } + + // Make sure image style URL requires 'azure' derivative scheme. + if ($route = $collection->get('image.style_public')) { + $route->setDefault('required_derivative_scheme', 'azure'); + } + } + +} diff --git a/tests/src/Unit/AzureFileSystemTest.php b/tests/src/Unit/AzureFileSystemTest.php index 51c9b8c..1938e84 100644 --- a/tests/src/Unit/AzureFileSystemTest.php +++ b/tests/src/Unit/AzureFileSystemTest.php @@ -14,7 +14,6 @@ use org\bovigo\vfs\vfsStream; use Prophecy\Argument; use Prophecy\PhpUnit\ProphecyTrait; -use Psr\Log\LoggerInterface; /** * Tests AzureFileSystem. @@ -95,9 +94,7 @@ private function getSut(FileSystemInterface $decorated, Settings $settings, ?Str if (!$streamWrapperManager) { $streamWrapperManager = $this->createMock(StreamWrapperManagerInterface::class); } - $logger = $this->createMock(LoggerInterface::class); - - return new AzureFileSystem($decorated, $streamWrapperManager, $settings, $logger); + return new AzureFileSystem($decorated, $streamWrapperManager, $settings); } /** diff --git a/tests/src/Unit/AzureTest.php b/tests/src/Unit/AzureTest.php index d9b4e1f..23ccc57 100644 --- a/tests/src/Unit/AzureTest.php +++ b/tests/src/Unit/AzureTest.php @@ -7,6 +7,7 @@ use Drupal\Core\DependencyInjection\ContainerBuilder; use Drupal\Core\File\FileUrlGeneratorInterface; use Drupal\Core\Logger\LoggerChannelFactory; +use Drupal\Core\Session\AccountInterface; use Drupal\helfi_azure_fs\Flysystem\Azure; use Drupal\Tests\UnitTestCase; use MicrosoftAzure\Storage\Common\Internal\Authentication\SharedAccessSignatureAuthScheme; @@ -15,6 +16,7 @@ use Prophecy\Argument; use Prophecy\PhpUnit\ProphecyTrait; use Psr\Log\LoggerInterface; +use Symfony\Component\HttpFoundation\RequestStack; /** * Tests Azure. @@ -37,7 +39,10 @@ public function testGetExternalUrl() : void { '/styles/test.jpg', '/styles/test).jpg', ); - $loggerFactory = new LoggerChannelFactory(); + $loggerFactory = new LoggerChannelFactory( + $this->prophesize(RequestStack::class)->reveal(), + $this->prophesize(AccountInterface::class)->reveal(), + ); $loggerFactory->addLogger($this->prophesize(LoggerInterface::class)->reveal()); $configuration = [