From 15e899cad26a2df606b5af0bff2cf8764146a5ab Mon Sep 17 00:00:00 2001 From: Torben Freudewald Date: Tue, 18 Jun 2024 15:50:13 +0200 Subject: [PATCH 1/2] [TASK] Add export query event An event for manipulating the export query is added equivalently to the already existing event for the check query --- Classes/Controller/XlsExportController.php | 5 ++ .../Event/AlternateExportQueryEvent.php | 65 +++++++++++++++++++ 2 files changed, 70 insertions(+) create mode 100644 Classes/Export/Event/AlternateExportQueryEvent.php diff --git a/Classes/Controller/XlsExportController.php b/Classes/Controller/XlsExportController.php index 96a23bc..4e67514 100644 --- a/Classes/Controller/XlsExportController.php +++ b/Classes/Controller/XlsExportController.php @@ -11,6 +11,7 @@ namespace Calien\Xlsexport\Controller; use Calien\Xlsexport\Export\Event\AlternateCheckQueryEvent; +use Calien\Xlsexport\Export\Event\AlternateExportQueryEvent; use Calien\Xlsexport\Traits\ExportWithTsSettingsTrait; use Doctrine\DBAL\DBALException; use Doctrine\DBAL\Driver\Exception; @@ -89,6 +90,10 @@ public function exportAction(int $id, string $config): ResponseInterface $settings = $this->selfSettings['exports.'][$config . '.']; + $event = $this->eventDispatcher->dispatch(new AlternateExportQueryEvent($settings, $config)); + + $settings = $event->getManipulatedSettings(); + $file = $this->doExport($settings, $this->pageId); //ins Archiv verschieben diff --git a/Classes/Export/Event/AlternateExportQueryEvent.php b/Classes/Export/Event/AlternateExportQueryEvent.php new file mode 100644 index 0000000..ea93f99 --- /dev/null +++ b/Classes/Export/Event/AlternateExportQueryEvent.php @@ -0,0 +1,65 @@ +exportKey = $config; + $this->exportConfiguration = $settings; + } + + /** + * checkExportConfigExists + * + * Event listener should call this method to check if access is needed + * + * @param string $exportKey + * @return bool + */ + public function checkExportConfigExists(string $exportKey): bool + { + return $exportKey === $this->exportKey; + } + + public function alternateExportQuery(string $export) + { + if ($this->exportConfiguration['export'] && !$this->exportConfiguration['manipulated']) { + $this->exportConfiguration['export'] = $export; + $this->exportConfiguration['manipulated'] = true; + } + } + + public function isPropagationStopped(): bool + { + $allManipulated = true; + if (!array_key_exists('manipulated', $this->exportConfiguration) || !$this->exportConfiguration['manipulated']) { + $allManipulated = false; + } + return $allManipulated; + } + + public function getManipulatedSettings(): array + { + return $this->exportConfiguration; + } +} From c8ef7bd4c7c2bd602e6fb743ab46dc284f5d7802 Mon Sep 17 00:00:00 2001 From: Torben Freudewald Date: Mon, 24 Jun 2024 09:44:24 +0200 Subject: [PATCH 2/2] [TASK] Adjust functions for phpstan --- Classes/Export/Event/AlternateExportQueryEvent.php | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/Classes/Export/Event/AlternateExportQueryEvent.php b/Classes/Export/Event/AlternateExportQueryEvent.php index ea93f99..b3c37e9 100644 --- a/Classes/Export/Event/AlternateExportQueryEvent.php +++ b/Classes/Export/Event/AlternateExportQueryEvent.php @@ -8,13 +8,10 @@ final class AlternateExportQueryEvent implements StoppableEventInterface { - /** - * @var string - */ protected string $exportKey = ''; /** - * @var array + * @var array */ protected array $exportConfiguration = []; @@ -41,7 +38,7 @@ public function checkExportConfigExists(string $exportKey): bool return $exportKey === $this->exportKey; } - public function alternateExportQuery(string $export) + public function alternateExportQuery(string $export): void { if ($this->exportConfiguration['export'] && !$this->exportConfiguration['manipulated']) { $this->exportConfiguration['export'] = $export;