[BUGFIX] Initialize extension name in command requests 83/23883/8
authorAlexander Stehlik <alexander.stehlik@googlemail.com>
Wed, 25 Sep 2013 06:40:37 +0000 (08:40 +0200)
committerAnja Leichsenring <aleichsenring@ab-softlab.de>
Sat, 28 Sep 2013 13:20:22 +0000 (15:20 +0200)
This patch initializes the extension name in the configuration manager
as soon as it is available during an Extbase command line request.

Resolves: #51329
Releases: 6.2, 6.1, 6.0
Change-Id: I73b0f0e7a0b20e1773c9eb92f0d2175416ce2bb1
Reviewed-on: https://review.typo3.org/23883
Reviewed-by: Wouter Wolters
Tested-by: Wouter Wolters
Reviewed-by: Anja Leichsenring
Tested-by: Anja Leichsenring
typo3/sysext/extbase/Classes/Mvc/Cli/Command.php
typo3/sysext/extbase/Classes/Mvc/Cli/RequestBuilder.php
typo3/sysext/extbase/Tests/Unit/Mvc/Cli/RequestBuilderTest.php

index 52867be..e50b8ec 100644 (file)
@@ -61,6 +61,13 @@ class Command {
        protected $commandMethodReflection;
 
        /**
+        * Name of the extension to which this command belongs
+        *
+        * @var string
+        */
+       protected $extensionName;
+
+       /**
         * Reflection service
         *
         * @var \TYPO3\CMS\Extbase\Reflection\ReflectionService
@@ -88,7 +95,8 @@ class Command {
                if (count($classNameParts) !== 4 || strpos($classNameParts[3], 'CommandController') === FALSE) {
                        throw new \InvalidArgumentException('Invalid controller class name "' . $controllerClassName . '"', 1305100019);
                }
-               $extensionKey = \TYPO3\CMS\Core\Utility\GeneralUtility::camelCaseToLowerCaseUnderscored($classNameParts[1]);
+               $this->extensionName = $classNameParts[1];
+               $extensionKey = \TYPO3\CMS\Core\Utility\GeneralUtility::camelCaseToLowerCaseUnderscored($this->extensionName);
                $this->commandIdentifier = strtolower($extensionKey . ':' . substr($classNameParts[3], 0, -17) . ':' . $controllerCommandName);
        }
 
@@ -116,6 +124,15 @@ class Command {
        }
 
        /**
+        * Returns the name of the extension to which this command belongs
+        *
+        * @return string
+        */
+       public function getExtensionName() {
+               return $this->extensionName;
+       }
+
+       /**
         * Returns a short description of this command
         *
         * @return string A short description
index b3528bf..e31f437 100644 (file)
@@ -50,6 +50,12 @@ class RequestBuilder {
        protected $commandManager;
 
        /**
+        * @var \TYPO3\CMS\Extbase\Configuration\ConfigurationManagerInterface
+        * @inject
+        */
+       protected $configurationManager;
+
+       /**
         * Builds a CLI request object from a command line.
         *
         * The given command line may be a string (e.g. "myextension:foo do-that-thing --force") or
@@ -70,6 +76,7 @@ class RequestBuilder {
                $commandIdentifier = trim(array_shift($rawCommandLineArguments));
                try {
                        $command = $this->commandManager->getCommandByIdentifier($commandIdentifier);
+                       $this->configurationManager->setConfiguration(array('extensionName' => $command->getExtensionName()));
                } catch (\TYPO3\CMS\Extbase\Mvc\Exception\CommandException $exception) {
                        $request->setArgument('exception', $exception);
                        $request->setControllerCommandName('error');
index bb17a1b..4c91682 100644 (file)
@@ -56,6 +56,11 @@ class RequestBuilderTest extends \TYPO3\CMS\Extbase\Tests\Unit\BaseTestCase {
        protected $mockReflectionService;
 
        /**
+        * @var \TYPO3\CMS\Extbase\Configuration\ConfigurationManagerInterface|\PHPUnit_Framework_MockObject_MockObject
+        */
+       protected $mockConfigurationManager;
+
+       /**
         * Sets up this test case
         *
         * @author Robert Lemke <robert@typo3.org>
@@ -70,10 +75,12 @@ class RequestBuilderTest extends \TYPO3\CMS\Extbase\Tests\Unit\BaseTestCase {
                $this->mockCommandManager = $this->getMock('TYPO3\\CMS\\Extbase\\Mvc\\Cli\\CommandManager');
                $this->mockCommandManager->expects($this->any())->method('getCommandByIdentifier')->with('some_extension_name:default:list')->will($this->returnValue($this->mockCommand));
                $this->mockReflectionService = $this->getMock('TYPO3\\CMS\\Extbase\\Reflection\\ReflectionService');
+               $this->mockConfigurationManager = $this->getMock('TYPO3\\CMS\\Extbase\\Configuration\\ConfigurationManagerInterface');
                $this->requestBuilder = $this->getAccessibleMock('TYPO3\CMS\Extbase\Mvc\Cli\RequestBuilder', array('dummy'));
                $this->requestBuilder->_set('objectManager', $this->mockObjectManager);
                $this->requestBuilder->_set('reflectionService', $this->mockReflectionService);
                $this->requestBuilder->_set('commandManager', $this->mockCommandManager);
+               $this->requestBuilder->_set('configurationManager', $this->mockConfigurationManager);
        }
 
        /**