[BUGFIX] Remove hardcoded calling script in help controller 09/29809/3
authorHelmut Hummel <helmut.hummel@typo3.org>
Sat, 3 May 2014 13:10:44 +0000 (15:10 +0200)
committerAnja Leichsenring <aleichsenring@ab-softlab.de>
Sat, 3 May 2014 14:16:29 +0000 (16:16 +0200)
The Extbase help command controller has the calling
script hardcoded in several places. This may cause
confusion if the calling script was different.

Use the real script from argv[0] instead.

Resolves: #58456
Releases: 6.2
Change-Id: I622484cb75ad87078ed8b5f923f1f3b972c64124
Reviewed-on: https://review.typo3.org/29809
Reviewed-by: Wouter Wolters
Tested-by: Wouter Wolters
Reviewed-by: Anja Leichsenring
Tested-by: Anja Leichsenring
typo3/sysext/extbase/Classes/Command/HelpCommandController.php
typo3/sysext/extbase/Classes/Mvc/Cli/Request.php
typo3/sysext/extbase/Classes/Mvc/Cli/RequestBuilder.php
typo3/sysext/extbase/Classes/Mvc/Cli/RequestHandler.php

index ea45d40..5f7ca2f 100644 (file)
@@ -56,9 +56,9 @@ class HelpCommandController extends \TYPO3\CMS\Extbase\Mvc\Controller\CommandCon
         */
        public function helpStubCommand() {
                $this->outputLine('Extbase %s', array(\TYPO3\CMS\Core\Utility\ExtensionManagementUtility::getExtensionVersion('extbase')));
-               $this->outputLine('usage: ./cli_dispatch.phpsh extbase <command identifier>');
+               $this->outputLine('usage: ' . $this->request->getCallingScript() . ' <command identifier>');
                $this->outputLine();
-               $this->outputLine('See \'./cli_dispatch.phpsh extbase help\' for a list of all available commands.');
+               $this->outputLine('See \'' . $this->request->getCallingScript() . ' help\' for a list of all available commands.');
                $this->outputLine();
        }
 
@@ -91,7 +91,7 @@ class HelpCommandController extends \TYPO3\CMS\Extbase\Mvc\Controller\CommandCon
        protected function displayHelpIndex() {
                $this->buildCommandsIndex();
                $this->outputLine('Extbase %s', array(\TYPO3\CMS\Core\Utility\ExtensionManagementUtility::getExtensionVersion('extbase')));
-               $this->outputLine('usage: ./cli_dispatch.phpsh extbase <command identifier>');
+               $this->outputLine('usage: ' . $this->request->getCallingScript() . ' <command identifier>');
                $this->outputLine();
                $this->outputLine('The following commands are currently available:');
                foreach ($this->commandsByExtensionsAndControllers as $extensionKey => $commandControllers) {
@@ -107,7 +107,7 @@ class HelpCommandController extends \TYPO3\CMS\Extbase\Mvc\Controller\CommandCon
                                $this->outputLine();
                        }
                }
-               $this->outputLine('See \'./cli_dispatch.phpsh extbase help <command identifier>\' for more information about a specific command.');
+               $this->outputLine('See \'' . $this->request->getCallingScript() . ' help <command identifier>\' for more information about a specific command.');
                $this->outputLine();
        }
 
@@ -133,7 +133,7 @@ class HelpCommandController extends \TYPO3\CMS\Extbase\Mvc\Controller\CommandCon
                                $usage .= sprintf(' <%s>', strtolower(preg_replace('/([A-Z])/', ' $1', $commandArgumentDefinition->getName())));
                        }
                }
-               $usage = './cli_dispatch.phpsh extbase ' . $this->commandManager->getShortestIdentifierForCommand($command) . ($hasOptions ? ' [<options>]' : '') . $usage;
+               $usage = $this->request->getCallingScript() . ' ' . $this->commandManager->getShortestIdentifierForCommand($command) . ($hasOptions ? ' [<options>]' : '') . $usage;
                $this->outputLine();
                $this->outputLine('USAGE:');
                $this->outputLine('  ' . $usage);
@@ -200,8 +200,8 @@ class HelpCommandController extends \TYPO3\CMS\Extbase\Mvc\Controller\CommandCon
                        }
                }
                $this->outputLine('');
-               $this->outputLine('Enter "./cli_dispatch.phpsh extbase help" for an overview of all available commands');
-               $this->outputLine('or "./cli_dispatch.phpsh extbase help <command identifier>" for a detailed description of the corresponding command.');
+               $this->outputLine('Enter "' . $this->request->getCallingScript() . ' help" for an overview of all available commands');
+               $this->outputLine('or "' . $this->request->getCallingScript() . ' help <command identifier>" for a detailed description of the corresponding command.');
        }
 
        /**
index d339a7c..cb21f67 100644 (file)
@@ -83,6 +83,25 @@ class Request implements \TYPO3\CMS\Extbase\Mvc\RequestInterface {
        protected $command = NULL;
 
        /**
+        * @var string
+        */
+       protected $callingScript;
+
+       /**
+        * @param string $callingScript
+        */
+       public function setCallingScript($callingScript) {
+               $this->callingScript = $callingScript;
+       }
+
+       /**
+        * @return string
+        */
+       public function getCallingScript() {
+               return $this->callingScript;
+       }
+
+       /**
         * Sets the dispatched flag
         *
         * @param boolean $flag If this request has been dispatched
index f40fd97..010a41a 100644 (file)
@@ -63,10 +63,12 @@ class RequestBuilder implements \TYPO3\CMS\Core\SingletonInterface {
         * name (like in $argv) but start with command right away.
         *
         * @param mixed $commandLine The command line, either as a string or as an array
+        * @param string $callingScript The calling script (usually ./typo3/cli_dispatch.phpsh)
         * @return \TYPO3\CMS\Extbase\Mvc\Cli\Request The CLI request as an object
         */
-       public function build($commandLine = '') {
+       public function build($commandLine = '', $callingScript = './typo3/cli_dispatch.phpsh extbase') {
                $request = $this->objectManager->get('TYPO3\\CMS\\Extbase\\Mvc\\Cli\\Request');
+               $request->setCallingScript($callingScript);
                $request->setControllerObjectName('TYPO3\\CMS\\Extbase\\Command\\HelpCommandController');
                $rawCommandLineArguments = is_array($commandLine) ? $commandLine : explode(' ', $commandLine);
                if (count($rawCommandLineArguments) === 0) {
index fdf0a1c..6ed1a42 100644 (file)
@@ -62,7 +62,11 @@ class RequestHandler implements \TYPO3\CMS\Extbase\Mvc\RequestHandlerInterface {
         */
        public function handleRequest() {
                $commandLine = isset($_SERVER['argv']) ? $_SERVER['argv'] : array();
-               $request = $this->requestBuilder->build(array_slice($commandLine, 1));
+               $callingScript = array_shift($commandLine);
+               if ($callingScript !== $_SERVER['_']) {
+                       $callingScript = $_SERVER['_'] . ' ' . $callingScript;
+               }
+               $request = $this->requestBuilder->build($commandLine, $callingScript . ' extbase');
                /** @var $response \TYPO3\CMS\Extbase\Mvc\Cli\Response */
                $response = $this->objectManager->get('TYPO3\\CMS\\Extbase\\Mvc\\Cli\\Response');
                $this->dispatcher->dispatch($request, $response);