Skip to content

Commit

Permalink
[BUGFIX] Fix synonym and stop word upload
Browse files Browse the repository at this point in the history
Fixes the upload of synonym and stop word lists.

Resolves: #4011
  • Loading branch information
dkd-friedrich committed May 17, 2024
1 parent 40c0ecf commit 4427b3c
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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();
}
Expand Down Expand Up @@ -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
Expand Down
12 changes: 5 additions & 7 deletions Classes/Utility/ManagedResourcesUtility.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;

/**
Expand All @@ -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 = [];
Expand All @@ -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();
}

Expand Down

0 comments on commit 4427b3c

Please sign in to comment.