Skip to content
Snippets Groups Projects
Commit 71d7b76b authored by Torsten Oppermann's avatar Torsten Oppermann
Browse files

[TASK] review

parent ceb5b748
No related branches found
No related tags found
1 merge request!11Feature security update
...@@ -28,6 +28,7 @@ namespace SGalinski\SgMail\Controller; ...@@ -28,6 +28,7 @@ namespace SGalinski\SgMail\Controller;
use SGalinski\SgMail\Service\BackendService; use SGalinski\SgMail\Service\BackendService;
use SGalinski\SgMail\Service\MailTemplateService; use SGalinski\SgMail\Service\MailTemplateService;
use SGalinski\SgMail\Service\RegisterService;
use SGalinski\SgMail\Service\TypoScriptSettingsService; use SGalinski\SgMail\Service\TypoScriptSettingsService;
use SGalinski\SgMail\Session\PhpSession; use SGalinski\SgMail\Session\PhpSession;
use TYPO3\CMS\Backend\Template\Components\DocHeaderComponent; use TYPO3\CMS\Backend\Template\Components\DocHeaderComponent;
...@@ -143,10 +144,13 @@ class ConfigurationController extends ActionController { ...@@ -143,10 +144,13 @@ class ConfigurationController extends ActionController {
]; ];
} }
$this->writeRegisterFile($templateName, self::DEFAULT_EXTENSION_KEY, $markers, $subject, $description); $registerService = $this->objectManager->get(RegisterService::class);
$registerService->writeRegisterFile(
$templateName, self::DEFAULT_EXTENSION_KEY, $markers, $subject, $description
);
MailTemplateService::registerExtensions(); MailTemplateService::registerExtensions();
$this->clearCaches(); $registerService->clearCaches();
// store selected template & extension key in the session // store selected template & extension key in the session
if (!($this->session instanceof PhpSession)) { if (!($this->session instanceof PhpSession)) {
...@@ -163,86 +167,4 @@ class ConfigurationController extends ActionController { ...@@ -163,86 +167,4 @@ class ConfigurationController extends ActionController {
['message' => LocalizationUtility::translate('backend.create_message', 'sg_mail')] ['message' => LocalizationUtility::translate('backend.create_message', 'sg_mail')]
); );
} }
/**
* Write the mail registration file
*
* @TODO move this to the register service class when security update is merged. refactor in FormEditorController xclass as well
*
* @param string $templateKey
* @param string $extensionKey
* @param array $markers
* @param string $subject
* @param string $description
*/
private function writeRegisterFile($templateKey, $extensionKey, $markers, $subject, $description) {
// get the location where registrations should be stored
$configurationLocation = $this->getRegistrationPath();
$registerFolder = GeneralUtility::getFileAbsFileName(
$configurationLocation
);
// create folder
GeneralUtility::mkdir($registerFolder);
$registerFile = GeneralUtility::getFileAbsFileName(
$registerFolder . '/' . $templateKey . '.php'
);
// build the register array
$newRegisterArray = [
'extension_key' => $extensionKey,
'template_key' => $templateKey,
'description' => $description,
'subject' => $subject,
'markers' => []
];
// add the markers for this template
foreach ($markers as $marker) {
$markerName = $marker['identifier'];
$newRegisterArray['markers'][] = [
'marker' => $markerName,
'type' => MailTemplateService::MARKER_TYPE_STRING,
'value' => $marker['value'],
'description' => $marker['description']
];
}
file_put_contents($registerFile, '<?php return ' . var_export($newRegisterArray, TRUE) . ';');
}
/**
* Returns the path to the configured location where automatic mail template registrations should be
*
* @TODO move this to the register service class when security update is merged. refactor in FormEditorController xclass as well
*
* @return string
*/
private function getRegistrationPath(): string {
// get typoscript settings from sg mail
/** @var TypoScriptSettingsService $typoScriptSettingsService */
$typoScriptSettingsService = $this->objectManager->get(TypoScriptSettingsService::class);
$tsSettings = $typoScriptSettingsService->getSettings(0, 'tx_sgmail');
// get the location where automatic registrations should be stored
return 'EXT:' . $tsSettings['mail']['configurationLocation'] . '/' . MailTemplateService::CONFIG_PATH;
}
/**
* Clear the sgmail register cache
*
* @TODO move this to the register service class when security update is merged. refactor in FormEditorController xclass as well
*
* @throws \TYPO3\CMS\Core\Cache\Exception\NoSuchCacheException
*/
private function clearCaches() {
$objectManager = GeneralUtility::makeInstance(ObjectManager::class);
$cacheManager = $objectManager->get(CacheManager::class);
/** @var FrontendInterface $cache */
$cache = $cacheManager->getCache(MailTemplateService::CACHE_NAME);
/** @var FrontendInterface $cache */
$cache->flush();
}
} }
...@@ -26,6 +26,7 @@ namespace SGalinski\SgMail\Controller; ...@@ -26,6 +26,7 @@ namespace SGalinski\SgMail\Controller;
* This copyright notice MUST APPEAR in all copies of the script! * This copyright notice MUST APPEAR in all copies of the script!
***************************************************************/ ***************************************************************/
use function Composer\Autoload\includeFile;
use SGalinski\SgMail\Domain\Model\Template; use SGalinski\SgMail\Domain\Model\Template;
use SGalinski\SgMail\Service\BackendService; use SGalinski\SgMail\Service\BackendService;
use SGalinski\SgMail\Service\MailTemplateService; use SGalinski\SgMail\Service\MailTemplateService;
...@@ -175,7 +176,9 @@ class MailController extends ActionController { ...@@ -175,7 +176,9 @@ class MailController extends ActionController {
$templateFromFile->setSubject($subject); $templateFromFile->setSubject($subject);
$subject = $registerArray[$parameters['selectedExtension']][$parameters['selectedTemplate']]['subject']; $subject = $registerArray[$parameters['selectedExtension']][$parameters['selectedTemplate']]['subject'];
if ($registerArray[$parameters['selectedExtension']][$parameters['selectedTemplate']]['templateContent']) { if ($registerArray[$parameters['selectedExtension']][$parameters['selectedTemplate']]['templateContent']) {
$templateFromFile->setContent($registerArray[$parameters['selectedExtension']][$parameters['selectedTemplate']]['templateContent']); $templateFromFile->setContent(
$registerArray[$parameters['selectedExtension']][$parameters['selectedTemplate']]['templateContent']
);
} elseif (file_exists($fallbackTemplateFile)) { } elseif (file_exists($fallbackTemplateFile)) {
$templateFromFile->setContent(file_get_contents($fallbackTemplateFile)); $templateFromFile->setContent(file_get_contents($fallbackTemplateFile));
} }
...@@ -381,10 +384,15 @@ class MailController extends ActionController { ...@@ -381,10 +384,15 @@ class MailController extends ActionController {
continue; continue;
} }
$registrationArray = include $pathToRegistrationFile;
$templateKey = $registrationArray['template_key'];
$extensionKey = $registrationArray['extension_key'];
// provide code example on how to register correctly // provide code example on how to register correctly
$code = '$GLOBALS[\'sg_mail\'][\'' . $extensionName . '\'][\'' $code = '$GLOBALS[\'sg_mail\'][\'' . $extensionKey . '\'][\''
. \str_replace('.php', '', $configFile) . $templateKey
. '\'] = \'EXT:' . $extensionName . '/Configuration/SgMail/' . $configFile . '\';'; . '\'] = \'EXT:' . $extensionName . '/' . MailTemplateService::CONFIG_PATH . '/' . $configFile . '\';';
$deprecationWarnings[] = [ $deprecationWarnings[] = [
'code' => $code 'code' => $code
]; ];
......
...@@ -227,7 +227,7 @@ class RegisterService implements \TYPO3\CMS\Core\SingletonInterface { ...@@ -227,7 +227,7 @@ class RegisterService implements \TYPO3\CMS\Core\SingletonInterface {
* *
* @throws \TYPO3\CMS\Core\Cache\Exception\NoSuchCacheException * @throws \TYPO3\CMS\Core\Cache\Exception\NoSuchCacheException
*/ */
private function clearCaches() { public function clearCaches() {
$objectManager = GeneralUtility::makeInstance(ObjectManager::class); $objectManager = GeneralUtility::makeInstance(ObjectManager::class);
$cacheManager = $objectManager->get(CacheManager::class); $cacheManager = $objectManager->get(CacheManager::class);
...@@ -236,5 +236,51 @@ class RegisterService implements \TYPO3\CMS\Core\SingletonInterface { ...@@ -236,5 +236,51 @@ class RegisterService implements \TYPO3\CMS\Core\SingletonInterface {
/** @var FrontendInterface $cache */ /** @var FrontendInterface $cache */
$cache->flush(); $cache->flush();
} }
/**
* Write the mail registration file
*
* @param string $templateKey
* @param string $extensionKey
* @param array $markers
* @param string $subject
* @param string $description
*/
public function writeRegisterFile($templateKey, $extensionKey, $markers, $subject, $description) {
// get the location where registrations should be stored
$configurationLocation = $this->getRegistrationPath();
$registerFolder = GeneralUtility::getFileAbsFileName(
$configurationLocation
);
// create folder
GeneralUtility::mkdir($registerFolder);
$registerFile = GeneralUtility::getFileAbsFileName(
$registerFolder . '/' . $templateKey . '.php'
);
// build the register array
$newRegisterArray = [
'extension_key' => $extensionKey,
'template_key' => $templateKey,
'description' => $description,
'subject' => $subject,
'markers' => []
];
// add the markers for this template
foreach ($markers as $marker) {
$markerName = $marker['identifier'];
$newRegisterArray['markers'][] = [
'marker' => $markerName,
'type' => MailTemplateService::MARKER_TYPE_STRING,
'value' => $marker['value'],
'description' => $marker['description']
];
}
file_put_contents($registerFile, '<?php return ' . var_export($newRegisterArray, TRUE) . ';');
}
} }
...@@ -67,3 +67,4 @@ if (!isset($TYPO3_CONF_VARS['SYS']['caching']['cacheConfigurations'][$cacheName] ...@@ -67,3 +67,4 @@ if (!isset($TYPO3_CONF_VARS['SYS']['caching']['cacheConfigurations'][$cacheName]
'citypower' 'citypower'
]; ];
} }
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