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

[BUGFIX] Fix wrong registration and deprecation view

parent 096dbca5
No related branches found
No related tags found
1 merge request!11Feature security update
...@@ -26,7 +26,6 @@ namespace SGalinski\SgMail\Controller; ...@@ -26,7 +26,6 @@ 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;
...@@ -368,35 +367,36 @@ class MailController extends ActionController { ...@@ -368,35 +367,36 @@ class MailController extends ActionController {
* @return array * @return array
*/ */
private function getDeprecationWarnings(): array { private function getDeprecationWarnings(): array {
$deprecationWarnings = []; debug($GLOBALS['sg_mail']);
$deprecationWarnings = [];
$extensionList = ExtensionManagementUtility::getLoadedExtensionListArray(); $extensionList = ExtensionManagementUtility::getLoadedExtensionListArray();
foreach ($extensionList as $extensionName) { foreach ($extensionList as $extensionName) {
$extensionConfigDirectory = ExtensionManagementUtility::extPath($extensionName); $extensionConfigDirectory = ExtensionManagementUtility::extPath($extensionName) .
$extensionConfigDirectory .= MailTemplateService::CONFIG_PATH; MailTemplateService::CONFIG_PATH;
if (!\is_dir($extensionConfigDirectory)) {
if (\is_dir($extensionConfigDirectory)) { continue;
$configFiles = GeneralUtility::getFilesInDir($extensionConfigDirectory); }
foreach ($configFiles as $configFile) {
$pathToRegistrationFile = $extensionConfigDirectory . '/' . $configFile;
if (!\file_exists($pathToRegistrationFile)) { $configFiles = GeneralUtility::getFilesInDir($extensionConfigDirectory);
continue; foreach ($configFiles as $configFile) {
} $pathToRegistrationFile = $extensionConfigDirectory . '/' . $configFile;
if (!\is_file($pathToRegistrationFile)) {
continue;
}
$registrationArray = include $pathToRegistrationFile; // already registered in the new way?
$templateKey = $registrationArray['template_key']; if (!isset($GLOBALS['sg_mail'][$extensionName][$configFile])) {
$extensionKey = $registrationArray['extension_key']; continue;
}
// provide code example on how to register correctly $registrationArray = include $pathToRegistrationFile;
$code = '$GLOBALS[\'sg_mail\'][\'' . $extensionKey . '\'][\'' $templateKey = $registrationArray['template_key'];
. $templateKey
. '\'] = \'EXT:' . $extensionName . '/' . MailTemplateService::CONFIG_PATH . '/' . $configFile . '\';';
$deprecationWarnings[] = [ // provide code example on how to register correctly
'code' => $code $code = '$GLOBALS[\'sg_mail\'][\'' . $extensionName . '\'][\'' . $templateKey . '\'] = \'EXT:' .
]; $extensionName . '/' . MailTemplateService::CONFIG_PATH . '/' . $configFile . '\';';
} $deprecationWarnings[] = ['code' => $code];
} }
} }
......
...@@ -812,27 +812,35 @@ class MailTemplateService { ...@@ -812,27 +812,35 @@ class MailTemplateService {
self::logDeprecation('registerExtensions'); self::logDeprecation('registerExtensions');
$extensionList = ExtensionManagementUtility::getLoadedExtensionListArray(); $extensionList = ExtensionManagementUtility::getLoadedExtensionListArray();
foreach ($extensionList as $extensionName) { foreach ($extensionList as $extensionName) {
$extensionConfigDirectory = ExtensionManagementUtility::extPath($extensionName); $extensionConfigDirectory = ExtensionManagementUtility::extPath($extensionName);
$extensionConfigDirectory .= self::CONFIG_PATH; $extensionConfigDirectory .= self::CONFIG_PATH;
if (\is_dir($extensionConfigDirectory)) { if (!\is_dir($extensionConfigDirectory)) {
$configFiles = GeneralUtility::getFilesInDir($extensionConfigDirectory); continue;
foreach ($configFiles as $configFile) { }
$pathToRegistrationFile = $extensionConfigDirectory . '/' . $configFile;
if (!\file_exists($pathToRegistrationFile)) { $configFiles = GeneralUtility::getFilesInDir($extensionConfigDirectory);
continue; foreach ($configFiles as $configFile) {
} $pathToRegistrationFile = $extensionConfigDirectory . '/' . $configFile;
$GLOBALS['sg_mail']['sg_mail'][$configFile] = $pathToRegistrationFile; if (!\is_file($pathToRegistrationFile)) {
continue;
} }
// already registered in the new way?
$configFileTest = str_replace('.php', '', $configFile);
$configFileTest = GeneralUtility::camelCaseToLowerCaseUnderscored($configFileTest);
if (isset($GLOBALS['sg_mail'][$extensionName][$configFileTest])) {
continue;
}
$GLOBALS['sg_mail'][$extensionName][$configFile] = $pathToRegistrationFile;
} }
} }
} }
/** /**
* Checks if a template is blacklisted for a given siterootId * Checks if a template is blacklisted for a given siteroot id
* *
* @param string $extensionKey * @param string $extensionKey
* @param string $templateName * @param string $templateName
......
...@@ -84,43 +84,32 @@ class RegisterService implements \TYPO3\CMS\Core\SingletonInterface { ...@@ -84,43 +84,32 @@ class RegisterService implements \TYPO3\CMS\Core\SingletonInterface {
private function registerExtensions(): array { private function registerExtensions(): array {
$this->registerArray = []; $this->registerArray = [];
$extensionConfiguration = unserialize($GLOBALS['TYPO3_CONF_VARS']['EXT']['extConf']['sg_mail'], ['array']);
// @TODO remove in version 5.0.0
if (((int) $extensionConfiguration['supportOldRegistrations']) === 0) {
MailTemplateService::registerExtensions();
}
foreach ($GLOBALS['sg_mail'] as $extension) { foreach ($GLOBALS['sg_mail'] as $extension) {
foreach ($extension as $key => $registerFile) { foreach ($extension as $key => $registerFile) {
if (\is_file($registerFile)) { $registerFile = GeneralUtility::getFileAbsFileName($registerFile);
$configArray = (include $registerFile); if (!\is_file($registerFile)) {
continue;
$extensionKey = $configArray['extension_key']; }
$templateKey = $configArray['template_key'];
if ($extensionKey === NULL || $templateKey === NULL) {
continue;
}
$this->writeRegisterArrayEntry( $configArray = (include $registerFile);
$extensionKey, $templateKey, $configArray $extensionKey = $configArray['extension_key'];
); $templateKey = $configArray['template_key'];
if ($extensionKey === NULL || $templateKey === NULL) {
continue;
} }
$this->writeRegisterArrayEntry($extensionKey, $templateKey, $configArray);
} }
} }
// read automatically created extension registrations and write the entries // read automatically created extension registrations and write the entries
$configurationLocation = $this->getRegistrationPath(); $configurationLocation = $this->getRegistrationPath();
$registerFolder = GeneralUtility::getFileAbsFileName( $registerFolder = GeneralUtility::getFileAbsFileName($configurationLocation);
$configurationLocation
);
if (\is_dir($registerFolder)) { if (\is_dir($registerFolder)) {
$configFiles = GeneralUtility::getFilesInDir($registerFolder); $configFiles = GeneralUtility::getFilesInDir($registerFolder);
foreach ($configFiles as $configFile) { foreach ($configFiles as $configFile) {
$pathToRegistrationFile = $registerFolder . '/' . $configFile; $pathToRegistrationFile = $registerFolder . '/' . $configFile;
if (!\is_file($pathToRegistrationFile)) {
if (!\file_exists($pathToRegistrationFile)) {
continue; continue;
} }
...@@ -129,26 +118,28 @@ class RegisterService implements \TYPO3\CMS\Core\SingletonInterface { ...@@ -129,26 +118,28 @@ class RegisterService implements \TYPO3\CMS\Core\SingletonInterface {
$filename = $pathAsArray[\count($pathAsArray) - 1]; $filename = $pathAsArray[\count($pathAsArray) - 1];
$filenameWithoutHash = GeneralUtility::trimExplode('_', $filename)[1]; $filenameWithoutHash = GeneralUtility::trimExplode('_', $filename)[1];
$hash = md5($GLOBALS['TYPO3_CONF_VARS']['SYS']['encryptionKey'] . '|' . $filenameWithoutHash); $hash = md5($GLOBALS['TYPO3_CONF_VARS']['SYS']['encryptionKey'] . '|' . $filenameWithoutHash);
// if the filename doesnt start with the hash value, ignore it // if the filename doesn't start with the hash value, ignore it
if (strpos($filename, $hash) !== 0) { if (strpos($filename, $hash) !== 0) {
continue; continue;
} }
$configArray = (include $pathToRegistrationFile); $configArray = (include $pathToRegistrationFile);
$extensionKey = $configArray['extension_key']; $extensionKey = $configArray['extension_key'];
$templateKey = $configArray['template_key']; $templateKey = $configArray['template_key'];
if ($extensionKey === NULL || $templateKey === NULL) { if ($extensionKey === NULL || $templateKey === NULL) {
continue; continue;
} }
$this->writeRegisterArrayEntry( $this->writeRegisterArrayEntry($extensionKey, $templateKey, $configArray);
$extensionKey, $templateKey, $configArray
);
} }
} }
// @TODO remove in version 5.0.0
$extensionConfiguration = unserialize($GLOBALS['TYPO3_CONF_VARS']['EXT']['extConf']['sg_mail'], ['array']);
if (((int) $extensionConfiguration['supportOldRegistrations']) === 0) {
MailTemplateService::registerExtensions();
}
return $this->registerArray; return $this->registerArray;
} }
...@@ -184,8 +175,8 @@ class RegisterService implements \TYPO3\CMS\Core\SingletonInterface { ...@@ -184,8 +175,8 @@ class RegisterService implements \TYPO3\CMS\Core\SingletonInterface {
} }
$templateDirectory .= '/'; $templateDirectory .= '/';
$templatePath = ExtensionManagementUtility::extPath($storeTemplateExtension) . self::DEFAULT_TEMPLATE_PATH $templatePath = ExtensionManagementUtility::extPath($storeTemplateExtension) .
. $templateDirectory; self::DEFAULT_TEMPLATE_PATH . $templateDirectory;
if ($configArray['template_path']) { if ($configArray['template_path']) {
$templatePath = $configArray[$templateKey]; $templatePath = $configArray[$templateKey];
......
...@@ -67,4 +67,3 @@ if (!isset($TYPO3_CONF_VARS['SYS']['caching']['cacheConfigurations'][$cacheName] ...@@ -67,4 +67,3 @@ 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