[BUGFIX] Initialize extension name in command requests 24/24124/2
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:40:02 +0000 (15:40 +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/24124
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 882db52..143dc54 100644 (file)
@@ -60,6 +60,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
@@ -86,7 +93,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);
        }
 
@@ -129,6 +137,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 31631fc..06cb83f 100644 (file)
@@ -47,6 +47,11 @@ class RequestBuilder {
        protected $commandManager;
 
        /**
+        * @var \TYPO3\CMS\Extbase\Configuration\ConfigurationManagerInterface
+        */
+       protected $configurationManager;
+
+       /**
         * @param \TYPO3\CMS\Extbase\Object\ObjectManagerInterface $objectManager
         * @return void
         */
@@ -71,6 +76,14 @@ class RequestBuilder {
        }
 
        /**
+        * @param \TYPO3\CMS\Extbase\Configuration\ConfigurationManagerInterface $configurationManager
+        * @return void
+        */
+       public function injectConfigurationManager(\TYPO3\CMS\Extbase\Configuration\ConfigurationManagerInterface $configurationManager) {
+               $this->configurationManager = $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
@@ -91,6 +104,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 f17dcdd..2f12311 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,13 @@ 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->requestBuilder = new \TYPO3\CMS\Extbase\Mvc\Cli\RequestBuilder();
+               $this->mockConfigurationManager = $this->getMock('TYPO3\\CMS\\Extbase\\Configuration\\ConfigurationManagerInterface');
+
+               $this->requestBuilder = $this->getAccessibleMock('TYPO3\CMS\Extbase\Mvc\Cli\RequestBuilder', array('dummy'));
                $this->requestBuilder->injectObjectManager($this->mockObjectManager);
                $this->requestBuilder->injectReflectionService($this->mockReflectionService);
                $this->requestBuilder->injectCommandManager($this->mockCommandManager);
+               $this->requestBuilder->injectConfigurationManager($this->mockConfigurationManager);
        }
 
        /**