From 6df32d4c24f99c8045c7fece060897c6f40b406f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Albrecht=20K=C3=B6hnlein?= Date: Thu, 18 Jan 2024 15:44:43 +0100 Subject: [PATCH] TYPO3 12 compatibility (#40) * Refactor outdated SignalSlot implementation to Events thanks @koehnlein! See discussion in https://github.com/macopedia/typo3-azurestorage/pull/40#issuecomment-1896182552 --- .../AbstractFileIndexEventListener.php} | 27 ++++++++++++------- .../EventListener/AfterFileAddedToIndex.php | 15 +++++++++++ .../EventListener/AfterFileUpdatedInIndex.php | 15 +++++++++++ Configuration/Services.yaml | 18 +++++++++++++ ext_localconf.php | 5 ---- 5 files changed, 66 insertions(+), 14 deletions(-) rename Classes/{Signal/FileIndexRepository.php => EventListener/AbstractFileIndexEventListener.php} (50%) create mode 100644 Classes/EventListener/AfterFileAddedToIndex.php create mode 100644 Classes/EventListener/AfterFileUpdatedInIndex.php create mode 100644 Configuration/Services.yaml diff --git a/Classes/Signal/FileIndexRepository.php b/Classes/EventListener/AbstractFileIndexEventListener.php similarity index 50% rename from Classes/Signal/FileIndexRepository.php rename to Classes/EventListener/AbstractFileIndexEventListener.php index 4c2a9d7..74c954a 100644 --- a/Classes/Signal/FileIndexRepository.php +++ b/Classes/EventListener/AbstractFileIndexEventListener.php @@ -1,20 +1,24 @@ getStorageObject($data['storage']); + /** @var ResourceStorage $storage */ + $storage = GeneralUtility::makeInstance(ResourceFactory::class)->getStorageObject((int)$data['storage']); // only process our driver if ($storage->getDriverType() !== StorageDriver::class) { @@ -25,14 +29,19 @@ public function recordUpdatedOrCreated($data) $imageDimensions = Extractor::getImageDimensions($file); if ($imageDimensions !== null) { - /* @var $metaDataRepository MetaDataRepository */ - $metaDataRepository = MetaDataRepository::getInstance(); + /** @var MetaDataRepository $metaDataRepository */ + $metaDataRepository = GeneralUtility::makeInstance(MetaDataRepository::class); $metaData = $metaDataRepository->findByFileUid($data['uid']); $metaData['width'] = $imageDimensions[0]; $metaData['height'] = $imageDimensions[1]; - $metaDataRepository->update($data['uid'], $metaData); + + if (isset($metaData['uid'])) { + $metaDataRepository->update($data['uid'], $metaData); + } else { + $metaDataRepository->createMetaDataRecord($data['uid'], $metaData); + } } } } -} \ No newline at end of file +} diff --git a/Classes/EventListener/AfterFileAddedToIndex.php b/Classes/EventListener/AfterFileAddedToIndex.php new file mode 100644 index 0000000..be95117 --- /dev/null +++ b/Classes/EventListener/AfterFileAddedToIndex.php @@ -0,0 +1,15 @@ +recordUpdatedOrCreated($event->getRecord()); + } +} diff --git a/Classes/EventListener/AfterFileUpdatedInIndex.php b/Classes/EventListener/AfterFileUpdatedInIndex.php new file mode 100644 index 0000000..d3b7f18 --- /dev/null +++ b/Classes/EventListener/AfterFileUpdatedInIndex.php @@ -0,0 +1,15 @@ +recordUpdatedOrCreated($event->getRelevantProperties()); + } +} diff --git a/Configuration/Services.yaml b/Configuration/Services.yaml new file mode 100644 index 0000000..6fc5200 --- /dev/null +++ b/Configuration/Services.yaml @@ -0,0 +1,18 @@ +services: + _defaults: + autowire: true + autoconfigure: true + public: false + + B3N\AzureStorage\TYPO3\: + resource: '../Classes/*' + + B3N\AzureStorage\TYPO3\EventListener\AfterFileAddedToIndex: + tags: + - name: event.listener + identifier: 'azurestorage/after-file-added-to-index' + + B3N\AzureStorage\TYPO3\EventListener\AfterFileUpdatedInIndex: + tags: + - name: event.listener + identifier: 'azurestorage/after-file-updated-in-index' diff --git a/ext_localconf.php b/ext_localconf.php index 3e36c00..9c7e377 100644 --- a/ext_localconf.php +++ b/ext_localconf.php @@ -24,8 +24,3 @@ } $extractorRegistry = \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance(\TYPO3\CMS\Core\Resource\Index\ExtractorRegistry::class); $extractorRegistry->registerExtractionService(\B3N\AzureStorage\TYPO3\Index\Extractor::class); - -/* @var $signalSlotDispatcher \TYPO3\CMS\Extbase\SignalSlot\Dispatcher */ -$signalSlotDispatcher = \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance(\TYPO3\CMS\Extbase\SignalSlot\Dispatcher::class); -$signalSlotDispatcher->connect(\TYPO3\CMS\Core\Resource\Index\FileIndexRepository::class, 'recordUpdated', \B3N\AzureStorage\TYPO3\Signal\FileIndexRepository::class, 'recordUpdatedOrCreated'); -$signalSlotDispatcher->connect(\TYPO3\CMS\Core\Resource\Index\FileIndexRepository::class, 'recordCreated', \B3N\AzureStorage\TYPO3\Signal\FileIndexRepository::class, 'recordUpdatedOrCreated');