Skip to content
Snippets Groups Projects
Commit 6eb533a4 authored by Stefan Galinski's avatar Stefan Galinski :video_game:
Browse files

Merge branch 'feature_Upgrade-to-TYPO3-10' into 'master'

Feature upgrade to typo3 10

See merge request !30
parents 62c9926a e99e8afd
No related branches found
No related tags found
1 merge request!30Feature upgrade to typo3 10
Showing
with 643 additions and 562 deletions
......@@ -29,54 +29,49 @@ namespace SGalinski\SgMail\Command;
use SGalinski\SgMail\Domain\Model\Mail;
use SGalinski\SgMail\Domain\Repository\MailRepository;
use SGalinski\SgMail\Service\PlaintextService;
use Symfony\Component\Console\Input\InputArgument;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Output\OutputInterface;
use TYPO3\CMS\Core\Mail\MailMessage;
use TYPO3\CMS\Core\Resource\FileInterface;
use TYPO3\CMS\Core\Utility\GeneralUtility;
use TYPO3\CMS\Extbase\Mvc\Controller\CommandController;
use TYPO3\CMS\Extbase\Persistence\Generic\PersistenceManager;
use Symfony\Component\Console\Command\Command;
use TYPO3\CMS\Core\Utility\VersionNumberUtility;
use TYPO3\CMS\Extbase\Object\ObjectManager;
/**
* Command controller for the mailing feature
*/
class SendMailCommandController extends CommandController {
class SendMailCommandController extends Command {
/**
* @var MailRepository
* Configure command
*/
protected $mailRepository;
/**
* Inject the MailRepository
*
* @param MailRepository $mailRepository
*/
public function injectMailRepository(MailRepository $mailRepository) {
$this->mailRepository = $mailRepository;
public function configure() {
$this->setDescription('Executes the sending of mails with a maximum of the given sentCount.')
->addArgument('sendCount', InputArgument::OPTIONAL, 'Send count', 50);
}
/**
* @var PersistenceManager
*/
protected $persistenceManager;
/**
* Inject the PersistenceManager
* Execute the command
*
* @param PersistenceManager $persistenceManager
*/
public function injectPersistenceManager(PersistenceManager $persistenceManager) {
$this->persistenceManager = $persistenceManager;
}
/**
* Executes the sending of mails with a maximum of the given sentCount.
*
* @param int $sendCount
* @return void
* @throws \TYPO3\CMS\Extbase\Persistence\Exception\UnknownObjectException
* @param InputInterface $input
* @param OutputInterface $output
* @return int
* @throws \TYPO3\CMS\Extbase\Object\Exception
* @throws \TYPO3\CMS\Extbase\Persistence\Exception\IllegalObjectTypeException
* @throws \TYPO3\CMS\Extbase\Persistence\Exception\UnknownObjectException
*/
public function runSendMailsCommand($sendCount = 50) {
$mailsToSend = $this->mailRepository->findMailsToSend($sendCount);
public function execute(InputInterface $input, OutputInterface $output) {
$sendCount = $input->getArgument('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();
......@@ -96,9 +91,9 @@ class SendMailCommandController extends CommandController {
if (empty($fromAddress) || empty($toAddresses)) {
continue;
}
$this->mailRepository->update($mailToSend);
$mailRepository->update($mailToSend);
$mailMessage = $this->objectManager->get(MailMessage::class);
$mailMessage = GeneralUtility::makeInstance(MailMessage::class);
$mailMessage->setFrom($fromAddress, $mailToSend->getFromName());
$mailMessage->setTo($toAddresses);
$mailMessage->setSubject($mailSubject);
......@@ -115,15 +110,21 @@ class SendMailCommandController extends CommandController {
$mailMessage->setReplyTo($replyTo);
}
$mailMessage->setBody($mailBody, 'text/html');
$plaintextService = GeneralUtility::makeInstance(PlaintextService::class);
$plaintextBody = $plaintextService->makePlain($mailBody);
$mailMessage->addPart($plaintextBody, 'text/plain');
if (version_compare(VersionNumberUtility::getCurrentTypo3Version(), '10.4.0', '<')) {
$mailMessage->setBody($mailBody, 'text/html');
$mailMessage->addPart($plaintextBody, 'text/plain');
} else {
$mailMessage->html($mailBody);
$mailMessage->text($plaintextBody);
}
$attachments = $mailToSend->getAttachments();
if ($attachments->count() > 0) {
foreach ($attachments as $attachment) {
try {
/** @var FileInterface $file */
$file = $attachment->getOriginalResource();
if (!$file) {
continue;
......@@ -133,17 +134,21 @@ class SendMailCommandController extends CommandController {
if (!$file) {
continue;
}
$mailMessage->attach(
\Swift_Attachment::newInstance(
$file->getContents(), $file->getName(), $file->getMimeType()
)
);
if (version_compare(VersionNumberUtility::getCurrentTypo3Version(), '10.4.0', '<')) {
$mailMessage->attach(
\Swift_Attachment::newInstance(
$file->getContents(), $file->getName(), $file->getMimeType()
)
);
} else {
$mailMessage->attach($file->getContents(), $file->getName(), $file->getMimeType());
}
} catch (\Exception $exception) {
continue;
}
}
}
try {
$mailMessage->send();
} catch (\Exception $exception) {
......@@ -152,6 +157,7 @@ class SendMailCommandController extends CommandController {
}
// Important for command controllers that change data
$this->persistenceManager->persistAll();
$mailRepository->persist();
return 0;
}
}
......@@ -129,7 +129,6 @@ class ConfigurationController extends ActionController {
'docHeader' => $this->docHeaderComponent->docHeaderContent(),
'selectedTemplateFilter' => $filters['filterTemplate'],
'selectedExtensionFilter' => $filters['filterExtension'],
'typo3Version' => VersionNumberUtility::convertVersionNumberToInteger(TYPO3_version),
'selectedTemplateKey' => $selectedTemplate,
'selectedExtensionKey' => $selectedExtension,
'mode' => 'editor'
......@@ -181,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')]
......@@ -251,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(
......@@ -262,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');
......@@ -286,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,
......
......@@ -32,7 +32,6 @@ use SGalinski\SgMail\Session\PhpSession;
use TYPO3\CMS\Backend\Clipboard\Clipboard;
use TYPO3\CMS\Backend\Template\Components\DocHeaderComponent;
use TYPO3\CMS\Backend\Utility\BackendUtility;
use TYPO3\CMS\Core\Page\PageRenderer;
use TYPO3\CMS\Core\Utility\GeneralUtility;
use TYPO3\CMS\Core\Utility\VersionNumberUtility;
use TYPO3\CMS\Extbase\Mvc\Controller\ActionController;
......@@ -104,15 +103,6 @@ class LayoutController extends ActionController {
*/
public function initializeView(ViewInterface $view) {
parent::initializeView($view);
$pageRenderer = GeneralUtility::makeInstance(PageRenderer::class);
$pageRenderer->addJsInlineCode(
'typo3_version', 'TYPO3.version='
. VersionNumberUtility::convertVersionNumberToInteger(VersionNumberUtility::getCurrentTypo3Version())
. ';'
);
if (version_compare(VersionNumberUtility::getCurrentTypo3Version(), '9.0.0', '<')) {
$pageRenderer->loadExtJS();
}
$this->initClipboard();
$view->assign('controller', 'Layout');
}
......@@ -124,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');
......@@ -158,7 +154,6 @@ class LayoutController extends ActionController {
BackendService::makeButtons($this->docHeaderComponent, $this->request);
$this->view->assign('pageUid', $pageUid);
$this->view->assign('docHeader', $this->docHeaderComponent->docHeaderContent());
$this->view->assign('typo3Version', VersionNumberUtility::convertVersionNumberToInteger(TYPO3_version));
}
/**
......
......@@ -36,7 +36,6 @@ use SGalinski\SgMail\Session\PhpSession;
use TYPO3\CMS\Backend\Template\Components\DocHeaderComponent;
use TYPO3\CMS\Backend\Utility\BackendUtility;
use TYPO3\CMS\Core\Messaging\FlashMessage;
use TYPO3\CMS\Core\Page\PageRenderer;
use TYPO3\CMS\Core\Utility\GeneralUtility;
use TYPO3\CMS\Core\Utility\VersionNumberUtility;
use TYPO3\CMS\Extbase\Mvc\Controller\ActionController;
......@@ -93,15 +92,6 @@ class MailController extends ActionController {
*/
public function initializeView(ViewInterface $view) {
parent::initializeView($view);
$pageRenderer = GeneralUtility::makeInstance(PageRenderer::class);
$pageRenderer->addJsInlineCode(
'typo3_version', 'TYPO3.version='
. VersionNumberUtility::convertVersionNumberToInteger(VersionNumberUtility::getCurrentTypo3Version())
. ';'
);
if (version_compare(VersionNumberUtility::getCurrentTypo3Version(), '9.0.0', '<')) {
$pageRenderer->loadExtJS();
}
$view->assign('controller', 'Mail');
}
......@@ -125,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');
......@@ -231,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'])
);
......@@ -283,21 +284,14 @@ class MailController extends ActionController {
BackendService::makeButtons($this->docHeaderComponent, $this->request);
$this->view->assign('docHeader', $this->docHeaderComponent->docHeaderContent());
$this->view->assign('typo3Version', VersionNumberUtility::convertVersionNumberToInteger(TYPO3_version));
/** @noinspection PhpInternalEntityUsedInspection */
$this->view->assign('beUserMail', $GLOBALS['BE_USER']->user['email']);
// get the default language label and pass it to the view
$pageTsConfig = BackendUtility::getPagesTSconfig($pageUid);
if (VersionNumberUtility::convertVersionNumberToInteger(TYPO3_version) >= 8000000) {
$defaultLanguageLabel = LocalizationUtility::translate(
'LLL:EXT:lang/Resources/Private/Language/locallang_mod_web_list.xlf:defaultLanguage'
);
} else {
$defaultLanguageLabel = LocalizationUtility::translate(
'lll:EXT:lang/locallang_mod_web_list.xlf:defaultLanguage'
);
}
$defaultLanguageLabel = LocalizationUtility::translate(
'LLL:EXT:core/Resources/Private/Language/locallang_mod_web_list.xlf:defaultLanguage'
);
if (isset($pageTsConfig['mod.']['SHARED.']['defaultLanguageLabel'])) {
$defaultLanguageLabel = $pageTsConfig['mod.']['SHARED.']['defaultLanguageLabel'];
......@@ -373,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']);
......
......@@ -37,7 +37,6 @@ use SGalinski\SgMail\Session\PhpSession;
use TYPO3\CMS\Backend\Template\Components\DocHeaderComponent;
use TYPO3\CMS\Backend\Utility\BackendUtility;
use TYPO3\CMS\Core\Messaging\FlashMessage;
use TYPO3\CMS\Core\Page\PageRenderer;
use TYPO3\CMS\Core\Utility\GeneralUtility;
use TYPO3\CMS\Core\Utility\VersionNumberUtility;
use TYPO3\CMS\Extbase\Mvc\Controller\ActionController;
......@@ -108,15 +107,6 @@ class NewsletterController extends ActionController {
*/
public function initializeView(ViewInterface $view) {
parent::initializeView($view);
$pageRenderer = GeneralUtility::makeInstance(PageRenderer::class);
$pageRenderer->addJsInlineCode(
'typo3_version', 'TYPO3.version='
. VersionNumberUtility::convertVersionNumberToInteger(VersionNumberUtility::getCurrentTypo3Version())
. ';'
);
if (version_compare(VersionNumberUtility::getCurrentTypo3Version(), '9.0.0', '<')) {
$pageRenderer->loadExtJS();
}
$view->assign('controller', 'Newsletter');
}
......@@ -140,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');
......@@ -277,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']];
......@@ -329,23 +328,15 @@ class NewsletterController extends ActionController {
BackendService::makeButtons($this->docHeaderComponent, $this->request);
$this->view->assign('docHeader', $this->docHeaderComponent->docHeaderContent());
$this->view->assign('typo3Version', VersionNumberUtility::convertVersionNumberToInteger(TYPO3_version));
/** @noinspection PhpInternalEntityUsedInspection */
$beUserMail = (!empty($arguments['emailAddress'])?$arguments['emailAddress']:$GLOBALS['BE_USER']->user['email']);
$this->view->assign('beUserMail', $beUserMail);
// get the default language label and pass it to the view
$pageTsConfig = BackendUtility::getPagesTSconfig($pageUid);
if (VersionNumberUtility::convertVersionNumberToInteger(TYPO3_version) >= 8000000) {
$defaultLanguageLabel = LocalizationUtility::translate(
'LLL:EXT:lang/Resources/Private/Language/locallang_mod_web_list.xlf:defaultLanguage'
);
} else {
$defaultLanguageLabel = LocalizationUtility::translate(
'lll:EXT:lang/locallang_mod_web_list.xlf:defaultLanguage'
);
}
$defaultLanguageLabel = LocalizationUtility::translate(
'LLL:EXT:core/Resources/Private/Language/locallang_mod_web_list.xlf:defaultLanguage'
);
if (isset($pageTsConfig['mod.']['SHARED.']['defaultLanguageLabel'])) {
$defaultLanguageLabel = $pageTsConfig['mod.']['SHARED.']['defaultLanguageLabel'];
}
......@@ -418,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');
......
......@@ -33,7 +33,6 @@ use SGalinski\SgMail\Session\PhpSession;
use TYPO3\CMS\Backend\Template\Components\DocHeaderComponent;
use TYPO3\CMS\Backend\Utility\BackendUtility;
use TYPO3\CMS\Core\Messaging\FlashMessage;
use TYPO3\CMS\Core\Page\PageRenderer;
use TYPO3\CMS\Core\Utility\GeneralUtility;
use TYPO3\CMS\Core\Utility\VersionNumberUtility;
use TYPO3\CMS\Extbase\Mvc\Controller\ActionController;
......@@ -75,15 +74,6 @@ class QueueController extends ActionController {
*/
public function initializeView(ViewInterface $view) {
parent::initializeView($view);
$pageRenderer = GeneralUtility::makeInstance(PageRenderer::class);
$pageRenderer->addJsInlineCode(
'typo3_version', 'TYPO3.version='
. VersionNumberUtility::convertVersionNumberToInteger(VersionNumberUtility::getCurrentTypo3Version())
. ';'
);
if (version_compare(VersionNumberUtility::getCurrentTypo3Version(), '9.0.0', '<')) {
$pageRenderer->loadExtJS();
}
$view->assign('controller', 'Queue');
}
......@@ -161,7 +151,6 @@ class QueueController extends ActionController {
$this->docHeaderComponent->setMetaInformation($pageInfo);
BackendService::makeButtons($this->docHeaderComponent, $this->request);
$this->view->assign('docHeader', $this->docHeaderComponent->docHeaderContent());
$this->view->assign('typo3Version', VersionNumberUtility::convertVersionNumberToInteger(TYPO3_version));
}
......@@ -218,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');
......
......@@ -26,55 +26,42 @@ namespace SGalinski\SgMail\Domain\Repository;
* This copyright notice MUST APPEAR in all copies of the script!
***************************************************************/
use TYPO3\CMS\Backend\Utility\BackendUtility;
use TYPO3\CMS\Core\Utility\GeneralUtility;
use TYPO3\CMS\Core\Utility\VersionNumberUtility;
use TYPO3\CMS\Extbase\Object\ObjectManagerInterface;
use TYPO3\CMS\Extbase\Persistence\Generic\Typo3QuerySettings;
use TYPO3\CMS\Extbase\Persistence\Repository;
use TYPO3\CMS\Frontend\Controller\TypoScriptFrontendController;
use TYPO3\CMS\Frontend\Page\PageRepository;
/**
* Abstract Repository
*/
abstract class AbstractRepository extends Repository {
/**
* Initializes the repository default settings
* AbstractRepository constructor.
*
* @return void
* @param ObjectManagerInterface $objectManager
*/
public function initializeObject() {
$querySettings = $this->objectManager->get(Typo3QuerySettings::class);
public function __construct(ObjectManagerInterface $objectManager) {
parent::__construct($objectManager);
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);
}
$this->setDefaultQuerySettings($querySettings);
}
/**
* Method creates a statement string of the enableFields for the given database table.
*
* @param string $table
* @param string $alias
* @param bool $ignoreEnableFields
* @return string
* Persist changes to database
*/
protected function getEnableFieldsStatement($table, $alias = '', $ignoreEnableFields = FALSE): string {
if (TYPO3_MODE === 'FE' && $GLOBALS['TSFE'] instanceof TypoScriptFrontendController) {
/** @var PageRepository $pageRepository */
$pageRepository = $GLOBALS['TSFE']->sys_page;
$statement = $pageRepository->enableFields($table);
} else {
$statement = BackendUtility::deleteClause($table);
if (!$ignoreEnableFields) {
$statement .= BackendUtility::BEenableFields($table);
}
}
if ($alias !== '') {
$statement = str_replace($table, $alias, $statement);
}
return $statement;
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\Extbase\Domain\Model\FrontendUserGroup;
use TYPO3\CMS\Extbase\Object\ObjectManagerInterface;
/**
* Frontend User Group Repository
......@@ -35,9 +36,12 @@ use TYPO3\CMS\Extbase\Domain\Model\FrontendUserGroup;
class FrontendUserGroupRepository extends \TYPO3\CMS\Extbase\Domain\Repository\FrontendUserGroupRepository {
/**
* initializes the object
* FrontendUserGroupRepository constructor.
*
* @param ObjectManagerInterface $objectManager
*/
public function initializeObject() {
public function __construct(ObjectManagerInterface $objectManager) {
parent::__construct($objectManager);
$this->objectType = FrontendUserGroup::class;
$querySettings = $this->createQuery()->getQuerySettings();
$querySettings->setRespectStoragePage(FALSE);
......
......@@ -31,6 +31,8 @@ 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\Object\ObjectManagerInterface;
use TYPO3\CMS\Extbase\Persistence\Generic\Typo3QuerySettings;
use TYPO3\CMS\Extbase\Persistence\Repository;
......@@ -41,13 +43,19 @@ class LayoutRepository extends Repository {
const LAYOUT_TABLE_NAME = 'tx_sgmail_domain_model_layout';
/**
* Initializes the repository default settings
* LayoutRepository constructor.
*
* @return void
* @param ObjectManagerInterface $objectManager
*/
public function initializeObject() {
/** @var $querySettings Typo3QuerySettings */
$querySettings = $this->objectManager->get(Typo3QuerySettings::class);
public function __construct(ObjectManagerInterface $objectManager) {
parent::__construct($objectManager);
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');
......
......@@ -45,7 +45,7 @@ class MailRepository extends AbstractRepository {
* @param int $limit
* @return array|QueryResultInterface
*/
public function findMailsToSend($limit = NULL) {
public function findMailsToSend(int $limit = NULL) {
$query = $this->createQuery();
if ($limit) {
$query->setLimit($limit);
......
......@@ -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)
);
......
......@@ -29,7 +29,10 @@ namespace SGalinski\SgMail\Finisher\Forms;
use SGalinski\SgMail\Service\MailTemplateService;
use SGalinski\SgMail\Service\RegisterService;
use TYPO3\CMS\Core\Context\Context;
use TYPO3\CMS\Core\Site\SiteFinder;
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,13 +108,23 @@ 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']);
$languageId = GeneralUtility::makeInstance(Context::class)->getPropertyFromAspect('language', 'id', 0);
$site = GeneralUtility::makeInstance(SiteFinder::class)->getSiteByPageId((int) $GLOBALS['TSFE']->id);
$siteLanguage = $site->getLanguageById($languageId);
$mailTemplateService->setLanguage($siteLanguage->getTypo3Language());
$mailToAddresses = trim((string) $this->parseOption('mailTo'));
if ($mailToAddresses !== '') {
......
......@@ -26,14 +26,11 @@ namespace SGalinski\SgMail\Service;
* This copyright notice MUST APPEAR in all copies of the script!
***************************************************************/
use Doctrine\DBAL\Driver\Mysqli\MysqliStatement;
use Doctrine\DBAL\Statement;
use SGalinski\SgMail\Domain\Model\Template;
use SGalinski\SgMail\Domain\Repository\FrontendUserGroupRepository;
use SGalinski\SgMail\Domain\Repository\MailRepository;
use SGalinski\SgMail\Domain\Repository\TemplateRepository;
use SGalinski\SgMail\Utility\ExtensionUtility;
use Symfony\Component\HttpFoundation\StreamedResponse;
use TYPO3\CMS\Backend\Template\Components\ButtonBar;
use TYPO3\CMS\Backend\Template\Components\DocHeaderComponent;
use TYPO3\CMS\Backend\Utility\BackendUtility;
......@@ -93,16 +90,6 @@ class BackendService {
1
)
);
if (!version_compare(VersionNumberUtility::getCurrentTypo3Version(), '9.0.0', '<')) {
$queryBuilder->andWhere(
$queryBuilder->expr()->eq(
'sys_language_uid',
0
)
);
}
$rows = $queryBuilder->execute()->fetchAll();
foreach ($rows as $row) {
......@@ -132,16 +119,9 @@ class BackendService {
public static function makeButtons($docHeaderComponent, $request) {
/** @var ButtonBar $buttonBar */
$buttonBar = $docHeaderComponent->getButtonBar();
/** @var IconFactory $iconFactory */
$iconFactory = GeneralUtility::makeInstance(IconFactory::class);
if (version_compare(VersionNumberUtility::getCurrentTypo3Version(), '9.0.0', '<')) {
$locallangPath = 'LLL:EXT:lang/Resources/Private/Language/locallang_core.xlf:';
} else {
$locallangPath = 'LLL:EXT:core/Resources/Private/Language/locallang_core.xlf:';
}
$locallangPath = 'LLL:EXT:core/Resources/Private/Language/locallang_core.xlf:';
// Refresh
$refreshButton = $buttonBar->makeLinkButton()
->setHref(GeneralUtility::getIndpEnv('REQUEST_URI'))
......@@ -201,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(
......@@ -339,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(
......@@ -348,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);
......@@ -373,10 +365,7 @@ class BackendService {
$templateRepository->add($template);
}
$objectManager = GeneralUtility::makeInstance(ObjectManager::class);
$persistenceManager = $objectManager->get(PersistenceManager::class);
$persistenceManager->persistAll();
$templateRepository->persist();
return $template;
}
......@@ -389,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',
......@@ -423,7 +417,7 @@ class BackendService {
$row[] = '"' . ($label ?: $field) . '"';
}
}
fwrite(
$handle, trim(
preg_replace(
......@@ -434,7 +428,7 @@ class BackendService {
)
);
}
$row = [];
foreach ($mail as $field => $value) {
if (!\in_array($field, $ignoreFields, TRUE)) {
......@@ -445,7 +439,7 @@ class BackendService {
}
}
}
fwrite(
$handle, trim(
preg_replace(
......@@ -456,7 +450,7 @@ class BackendService {
)
);
}
$offset += self::CSV_EXPORT_BATCH_SIZE;
}
}
......@@ -475,7 +469,7 @@ class BackendService {
$registerService = GeneralUtility::makeInstance(RegisterService::class);
$registerArray = $registerService->getRegisterArray();
$extensionConfiguration = ExtensionUtility::getExtensionConfiguration();
$extensionConfiguration = $GLOBALS['TYPO3_CONF_VARS']['EXTENSIONS']['sg_mail'] ?? [];
if (isset($extensionConfiguration['excludeTemplates']) && $extensionConfiguration['excludeTemplates'] !== '') {
$excludedTemplatesWithSiteId = GeneralUtility::trimExplode(
';', $extensionConfiguration['excludeTemplates'], TRUE
......@@ -485,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]);
}
......@@ -502,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]);
}
......
......@@ -33,8 +33,6 @@ use SGalinski\SgMail\Domain\Model\Template;
use SGalinski\SgMail\Domain\Repository\LayoutRepository;
use SGalinski\SgMail\Domain\Repository\MailRepository;
use SGalinski\SgMail\Domain\Repository\TemplateRepository;
use Swift_Attachment;
use Swift_OutputByteStream;
use TYPO3\CMS\Core\Database\ConnectionPool;
use TYPO3\CMS\Core\Mail\MailMessage;
use TYPO3\CMS\Core\Resource\File;
......@@ -44,7 +42,6 @@ use TYPO3\CMS\Core\Utility\GeneralUtility;
use TYPO3\CMS\Core\Utility\VersionNumberUtility;
use TYPO3\CMS\Extbase\Domain\Model\FileReference;
use TYPO3\CMS\Extbase\Object\ObjectManager;
use TYPO3\CMS\Extbase\Persistence\Generic\PersistenceManager;
use TYPO3\CMS\Extbase\Utility\LocalizationUtility;
use TYPO3\CMS\Fluid\View\StandaloneView;
use TYPO3\CMS\Frontend\Controller\TypoScriptFrontendController;
......@@ -81,16 +78,13 @@ class MailTemplateService {
* @var \SGalinski\SgMail\Domain\Repository\LayoutRepository
*/
protected $layoutRepository;
/**
* @var \TYPO3\CMS\Extbase\Persistence\Generic\PersistenceManager
*/
protected $persistenceManager;
/**
* @var \TYPO3\CMS\Extbase\Object\ObjectManager
* @deprecated Not used since TYPO3 10
*/
protected $objectManager;
/**
* @var TYPO3\CMS\Core\Resource\ResourceFactory
* @var \TYPO3\CMS\Core\Resource\ResourceFactory
*/
protected $resourceFactory;
/**
......@@ -116,7 +110,7 @@ class MailTemplateService {
/**
* @var boolean $ignoreMailQueue
*/
private $ignoreMailQueue = FALSE;
private $ignoreMailQueue = TRUE;
/**
* @var \TYPO3\CMS\Core\Mail\MailMessage $mailMessage
*/
......@@ -196,16 +190,24 @@ class MailTemplateService {
$this->markers = $markers;
$this->markerLabels = $markerLabels;
/** @var ObjectManager objectManager */
$this->objectManager = GeneralUtility::makeInstance(ObjectManager::class);
$this->mailMessage = $this->objectManager->get(MailMessage::class);
$typoScriptSettingsService = $this->objectManager->get(TypoScriptSettingsService::class);
$tsSettings = $typoScriptSettingsService->getSettings(0, 'tx_sgmail');
$this->templateRepository = $this->objectManager->get(TemplateRepository::class);
$this->layoutRepository = $this->objectManager->get(LayoutRepository::class);
$this->persistenceManager = $this->objectManager->get(PersistenceManager::class);
$this->resourceFactory = $this->objectManager->get(ResourceFactory::class);
$this->resourceFactory = GeneralUtility::makeInstance(ResourceFactory::class);
$this->mailMessage = GeneralUtility::makeInstance(MailMessage::class);
if (version_compare(VersionNumberUtility::getCurrentTypo3Version(), '10.4.0')) {
$this->objectManager = GeneralUtility::makeInstance(ObjectManager::class);
/** @var TypoScriptSettingsService $typoScriptSettingsService */
$typoScriptSettingsService = $this->objectManager->get(TypoScriptSettingsService::class);
/** @var TemplateRepository templateRepository */
$this->templateRepository = $this->objectManager->get(TemplateRepository::class);
/** @var LayoutRepository layoutRepository */
$this->layoutRepository = $this->objectManager->get(LayoutRepository::class);
} else {
$typoScriptSettingsService = GeneralUtility::makeInstance(TypoScriptSettingsService::class);
$this->templateRepository = GeneralUtility::makeInstance(TemplateRepository::class);
$this->layoutRepository = GeneralUtility::makeInstance(LayoutRepository::class);
}
$tsSettings = $typoScriptSettingsService->getSettings(0, 'tx_sgmail');
// use defaultMailFromAddress if it is provided in LocalConfiguration.php; use the sg_mail TS setting as fallback
if (\filter_var($GLOBALS['TYPO3_CONF_VARS']['MAIL']['defaultMailFromAddress'], FILTER_VALIDATE_EMAIL)) {
$this->fromAddress = $GLOBALS['TYPO3_CONF_VARS']['MAIL']['defaultMailFromAddress'];
......@@ -364,24 +366,6 @@ class MailTemplateService {
return $this;
}
/**
* IMPORTANT: make sure to set $this->>ignoreMailQueue(TRUE), if you're using this method to add an attachment!
* Otherwise the attachment is ignored when sending the mail via mail queue.
*
* @param Swift_OutputByteStream $data
* @param string $filename
* @param string $contentType
* @return MailTemplateService
*/
public function addAttachment($data, $filename, $contentType): MailTemplateService {
$attachment = Swift_Attachment::newInstance()
->setFilename($filename)
->setContentType($contentType)
->setBody($data);
$this->mailMessage->attach($attachment);
return $this;
}
/**
* Adds a file resource as attachment
*
......@@ -552,9 +536,15 @@ class MailTemplateService {
//TODO: this can be avoided if the sending logic is decoupled from this function
if ($isPreview) {
$mailRepository = $this->objectManager->get(MailRepository::class);
if (version_compare(VersionNumberUtility::getCurrentTypo3Version(), '10.4.0', '<')) {
/** @var MailRepository $mailRepository */
$mailRepository = $this->objectManager->get(MailRepository::class);
} else {
$mailRepository = GeneralUtility::makeInstance(MailRepository::class);
}
$mailRepository->remove($mail);
$this->persistenceManager->persistAll();
$mailRepository->persist();
}
return $success;
......@@ -586,9 +576,7 @@ class MailTemplateService {
*/
protected function getPageUid(): int {
if (TYPO3_MODE === 'FE') {
/** @var TypoScriptFrontendController $typoscriptFrontendController */
$typoscriptFrontendController = $GLOBALS['TSFE'];
$pageUid = (int) $typoscriptFrontendController->id;
$pageUid = (int) $GLOBALS['TSFE']->id;
} else {
$pageUid = (int) GeneralUtility::_GP('id');
}
......@@ -825,8 +813,13 @@ class MailTemplateService {
$defaultTemplateContent = \file_get_contents($defaultTemplateFile);
} else {
// use configured default html template
/** @var TypoScriptSettingsService $typoScriptSettingsService */
$typoScriptSettingsService = $this->objectManager->get(TypoScriptSettingsService::class);
if (version_compare(VersionNumberUtility::getCurrentTypo3Version(), '10.4.0', '<')) {
/** @var TypoScriptSettingsService $typoScriptSettingsService */
$typoScriptSettingsService = $this->objectManager->get(TypoScriptSettingsService::class);
} else {
$typoScriptSettingsService = GeneralUtility::makeInstance(TypoScriptSettingsService::class);
}
$tsSettings = $typoScriptSettingsService->getSettings(0, 'tx_sgmail');
$defaultTemplateFile = GeneralUtility::getFileAbsFileName(
$tsSettings['mail']['defaultHtmlTemplate']
......@@ -872,8 +865,13 @@ class MailTemplateService {
$template, RegisterService $registerService, $defaultTemplateContent,
$siteRootId
) {
/** @var StandaloneView $emailView */
$emailView = $this->objectManager->get(StandaloneView::class);
if (version_compare(VersionNumberUtility::getCurrentTypo3Version(), '10.4.0', '<')) {
/** @var StandaloneView $emailView */
$emailView = $this->objectManager->get(StandaloneView::class);
} else {
$emailView = GeneralUtility::makeInstance(StandaloneView::class);
}
$emailView->assignMultiple($this->markers);
$emailView->assign('all_fields', $this->getAllMarker($this->markers));
......@@ -1046,31 +1044,19 @@ class MailTemplateService {
*/
private function getAvailableLanguages(): array {
$out = [0 => ''];
if (version_compare(VersionNumberUtility::getCurrentTypo3Version(), '9.0.0', '<')) {
$queryBuilder = GeneralUtility::makeInstance(ConnectionPool::class)->getQueryBuilderForTable(
'sys_language'
);
$rows = $queryBuilder->select('*')
->from('sys_language')->execute()->fetchAll();
foreach ($rows as $row) {
$out[(int) $row['uid']] = $row['language_isocode'];
}
} else {
try {
$site = GeneralUtility::makeInstance(SiteMatcher::class)->matchByPageId(0);
} catch (\Exception $exception) {
return [0 => ''];
}
$availableLanguages = $site->getLanguages();
$out = [];
foreach ($availableLanguages as $language) {
$languageId = $language->getLanguageId();
if ($languageId < 0) {
continue;
}
$out[$language->getLanguageId()] = strtolower($language->getTwoLetterIsoCode());
try {
$site = GeneralUtility::makeInstance(SiteMatcher::class)->matchByPageId(0);
} catch (\Exception $exception) {
return [0 => ''];
}
$availableLanguages = $site->getLanguages();
$out = [];
foreach ($availableLanguages as $language) {
$languageId = $language->getLanguageId();
if ($languageId < 0) {
continue;
}
$out[$language->getLanguageId()] = strtolower($language->getTwoLetterIsoCode());
}
return $out;
}
......@@ -1097,7 +1083,7 @@ class MailTemplateService {
$extensionKey, $templateName, $subject, $emailBody, $priority, $sendingTime = 0,
$lastSendingTime = 0, $language = self::DEFAULT_LANGUAGE, $pid = 0
): Mail {
$mail = $this->objectManager->get(Mail::class);
$mail = new Mail();
$mail->setPid($pid);
$mail->setExtensionKey($extensionKey);
$mail->setTemplateName($templateName);
......@@ -1129,16 +1115,22 @@ class MailTemplateService {
'uid' => uniqid('NEW_MAIL', TRUE)
]
);
$newFileReference = GeneralUtility::makeInstance(FileReference::class);
$newFileReference = new FileReference();
$newFileReference->setOriginalResource($coreFileReferenceMailFile);
$mail->addAttachment($newFileReference);
}
}
}
$mailRepository = $this->objectManager->get(MailRepository::class);
if (version_compare(VersionNumberUtility::getCurrentTypo3Version(), '10.4.0', '<')) {
/** @var MailRepository $mailRepository */
$mailRepository = $this->objectManager->get(MailRepository::class);
} else {
$mailRepository = GeneralUtility::makeInstance(MailRepository::class);
}
$mailRepository->add($mail);
$this->persistenceManager->persistAll();
$mailRepository->persist();
return $mail;
}
......@@ -1180,7 +1172,13 @@ class MailTemplateService {
* @throws \TYPO3\CMS\Extbase\Persistence\Exception\UnknownObjectException
*/
public function sendMailFromQueue($uid): bool {
$mailRepository = $this->objectManager->get(MailRepository::class);
if (version_compare(VersionNumberUtility::getCurrentTypo3Version(), '10.4.0', '<')) {
/** @var MailRepository $mailRepository */
$mailRepository = $this->objectManager->get(MailRepository::class);
} else {
$mailRepository = GeneralUtility::makeInstance(MailRepository::class);
}
/** @var Mail $mailToSend */
if (!isset(self::$mailObjectCache[$uid]) || !self::$mailObjectCache[$uid] instanceof Mail) {
$mailToSend = $this->getMailObjectByUid($uid);
......@@ -1191,19 +1189,25 @@ class MailTemplateService {
$mailToSend = self::$mailObjectCache[$uid];
}
$this->mailMessage->setBody($mailToSend->getMailBody(), 'text/html');
$plaintextService = GeneralUtility::makeInstance(PlaintextService::class);
$plaintextBody = $plaintextService->makePlain($mailToSend->getMailBody());
$this->mailMessage->addPart($plaintextBody, 'text/plain');
if (version_compare(VersionNumberUtility::getCurrentTypo3Version(), '10.4.0', '<')) {
$this->mailMessage->setBody($mailToSend->getMailBody(), 'text/html');
$this->mailMessage->addPart($plaintextBody, 'text/plain');
} else {
$this->mailMessage->html($mailToSend->getMailBody());
$this->mailMessage->text($plaintextBody);
}
$toAddresses = \trim($mailToSend->getToAddress());
$addressesArray = GeneralUtility::trimExplode(',', $toAddresses, TRUE);
if (\count($addressesArray) > 1) {
$toAddresses = $addressesArray;
}
$this->mailMessage->setTo($toAddresses);
$this->mailMessage->setFrom($mailToSend->getFromAddress(), $mailToSend->getFromName());
$this->mailMessage->setSubject($mailToSend->getMailSubject());
if ($mailToSend->getBccAddresses()) {
$this->mailMessage->setBcc(GeneralUtility::trimExplode(',', $mailToSend->getBccAddresses()));
}
......@@ -1215,6 +1219,7 @@ class MailTemplateService {
if ($mailToSend->getReplyTo()) {
$this->mailMessage->setReplyTo($mailToSend->getReplyTo());
}
$attachments = $mailToSend->getAttachments();
if ($attachments->count() > 0) {
foreach ($attachments as $attachment) {
......@@ -1222,23 +1227,32 @@ class MailTemplateService {
* @var FileReference $attachment
*/
$file = $attachment->getOriginalResource()->getOriginalFile();
$this->mailMessage->attach(
\Swift_Attachment::newInstance($file->getContents(), $file->getName(), $file->getMimeType())
);
if (version_compare(VersionNumberUtility::getCurrentTypo3Version(), '10.4.0', '<')) {
$this->mailMessage->attach(
\Swift_Attachment::newInstance($file->getContents(), $file->getName(), $file->getMimeType())
);
} else {
$this->mailMessage->attach(
$file->getContents(), $file->getName(), $file->getMimeType()
);
}
}
}
$dateTime = new DateTime();
if ((int) $mailToSend->getSendingTime() === 0) {
$mailToSend->setSendingTime($dateTime->getTimestamp());
}
$mailToSend->setLastSendingTime($dateTime->getTimestamp());
$success = $this->mailMessage->send();
if ($success) {
$mailRepository->update($mailToSend);
$this->persistenceManager->persistAll();
$mailRepository->persist();
} else {
$this->mailMessage->getFailedRecipients();
}
unset(self::$mailObjectCache[$uid]); // free the memory
return $success;
}
......@@ -1250,7 +1264,13 @@ class MailTemplateService {
* @return bool|object
*/
private function getMailObjectByUid($uid) {
$mailRepository = $this->objectManager->get(MailRepository::class);
if (version_compare(VersionNumberUtility::getCurrentTypo3Version(), '10.4.0', '<')) {
/** @var MailRepository $mailRepository */
$mailRepository = $this->objectManager->get(MailRepository::class);
} else {
$mailRepository = GeneralUtility::makeInstance(MailRepository::class);
}
$mailObject = $mailRepository->findOneByUid($uid);
if (!$mailObject || $mailObject->getBlacklisted()) {
return FALSE;
......
......@@ -33,6 +33,7 @@ use TYPO3\CMS\Core\Cache\Frontend\VariableFrontend;
use TYPO3\CMS\Core\Database\ConnectionPool;
use TYPO3\CMS\Core\Utility\ExtensionManagementUtility;
use TYPO3\CMS\Core\Utility\GeneralUtility;
use TYPO3\CMS\Core\Utility\VersionNumberUtility;
use TYPO3\CMS\Extbase\Object\ObjectManager;
/**
......@@ -216,8 +217,13 @@ class RegisterService implements \TYPO3\CMS\Core\SingletonInterface {
* @throws \TYPO3\CMS\Core\Cache\Exception\NoSuchCacheException
*/
public function clearCaches() {
$objectManager = GeneralUtility::makeInstance(ObjectManager::class);
$cacheManager = $objectManager->get(CacheManager::class);
if (version_compare(VersionNumberUtility::getCurrentTypo3Version(), '10.4.0', '<')) {
$objectManager = GeneralUtility::makeInstance(ObjectManager::class);
/** @var CacheManager $cacheManager */
$cacheManager = $objectManager->get(CacheManager::class);
} else {
$cacheManager = GeneralUtility::makeInstance(CacheManager::class);
}
/** @var FrontendInterface $cache */
$cache = $cacheManager->getCache(self::CACHE_NAME);
......
......@@ -29,6 +29,7 @@ namespace SGalinski\SgMail\Service;
use TYPO3\CMS\Core\SingletonInterface;
use TYPO3\CMS\Core\TypoScript\TypoScriptService;
use TYPO3\CMS\Core\Utility\GeneralUtility;
use TYPO3\CMS\Core\Utility\VersionNumberUtility;
use TYPO3\CMS\Extbase\Configuration\BackendConfigurationManager;
use TYPO3\CMS\Extbase\Object\ObjectManager;
......@@ -37,23 +38,11 @@ use TYPO3\CMS\Extbase\Object\ObjectManager;
*
*/
class TypoScriptSettingsService implements SingletonInterface {
/**
* @var \TYPO3\CMS\Extbase\Object\ObjectManagerInterface
*/
protected $objectManager;
/**
* @var array
*/
protected static $typoScriptCache = [];
/**
* Initializes the class
*/
public function __construct() {
$this->objectManager = GeneralUtility::makeInstance(ObjectManager::class);
}
/**
* Returns the typoscript settings of a given page and extension
*
......@@ -67,9 +56,17 @@ class TypoScriptSettingsService implements SingletonInterface {
if (!isset(self::$typoScriptCache[$cacheHash])) {
$tmpId = $_POST['id'];
$_POST['id'] = $pageId;
if (version_compare(VersionNumberUtility::getCurrentTypo3Version(), '10.4.0', '<')) {
$objectManager = GeneralUtility::makeInstance(ObjectManager::class);
/** @var TypoScriptService $typoScriptService */
$typoScriptService = $objectManager->get(TypoScriptService::class);
/** @var BackendConfigurationManager $configurationManager */
$configurationManager = $objectManager->get(BackendConfigurationManager::class);
} else {
$typoScriptService = GeneralUtility::makeInstance(TypoScriptService::class);
$configurationManager = GeneralUtility::makeInstance(BackendConfigurationManager::class);
}
$typoScriptService = $this->objectManager->get(TypoScriptService::class);
$configurationManager = $this->objectManager->get(BackendConfigurationManager::class);
self::$typoScriptCache[$cacheHash] = $typoScriptService->convertTypoScriptArrayToPlainArray(
(array) $configurationManager->getTypoScriptSetup()['module.'][$extensionKey . '.']['settings.']
);
......
<?php
namespace SGalinski\SgMail\Updates;
/***************************************************************
* Copyright notice
*
* (c) sgalinski Internet Services (https://www.sgalinski.de)
*
* All rights reserved
*
* This script is part of the TYPO3 project. The TYPO3 project is
* free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 3 of the License, or
* (at your option) any later version.
*
* The GNU General Public License can be found at
* http://www.gnu.org/copyleft/gpl.html.
*
* This script is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* This copyright notice MUST APPEAR in all copies of the script!
***************************************************************/
use SGalinski\SgMail\Service\BackendService;
use TYPO3\CMS\Core\Database\ConnectionPool;
use TYPO3\CMS\Core\Utility\GeneralUtility;
use TYPO3\CMS\Install\Updates\AbstractUpdate;
/**
* Migrate template db entries to the correct root pages
*/
class MigrateData extends AbstractUpdate {
protected $identifier = '';
/**
* @var string
*/
protected $title = 'Find all templates & queue entries without site root and assign the correct site root id';
/**
* @var \TYPO3\CMS\Extbase\Object\ObjectManager
*/
protected $objectManager;
/**
* @var array
*/
protected $tables = [
'tx_sgmail_domain_model_mail', 'tx_sgmail_domain_model_template'
];
/**
* Checks whether updates are required.
*
* @param string &$description The description for the update
* @return bool Whether an update is required (TRUE) or not (FALSE)
*/
public function checkForUpdate(&$description) {
$description = 'Set the site_root_id for all the queue entries and templates if not set or pid = 0';
$oldRowsFound = FALSE;
foreach ($this->tables as $table) {
$queryBuilder = GeneralUtility::makeInstance(ConnectionPool::class)->getQueryBuilderForTable($table);
$queryBuilder->getRestrictions()->removeAll();
$rowCount = $queryBuilder->select('*')
->from($table)
->where(
$queryBuilder->expr()->eq('site_root_id', 0)
)->execute()->rowCount();
if ($rowCount > 0) {
$oldRowsFound = TRUE;
break;
}
}
return !(!$oldRowsFound || $this->isWizardDone());
}
/**
* Performs the accordant updates.
*
* @param array &$dbQueries Queries done in this update
* @param mixed &$customMessages Custom messages
* @return bool Whether everything went smoothly or not
*/
public function performUpdate(array &$dbQueries, &$customMessages) {
foreach ($this->tables as $table) {
$queryBuilder = GeneralUtility::makeInstance(ConnectionPool::class)->getQueryBuilderForTable($table);
$queryBuilder->getRestrictions()->removeAll();
$rows = $queryBuilder->select('uid', 'pid')
->from($table)
->where(
$queryBuilder->expr()->eq('site_root_id', 0)
)->execute()->fetchAll();
$dbQueries[] = $queryBuilder->getSQL();
/** @var array $result */
foreach ($rows as $row) {
$siteRootId = BackendService::getSiteRoot($row[1]);
if ($siteRootId === NULL) {
$this->retrieveFirstSiteRoot();
}
$queryBuilder->update($table)
->where(
$queryBuilder->expr()->eq('uid', $queryBuilder->createNamedParameter($row[0]))
)
->set('site_root_id', (int) $siteRootId);
$dbQueries[] = $queryBuilder->getSQL();
}
}
$this->markWizardAsDone();
return TRUE;
}
/**
* Get the first site root that is not pid = 0
*
* @return int
*/
private function retrieveFirstSiteRoot() {
$queryBuilder = GeneralUtility::makeInstance(ConnectionPool::class)->getQueryBuilderForTable('pages');
$queryBuilder->getRestrictions()->removeAll();
$pagesResult = $queryBuilder->select('uid')
->from('pages')
->where(
$queryBuilder->expr()->andX(
$queryBuilder->expr()->eq('is_siteroot', 1),
$queryBuilder->expr()->neq('uid', 0)
)
)
->setMaxResults(1)
->execute()->fetch();
$dbQueries[] = $queryBuilder->getSQL();
if (empty($pagesResult)) {
return 0;
}
return $pagesResult[0][0];
}
}
<?php
/***************************************************************
* Copyright notice
*
* (c) sgalinski Internet Services (https://www.sgalinski.de)
*
* All rights reserved
*
* This script is part of the TYPO3 project. The TYPO3 project is
* free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 3 of the License, or
* (at your option) any later version.
*
* The GNU General Public License can be found at
* http://www.gnu.org/copyleft/gpl.html.
*
* This script is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* This copyright notice MUST APPEAR in all copies of the script!
***************************************************************/
namespace SGalinski\SgMail\Updates;
use TYPO3\CMS\Core\Database\ConnectionPool;
use TYPO3\CMS\Core\Utility\GeneralUtility;
use TYPO3\CMS\Install\Updates\DatabaseUpdatedPrerequisite;
use TYPO3\CMS\Install\Updates\UpgradeWizardInterface;
use TYPO3\CMS\Scheduler\Scheduler;
use TYPO3\CMS\Scheduler\Task\ExecuteSchedulableCommandTask;
/**
* Class MigrateSchedulerTasks
*
* @package SGalinski\SgMail\Updates
*/
class MigrateSchedulerTasks implements UpgradeWizardInterface {
/**
* Identifier of the upgrade
*/
const IDENTIFIER = 'tx_sgmail_migrateschedulertasks';
/**
* @inheritDoc
*/
public function getIdentifier(): string {
return self::IDENTIFIER;
}
/**
* @inheritDoc
*/
public function getTitle(): string {
return 'Migrate sg_mail scheduler tasks to symfony commands API';
}
/**
* @inheritDoc
*/
public function getDescription(): string {
return 'This upgrade migrates all sg_mail scheduler tasks, created with the old CommandController API to the new Symfony Commands API';
}
/**
* @inheritDoc
*/
public function executeUpdate(): bool {
$queryBuilder = GeneralUtility::makeInstance(ConnectionPool::class)->getQueryBuilderForTable(
'tx_scheduler_task'
);
$tasks = $queryBuilder->select('serialized_task_object')
->from('tx_scheduler_task')
->where(
$queryBuilder->expr()->eq('disable', 0)
)->execute()->fetchAll();
foreach ($tasks as $_task) {
$task = unserialize($_task['serialized_task_object'], [\__PHP_Incomplete_Class::class]);
$taskVars = $this->cleanArrayKeys((array)$task);
$identifier = $taskVars['*commandIdentifier'];
if (
$identifier === 'sg_mail:sendmail:runsendmails'
) {
$this->replaceTask($taskVars);
}
}
return TRUE;
}
/**
* Replace the given extbase task implementation with the new Symfony Commands API one
*
* @param array $task
*/
protected function replaceTask(array $task) {
$commandTask = GeneralUtility::makeInstance(ExecuteSchedulableCommandTask::class);
switch ($task['*commandIdentifier']) {
case 'sg_mail:sendmail:runsendmails':
$commandTask->setCommandIdentifier('sg_mail:sendMail');
break;
}
if (is_array($task['*arguments'])) {
$commandTask->setArguments($task['*arguments']);
}
if (is_array($task['*defaults'])) {
foreach ($task['*defaults'] as $key => $default) {
$commandTask->addDefaultValue($key, $default);
}
}
$commandTask->setTaskGroup($task['*taskGroup']);
$commandTask->setExecution($task['*execution']);
$commandTask->setExecutionTime($task['*executionTime']);
$commandTask->setRunOnNextCronJob($task['*runOnNextCronJob']);
$commandTask->setTaskUid($task['*taskUid']);
GeneralUtility::makeInstance(Scheduler::class)->saveTask($commandTask);
}
/**
* @inheritDoc
*/
public function updateNecessary(): bool {
$queryBuilder = GeneralUtility::makeInstance(ConnectionPool::class)->getQueryBuilderForTable(
'tx_scheduler_task'
);
$tasks = $queryBuilder->select('serialized_task_object')
->from('tx_scheduler_task')
->where(
$queryBuilder->expr()->eq('disable', 0)
)->execute()->fetchAll();
foreach ($tasks as $_task) {
$task = unserialize($_task['serialized_task_object'], [\__PHP_Incomplete_Class::class]);
$taskVars = $this->cleanArrayKeys((array)$task);
$identifier = $taskVars['*commandIdentifier'];
if (
$identifier === 'sg_mail:sendmail:runsendmails'
) {
return TRUE;
}
}
return FALSE;
}
/**
* Cleans array keys from their hidden \0
*
* @param array $array
* @return array
*/
protected function cleanArrayKeys(array $array) {
$newArray = [];
foreach($array as $key => $value) {
$newArray[str_replace("\0", '', $key)] = $value;
}
return $newArray;
}
/**
* @inheritDoc
*/
public function getPrerequisites(): array {
return [
DatabaseUpdatedPrerequisite::class
];
}
}
......@@ -28,66 +28,48 @@ namespace SGalinski\SgMail\Updates;
use TYPO3\CMS\Core\Database\ConnectionPool;
use TYPO3\CMS\Core\Utility\GeneralUtility;
use TYPO3\CMS\Install\Updates\AbstractUpdate;
use TYPO3\CMS\Install\Updates\DatabaseUpdatedPrerequisite;
use TYPO3\CMS\Install\Updates\UpgradeWizardInterface;
/**
* Makes german templates the default and former default as english templates
*/
class UpdateGermanAsDefault extends AbstractUpdate {
class UpdateGermanAsDefault implements UpgradeWizardInterface {
/**
* @var string
* The wizard identifier
*/
protected $identifier = 'tx_sgmail_update_german_as_default';
const IDENTIFIER = 'tx_sgmail_update_german_as_default';
/**
* @var string
*/
protected $title = 'Makes german templates the default and former default as english templates. WARNING: ONLY EXECUTE THIS IF IT MAKES SENSE FOR YOUR TYPO3 INSTANCE';
protected $table = 'tx_sgmail_domain_model_template';
/**
* @var \TYPO3\CMS\Extbase\Object\ObjectManager
* @return string
*/
protected $objectManager;
public function getIdentifier(): string {
return self::IDENTIFIER;
}
/**
* @var string
* @return string
*/
protected $table = 'tx_sgmail_domain_model_template';
public function getTitle(): string {
return 'Makes german templates the default and former default as english templates. WARNING: ONLY EXECUTE THIS IF IT MAKES SENSE FOR YOUR TYPO3 INSTANCE';
}
/**
* Checks whether updates are required.
*
* @param string &$description The description for the update
* @return bool Whether an update is required (TRUE) or not (FALSE)
* @return string
*/
public function checkForUpdate(&$description) {
$description = 'Update if there are german templates';
$queryBuilder = GeneralUtility::makeInstance(ConnectionPool::class)->getQueryBuilderForTable($this->table);
$queryBuilder->getRestrictions()->removeAll();
$rowCount = $queryBuilder->select('*')
->from($this->table)
->where(
$queryBuilder->expr()->eq('language', $queryBuilder->createNamedParameter('de'))
)
->execute()->rowCount();
if ($rowCount > 0) {
return TRUE;
}
return !(!FALSE || $this->isWizardDone());
public function getDescription(): string {
return '';
}
/**
* Performs the according updates.
*
* @param array &$dbQueries Queries done in this update
* @param mixed &$customMessages Custom messages
* @return bool Whether everything went smoothly or not
* @return bool
*/
public function performUpdate(array &$dbQueries, &$customMessages) {
$dbQueries = [];
public function executeUpdate(): bool {
$queryBuilder = GeneralUtility::makeInstance(ConnectionPool::class)->getQueryBuilderForTable($this->table);
$queryBuilder->getRestrictions()->removeAll();
$resultGerman = $queryBuilder->select('uid')
......@@ -96,7 +78,6 @@ class UpdateGermanAsDefault extends AbstractUpdate {
$queryBuilder->expr()->eq('language', $queryBuilder->createNamedParameter('de'))
)
->execute()->fetchAll();
$dbQueries[] = $queryBuilder->getSQL();
$resultDefault = $queryBuilder->select('uid')
->from($this->table)
......@@ -104,7 +85,6 @@ class UpdateGermanAsDefault extends AbstractUpdate {
$queryBuilder->expr()->eq('language', $queryBuilder->createNamedParameter('default'))
)
->execute()->fetchAll();
$dbQueries[] = $queryBuilder->getSQL();
/** @var array $resultGerman */
foreach ($resultGerman as $row) {
......@@ -114,7 +94,6 @@ class UpdateGermanAsDefault extends AbstractUpdate {
)
->set('language', 'default', TRUE)
->execute();
$dbQueries[] = $queryBuilder->getSQL();
}
/** @var array $resultGerman */
......@@ -125,10 +104,32 @@ class UpdateGermanAsDefault extends AbstractUpdate {
)
->set('language', 'en', TRUE)
->execute();
$dbQueries[] = $queryBuilder->getSQL();
}
$this->markWizardAsDone();
return TRUE;
}
/**
* @return bool
*/
public function updateNecessary(): bool {
$queryBuilder = GeneralUtility::makeInstance(ConnectionPool::class)->getQueryBuilderForTable($this->table);
$queryBuilder->getRestrictions()->removeAll();
$rowCount = $queryBuilder->select('*')
->from($this->table)
->where(
$queryBuilder->expr()->eq('language', $queryBuilder->createNamedParameter('de'))
)
->execute()->rowCount();
return $rowCount > 0;
}
/**
* @return array|string[]
*/
public function getPrerequisites(): array {
return [
DatabaseUpdatedPrerequisite::class
];
}
}
......@@ -30,27 +30,17 @@ use SGalinski\SgMail\Service\BackendService;
use TYPO3\CMS\Core\Database\Connection;
use TYPO3\CMS\Core\Database\ConnectionPool;
use TYPO3\CMS\Core\Utility\GeneralUtility;
use TYPO3\CMS\Install\Updates\AbstractUpdate;
use TYPO3\CMS\Install\Updates\DatabaseUpdatedPrerequisite;
use TYPO3\CMS\Install\Updates\UpgradeWizardInterface;
/**
* Fix all incorrect / deprecated language codes (be languages instead of sys languages) in the database
*/
class UpdateLanguages extends AbstractUpdate {
/**
* @var string
*/
protected $identifier = 'tx_sgmail_update_languages';
/**
* @var string
*/
protected $title = 'Find all templates & queue entries with an incorrect (be languages instead of sys languages) language code and fix it';
class UpdateLanguages implements UpgradeWizardInterface {
/**
* @var \TYPO3\CMS\Extbase\Object\ObjectManager
* The wizard identifier
*/
protected $objectManager;
const IDENTIFIER = 'tx_sgmail_update_languages';
/**
* @var array
......@@ -73,19 +63,54 @@ class UpdateLanguages extends AbstractUpdate {
];
/**
* Checks whether updates are required.
*
* @param string &$description The description for the update
* @return bool Whether an update is required (TRUE) or not (FALSE)
* @throws \InvalidArgumentException
* @return string
*/
public function getIdentifier(): string {
return self::IDENTIFIER;
}
/**
* @return string
*/
public function getTitle(): string {
return 'Find all templates & queue entries with an incorrect (be languages instead of sys languages) language code and fix it';
}
/**
* @return string
*/
public function checkForUpdate(&$description) {
public function getDescription(): string {
return '';
}
/**
* @return bool
*/
public function executeUpdate(): bool {
foreach ($this->tables as $table) {
$queryBuilder = GeneralUtility::makeInstance(ConnectionPool::class)->getQueryBuilderForTable($table);
$queryBuilder->getRestrictions()->removeAll();
foreach ($this->languageMap as $origin => $target) {
$queryBuilder->update($table)
->where(
$queryBuilder->expr()->eq('language', $queryBuilder->createNamedParameter($origin))
)
->set('language', $target, TRUE)
->execute();
}
}
return TRUE;
}
/**
* @return bool
*/
public function updateNecessary(): bool {
$upgradeNecessary = FALSE;
if (count($this->languageMap) > 0) {
$languages = BackendService::getLanguages();;
$description = 'Check all the language codes in the database';
$languages = BackendService::getLanguages();
foreach ($this->tables as $table) {
$queryBuilder = GeneralUtility::makeInstance(ConnectionPool::class)->getQueryBuilderForTable($table);
......@@ -109,34 +134,15 @@ class UpdateLanguages extends AbstractUpdate {
}
}
return !(!$upgradeNecessary || $this->isWizardDone());
return $upgradeNecessary;
}
/**
* Performs the accordant updates.
*
* @param array &$dbQueries Queries done in this update
* @param mixed &$customMessages Custom messages
* @return bool Whether everything went smoothly or not
* @return array|string[]
*/
public function performUpdate(array &$dbQueries, &$customMessages) {
$dbQueries = [];
foreach ($this->tables as $table) {
$queryBuilder = GeneralUtility::makeInstance(ConnectionPool::class)->getQueryBuilderForTable($table);
$queryBuilder->getRestrictions()->removeAll();
foreach ($this->languageMap as $origin => $target) {
$queryBuilder->update($table)
->where(
$queryBuilder->expr()->eq('language', $queryBuilder->createNamedParameter($origin))
)
->set('language', $target, TRUE)
->execute();
$dbQueries[] = $queryBuilder->getSQL();
}
}
$this->markWizardAsDone();
return TRUE;
public function getPrerequisites(): array {
return [
DatabaseUpdatedPrerequisite::class
];
}
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment