From cbaec8e0a0593de36de3b167435033b0a56add83 Mon Sep 17 00:00:00 2001
From: Romain Canon <romain.hydrocanon@gmail.com>
Date: Thu, 7 Sep 2017 19:28:50 +0200
Subject: [PATCH] [TASK] Remove context service from install tool

This service was not useful anymore as the install tool modules handling
changed.

It is replaced by a single string that allows doing basically the same
job.

Resolves: #82353
Releases: master
Change-Id: I34e28e0d1a716b293897f54f7f800e5e6fb8e0c5
Reviewed-on: https://review.typo3.org/53966
Reviewed-by: Anja Leichsenring <aleichsenring@ab-softlab.de>
Tested-by: Anja Leichsenring <aleichsenring@ab-softlab.de>
Tested-by: TYPO3com <no-reply@typo3.com>
Reviewed-by: Matthias Vogel <typo3@kanti.de>
Tested-by: Matthias Vogel <typo3@kanti.de>
Reviewed-by: Simon Praetorius <simon@praetorius.me>
Tested-by: Simon Praetorius <simon@praetorius.me>
Reviewed-by: Stefan Neufeind <typo3.neufeind@speedpartner.de>
Tested-by: Stefan Neufeind <typo3.neufeind@speedpartner.de>
Reviewed-by: Andreas Fernandez <typo3@scripting-base.de>
Tested-by: Andreas Fernandez <typo3@scripting-base.de>
---
 .../Classes/Controller/AbstractController.php |  2 +-
 .../Controller/Action/AbstractAction.php      | 21 +++---
 .../Controller/Action/ActionInterface.php     |  5 +-
 .../Classes/Controller/AjaxController.php     |  2 +-
 .../Classes/Controller/StepController.php     | 11 ++--
 .../Classes/Controller/ToolController.php     |  2 +-
 .../Classes/Service/ContextService.php        | 66 -------------------
 .../Private/Layouts/ToolAuthenticated.html    |  2 +-
 .../Templates/Action/Common/Login.html        |  2 +-
 9 files changed, 28 insertions(+), 85 deletions(-)
 delete mode 100644 typo3/sysext/install/Classes/Service/ContextService.php

diff --git a/typo3/sysext/install/Classes/Controller/AbstractController.php b/typo3/sysext/install/Classes/Controller/AbstractController.php
index d7e95f57639f..6381d1c2a3ce 100644
--- a/typo3/sysext/install/Classes/Controller/AbstractController.php
+++ b/typo3/sysext/install/Classes/Controller/AbstractController.php
@@ -44,7 +44,7 @@ class AbstractController
         $action = GeneralUtility::makeInstance(LoginForm::class);
         $action->setController('common');
         $action->setAction('login');
