Commit ff0a1e84 authored by Fabian Galinski's avatar Fabian Galinski 😾
Browse files

[TASK] Refactoring of the addFileResourceAttachment function

parent ec43cbcb
...@@ -35,8 +35,6 @@ use Swift_Attachment; ...@@ -35,8 +35,6 @@ use Swift_Attachment;
use Swift_OutputByteStream; use Swift_OutputByteStream;
use TYPO3\CMS\Core\Database\ConnectionPool; use TYPO3\CMS\Core\Database\ConnectionPool;
use TYPO3\CMS\Core\Mail\MailMessage; use TYPO3\CMS\Core\Mail\MailMessage;
use TYPO3\CMS\Core\Resource\FileInterface;
use TYPO3\CMS\Core\Resource\ResourceFactory;
use TYPO3\CMS\Core\Utility\GeneralUtility; use TYPO3\CMS\Core\Utility\GeneralUtility;
use TYPO3\CMS\Extbase\Domain\Model\FileReference; use TYPO3\CMS\Extbase\Domain\Model\FileReference;
use TYPO3\CMS\Extbase\Object\ObjectManager; use TYPO3\CMS\Extbase\Object\ObjectManager;
...@@ -398,30 +396,24 @@ class MailTemplateService { ...@@ -398,30 +396,24 @@ class MailTemplateService {
} }
/** /**
* Add a file resource as attachment * Adds a file resource as attachment
*
* @param FileReference $file
* *
* @param FileInterface|FileReference $file
* @return MailTemplateService * @return MailTemplateService
* @throws \TYPO3\CMS\Core\Resource\Exception\ResourceDoesNotExistException * @throws \TYPO3\CMS\Core\Resource\Exception\ResourceDoesNotExistException
*/ */
public function addFileResourceAttachment($file): MailTemplateService { public function addFileResourceAttachment(FileReference $file): MailTemplateService {
if ($file instanceof FileReference) { $originalResource = $file->getOriginalResource();
$file = $file->getOriginalResource()->getOriginalFile(); if (!$originalResource) {
} return $this;
$fileReference = $this->objectManager->get(FileReference::class); }
$resourceFactory = $this->objectManager->get(ResourceFactory::class);
$falFileReference = $resourceFactory->createFileReferenceObject( $this->markers[] = $file;
[
'uid_local' => $file->getUid(),
'uid_foreign' => uniqid('NEW_', TRUE),
'uid' => uniqid('NEW_', TRUE),
'crop' => NULL,
]
);
$fileReference->setOriginalResource($falFileReference);
$this->markers[] = $fileReference;
/** @noinspection PhpParamsInspection */ /** @noinspection PhpParamsInspection */
$this->addAttachment($file->getContents(), $file->getName(), $file->getMimeType()); $this->addAttachment(
$originalResource->getContents(), $originalResource->getName(), $originalResource->getMimeType()
);
return $this; return $this;
} }
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment