Commit a1b6c704 authored by Markus Guenther's avatar Markus Guenther
Browse files

[FEATURE] Use objectManager as class variable and don´t init this multiple times

parent d3e3307f
......@@ -113,30 +113,38 @@ class MailTemplateService {
/**
* @var \SGalinski\SgMail\Domain\Repository\TemplateRepository
* @inject
*/
protected $templateRepository;
/**
* @var \TYPO3\CMS\Extbase\Persistence\Generic\PersistenceManager
* @inject
*/
protected $persistenceManager;
/**
* @var \TYPO3\CMS\Extbase\Object\ObjectManager
*/
protected $objectManager;
/**
* MailTemplateService constructor.
*/
public function __construct() {
$objectManager = GeneralUtility::makeInstance(ObjectManager::class);
$this->mailMessage = $objectManager->get(MailMessage::class);
$typoScriptSettingsService = $objectManager->get(TypoScriptSettingsService::class);
/** @var ObjectManager objectManager */
$this->objectManager = GeneralUtility::makeInstance(ObjectManager::class);
/** @var MailMessage mailMessage */
$this->mailMessage = $this->objectManager->get(MailMessage::class);
/** @var TypoScriptSettingsService $typoScriptSettingsService */
$typoScriptSettingsService = $this->objectManager->get(TypoScriptSettingsService::class);
$this->tsSettings = $typoScriptSettingsService->getSettings(0, 'tx_sgmail');
$this->language = $this->tsSettings['templateDefaultLanguage'];
/** @var TemplateRepository templateRepository */
$this->templateRepository = $this->objectManager->get(TemplateRepository::class);
/** @var PersistenceManager persistenceManager */
$this->persistenceManager = $this->objectManager->get(PersistenceManager::class);
$this->fromAddress = $this->tsSettings['mail']['default']['from'];
$this->mailMessage->setFrom($this->fromAddress);
$this->bccAddresses = GeneralUtility::trimExplode(',', $this->tsSettings['mail']['default']['bcc']);
$this->ccAddresses = GeneralUtility::trimExplode(',', $this->tsSettings['mail']['default']['cc']);
......@@ -229,9 +237,8 @@ class MailTemplateService {
$this->setMarkers($previewMarker);
}
$objectManager = GeneralUtility::makeInstance(ObjectManager::class);
/** @var StandaloneView $emailView */
$emailView = $objectManager->get(StandaloneView::class);
$emailView = $this->objectManager->get(StandaloneView::class);
if (!isset($defaultTemplateContent)) {
$emailView->setTemplateSource($template->getContent());
......@@ -269,10 +276,7 @@ class MailTemplateService {
* @param bool $sent
*/
private function addMailToMailQueue($subject, $emailBody, $priority, $sent = FALSE) {
/** @var ObjectManager $objectManager */
$objectManager = GeneralUtility::makeInstance(ObjectManager::class);
$mail = $objectManager->get(Mail::class);
$mail = $this->objectManager->get(Mail::class);
$mail->setFromAddress($this->fromAddress);
$mail->setToAddress($this->toAddresses);
$mail->setMailSubject($subject);
......@@ -282,7 +286,7 @@ class MailTemplateService {
$mail->setCcAddresses(implode(',', $this->ccAddresses));
$mail->setSent($sent);
$mailRepository = $objectManager->get(MailRepository::class);
$mailRepository = $this->objectManager->get(MailRepository::class);
$mailRepository->add($mail);
$this->persistenceManager->persistAll();
}
......
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