-        $action->setContext($request->getAttribute('context', 'standalone'));
+        $action->setContext($request->getAttribute('context'));
         $action->setToken($this->generateTokenForAction('login'));
         $action->setPostValues($request->getParsedBody()['install'] ?? []);
         if ($message) {
diff --git a/typo3/sysext/install/Classes/Controller/Action/AbstractAction.php b/typo3/sysext/install/Classes/Controller/Action/AbstractAction.php
index a1fcaa1191a2..11e447c7ef00 100644
--- a/typo3/sysext/install/Classes/Controller/Action/AbstractAction.php
+++ b/typo3/sysext/install/Classes/Controller/Action/AbstractAction.php
@@ -16,7 +16,6 @@ namespace TYPO3\CMS\Install\Controller\Action;
 
 use TYPO3\CMS\Core\Utility\GeneralUtility;
 use TYPO3\CMS\Fluid\View\StandaloneView;
-use TYPO3\CMS\Install\Service\ContextService;
 
 /**
  * General purpose controller action helper methods and bootstrap
@@ -54,9 +53,9 @@ abstract class AbstractAction implements ActionInterface
     protected $messages = [];
 
     /**
-     * @var ContextService
+     * @var string
      */
-    protected $contextService;
+    protected $context = self::CONTEXT_STANDALONE;
 
     /**
      * Handles the action
@@ -88,8 +87,8 @@ abstract class AbstractAction implements ActionInterface
             ->assign('action', $this->action)
             ->assign('controller', $this->controller)
             ->assign('token', $this->token)
-            ->assign('context', $this->contextService->getContextString())
-            ->assign('contextService', $this->contextService)
+            ->assign('context', $this->context)
+            ->assign('backendContext', $this->context === self::CONTEXT_BACKEND)
             ->assign('messages', $this->messages)
             ->assign('typo3Version', TYPO3_version)
             ->assign('siteName', $GLOBALS['TYPO3_CONF_VARS']['SYS']['sitename']);
@@ -155,13 +154,19 @@ abstract class AbstractAction implements ActionInterface
 
     /**
      * Context determines if the install tool is called within backend or standalone
-     * This method creates a context service that distinguishes between standalone and backend context
      *
-     * @param $context string Either 'standalone' or 'backend'
+     * @param $context string One of the `CONTEXT_*` constants.
      */
     public function setContext($context)
     {
-        $this->contextService = GeneralUtility::makeInstance(\TYPO3\CMS\Install\Service\ContextService::class, $context);
+        switch ($context) {
+            case self::CONTEXT_STANDALONE:
+            case self::CONTEXT_BACKEND:
+                $this->context = $context;
+                break;
+            default:
+                $this->context = self::CONTEXT_STANDALONE;
+        }
     }
 
     /**
diff --git a/typo3/sysext/install/Classes/Controller/Action/ActionInterface.php b/typo3/sysext/install/Classes/Controller/Action/ActionInterface.php
index c39096ac527c..9ff1d76913ac 100644
--- a/typo3/sysext/install/Classes/Controller/Action/ActionInterface.php
+++ b/typo3/sysext/install/Classes/Controller/Action/ActionInterface.php
@@ -19,6 +19,9 @@ namespace TYPO3\CMS\Install\Controller\Action;
  */
 interface ActionInterface
 {
+    const CONTEXT_STANDALONE = 'standalone';
+    const CONTEXT_BACKEND = 'backend';
+
     /**
      * Handle this action
      *
@@ -49,7 +52,7 @@ interface ActionInterface
     public function setAction($action);
 
     /**
-     * Set the context name, can be "installer", "standalone" or "backend"
+     * Set the context name, must be one of the `CONTEXT_*` constants.
      *
      * @param string $context
      */
diff --git a/typo3/sysext/install/Classes/Controller/AjaxController.php b/typo3/sysext/install/Classes/Controller/AjaxController.php
index 8631ec678f23..ef0546734255 100644
--- a/typo3/sysext/install/Classes/Controller/AjaxController.php
+++ b/typo3/sysext/install/Classes/Controller/AjaxController.php
@@ -115,7 +115,7 @@ class AjaxController extends AbstractController
         }
         $toolAction->setController('ajax');
         $toolAction->setAction($action);
-        $toolAction->setContext($request->getAttribute('context', 'standalone'));
+        $toolAction->setContext($request->getAttribute('context'));
         $toolAction->setToken($this->generateTokenForAction($action));
         $toolAction->setPostValues($request->getParsedBody()['install'] ?? []);
         return $this->output($toolAction->handle());
diff --git a/typo3/sysext/install/Classes/Controller/StepController.php b/typo3/sysext/install/Classes/Controller/StepController.php
index 311c0c7e456c..669a5d462a30 100644
--- a/typo3/sysext/install/Classes/Controller/StepController.php
+++ b/typo3/sysext/install/Classes/Controller/StepController.php
@@ -18,6 +18,7 @@ use Psr\Http\Message\ResponseInterface;
 use Psr\Http\Message\ServerRequestInterface;
 use TYPO3\CMS\Core\Messaging\FlashMessage;
 use TYPO3\CMS\Core\Utility\GeneralUtility;
+use TYPO3\CMS\Install\Controller\Action\ActionInterface;
 use TYPO3\CMS\Install\Controller\Action\Step\AbstractStepAction;
 use TYPO3\CMS\Install\Service\EnableFileService;
 use TYPO3\CMS\Install\Service\SessionService;
@@ -82,7 +83,7 @@ class StepController extends AbstractController
             $action = GeneralUtility::makeInstance(\TYPO3\CMS\Install\Controller\Action\Common\InstallToolDisabledAction::class);
             $action->setAction('installToolDisabled');
         }
-        $action->setContext('standalone');
+        $action->setContext(ActionInterface::CONTEXT_STANDALONE);
         $action->setController('common');
         return $this->output($action->handle());
     }
@@ -98,7 +99,7 @@ class StepController extends AbstractController
         /** @var \TYPO3\CMS\Install\Controller\Action\ActionInterface $action */
         $action = GeneralUtility::makeInstance(\TYPO3\CMS\Install\Controller\Action\Common\InstallToolPasswordNotSetAction::class);
         $action->setController('common');
-        $action->setContext('standalone');
+        $action->setContext(ActionInterface::CONTEXT_STANDALONE);
         $action->setAction('installToolPasswordNotSet');
         return $this->output($action->handle());
     }
@@ -119,7 +120,7 @@ class StepController extends AbstractController
             /** @var AbstractStepAction $stepAction */
             $stepAction = $this->getActionInstance($action);
             $stepAction->setAction($action);
-            $stepAction->setContext('standalone');
+            $stepAction->setContext(ActionInterface::CONTEXT_STANDALONE);
             $stepAction->setToken($this->generateTokenForAction($action));
             $stepAction->setPostValues($postValues);
             $messages = $stepAction->execute();
@@ -149,7 +150,7 @@ class StepController extends AbstractController
         $stepAction = $this->getActionInstance($action);
         $stepAction->setAction($action);
         $stepAction->setController('step');
