diff --git a/typo3/sysext/core/Documentation/Changelog/master/Breaking-71521-PropertyUserAuthenticationRemovedFromCommandController.rst b/typo3/sysext/core/Documentation/Changelog/master/Breaking-71521-PropertyUserAuthenticationRemovedFromCommandController.rst new file mode 100644 index 0000000000000000000000000000000000000000..ce1c8a80c1e26ab94637c98006046baff028f403 --- /dev/null +++ b/typo3/sysext/core/Documentation/Changelog/master/Breaking-71521-PropertyUserAuthenticationRemovedFromCommandController.rst @@ -0,0 +1,22 @@ +============================================================================= +Breaking: #71521 - Property userAuthentication removed from CommandController +============================================================================= + +Description +=========== + +The property ``$userAuthentication`` was removed from the Extbase ``CommandController`` class and +has been migrated to the newly introduced ``getBackendUserAuthentication()`` method. + + +Impact +====== + +All command controllers deriving from ``CommandController`` with see a fatal error when accessing +properties or methods of the removed ``$userAuthentication`` property. + + +Migration +========= + +Use the newly introduced ``getBackendUserAuthentication()`` method. diff --git a/typo3/sysext/core/Documentation/Changelog/master/Important-71521-InternalChangesInCommandController.rst b/typo3/sysext/core/Documentation/Changelog/master/Important-71521-InternalChangesInCommandController.rst new file mode 100644 index 0000000000000000000000000000000000000000..13aec2620eeb26aaf8ef976856645ed3fc06f2f1 --- /dev/null +++ b/typo3/sysext/core/Documentation/Changelog/master/Important-71521-InternalChangesInCommandController.rst @@ -0,0 +1,10 @@ +========================================================= +Important: #71521 - Internal changes in CommandController +========================================================= + +Description +=========== + +The ``CommandController::processRequest()`` method has been changed to initialize arguments and output. + +If this method was overridden without calling the parent method, these changes must be copied to prevent errors. diff --git a/typo3/sysext/extbase/Classes/Mvc/Controller/CommandController.php b/typo3/sysext/extbase/Classes/Mvc/Controller/CommandController.php index 6feaa99a00461b24acd75f71b2bbb2b051eb9362..df710aa65b1d38f6e0c3441d525fcb4206d44749 100644 --- a/typo3/sysext/extbase/Classes/Mvc/Controller/CommandController.php +++ b/typo3/sysext/extbase/Classes/Mvc/Controller/CommandController.php @@ -15,16 +15,20 @@ namespace TYPO3\CMS\Extbase\Mvc\Controller; */ use TYPO3\CMS\Core\Authentication\AbstractUserAuthentication; +use TYPO3\CMS\Core\Authentication\BackendUserAuthentication; use TYPO3\CMS\Extbase\Mvc\Cli\CommandArgumentDefinition; use TYPO3\CMS\Extbase\Mvc\Cli\ConsoleOutput; use TYPO3\CMS\Extbase\Mvc\Cli\Request; use TYPO3\CMS\Extbase\Mvc\Cli\Response; +use TYPO3\CMS\Extbase\Mvc\Controller\Arguments; use TYPO3\CMS\Extbase\Mvc\Exception\InvalidArgumentTypeException; use TYPO3\CMS\Extbase\Mvc\Exception\NoSuchCommandException; use TYPO3\CMS\Extbase\Mvc\Exception\StopActionException; use TYPO3\CMS\Extbase\Mvc\Exception\UnsupportedRequestTypeException; use TYPO3\CMS\Extbase\Mvc\RequestInterface; use TYPO3\CMS\Extbase\Mvc\ResponseInterface; +use TYPO3\CMS\Extbase\Object\ObjectManagerInterface; +use TYPO3\CMS\Extbase\Reflection\ReflectionService; /** * A controller which processes requests from the command line @@ -64,22 +68,17 @@ class CommandController implements CommandControllerInterface protected $requestAdminPermissions = false; /** - * @var AbstractUserAuthentication - */ - protected $userAuthentication; - - /** - * @var \TYPO3\CMS\Extbase\Reflection\ReflectionService + * @var ReflectionService */ protected $reflectionService; /** - * @var \TYPO3\CMS\Extbase\Object\ObjectManagerInterface + * @var ObjectManagerInterface */ protected $objectManager; /** - * @var \TYPO3\CMS\Extbase\Mvc\Cli\ConsoleOutput + * @var ConsoleOutput */ protected $output; @@ -87,18 +86,15 @@ class CommandController implements CommandControllerInterface * @param \TYPO3\CMS\Extbase\Object\ObjectManagerInterface $objectManager * @return void */ - public function injectObjectManager(\TYPO3\CMS\Extbase\Object\ObjectManagerInterface $objectManager) + public function injectObjectManager(ObjectManagerInterface $objectManager) { $this->objectManager = $objectManager; - $this->arguments = $this->objectManager->get(\TYPO3\CMS\Extbase\Mvc\Controller\Arguments::class); - $this->userAuthentication = isset($GLOBALS['BE_USER']) ? $GLOBALS['BE_USER'] : null; - $this->output = $this->objectManager->get(ConsoleOutput::class); } /** * @param \TYPO3\CMS\Extbase\Reflection\ReflectionService $reflectionService */ - public function injectReflectionService(\TYPO3\CMS\Extbase\Reflection\ReflectionService $reflectionService) + public function injectReflectionService(ReflectionService $reflectionService) { $this->reflectionService = $reflectionService; } @@ -134,6 +130,8 @@ class CommandController implements CommandControllerInterface $this->response = $response; $this->commandMethodName = $this->resolveCommandMethodName(); + $this->output = $this->objectManager->get(ConsoleOutput::class); + $this->arguments = $this->objectManager->get(Arguments::class); $this->initializeCommandMethodArguments(); $this->mapRequestArgumentsToControllerArguments(); $this->callCommandMethod(); @@ -168,7 +166,6 @@ class CommandController implements CommandControllerInterface */ protected function initializeCommandMethodArguments() { - $this->arguments->removeAll(); $methodParameters = $this->reflectionService->getMethodParameters(get_class($this), $this->commandMethodName); foreach ($methodParameters as $parameterName => $parameterInfo) { @@ -271,11 +268,14 @@ class CommandController implements CommandControllerInterface */ protected function ensureAdminRoleIfRequested() { - if (!$this->requestAdminPermissions || !$this->userAuthentication || !isset($this->userAuthentication->user['admin'])) { + $userAuthentication = $this->getBackendUserAuthentication(); + + if (!$this->requestAdminPermissions || $userAuthentication === null || !isset($userAuthentication->user['admin'])) { return null; } - $originalRole = $this->userAuthentication->user['admin']; - $this->userAuthentication->user['admin'] = 1; + + $originalRole = $userAuthentication->user['admin']; + $userAuthentication->user['admin'] = 1; return $originalRole; } @@ -286,8 +286,10 @@ class CommandController implements CommandControllerInterface */ protected function restoreUserRole($originalRole) { - if ($originalRole !== null) { - $this->userAuthentication->user['admin'] = $originalRole; + $userAuthentication = $this->getBackendUserAuthentication(); + + if ($originalRole !== null && $userAuthentication !== null) { + $userAuthentication->user['admin'] = $originalRole; } } @@ -359,4 +361,14 @@ class CommandController implements CommandControllerInterface $this->response->send(); exit($exitCode); } + + /** + * Returns the global BackendUserAuthentication object. + * + * @return BackendUserAuthentication|null + */ + protected function getBackendUserAuthentication() + { + return isset($GLOBALS['BE_USER']) ? $GLOBALS['BE_USER'] : null; + } } diff --git a/typo3/sysext/extbase/Tests/Unit/Mvc/Controller/CommandControllerTest.php b/typo3/sysext/extbase/Tests/Unit/Mvc/Controller/CommandControllerTest.php index ba95ed6045806e570d383ae2966e0fb71d3c9999..93fdd24e85b0821398541afc0426ee1ab03e1fc7 100644 --- a/typo3/sysext/extbase/Tests/Unit/Mvc/Controller/CommandControllerTest.php +++ b/typo3/sysext/extbase/Tests/Unit/Mvc/Controller/CommandControllerTest.php @@ -94,7 +94,7 @@ class CommandControllerTest extends \TYPO3\CMS\Core\Tests\UnitTestCase } } )); - $this->commandController->_set('userAuthentication', $mockedUserAuthentication); + $GLOBALS['BE_USER'] = $mockedUserAuthentication; $this->commandController->_set('arguments', array()); $this->commandController->_set('commandMethodName', 'dummyCommand'); $this->commandController->_set('requestAdminPermissions', true);