Skip to content

Commit

Permalink
TYPO3 12 compatibility (#40)
Browse files Browse the repository at this point in the history
* Refactor outdated SignalSlot implementation to Events
thanks @koehnlein!
See discussion in #40 (comment)
  • Loading branch information
koehnlein authored Jan 18, 2024
1 parent dcda34f commit 6df32d4
Show file tree
Hide file tree
Showing 5 changed files with 66 additions and 14 deletions.
Original file line number Diff line number Diff line change
@@ -1,20 +1,24 @@
<?php

namespace B3N\AzureStorage\TYPO3\Signal;
declare(strict_types=1);

namespace B3N\AzureStorage\TYPO3\EventListener;

use B3N\AzureStorage\TYPO3\Driver\StorageDriver;
use B3N\AzureStorage\TYPO3\Index\Extractor;
use TYPO3\CMS\Core\Resource\File;
use TYPO3\CMS\Core\Resource\Index\MetaDataRepository;
use TYPO3\CMS\Core\Resource\ResourceFactory;
use TYPO3\CMS\Core\Resource\ResourceStorage;
use TYPO3\CMS\Core\Utility\GeneralUtility;

class FileIndexRepository
abstract class AbstractFileIndexEventListener
{
public function recordUpdatedOrCreated($data)
protected function recordUpdatedOrCreated($data)
{
if ($data['type'] === File::FILETYPE_IMAGE) {
/* @var $storage \TYPO3\CMS\Core\Resource\ResourceStorage */
$storage = ResourceFactory::getInstance()->getStorageObject($data['storage']);
/** @var ResourceStorage $storage */
$storage = GeneralUtility::makeInstance(ResourceFactory::class)->getStorageObject((int)$data['storage']);

// only process our driver
if ($storage->getDriverType() !== StorageDriver::class) {
Expand All @@ -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);
}
}
}
}
}
}
15 changes: 15 additions & 0 deletions Classes/EventListener/AfterFileAddedToIndex.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
<?php

declare(strict_types=1);

namespace B3N\AzureStorage\TYPO3\EventListener;

use TYPO3\CMS\Core\Resource\Event\AfterFileAddedToIndexEvent;

class AfterFileAddedToIndex extends AbstractFileIndexEventListener
{
public function __invoke(AfterFileAddedToIndexEvent $event): void
{
$this->recordUpdatedOrCreated($event->getRecord());
}
}
15 changes: 15 additions & 0 deletions Classes/EventListener/AfterFileUpdatedInIndex.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
<?php

declare(strict_types=1);

namespace B3N\AzureStorage\TYPO3\EventListener;

use TYPO3\CMS\Core\Resource\Event\AfterFileUpdatedInIndexEvent;

class AfterFileUpdatedInIndex extends AbstractFileIndexEventListener
{
public function __invoke(AfterFileUpdatedInIndexEvent $event): void
{
$this->recordUpdatedOrCreated($event->getRelevantProperties());
}
}
18 changes: 18 additions & 0 deletions Configuration/Services.yaml
Original file line number Diff line number Diff line change
@@ -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'
5 changes: 0 additions & 5 deletions ext_localconf.php
Original file line number Diff line number Diff line change
Expand Up @@ -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');

0 comments on commit 6df32d4

Please sign in to comment.