-        $stepAction->setContext('standalone');
+        $stepAction->setContext(ActionInterface::CONTEXT_STANDALONE);
         $stepAction->setToken($this->generateTokenForAction($action));
         $stepAction->setPostValues($postValues);
 
@@ -242,7 +243,7 @@ class StepController extends AbstractController
                 $action->setStepsCounter($currentStep, $totalSteps);
             }
             $action->setController('step');
-            $action->setContext('standalone');
+            $action->setContext(ActionInterface::CONTEXT_STANDALONE);
             $action->setAction('environmentAndFolders');
             if (!empty($errorMessagesFromExecute)) {
                 $action->setMessages($errorMessagesFromExecute);
diff --git a/typo3/sysext/install/Classes/Controller/ToolController.php b/typo3/sysext/install/Classes/Controller/ToolController.php
index 205329ddd7c9..e590b7ddc255 100644
--- a/typo3/sysext/install/Classes/Controller/ToolController.php
+++ b/typo3/sysext/install/Classes/Controller/ToolController.php
@@ -62,7 +62,7 @@ class ToolController extends AbstractController
         $toolAction->setController('tool');
         $toolAction->setAction($action);
         $toolAction->setToken($this->generateTokenForAction($action));
-        $toolAction->setContext($request->getAttribute('context', 'standalone'));
+        $toolAction->setContext($request->getAttribute('context'));
         $toolAction->setPostValues($request->getParsedBody()['install'] ?? []);
         return $this->output($toolAction->handle());
     }
diff --git a/typo3/sysext/install/Classes/Service/ContextService.php b/typo3/sysext/install/Classes/Service/ContextService.php
deleted file mode 100644
index ca8d3311ca56..000000000000
--- a/typo3/sysext/install/Classes/Service/ContextService.php
+++ /dev/null
@@ -1,66 +0,0 @@
-<?php
-namespace TYPO3\CMS\Install\Service;
-
-/*
- * This file is part of the TYPO3 CMS project.
- *
- * It is free software; you can redistribute it and/or modify it under
- * the terms of the GNU General Public License, either version 2
- * of the License, or any later version.
- *
- * For the full copyright and license information, please read the
- * LICENSE.txt file that was distributed with this source code.
- *
- * The TYPO3 project - inspiring people to share!
- */
-
-/**
- * Service for determining the current context (as a backend module or in standalone mode)
- */
-class ContextService
-{
-    /**
-     * @var bool
-     */
-    private $backendContext = false;
-
-    /**
-     * Constructor, prepare the context information
-     *
-     * @param string $context
-     */
-    public function __construct($context)
-    {
-        $this->backendContext = ($context === 'backend');
-    }
-
-    /**
-     * Is the install tool running in the backend?
-     *
-     * @return bool
-     */
-    public function isBackendContext()
-    {
-        return $this->backendContext;
-    }
-
-    /**
-     * Is the install tool running as a standalone application?
-     *
-     * @return bool
-     */
-    public function isStandaloneContext()
-    {
-        return !$this->backendContext;
-    }
-
-    /**
-     * Is the install tool running as a standalone application?
-     *
-     * @return bool
-     */
-    public function getContextString()
-    {
-        return $this->isBackendContext() ? 'backend' : 'standalone';
-    }
-}
diff --git a/typo3/sysext/install/Resources/Private/Layouts/ToolAuthenticated.html b/typo3/sysext/install/Resources/Private/Layouts/ToolAuthenticated.html
index fb55c2e2bd2d..ec7b1842f0f8 100644
--- a/typo3/sysext/install/Resources/Private/Layouts/ToolAuthenticated.html
+++ b/typo3/sysext/install/Resources/Private/Layouts/ToolAuthenticated.html
@@ -5,7 +5,7 @@
 	<f:render partial="Action/Common/Headers" arguments="{_all}" />
 </head>
 <body class="{context}">
-<f:if condition="{contextService.backendContext}">
+<f:if condition="{backendContext}">
 	<f:then>
 		<div class="module" data-module-id="" data-module-name="">
 			<div class="module-docheader t3js-module-docheader" style="height: auto;">
diff --git a/typo3/sysext/install/Resources/Private/Templates/Action/Common/Login.html b/typo3/sysext/install/Resources/Private/Templates/Action/Common/Login.html
index 3f2ea2e70eb6..7670acee6fb2 100644
--- a/typo3/sysext/install/Resources/Private/Templates/Action/Common/Login.html
+++ b/typo3/sysext/install/Resources/Private/Templates/Action/Common/Login.html
@@ -15,7 +15,7 @@
 	<link rel="stylesheet" type="text/css" href="{f:uri.resource(path: 'Css/install.css')}?{time}" />
 </head>
 <body class="{context}">
-	<f:if condition="{contextService.backendContext}">
+	<f:if condition="{backendContext}">
 		<div id="typo3-docheader">
 			<div class="typo3-docheader-functions"></div>
 			<div class="typo3-docheader-buttons"></div>
-- 
GitLab