[BUGFIX] Respect access method with updater in EM 85/38485/5
authorJigal van Hemert <jigal.van.hemert@typo3.org>
Sat, 4 Apr 2015 19:46:24 +0000 (21:46 +0200)
committerMarkus Klein <klein.t3@reelworx.at>
Thu, 9 Apr 2015 22:49:37 +0000 (00:49 +0200)
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 <xavier@typo3.org>
Tested-by: Xavier Perseguers <xavier@typo3.org>
Reviewed-by: Markus Klein <klein.t3@reelworx.at>
Tested-by: Markus Klein <klein.t3@reelworx.at>
typo3/sysext/extensionmanager/Classes/Utility/UpdateScriptUtility.php

index 79eb1d0..70f6e46 100644 (file)
@@ -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 . '<?php ');
+                       if (!class_exists($className)) {
+                               throw new \TYPO3\CMS\Extensionmanager\Exception\ExtensionManagerException(
+                                       sprintf('class.ext_update.php of extension "%s" did not declare ext_update class', $extensionKey),
+                                       1428176468
+                               );
+                       }
+                       $updater = GeneralUtility::makeInstance($className);
+                       $updateScriptCanBeCalled = $updater->access();
                }
-               return $updateScriptFileExists;
+               return $updateScriptCanBeCalled;
        }
 
        /**