From 708c2d57fb69fd4f4c4f71e73e908058be32dce5 Mon Sep 17 00:00:00 2001 From: Jigal van Hemert Date: Sat, 4 Apr 2015 21:46:24 +0200 Subject: [PATCH] [BUGFIX] Respect access method with updater in EM The Extension Manager checks the access method in each update script when rendering the icon in the list of extensions. Resolves: #66263 Releases: master, 6.2 Change-Id: Ibafae8943e710d3f762d77160e8e6864ff9c47f2 Reviewed-on: http://review.typo3.org/38485 Reviewed-by: Xavier Perseguers Tested-by: Xavier Perseguers Reviewed-by: Markus Klein Tested-by: Markus Klein --- .../Classes/Utility/UpdateScriptUtility.php | 33 ++++++++++++++++--- 1 file changed, 29 insertions(+), 4 deletions(-) diff --git a/typo3/sysext/extensionmanager/Classes/Utility/UpdateScriptUtility.php b/typo3/sysext/extensionmanager/Classes/Utility/UpdateScriptUtility.php index 79eb1d0353b6..70f6e46562f5 100644 --- a/typo3/sysext/extensionmanager/Classes/Utility/UpdateScriptUtility.php +++ b/typo3/sysext/extensionmanager/Classes/Utility/UpdateScriptUtility.php @@ -13,6 +13,7 @@ namespace TYPO3\CMS\Extensionmanager\Utility; * * The TYPO3 project - inspiring people to share! */ +use TYPO3\CMS\Core\Utility\GeneralUtility; /** * Utility to find and execute class.ext_update.php scripts of extensions @@ -87,13 +88,37 @@ class UpdateScriptUtility { * * @param string $extensionKey Extension key * @return bool True, if there is some update script + * @throws \TYPO3\CMS\Extensionmanager\Exception\ExtensionManagerException */ public function checkUpdateScriptExists($extensionKey) { - $updateScriptFileExists = FALSE; - if (file_exists($this->getUpdateFileLocation($extensionKey))) { - $updateScriptFileExists = TRUE; + $updateScriptCanBeCalled = FALSE; + $updateScript = $this->getUpdateFileLocation($extensionKey); + if (file_exists($updateScript)) { + // get script contents + $scriptSourceCode = GeneralUtility::getUrl($updateScript); + // check if it has a namespace + if (!preg_match('/<\?php.*namespace\s+([^;]+);.*class/is', $scriptSourceCode, $matches)) { + // if no, rename the class with a unique name + $className = uniqid('ext_update'); + $scriptSourceCode = preg_replace('/^\s*class\s+ext_update\s+/m', 'class ' . $className . ' ', $scriptSourceCode); + } else { + $className = $matches[1] . '\ext_update'; + } + // load class and call access function + if (!preg_match('/\?>$/is', $scriptSourceCode)) { + $scriptSourceCode .= '?>'; + } + eval('?>' . $scriptSourceCode . 'access(); } - return $updateScriptFileExists; + return $updateScriptCanBeCalled; } /** -- 2.20.1