Commit 251d7f63 authored by Kevin Ditscheid's avatar Kevin Ditscheid
Browse files

[TASK] Do version switches for ObjectManager initializations

parent b753ba16
......@@ -32,14 +32,12 @@ use SGalinski\SgMail\Service\PlaintextService;
use Symfony\Component\Console\Input\InputArgument;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Output\OutputInterface;
use Symfony\Component\Mime\Part\TextPart;
use TYPO3\CMS\Core\Mail\MailMessage;
use TYPO3\CMS\Core\Resource\FileInterface;
use TYPO3\CMS\Core\Utility\GeneralUtility;
use Symfony\Component\Console\Command\Command;
use TYPO3\CMS\Core\Utility\VersionNumberUtility;
use TYPO3\CMS\Extbase\Object\ObjectManager;
use TYPO3\CMS\Extbase\Persistence\Generic\PersistenceManager;
/**
* Command controller for the mailing feature
......@@ -65,10 +63,15 @@ class SendMailCommandController extends Command {
*/
public function execute(InputInterface $input, OutputInterface $output) {
$sendCount = $input->getArgument('sendCount');
$objectManager = GeneralUtility::makeInstance(ObjectManager::class);
$mailRepository = $objectManager->get(MailRepository::class);
$mailsToSend = $mailRepository->findMailsToSend($sendCount);
if (version_compare(VersionNumberUtility::getCurrentTypo3Version(), '10.4.0', '<')) {
$objectManager = GeneralUtility::makeInstance(ObjectManager::class);
/** @var MailRepository $mailRepository */
$mailRepository = $objectManager->get(MailRepository::class);
} else {
$mailRepository = GeneralUtility::makeInstance(MailRepository::class);
}
$mailsToSend = $mailRepository->findMailsToSend($sendCount);
foreach ($mailsToSend as $mailToSend) {
/** @var Mail $mailToSend */
$fromAddress = $mailToSend->getFromAddress();
......@@ -107,17 +110,16 @@ class SendMailCommandController extends Command {
$mailMessage->setReplyTo($replyTo);
}
$plaintextService = GeneralUtility::makeInstance(PlaintextService::class);
$plaintextBody = $plaintextService->makePlain($mailBody);
if (version_compare(VersionNumberUtility::getCurrentTypo3Version(), '10.4.0', '<')) {
$mailMessage->setBody($mailBody, 'text/html');
$mailMessage->addPart($plaintextBody, 'text/plain');
} else {
$part = new TextPart($mailBody);
$mailMessage->setBody($part);
$mailMessage->html($mailBody);
$mailMessage->text($plaintextBody);
}
$plaintextService = GeneralUtility::makeInstance(PlaintextService::class);
$plaintextBody = $plaintextService->makePlain($mailBody);
$mailMessage->addPart($plaintextBody, 'text/plain');
$attachments = $mailToSend->getAttachments();
if ($attachments->count() > 0) {
foreach ($attachments as $attachment) {
......@@ -141,12 +143,12 @@ class SendMailCommandController extends Command {
} else {
$mailMessage->attach($file->getContents(), $file->getName(), $file->getMimeType());
}
} catch (\Exception $exception) {
continue;
}
}
}
try {
$mailMessage->send();
} catch (\Exception $exception) {
......@@ -155,7 +157,7 @@ class SendMailCommandController extends Command {
}
// Important for command controllers that change data
$objectManager->get(PersistenceManager::class)->persistAll();
$mailRepository->persist();
return 0;
}
}
......@@ -33,6 +33,7 @@ use TYPO3\CMS\Backend\Template\Components\DocHeaderComponent;
use TYPO3\CMS\Backend\Utility\BackendUtility;
use TYPO3\CMS\Core\Messaging\FlashMessage;
use TYPO3\CMS\Core\Utility\GeneralUtility;
use TYPO3\CMS\Core\Utility\VersionNumberUtility;
use TYPO3\CMS\Extbase\Mvc\Controller\ActionController;
use TYPO3\CMS\Extbase\Mvc\Exception\StopActionException;
use TYPO3\CMS\Extbase\Mvc\Exception\UnsupportedRequestTypeException;
......@@ -179,24 +180,33 @@ class ConfigurationController extends ActionController {
'markerLabel' => $markerLabel
];
}
if (version_compare(VersionNumberUtility::getCurrentTypo3Version(), '10.4.0', '<')) {
/** @var RegisterService $registerService */
$registerService = $this->objectManager->get(RegisterService::class);
} else {
$registerService = GeneralUtility::makeInstance(RegisterService::class);
}
$registerService = $this->objectManager->get(RegisterService::class);
$registerService->writeRegisterFile(
$templateName, $extensionKey, $markers, $subject, $description
);
$registerService->clearCaches();
// store selected template & extension key in the session
if (!($this->session instanceof PhpSession)) {
$this->session = $this->objectManager->get(PhpSession::class);
if (version_compare(VersionNumberUtility::getCurrentTypo3Version(), '10.4.0', '<')) {
/** @var PhpSession session */
$this->session = $this->objectManager->get(PhpSession::class);
} else {
$this->session = GeneralUtility::makeInstance(PhpSession::class);
}
$this->session->setSessionKey('sg_mail_controller_session');
} else {
$this->session->setSessionKey('sg_mail_controller_session');
}
$this->session->setDataByKey('selectedTemplate', $templateName);
$this->session->setDataByKey('selectedExtension', self::DEFAULT_EXTENSION_KEY);
$this->redirect(
'index', 'Mail', NULL,
['message' => LocalizationUtility::translate('backend.create_message', 'sg_mail')]
......@@ -249,7 +259,13 @@ class ConfigurationController extends ActionController {
];
}
$registerService = $this->objectManager->get(RegisterService::class);
if (version_compare(VersionNumberUtility::getCurrentTypo3Version(), '10.4.0', '<')) {
/** @var RegisterService $registerService */
$registerService = $this->objectManager->get(RegisterService::class);
} else {
$registerService = GeneralUtility::makeInstance(RegisterService::class);
}
$registerService->migrateTemplateEntries($oldTemplateName, $oldExtensionKey, $templateName, $extensionKey);
$registerService->deleteRegisterFile($oldTemplateName);
$registerService->writeRegisterFile(
......@@ -260,7 +276,13 @@ class ConfigurationController extends ActionController {
// store selected template & extension key in the session
if (!($this->session instanceof PhpSession)) {
$this->session = $this->objectManager->get(PhpSession::class);
if (version_compare(VersionNumberUtility::getCurrentTypo3Version(), '10.4.0', '<')) {
/** @var PhpSession session */
$this->session = $this->objectManager->get(PhpSession::class);
} else {
$this->session = GeneralUtility::makeInstance(PhpSession::class);
}
$this->session->setSessionKey('sg_mail_controller_session');
} else {
$this->session->setSessionKey('sg_mail_controller_session');
......@@ -284,7 +306,13 @@ class ConfigurationController extends ActionController {
* @throws \TYPO3\CMS\Core\Cache\Exception\NoSuchCacheException
*/
public function deleteAction(string $selectedTemplate, string $selectedExtension) {
$registerService = $this->objectManager->get(RegisterService::class);
if (version_compare(VersionNumberUtility::getCurrentTypo3Version(), '10.4.0', '<')) {
/** @var RegisterService $registerService */
$registerService = $this->objectManager->get(RegisterService::class);
} else {
$registerService = GeneralUtility::makeInstance(RegisterService::class);
}
$registerService->deleteTemplate($selectedExtension, $selectedTemplate);
$this->redirect(
'index', 'Mail', NULL,
......
......@@ -33,6 +33,7 @@ use TYPO3\CMS\Backend\Clipboard\Clipboard;
use TYPO3\CMS\Backend\Template\Components\DocHeaderComponent;
use TYPO3\CMS\Backend\Utility\BackendUtility;
use TYPO3\CMS\Core\Utility\GeneralUtility;
use TYPO3\CMS\Core\Utility\VersionNumberUtility;
use TYPO3\CMS\Extbase\Mvc\Controller\ActionController;
use TYPO3\CMS\Extbase\Mvc\Exception\NoSuchArgumentException;
use TYPO3\CMS\Extbase\Mvc\View\ViewInterface;
......@@ -113,7 +114,13 @@ class LayoutController extends ActionController {
$pageUid = (int) GeneralUtility::_GP('id');
if (!($this->session instanceof PhpSession)) {
$this->session = $this->objectManager->get(PhpSession::class);
if (version_compare(VersionNumberUtility::getCurrentTypo3Version(), '10.4.0', '<')) {
/** @var PhpSession session */
$this->session = $this->objectManager->get(PhpSession::class);
} else {
$this->session = GeneralUtility::makeInstance(PhpSession::class);
}
$this->session->setSessionKey('sg_mail_controller_session');
} else {
$this->session->setSessionKey('sg_mail_controller_session');
......
......@@ -37,6 +37,7 @@ use TYPO3\CMS\Backend\Template\Components\DocHeaderComponent;
use TYPO3\CMS\Backend\Utility\BackendUtility;
use TYPO3\CMS\Core\Messaging\FlashMessage;
use TYPO3\CMS\Core\Utility\GeneralUtility;
use TYPO3\CMS\Core\Utility\VersionNumberUtility;
use TYPO3\CMS\Extbase\Mvc\Controller\ActionController;
use TYPO3\CMS\Extbase\Mvc\View\ViewInterface;
use TYPO3\CMS\Extbase\Object\ObjectManager;
......@@ -114,7 +115,13 @@ class MailController extends ActionController {
$pid = (int) GeneralUtility::_GP('id');
if (!($this->session instanceof PhpSession)) {
$this->session = $this->objectManager->get(PhpSession::class);
if (version_compare(VersionNumberUtility::getCurrentTypo3Version(), '10.4.0', '<')) {
/** @var PhpSession session */
$this->session = $this->objectManager->get(PhpSession::class);
} else {
$this->session = GeneralUtility::makeInstance(PhpSession::class);
}
$this->session->setSessionKey('sg_mail_controller_session');
} else {
$this->session->setSessionKey('sg_mail_controller_session');
......@@ -220,8 +227,13 @@ class MailController extends ActionController {
$this->view->assign('languageTemplates', $templates);
$this->view->assign('languageLabels', BackendService::getLanguageLabels($languages));
$this->view->assign('templates', $registerArray);
if (version_compare(VersionNumberUtility::getCurrentTypo3Version(), '10.4.0', '<')) {
/** @var RegisterService $registerService */
$registerService = $this->objectManager->get(RegisterService::class);
} else {
$registerService = GeneralUtility::makeInstance(RegisterService::class);
}
$registerService = $this->objectManager->get(RegisterService::class);
$this->view->assign(
'isManual', $registerService->isManuallyRegisteredTemplate($parameters['selectedTemplate'])
);
......@@ -355,13 +367,19 @@ class MailController extends ActionController {
$this->redirect('index', NULL, NULL, $arguments);
}
$objectManager = GeneralUtility::makeInstance(ObjectManager::class);
/** @var \SGalinski\SgMail\Service\MailTemplateService $mailTemplateService */
$mailTemplateService = $objectManager->get(
MailTemplateService::class, $parameters['selectedTemplate'], $parameters['selectedExtension']
);
$mailIsSend = FALSE;
if (version_compare(VersionNumberUtility::getCurrentTypo3Version(), '10.4.0', '<')) {
$objectManager = GeneralUtility::makeInstance(ObjectManager::class);
/** @var \SGalinski\SgMail\Service\MailTemplateService $mailTemplateService */
$mailTemplateService = $objectManager->get(
MailTemplateService::class, $parameters['selectedTemplate'], $parameters['selectedExtension']
);
} else {
$mailTemplateService = GeneralUtility::makeInstance(
MailTemplateService::class, $parameters['selectedTemplate'], $parameters['selectedExtension']
);
}
$mailIsSend = FALSE;
foreach ((array) $parameters['templates'] as $key => $template) {
$mailTemplateService->setLanguage($key);
$mailTemplateService->setToAddresses($parameters['emailAddress']);
......
......@@ -38,6 +38,7 @@ use TYPO3\CMS\Backend\Template\Components\DocHeaderComponent;
use TYPO3\CMS\Backend\Utility\BackendUtility;
use TYPO3\CMS\Core\Messaging\FlashMessage;
use TYPO3\CMS\Core\Utility\GeneralUtility;
use TYPO3\CMS\Core\Utility\VersionNumberUtility;
use TYPO3\CMS\Extbase\Mvc\Controller\ActionController;
use TYPO3\CMS\Extbase\Mvc\View\ViewInterface;
use TYPO3\CMS\Extbase\Object\ObjectManager;
......@@ -129,7 +130,13 @@ class NewsletterController extends ActionController {
$pid = (int) GeneralUtility::_GP('id');
if (!($this->session instanceof PhpSession)) {
$this->session = $this->objectManager->get(PhpSession::class);
if (version_compare(VersionNumberUtility::getCurrentTypo3Version(), '10.4.0', '<')) {
/** @var PhpSession session */
$this->session = $this->objectManager->get(PhpSession::class);
} else {
$this->session = GeneralUtility::makeInstance(PhpSession::class);
}
$this->session->setSessionKey('sg_mail_controller_session');
} else {
$this->session->setSessionKey('sg_mail_controller_session');
......@@ -266,14 +273,17 @@ class NewsletterController extends ActionController {
$this->view->assign('languageTemplates', $templates);
$this->view->assign('languageLabels', BackendService::getLanguageLabels($languages));
$this->view->assign('templates', $registerArray);
if (version_compare(VersionNumberUtility::getCurrentTypo3Version(), '10.4.0', '<')) {
/** @var RegisterService $registerService */
$registerService = $this->objectManager->get(RegisterService::class);
} else {
$registerService = GeneralUtility::makeInstance(RegisterService::class);
}
$registerService = $this->objectManager->get(RegisterService::class);
$this->view->assign(
'isManual', $registerService->isManuallyRegisteredTemplate($parameters['selectedTemplate'])
);
$templateDescription = $registerArray[$parameters['selectedExtension']][$parameters['selectedTemplate']]['description'];
if (\is_array($templateDescription)) {
if ($languages[0]['isocode']) {
$templateDescription = $templateDescription[$languages[0]['isocode']];
......@@ -399,20 +409,25 @@ class NewsletterController extends ActionController {
}
}
$objectManager = GeneralUtility::makeInstance(ObjectManager::class);
/** @var \SGalinski\SgMail\Service\MailTemplateService $mailTemplateService */
$mailTemplateService = $objectManager->get(
MailTemplateService::class, $parameters['selectedTemplate'], $parameters['selectedExtension']
);
$mailIsSend = FALSE;
if (version_compare(VersionNumberUtility::getCurrentTypo3Version(), '10.4.0', '<')) {
$objectManager = GeneralUtility::makeInstance(ObjectManager::class);
/** @var \SGalinski\SgMail\Service\MailTemplateService $mailTemplateService */
$mailTemplateService = $objectManager->get(
MailTemplateService::class, $parameters['selectedTemplate'], $parameters['selectedExtension']
);
} else {
$mailTemplateService = GeneralUtility::makeInstance(
MailTemplateService::class, $parameters['selectedTemplate'], $parameters['selectedExtension']
);
}
$mailIsSend = FALSE;
$mailTemplateService->setTemplateName($parameters['selectedTemplate']);
$mailTemplateService->setExtensionKey($parameters['selectedExtension']);
$mailTemplateService->setFromName($parameter['fromName']);
$mailTemplateService->setFromAddress($parameter['fromMail']);
$mailTemplateService->setSubject($parameter['subject']);
$mailTemplateService->setReplyToAddress($parameter['replyTo']);
if (!$this->request->getArgument('sendRealEmails')) {
// Send test emails
$message = LocalizationUtility::translate('backend.success_mail', 'sg_mail');
......
......@@ -34,6 +34,7 @@ use TYPO3\CMS\Backend\Template\Components\DocHeaderComponent;
use TYPO3\CMS\Backend\Utility\BackendUtility;
use TYPO3\CMS\Core\Messaging\FlashMessage;
use TYPO3\CMS\Core\Utility\GeneralUtility;
use TYPO3\CMS\Core\Utility\VersionNumberUtility;
use TYPO3\CMS\Extbase\Mvc\Controller\ActionController;
use TYPO3\CMS\Extbase\Mvc\View\ViewInterface;
use TYPO3\CMS\Extbase\Utility\LocalizationUtility;
......@@ -206,7 +207,13 @@ class QueueController extends ActionController {
*/
protected function initSessionAndTemplateFilter(array &$filters) {
if (!($this->session instanceof PhpSession)) {
$this->session = $this->objectManager->get(PhpSession::class);
if (version_compare(VersionNumberUtility::getCurrentTypo3Version(), '10.4.0', '<')) {
/** @var PhpSession session */
$this->session = $this->objectManager->get(PhpSession::class);
} else {
$this->session = GeneralUtility::makeInstance(PhpSession::class);
}
$this->session->setSessionKey('sg_mail_controller_session');
} else {
$this->session->setSessionKey('sg_mail_controller_session');
......
......@@ -27,6 +27,8 @@ namespace SGalinski\SgMail\Domain\Repository;
***************************************************************/
use TYPO3\CMS\Backend\Utility\BackendUtility;
use TYPO3\CMS\Core\Utility\GeneralUtility;
use TYPO3\CMS\Core\Utility\VersionNumberUtility;
use TYPO3\CMS\Extbase\Persistence\Generic\Typo3QuerySettings;
use TYPO3\CMS\Extbase\Persistence\Repository;
use TYPO3\CMS\Frontend\Controller\TypoScriptFrontendController;
......@@ -42,7 +44,13 @@ abstract class AbstractRepository extends Repository {
* @return void
*/
public function initializeObject() {
$querySettings = $this->objectManager->get(Typo3QuerySettings::class);
if (version_compare(VersionNumberUtility::getCurrentTypo3Version(), '10.4.0', '<')) {
/** @var Typo3QuerySettings $querySettings */
$querySettings = $this->objectManager->get(Typo3QuerySettings::class);
} else {
$querySettings = GeneralUtility::makeInstance(Typo3QuerySettings::class);
}
$querySettings->setRespectStoragePage(FALSE);
if (TYPO3_MODE === 'BE') {
$querySettings->setIgnoreEnableFields(TRUE);
......
......@@ -31,6 +31,7 @@ use TYPO3\CMS\Core\Database\Connection;
use TYPO3\CMS\Core\Database\ConnectionPool;
use TYPO3\CMS\Core\Database\Query\Restriction\DeletedRestriction;
use TYPO3\CMS\Core\Utility\GeneralUtility;
use TYPO3\CMS\Core\Utility\VersionNumberUtility;
use TYPO3\CMS\Extbase\Persistence\Generic\Typo3QuerySettings;
use TYPO3\CMS\Extbase\Persistence\Repository;
......@@ -46,8 +47,13 @@ class LayoutRepository extends Repository {
* @return void
*/
public function initializeObject() {
/** @var $querySettings Typo3QuerySettings */
$querySettings = $this->objectManager->get(Typo3QuerySettings::class);
if (version_compare(VersionNumberUtility::getCurrentTypo3Version(), '10.4.0', '<')) {
/** @var $querySettings Typo3QuerySettings */
$querySettings = $this->objectManager->get(Typo3QuerySettings::class);
} else {
$querySettings = GeneralUtility::makeInstance(Typo3QuerySettings::class);
}
$querySettings->setRespectStoragePage(FALSE);
$querySettings->setLanguageOverlayMode(TRUE);
$querySettings->setLanguageMode('content_fallback');
......
......@@ -304,4 +304,11 @@ class MailRepository extends AbstractRepository {
return $queryBuilder->orderBy('tstamp', 'desc');
}
/**
* Persist the changes to database
*/
public function persist() {
$this->persistenceManager->persistAll();
}
}
......@@ -28,6 +28,7 @@ namespace SGalinski\SgMail\Domain\Repository;
use TYPO3\CMS\Core\Database\ConnectionPool;
use TYPO3\CMS\Core\Utility\GeneralUtility;
use TYPO3\CMS\Core\Utility\VersionNumberUtility;
use TYPO3\CMS\Extbase\Persistence\Generic\Typo3QuerySettings;
/**
......@@ -44,15 +45,18 @@ class TemplateRepository extends AbstractRepository {
*/
public function findOneByTemplate($extensionKey, $templateName, $language, $pid = 0) {
$query = $this->createQuery();
if (version_compare(VersionNumberUtility::getCurrentTypo3Version(), '10.4.0', '<')) {
/** @var Typo3QuerySettings $querySettings */
$querySettings = $this->objectManager->get(Typo3QuerySettings::class);
} else {
$querySettings = GeneralUtility::makeInstance(Typo3QuerySettings::class);
}
$querySettings = $this->objectManager->get(Typo3QuerySettings::class);
$querySettings->setRespectStoragePage(FALSE);
$constraintsAnd[] = $query->equals('extension_key', $extensionKey);
$constraintsAnd[] = $query->equals('template_name', $templateName);
$constraintsAnd[] = $query->equals('language', $language);
$constraintsAnd[] = $query->equals('pid', (int) $pid);
$query->matching(
$query->logicalAnd($constraintsAnd)
);
......@@ -78,4 +82,11 @@ class TemplateRepository extends AbstractRepository {
)
)->execute();
}
/**
* Persist changes to database
*/
public function persist() {
$this->persistenceManager->persistAll();
}
}
......@@ -30,6 +30,7 @@ namespace SGalinski\SgMail\Finisher\Forms;
use SGalinski\SgMail\Service\MailTemplateService;
use SGalinski\SgMail\Service\RegisterService;
use TYPO3\CMS\Core\Utility\GeneralUtility;
use TYPO3\CMS\Core\Utility\VersionNumberUtility;
use TYPO3\CMS\Extbase\Object\ObjectManager;
use TYPO3\CMS\Form\Domain\Finishers\AbstractFinisher;
......@@ -105,10 +106,17 @@ class FormsFinisher extends AbstractFinisher {
$extensionKey = trim((string) $this->parseOption('extension'));
$extensionKey = $extensionKey ?: 'sg_mail';
$objectManager = GeneralUtility::makeInstance(ObjectManager::class);
$mailTemplateService = $objectManager->get(
MailTemplateService::class, $templateName, $extensionKey, $markers, $markerLabels
);
if (version_compare(VersionNumberUtility::getCurrentTypo3Version(), '10.4.0', '<')) {
$objectManager = GeneralUtility::makeInstance(ObjectManager::class);
/** @var MailTemplateService $mailTemplateService */
$mailTemplateService = $objectManager->get(
MailTemplateService::class, $templateName, $extensionKey, $markers, $markerLabels
);
} else {
$mailTemplateService = GeneralUtility::makeInstance(
MailTemplateService::class, $templateName, $extensionKey, $markers, $markerLabels
);
}
$mailTemplateService->setIgnoreMailQueue(TRUE);
$mailTemplateService->setLanguage($GLOBALS['TSFE']->config['config']['language']);
......
......@@ -39,6 +39,7 @@ use TYPO3\CMS\Core\Database\Query\Restriction\DeletedRestriction;
use TYPO3\CMS\Core\Imaging\Icon;
use TYPO3\CMS\Core\Imaging\IconFactory;
use TYPO3\CMS\Core\Utility\GeneralUtility;
use TYPO3\CMS\Core\Utility\VersionNumberUtility;
use TYPO3\CMS\Extbase\Mvc\Request;
use TYPO3\CMS\Extbase\Object\ObjectManager;
use TYPO3\CMS\Extbase\Persistence\Generic\PersistenceManager;
......@@ -180,10 +181,13 @@ class BackendService {
$selectedExtension, $selectedTemplate, array $languages, $pid
): array {
$selectedTemplates = [];
$objectManager = GeneralUtility::makeInstance(ObjectManager::class);
/** @var TemplateRepository $templateRepository */
$templateRepository = $objectManager->get(TemplateRepository::class);
if (version_compare(VersionNumberUtility::getCurrentTypo3Version(), '10.4.0', '<')) {
$objectManager = GeneralUtility::makeInstance(ObjectManager::class);
/** @var TemplateRepository $templateRepository */
$templateRepository = $objectManager->get(TemplateRepository::class);
} else {
$templateRepository = GeneralUtility::makeInstance(TemplateRepository::class);
}
foreach ($languages as $language) {
$selectedTemplates[$language['isocode']] = $templateRepository->findOneByTemplate(
......@@ -318,8 +322,13 @@ class BackendService {
*/
public static function saveTemplate($pid, $selectedExtension, $selectedTemplate, $language, $templateData
): Template {
$objectManager = GeneralUtility::makeInstance(ObjectManager::class);
$templateRepository = $objectManager->get(TemplateRepository::class);
if (version_compare(VersionNumberUtility::getCurrentTypo3Version(), '10.4.0', '<')) {
$objectManager = GeneralUtility::makeInstance(ObjectManager::class);
/** @var TemplateRepository $templateRepository */
$templateRepository = $objectManager->get(TemplateRepository::class);
} else {
$templateRepository = GeneralUtility::makeInstance(TemplateRepository::class);
}
/** @var Template $template */
$template = $templateRepository->findOneByTemplate(
......@@ -327,10 +336,14 @@ class BackendService {
);
$templateAlreadyExists = TRUE;
$objectManager = GeneralUtility::makeInstance(ObjectManager::class);
if ($template === NULL) {
$templateAlreadyExists = FALSE;
$template = $objectManager->get(Template::class);
if (version_compare(VersionNumberUtility::getCurrentTypo3Version(), '10.4.0', '<')) {
/** @var Template $template */
$template = $objectManager->get(Template::class);
} else {
$template = GeneralUtility::makeInstance(Template::class);
}
}
$template->setExtensionKey($selectedExtension);
......@@ -352,10 +365,7 @@ class BackendService {
$templateRepository->add($template);
}
$objectManager = GeneralUtility::makeInstance(ObjectManager::class);
$persistenceManager = $objectManager->get(PersistenceManager::class);
$persistenceManager->persistAll();
$templateRepository->persist();
return $template;
}
......@@ -368,8 +378,13 @@ class BackendService {
* @throws \InvalidArgumentException
*/
public static function writeCsvFromQueue(array $filters = []) {
$objectManager = GeneralUtility::makeInstance(ObjectManager::class);
$mailRepository = $objectManager->get(MailRepository::class);
if (version_compare(VersionNumberUtility::getCurrentTypo3Version(), '10.4.0', '<')) {
$objectManager = GeneralUtility::makeInstance(ObjectManager::class);
/** @var MailRepository $mailRepository */
$mailRepository = $objectManager->get(MailRepository::class);
} else {
$mailRepository = GeneralUtility::makeInstance(MailRepository::class);
}
$pageUid = (int) GeneralUtility::_GP('id');
$ignoreFields = ['uid', 'pid', 'tstamp',
......@@ -464,7 +479,7 @@ class BackendService {
$currentSiteBlacklist = GeneralUtility::trimExplode(',', $currentSite, TRUE);
if ((int) $currentSiteBlacklist[0] === $siteRootId) {
foreach ($currentSiteBlacklist as $excludedTemplate) {
list($extensionKey, $templateName) = GeneralUtility::trimExplode('.', $excludedTemplate);
[$extensionKey, $templateName] = GeneralUtility::trimExplode('.', $excludedTemplate);
if ($extensionKey && $templateName && isset($registerArray[$extensionKey][$templateName])) {
unset($registerArray[$extensionKey][$templateName]);
}
......@@ -481,7 +496,7 @@ class BackendService {
',', $extensionConfiguration['excludeTemplatesAllDomains'], TRUE
);
foreach ($excludedTemplates as $excludedTemplate) {
list($extensionKey, $templateName) = GeneralUtility::trimExplode('.', $excludedTemplate);
[$extensionKey, $templateName] = GeneralUtility::trimExplode('.', $excludedTemplate);
if ($extensionKey && $templateName && isset($registerArray[$extensionKey][$templateName])) {
unset($registerArray[$extensionKey][$templateName]);
}
......
......@@ -39,9 +39,9 @@ use TYPO3\CMS\Core\Resource\File;
use TYPO3\CMS\Core\Resource\ResourceFactory;
use TYPO3\CMS\Core\Routing\SiteMatcher;
use TYPO3\CMS\Core\Utility\GeneralUtility;
use TYPO3\CMS\Core\Utility\VersionNumberUtility;
use TYPO3\CMS\Extbase\Domain\Model\FileReference;