diff --git a/core/lib/Thelia/Action/Document.php b/core/lib/Thelia/Action/Document.php index 2a630be2f..228dea9f5 100644 --- a/core/lib/Thelia/Action/Document.php +++ b/core/lib/Thelia/Action/Document.php @@ -93,45 +93,48 @@ class Document extends BaseCachedFile implements EventSubscriberInterface * * This method updates the cache_file_path and file_url attributes of the event * - * @param DocumentEvent $event - * @throws \InvalidArgumentException, DocumentException + * @param DocumentEvent $event Event + * + * @throws \Thelia\Exception\DocumentException + * @throws \InvalidArgumentException , DocumentException */ public function processDocument(DocumentEvent $event) { $subdir = $event->getCacheSubdirectory(); - $source_file = $event->getSourceFilepath(); + $sourceFile = $event->getSourceFilepath(); - if (null == $subdir || null == $source_file) { + if (null == $subdir || null == $sourceFile) { throw new \InvalidArgumentException("Cache sub-directory and source file path cannot be null"); } - $originalDocumentPathInCache = $this->getCacheFilePath($subdir, $source_file, true); + $originalDocumentPathInCache = $this->getCacheFilePath($subdir, $sourceFile, true); if (! file_exists($originalDocumentPathInCache)) { - if (! file_exists($source_file)) { - throw new DocumentException(sprintf("Source document file %s does not exists.", $source_file)); + if (! file_exists($sourceFile)) { + throw new DocumentException(sprintf("Source document file %s does not exists.", $sourceFile)); } $mode = ConfigQuery::read('original_document_delivery_mode', 'symlink'); if ($mode == 'symlink') { - if (false == symlink($source_file, $originalDocumentPathInCache)) { - throw new DocumentException(sprintf("Failed to create symbolic link for %s in %s document cache directory", basename($source_file), $subdir)); + if (false == symlink($sourceFile, $originalDocumentPathInCache)) { + throw new DocumentException(sprintf("Failed to create symbolic link for %s in %s document cache directory", basename($sourceFile), $subdir)); } - } else {// mode = 'copy' - if (false == @copy($source_file, $originalDocumentPathInCache)) { - throw new DocumentException(sprintf("Failed to copy %s in %s document cache directory", basename($source_file), $subdir)); + } else { + // mode = 'copy' + if (false == @copy($sourceFile, $originalDocumentPathInCache)) { + throw new DocumentException(sprintf("Failed to copy %s in %s document cache directory", basename($sourceFile), $subdir)); } } } // Compute the document URL - $document_url = $this->getCacheFileURL($subdir, basename($originalDocumentPathInCache)); + $documentUrl = $this->getCacheFileURL($subdir, basename($originalDocumentPathInCache)); // Update the event with file path and file URL - $event->setDocumentPath($originalDocumentPathInCache); - $event->setDocumentUrl(URL::getInstance()->absoluteUrl($document_url, null, URL::PATH_TO_FILE)); + $event->setDocumentPath($documentUrl); + $event->setDocumentUrl(URL::getInstance()->absoluteUrl($documentUrl, null, URL::PATH_TO_FILE)); } /** @@ -173,7 +176,7 @@ class Document extends BaseCachedFile implements EventSubscriberInterface ); } - $newUploadedFile = $fileManager->copyUploadedFile($event->getParentId(), $event->getDocumentType(), $event->getModelDocument(), $event->getUploadedFile()); + $newUploadedFile = $fileManager->copyUploadedFile($event->getParentId(), $event->getDocumentType(), $event->getModelDocument(), $event->getUploadedFile(), FileManager::FILE_TYPE_DOCUMENTS); $event->setUploadedFile($newUploadedFile); } @@ -206,10 +209,7 @@ class Document extends BaseCachedFile implements EventSubscriberInterface $url = $fileManager->getUploadDir($event->getDocumentType(), FileManager::FILE_TYPE_DOCUMENTS) . '/' . $event->getOldModelDocument()->getFile(); unlink(str_replace('..', '', $url)); - $newUploadedFile = $fileManager->copyUploadedFile( - $event->getModelDocument()->getParentId(), - $event->getDocumentType(), - $event->getModelDocument(), $event->getUploadedFile()); + $newUploadedFile = $fileManager->copyUploadedFile($event->getParentId(), $event->getDocumentType(), $event->getModelDocument(), $event->getUploadedFile(), FileManager::FILE_TYPE_DOCUMENTS); $event->setUploadedFile($newUploadedFile); } diff --git a/core/lib/Thelia/Action/Image.php b/core/lib/Thelia/Action/Image.php index da501eef1..9de87182b 100755 --- a/core/lib/Thelia/Action/Image.php +++ b/core/lib/Thelia/Action/Image.php @@ -291,7 +291,7 @@ class Image extends BaseCachedFile implements EventSubscriberInterface ); } - $newUploadedFile = $fileManager->copyUploadedFile($event->getParentId(), $event->getImageType(), $event->getModelImage(), $event->getUploadedFile()); + $newUploadedFile = $fileManager->copyUploadedFile($event->getParentId(), $event->getImageType(), $event->getModelImage(), $event->getUploadedFile(), FileManager::FILE_TYPE_IMAGES); $event->setUploadedFile($newUploadedFile); } @@ -321,13 +321,10 @@ class Image extends BaseCachedFile implements EventSubscriberInterface // Copy and save file if ($event->getUploadedFile()) { // Remove old picture file from file storage - $url = $fileManager->getUploadDir($event->getImageType()) . '/' . $event->getOldModelImage()->getFile(); + $url = $fileManager->getUploadDir($event->getImageType(), FileManager::FILE_TYPE_IMAGES) . '/' . $event->getOldModelImage()->getFile(); unlink(str_replace('..', '', $url)); - $newUploadedFile = $fileManager->copyUploadedFile( - $event->getModelImage()->getParentId(), - $event->getImageType(), - $event->getModelImage(), $event->getUploadedFile()); + $newUploadedFile = $fileManager->copyUploadedFile($event->getParentId(), $event->getImageType(), $event->getModelImage(), $event->getUploadedFile(), FileManager::FILE_TYPE_IMAGES); $event->setUploadedFile($newUploadedFile); } diff --git a/core/lib/Thelia/Config/Resources/config.xml b/core/lib/Thelia/Config/Resources/config.xml index e1f3f9920..2f06e9606 100755 --- a/core/lib/Thelia/Config/Resources/config.xml +++ b/core/lib/Thelia/Config/Resources/config.xml @@ -60,25 +60,25 @@
- + - + - + - + diff --git a/core/lib/Thelia/Config/Resources/routing/admin.xml b/core/lib/Thelia/Config/Resources/routing/admin.xml index ed8f21214..2fd666896 100755 --- a/core/lib/Thelia/Config/Resources/routing/admin.xml +++ b/core/lib/Thelia/Config/Resources/routing/admin.xml @@ -56,16 +56,18 @@{$TITLE} +