Skip to content

Commit

Permalink
Merge pull request #222 from clickstorm/master
Browse files Browse the repository at this point in the history
[TASK] replace solrfal signal/slot with event listener
  • Loading branch information
support-beech authored Oct 9, 2023
2 parents dd67563 + 9cb4162 commit 7f402e1
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 26 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -8,17 +8,17 @@
* All code (c) Beech Applications B.V. all rights reserved
*/

namespace BeechIt\FalSecuredownload\Aspects;
namespace BeechIt\FalSecuredownload\EventListener;

use ApacheSolrForTypo3\Solrfal\Queue\Item;
use ArrayObject;
use ApacheSolrForTypo3\Solrfal\Event\Indexing\AfterFileMetaDataHasBeenRetrievedEvent;
use BeechIt\FalSecuredownload\Aspects\PublicUrlAspect;
use BeechIt\FalSecuredownload\Security\CheckPermissions;
use TYPO3\CMS\Core\Resource\File;
use TYPO3\CMS\Core\SingletonInterface;
use TYPO3\CMS\Core\Utility\ArrayUtility;
use TYPO3\CMS\Core\Utility\GeneralUtility;

class SolrFalAspect implements SingletonInterface
class AfterFileMetaDataHasBeenRetrievedEventListener implements SingletonInterface
{
protected CheckPermissions $checkPermissionsService;
protected PublicUrlAspect $publicUrlAspect;
Expand All @@ -31,12 +31,12 @@ public function __construct()

/**
* Add correct fe_group info and public_url
*
* @param Item $item
* @param ArrayObject $metadata
*/
public function fileMetaDataRetrieved(Item $item, ArrayObject $metadata): void
public function __invoke(AfterFileMetaDataHasBeenRetrievedEvent $event)
{
$item = $event->getFileIndexQueueItem();
$metadata = $event->getMetaData();

if ($item->getFile() instanceof File && !$item->getFile()->getStorage()->isPublic()) {
$resourcePermissions = $this->checkPermissionsService->getPermissions($item->getFile());
// If there are already permissions set, refine these with actual file permissions
Expand All @@ -54,5 +54,7 @@ public function fileMetaDataRetrieved(Item $item, ArrayObject $metadata): void
$this->publicUrlAspect->setEnabled(false);
$metadata['public_url'] = $item->getFile()->getPublicUrl();
$this->publicUrlAspect->setEnabled(true);

$event->overrideMetaData($metadata);
}
}
5 changes: 5 additions & 0 deletions Configuration/Services.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -69,3 +69,8 @@ services:
tags:
- name: event.listener
event: TYPO3\CMS\Core\Resource\Event\GeneratePublicUrlForResourceEvent

BeechIt\FalSecuredownload\EventListener\AfterFileMetaDataHasBeenRetrievedEventListener:
tags:
- name: event.listener
event: ApacheSolrForTypo3\Solrfal\Event\Indexing\AfterFileMetaDataHasBeenRetrievedEvent
18 changes: 0 additions & 18 deletions ext_localconf.php
Original file line number Diff line number Diff line change
Expand Up @@ -56,24 +56,6 @@
$GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['ke_search']['modifyFileIndexEntryFromContentIndexer'][] = KeSearchFilesHook::class;
$GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['ke_search']['modifyFileIndexEntry'][] = KeSearchFilesHook::class;

if (ExtensionManagementUtility::isLoaded('solrfal')) {
// TODO Must be made compatible to TYPO3 v12 as there is no TYPO3\CMS\Extbase\SignalSlot\Dispatcher anymore
// https://docs.typo3.org/c/typo3/cms-core/main/en-us/Changelog/10.4/Deprecation-90625-ExtbaseSignalSlotDispatcher.html
// TODO to do this the EventDispatcher implementation of EXT:solrfal must be known
// https://docs.typo3.org/m/typo3/reference-coreapi/main/en-us/ApiOverview/Events/EventDispatcher/Index.html#eventdispatcher
/** @var Dispatcher $signalSlotDispatcher */
$signalSlotDispatcher = GeneralUtility::makeInstance(Dispatcher::class);

// @Todo convert this to event listener
// ext:solrfal enrich metadata and generate correct public url slot
$signalSlotDispatcher->connect(
DocumentFactory::class,
'fileMetaDataRetrieved',
SolrFalAspect::class,
'fileMetaDataRetrieved'
);
}

if (ExtensionConfiguration::trackDownloads()) {
// register FormEngine node for rendering download statistics in fe_users
$GLOBALS['TYPO3_CONF_VARS']['SYS']['formEngine']['nodeRegistry'][1470920616] = [
Expand Down

0 comments on commit 7f402e1

Please sign in to comment.