From 4427b3c92b17214b4872bfe8a22efdea77527a97 Mon Sep 17 00:00:00 2001 From: Markus Friedrich Date: Fri, 17 May 2024 15:38:38 +0200 Subject: [PATCH] [BUGFIX] Fix synonym and stop word upload Fixes the upload of synonym and stop word lists. Resolves: #4011 --- .../CoreOptimizationModuleController.php | 24 +++++++++++++++++-- Classes/Utility/ManagedResourcesUtility.php | 12 ++++------ 2 files changed, 27 insertions(+), 9 deletions(-) diff --git a/Classes/Controller/Backend/Search/CoreOptimizationModuleController.php b/Classes/Controller/Backend/Search/CoreOptimizationModuleController.php index 7279fc483a..f67dc6e4c4 100644 --- a/Classes/Controller/Backend/Search/CoreOptimizationModuleController.php +++ b/Classes/Controller/Backend/Search/CoreOptimizationModuleController.php @@ -19,6 +19,7 @@ use ApacheSolrForTypo3\Solr\Utility\ManagedResourcesUtility; use Psr\Http\Message\ResponseInterface; use TYPO3\CMS\Core\Http\RedirectResponse; +use TYPO3\CMS\Core\Http\UploadedFile; use TYPO3\CMS\Core\Type\ContextualFeedbackSeverity; use TYPO3\CMS\Core\Utility\GeneralUtility; use TYPO3Fluid\Fluid\View\ViewInterface; @@ -136,10 +137,19 @@ public function exportSynonymsAction(string $fileFormat = 'txt'): ResponseInterf * @noinspection PhpUnused */ public function importSynonymListAction( - array $synonymFileUpload, bool $overrideExisting = false, bool $deleteSynonymsBefore = false ): ResponseInterface { + $synonymFileUpload = $this->request->getUploadedFiles()['synonymFileUpload'] ?? null; + if (!$synonymFileUpload instanceof UploadedFile) { + $this->addFlashMessage( + 'Synonyms upload not found.', + '', + ContextualFeedbackSeverity::ERROR + ); + return new RedirectResponse($this->uriBuilder->uriFor('index'), 303); + } + if ($deleteSynonymsBefore) { $this->deleteAllSynonyms(); } @@ -167,8 +177,18 @@ public function importSynonymListAction( /** * @noinspection PhpUnused */ - public function importStopWordListAction(array $stopwordsFileUpload, bool $replaceStopwords): ResponseInterface + public function importStopWordListAction(bool $replaceStopwords): ResponseInterface { + $stopwordsFileUpload = $this->request->getUploadedFiles()['stopwordsFileUpload'] ?? null; + if (!$stopwordsFileUpload instanceof UploadedFile) { + $this->addFlashMessage( + 'Stop Word upload not found.', + '', + ContextualFeedbackSeverity::ERROR + ); + return new RedirectResponse($this->uriBuilder->uriFor('index'), 303); + } + $this->saveStopWordsAction( ManagedResourcesUtility::importStopwordsFromPlainTextContents($stopwordsFileUpload), $replaceStopwords diff --git a/Classes/Utility/ManagedResourcesUtility.php b/Classes/Utility/ManagedResourcesUtility.php index 1e8ecf95c5..4cb1d90392 100644 --- a/Classes/Utility/ManagedResourcesUtility.php +++ b/Classes/Utility/ManagedResourcesUtility.php @@ -18,7 +18,7 @@ namespace ApacheSolrForTypo3\Solr\Utility; use ApacheSolrForTypo3\Solr\Exception\InvalidArgumentException; -use TYPO3\CMS\Core\Http\Stream; +use TYPO3\CMS\Core\Http\UploadedFile; use TYPO3\CMS\Core\Utility\GeneralUtility; /** @@ -45,10 +45,9 @@ public static function exportSynonymsToTxt(array $synonyms): string /** * Read plain text synonym file and import these synonyms */ - public static function importSynonymsFromPlainTextContents(array $synonymFileUpload): array + public static function importSynonymsFromPlainTextContents(UploadedFile $synonymFileUpload): array { - $fileStream = new Stream($synonymFileUpload['tmp_name']); - + $fileStream = $synonymFileUpload->getStream(); $fileLines = GeneralUtility::trimExplode(PHP_EOL, $fileStream->getContents(), true); $synonymList = []; @@ -62,10 +61,9 @@ public static function importSynonymsFromPlainTextContents(array $synonymFileUpl /** * Read plain text stopword file */ - public static function importStopwordsFromPlainTextContents(array $stopwordsFileUpload): string + public static function importStopwordsFromPlainTextContents(UploadedFile $stopwordsFileUpload): string { - $fileStream = new Stream($stopwordsFileUpload['tmp_name']); - + $fileStream = $stopwordsFileUpload->getStream(); return $fileStream->getContents(); }