From e490feae936f3ebd757d4828766fa24a0aa2aedc Mon Sep 17 00:00:00 2001 From: Dirk Date: Tue, 18 Aug 2020 14:27:44 +0200 Subject: [PATCH 1/2] Fix filename handling --- .../Service/DestinationDataImportService.php | 27 ++++++++++++++----- 1 file changed, 20 insertions(+), 7 deletions(-) diff --git a/Classes/Service/DestinationDataImportService.php b/Classes/Service/DestinationDataImportService.php index 136dae3..0ccb274 100644 --- a/Classes/Service/DestinationDataImportService.php +++ b/Classes/Service/DestinationDataImportService.php @@ -87,9 +87,9 @@ class DestinationDataImportService { */ protected $environment; /** - * @var bool + * @var */ - protected $tmpCurrentEvent = FALSE; + protected $tmpCurrentEvent; /** * @var */ @@ -545,21 +545,34 @@ class DestinationDataImportService { $this->storage = $this->resourceFactory->getDefaultStorage(); + $orgFileUrl = urldecode($media_object['url']); + $orgFileNameSanitized = $this->storage->sanitizeFileName( + strtolower( + basename( + urldecode($media_object['url']) + ) + ) + ); + + $this->logger->info('File attached:' . $orgFileUrl); + $this->logger->info('File attached sanitized:' . $orgFileNameSanitized); + //die(); + if ($this->storage == null) { $this->logger->error('No default storage defined. Cancel import.'); die(); } // Check if file already exists - if (file_exists($this->environment->getPublicPath() . '/fileadmin/' . $this->filesFolder . strtolower(basename($media_object['url'])))) { + if (file_exists($this->environment->getPublicPath() . '/fileadmin/' . $this->filesFolder . $orgFileNameSanitized)) { $this->logger->info('File already exists'); } else { - $this->logger->info("File don't exist"); + $this->logger->info("File don't exist " . $orgFileNameSanitized); // Load the file - if ($file = $this->loadFile($media_object['url'])) { + if ($file = $this->loadFile($orgFileUrl)) { // Move file to defined folder $this->logger->info('Adding file ' . $file); - $this->storage->addFile($this->environment->getPublicPath() . "/uploads/tx_events/" . $file, $this->storage->getFolder($this->filesFolder), basename($media_object['url'])); + $this->storage->addFile($this->environment->getPublicPath() . "/uploads/tx_events/" . $file, $this->storage->getFolder($this->filesFolder)); } else { $error = true; } @@ -571,7 +584,7 @@ class DestinationDataImportService { // TODO: How to delete file references? } else { $this->logger->info('No relation found'); - $file = $this->storage->getFile($this->filesFolder . basename($media_object['url'])); + $file = $this->storage->getFile($this->filesFolder . $orgFileNameSanitized); $this->metaDataRepository->update($file->getUid(), array('title' => $media_object['value'], 'description' => $media_object['description'], 'alternative' => 'DD Import')); $this->createFileRelations($file->getUid(), 'tx_events_domain_model_event', $this->tmpCurrentEvent->getUid(), 'images', $this->storagePid); } From fbf9d559855158b588df09aba63f74b6de0bbe09 Mon Sep 17 00:00:00 2001 From: Dirk Date: Tue, 18 Aug 2020 15:22:34 +0200 Subject: [PATCH 2/2] Remove strtolower --- Classes/Service/DestinationDataImportService.php | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/Classes/Service/DestinationDataImportService.php b/Classes/Service/DestinationDataImportService.php index 0ccb274..46d481d 100644 --- a/Classes/Service/DestinationDataImportService.php +++ b/Classes/Service/DestinationDataImportService.php @@ -547,10 +547,8 @@ class DestinationDataImportService { $orgFileUrl = urldecode($media_object['url']); $orgFileNameSanitized = $this->storage->sanitizeFileName( - strtolower( - basename( - urldecode($media_object['url']) - ) + basename( + urldecode($media_object['url']) ) );