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

[TASK] WIP Refactoring registration process

parent 172d9084
No related branches found
No related tags found
1 merge request!11Feature security update
...@@ -798,7 +798,6 @@ class MailTemplateService { ...@@ -798,7 +798,6 @@ class MailTemplateService {
// @TODO remove this deprecated function in version 5.0.0 // @TODO remove this deprecated function in version 5.0.0
self::logDeprecation('registerExtensions'); self::logDeprecation('registerExtensions');
$registerService = GeneralUtility::makeInstance(RegisterService::class);
$extensionList = ExtensionManagementUtility::getLoadedExtensionListArray(); $extensionList = ExtensionManagementUtility::getLoadedExtensionListArray();
foreach ($extensionList as $extensionName) { foreach ($extensionList as $extensionName) {
...@@ -813,7 +812,7 @@ class MailTemplateService { ...@@ -813,7 +812,7 @@ class MailTemplateService {
if (!\file_exists($pathToRegistrationFile)) { if (!\file_exists($pathToRegistrationFile)) {
continue; continue;
} }
$registerService->register($pathToRegistrationFile); $GLOBALS['sgmail']['sg_mail'][$configFile] = $pathToRegistrationFile;
} }
} }
} }
......
...@@ -27,19 +27,17 @@ namespace SGalinski\SgMail\Service; ...@@ -27,19 +27,17 @@ namespace SGalinski\SgMail\Service;
***************************************************************/ ***************************************************************/
use TYPO3\CMS\Core\Cache\CacheManager; use TYPO3\CMS\Core\Cache\CacheManager;
use TYPO3\CMS\Core\Cache\Frontend\FrontendInterface;
use TYPO3\CMS\Core\Utility\ExtensionManagementUtility; use TYPO3\CMS\Core\Utility\ExtensionManagementUtility;
use TYPO3\CMS\Core\Utility\GeneralUtility; use TYPO3\CMS\Core\Utility\GeneralUtility;
/** /**
* Provides an api for registering your mail templates * Provides an api for registering your mail templates
*
* @package SGalinski\SgMail\Service
*/ */
class RegisterService implements \TYPO3\CMS\Core\SingletonInterface { class RegisterService implements \TYPO3\CMS\Core\SingletonInterface {
const CACHE_NAME = 'sg_mail_registerArrayCache'; const CACHE_NAME = 'sg_mail_registerArrayCache';
const CACHE_LIFETIME_IN_SECONDS = 86400; const CACHE_LIFETIME_IN_SECONDS = 86400;
const DEFAULT_TEMPLATE_PATH = 'Resources/Private/Templates/SgMail/'; const DEFAULT_TEMPLATE_PATH = 'Resources/Private/Templates/SgMail/';
const CONFIG_PATH = 'Configuration/MailTemplates/Forms';
/** /**
* contains the actual registration data * contains the actual registration data
...@@ -62,7 +60,7 @@ class RegisterService implements \TYPO3\CMS\Core\SingletonInterface { ...@@ -62,7 +60,7 @@ class RegisterService implements \TYPO3\CMS\Core\SingletonInterface {
* @api * @api
*/ */
public function register($pathToRegisterFile) { public function register($pathToRegisterFile) {
if (file_exists($pathToRegisterFile)) { if (\file_exists($pathToRegisterFile)) {
$this->registrationFiles[] = [ $this->registrationFiles[] = [
'path' => $pathToRegisterFile 'path' => $pathToRegisterFile
]; ];
...@@ -78,13 +76,12 @@ class RegisterService implements \TYPO3\CMS\Core\SingletonInterface { ...@@ -78,13 +76,12 @@ class RegisterService implements \TYPO3\CMS\Core\SingletonInterface {
* @throws \InvalidArgumentException * @throws \InvalidArgumentException
*/ */
public function getRegisterArray(): array { public function getRegisterArray(): array {
/** @var CacheManager $cacheManager */
$cacheManager = GeneralUtility::makeInstance(CacheManager::class); $cacheManager = GeneralUtility::makeInstance(CacheManager::class);
/** @var FrontendInterface $cache */
$cache = $cacheManager->getCache(self::CACHE_NAME); $cache = $cacheManager->getCache(self::CACHE_NAME);
$cacheId = md5('sg_mail'); $cacheId = \md5('sg_mail');
/** @var array entry */
if (($entry = $cache->get($cacheId)) === FALSE) { $entry = $cache->get($cacheId);
if (!$entry) {
$entry = $this->registerExtensions(); $entry = $this->registerExtensions();
if ($entry === NULL) { if ($entry === NULL) {
...@@ -99,15 +96,51 @@ class RegisterService implements \TYPO3\CMS\Core\SingletonInterface { ...@@ -99,15 +96,51 @@ class RegisterService implements \TYPO3\CMS\Core\SingletonInterface {
/** /**
* Read every registered file and create a registration entry in the registerArray if possible * Read every registered file and create a registration entry in the registerArray if possible
*
* @return array * @return array
*/ */
public function registerExtensions(): array { private function registerExtensions(): array {
// clear registerArray
$this->registerArray = []; $this->registerArray = [];
foreach ($this->registrationFiles as $registerFile) { // @TODO remove in version 5.0.0
if (\is_file($registerFile['path'])) { MailTemplateService::registerExtensions();
$configArray = (include $registerFile['path']);
foreach ($GLOBALS['sgmail'] as $extension) {
foreach ($extension as $key => $registerFile) {
if (\is_file($registerFile)) {
$configArray = (include $registerFile);
$extensionKey = $configArray['extension_key'];
$templateKey = $configArray['template_key'];
if ($extensionKey === NULL || $templateKey === NULL) {
continue;
}
$this->writeRegisterArrayEntry(
$extensionKey, $templateKey, $configArray
);
}
}
}
// @TODO read automatically created extension registrations and write the entries
// get the location where automatic registrations should be stored
$configurationLocation = $this->getRegistrationPath();
$registerFolder = GeneralUtility::getFileAbsFileName(
$configurationLocation
);
if (\is_dir($registerFolder)) {
$configFiles = GeneralUtility::getFilesInDir($registerFolder);
foreach ($configFiles as $configFile) {
$pathToRegistrationFile = $registerFolder . '/' . $configFile;
if (!\file_exists($pathToRegistrationFile)) {
continue;
}
// @TODO SECURITY CHECK WITH HASH
$configArray = (include $pathToRegistrationFile);
$extensionKey = $configArray['extension_key']; $extensionKey = $configArray['extension_key'];
$templateKey = $configArray['template_key']; $templateKey = $configArray['template_key'];
...@@ -128,8 +161,8 @@ class RegisterService implements \TYPO3\CMS\Core\SingletonInterface { ...@@ -128,8 +161,8 @@ class RegisterService implements \TYPO3\CMS\Core\SingletonInterface {
/** /**
* write a single entry into the register array * write a single entry into the register array
* *
* @param $extensionKey * @param string $extensionKey
* @param $templateKey * @param string $templateKey
* @param array $configArray * @param array $configArray
* @param bool $transformTemplateFolder * @param bool $transformTemplateFolder
* @param string $storeTemplateExtension * @param string $storeTemplateExtension
...@@ -187,5 +220,20 @@ class RegisterService implements \TYPO3\CMS\Core\SingletonInterface { ...@@ -187,5 +220,20 @@ class RegisterService implements \TYPO3\CMS\Core\SingletonInterface {
public function getRegistrationFiles(): array { public function getRegistrationFiles(): array {
return $this->registrationFiles; return $this->registrationFiles;
} }
/**
* Returns the path to the configured location where automatic mail template registrations should be
*
* @return string
*/
private function getRegistrationPath(): string {
// get typoscript settings from sg mail
/** @var TypoScriptSettingsService $typoScriptSettingsService */
$typoScriptSettingsService = GeneralUtility::makeInstance(TypoScriptSettingsService::class);
$tsSettings = $typoScriptSettingsService->getSettings(0, 'tx_sgmail');
// get the location where automatic registrations should be stored
return 'EXT:' . $tsSettings['mail']['configurationLocation'] . '/' . RegisterService::CONFIG_PATH;
}
} }
...@@ -136,13 +136,12 @@ class FormEditorController extends \TYPO3\CMS\Form\Controller\FormEditorControll ...@@ -136,13 +136,12 @@ class FormEditorController extends \TYPO3\CMS\Form\Controller\FormEditorControll
} }
// call register function in register service class // call register function in register service class
$registrationService = GeneralUtility::makeInstance(RegisterService::class); $registrationService = $this->objectManager->get(RegisterService::class);
// write the new Register.php file and add it to the registrationFiles array in the RegisterService // write the new Register.php file and add it to the registrationFiles array in the RegisterService
$registerFilePath = $this->writeRegisterFile($renderables, $extensionKey, $templateKey); $this->writeRegisterFile($renderables, $extensionKey, $templateKey);
$registrationService->register($registerFilePath); $registrationService->getRegisterArray();
$registrationService->registerExtensions();
// clear caches
$this->clearCaches(); $this->clearCaches();
} }
...@@ -161,7 +160,7 @@ class FormEditorController extends \TYPO3\CMS\Form\Controller\FormEditorControll ...@@ -161,7 +160,7 @@ class FormEditorController extends \TYPO3\CMS\Form\Controller\FormEditorControll
$registerFolder = GeneralUtility::getFileAbsFileName( $registerFolder = GeneralUtility::getFileAbsFileName(
$configurationLocation $configurationLocation
); );
// create folder
GeneralUtility::mkdir($registerFolder); GeneralUtility::mkdir($registerFolder);
$hashPrefix = md5($GLOBALS['TYPO3_CONF_VARS']['SYS']['encryptionKey'] . '|' . $templateKey . '.php'); $hashPrefix = md5($GLOBALS['TYPO3_CONF_VARS']['SYS']['encryptionKey'] . '|' . $templateKey . '.php');
...@@ -226,6 +225,6 @@ class FormEditorController extends \TYPO3\CMS\Form\Controller\FormEditorControll ...@@ -226,6 +225,6 @@ class FormEditorController extends \TYPO3\CMS\Form\Controller\FormEditorControll
$tsSettings = $typoScriptSettingsService->getSettings(0, 'tx_sgmail'); $tsSettings = $typoScriptSettingsService->getSettings(0, 'tx_sgmail');
// get the location where automatic registrations should be stored // get the location where automatic registrations should be stored
return 'EXT:' . $tsSettings['mail']['configurationLocation'] . '/' . MailTemplateService::CONFIG_PATH; return 'EXT:' . $tsSettings['mail']['configurationLocation'] . '/' . RegisterService::CONFIG_PATH;
} }
} }
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