From 496e1673236023cfc8e2b9226cf46365b1235084 Mon Sep 17 00:00:00 2001
From: Benni Mack <benni@typo3.org>
Date: Mon, 27 Mar 2017 09:39:34 +0200
Subject: [PATCH] [TASK] Extbase commands do not need to ensure admin role

The methods in Extbase's command controller to request
the admin role for $BE_USER are not needed anymore,
because CLI users are always admins nowadays.

The methods are therefore marked as deprecated.

Resolves: #79591
Releases: master
Change-Id: I79865af20a45d455a9417ceca42e4068cc15dc3f
Reviewed-on: https://review.typo3.org/51250
Reviewed-by: Mathias Brodala <mbrodala@pagemachine.de>
Tested-by: TYPO3com <no-reply@typo3.com>
Reviewed-by: Daniel Goerz <ervaude@gmail.com>
Tested-by: Daniel Goerz <ervaude@gmail.com>
Tested-by: Mathias Brodala <mbrodala@pagemachine.de>
Reviewed-by: Georg Ringer <georg.ringer@gmail.com>
Tested-by: Georg Ringer <georg.ringer@gmail.com>
---
 ...baseCommandControllersAdminRoleMethods.rst | 35 +++++++++++++++++++
 .../Mvc/Controller/CommandController.php      |  5 +++
 2 files changed, 40 insertions(+)
 create mode 100644 typo3/sysext/core/Documentation/Changelog/master/Deprecation-79591-ExtbaseCommandControllersAdminRoleMethods.rst

diff --git a/typo3/sysext/core/Documentation/Changelog/master/Deprecation-79591-ExtbaseCommandControllersAdminRoleMethods.rst b/typo3/sysext/core/Documentation/Changelog/master/Deprecation-79591-ExtbaseCommandControllersAdminRoleMethods.rst
new file mode 100644
index 000000000000..5631204d15ad
--- /dev/null
+++ b/typo3/sysext/core/Documentation/Changelog/master/Deprecation-79591-ExtbaseCommandControllersAdminRoleMethods.rst
@@ -0,0 +1,35 @@
+.. include:: ../../Includes.txt
+
+====================================================================
+Deprecation: #79591 - Extbase command controllers admin role methods
+====================================================================
+
+See :issue:`79591`
+
+Description
+===========
+
+The methods php:``CommandController->ensureAdminRoleIfRequested()`` and
+php:``CommandController->restoreUserRole()`` have been marked as deprecated.
+
+All CLI scripts are now executed with administrator access rights, so this functionality is obsolete.
+
+
+Impact
+======
+
+Calling any of the methods above will trigger a deprecation log warning.
+
+
+Affected Installations
+======================
+
+Any installation with custom CLI Extbase Command Controllers using the methods above.
+
+
+Migration
+=========
+
+Remove the affected lines where the methods are called, as they are not necessary anymore.
+
+.. index:: CLI
\ No newline at end of file
diff --git a/typo3/sysext/extbase/Classes/Mvc/Controller/CommandController.php b/typo3/sysext/extbase/Classes/Mvc/Controller/CommandController.php
index 24c37230f650..741debf70f3d 100644
--- a/typo3/sysext/extbase/Classes/Mvc/Controller/CommandController.php
+++ b/typo3/sysext/extbase/Classes/Mvc/Controller/CommandController.php
@@ -15,6 +15,7 @@ namespace TYPO3\CMS\Extbase\Mvc\Controller;
  */
 
 use TYPO3\CMS\Core\Authentication\BackendUserAuthentication;
+use TYPO3\CMS\Core\Utility\GeneralUtility;
 use TYPO3\CMS\Extbase\Mvc\Cli\CommandArgumentDefinition;
 use TYPO3\CMS\Extbase\Mvc\Cli\ConsoleOutput;
 use TYPO3\CMS\Extbase\Mvc\Cli\Request;
@@ -263,9 +264,11 @@ class CommandController implements CommandControllerInterface
      * and returns the original state or NULL
      *
      * @return NULL|int
+     * @deprecated since TYPO3 v8, will be removed in TYPO3 v9, because admin role is always used in CLI mode
      */
     protected function ensureAdminRoleIfRequested()
     {
+        GeneralUtility::logDeprecatedFunction();
         $userAuthentication = $this->getBackendUserAuthentication();
 
         if (!$this->requestAdminPermissions || $userAuthentication === null || !isset($userAuthentication->user['admin'])) {
@@ -281,9 +284,11 @@ class CommandController implements CommandControllerInterface
      * Restores the original user role
      *
      * @param NULL|int $originalRole
+     * @deprecated since TYPO3 v8, will be removed in TYPO3 v9, because admin role is always used in CLI mode
      */
     protected function restoreUserRole($originalRole)
     {
+        GeneralUtility::logDeprecatedFunction();
         $userAuthentication = $this->getBackendUserAuthentication();
 
         if ($originalRole !== null && $userAuthentication !== null) {
-- 
GitLab