[TASK] Drop extbase from install tool backend integration 45/45945/6
authorChristian Kuhn <lolli@schwarzbu.ch>
Fri, 15 Jan 2016 14:46:20 +0000 (15:46 +0100)
committerAnja Leichsenring <aleichsenring@ab-softlab.de>
Fri, 15 Jan 2016 16:09:54 +0000 (17:09 +0100)
Using extbase for the tiny "create enable install tool file"
backend controller makes the module more fragile than it
should be. To further stabilize and simplify the backend
integration of the install tool the controller is rewritten
and does not use extbase anymore.

Change-Id: I388376fd903e199569d464583b668fc4df0d24bc
Resolves: #72740
Releases: master
Reviewed-on: https://review.typo3.org/45945
Reviewed-by: Georg Ringer <georg.ringer@gmail.com>
Tested-by: Georg Ringer <georg.ringer@gmail.com>
Reviewed-by: Anja Leichsenring <aleichsenring@ab-softlab.de>
Tested-by: Anja Leichsenring <aleichsenring@ab-softlab.de>
typo3/sysext/install/Classes/Controller/BackendModuleController.php
typo3/sysext/install/Resources/Private/Layouts/BackendModule.html [deleted file]
typo3/sysext/install/Resources/Private/Templates/BackendModule/Index.html [deleted file]
typo3/sysext/install/Resources/Private/Templates/BackendModule/ShowEnableInstallToolButton.html
typo3/sysext/install/ext_tables.php

index f247058..ad070d9 100644 (file)
@@ -14,103 +14,74 @@ namespace TYPO3\CMS\Install\Controller;
  * The TYPO3 project - inspiring people to share!
  */
 
+use Psr\Http\Message\ResponseInterface;
+use Psr\Http\Message\ServerRequestInterface;
+use TYPO3\CMS\Backend\Template\ModuleTemplate;
+use TYPO3\CMS\Core\FormProtection\AbstractFormProtection;
+use TYPO3\CMS\Core\FormProtection\FormProtectionFactory;
+use TYPO3\CMS\Core\Utility\ExtensionManagementUtility;
+use TYPO3\CMS\Core\Utility\GeneralUtility;
+use TYPO3\CMS\Fluid\View\StandaloneView;
+use TYPO3\CMS\Install\Service\EnableFileService;
+
 /**
  * Backend module controller
  *
- * Embeds in backend an only shows the 'enable install tool button' or redirects
+ * Embeds in backend and only shows the 'enable install tool button' or redirects
  * to step installer if install tool is enabled.
  *
- * This is a classic extbase module that does not interfere with the other code
- * within the install tool.
+ * This is a classic backend module that does not interfere with other code
+ * within the install tool, it can be seen as a facade around install tool just
+ * to embed the install tool in backend.
  */
-class BackendModuleController extends \TYPO3\CMS\Extbase\Mvc\Controller\ActionController
+class BackendModuleController
 {
-    /**
-     * @var \TYPO3\CMS\Install\Service\EnableFileService
-     */
-    protected $enableFileService;
-
-    /**
-     * @var \TYPO3\CMS\Core\FormProtection\AbstractFormProtection
-     */
-    protected $formProtection;
-
-    /**
-     * @param \TYPO3\CMS\Install\Service\EnableFileService $enableFileService
-     */
-    public function injectEnableFileService(\TYPO3\CMS\Install\Service\EnableFileService $enableFileService)
-    {
-        $this->enableFileService = $enableFileService;
-    }
-
-    /**
-     * Set formprotection property
-     */
-    public function initializeAction()
-    {
-        $this->formProtection = \TYPO3\CMS\Core\FormProtection\FormProtectionFactory::get();
-    }
 
     /**
      * Index action shows install tool / step installer or redirect to action to enable install tool
      *
-     * @return void
-     */
-    public function indexAction()
-    {
-        if ($this->enableFileService->checkInstallToolEnableFile()) {
-            \TYPO3\CMS\Core\Utility\HttpUtility::redirect('sysext/install/Start/Install.php?install[context]=backend');
-        } else {
-            $this->forward('showEnableInstallToolButton');
-        }
-    }
-
-    /**
-     * Show enable install tool
-     *
-     * @return void
+     * @param ServerRequestInterface $request
+     * @param ResponseInterface $response
+     * @return ResponseInterface
      */
-    public function showEnableInstallToolButtonAction()
+    public function index(ServerRequestInterface $request, ResponseInterface $response)
     {
-        $token = $this->formProtection->generateToken('installTool');
-        $this->view->assign('installToolEnableToken', $token);
-    }
+        /** @var EnableFileService $enableFileService */
+        $enableFileService = GeneralUtility::makeInstance(EnableFileService::class);
+        /** @var AbstractFormProtection $formProtection */
+        $formProtection = FormProtectionFactory::get();
 
-    /**
-     * Enable the install tool
-     *
-     * @param string $installToolEnableToken
-     * @throws \RuntimeException
-     */
-    public function enableInstallToolAction($installToolEnableToken)
-    {
-        if (!$this->formProtection->validateToken($installToolEnableToken, 'installTool')) {
-            throw new \RuntimeException('Given form token was not valid', 1369161225);
+        if ($enableFileService->checkInstallToolEnableFile()) {
+            // Install tool is open and valid, redirect to it
+            $response = $response->withStatus(303)->withHeader('Location', 'sysext/install/Start/Install.php?install[context]=backend');
+        } elseif ($request->getMethod() === 'POST' && $request->getParsedBody()['action'] === 'enableInstallTool') {
+            // Request to open the install tool
+            $installToolEnableToken = $request->getParsedBody()['installToolEnableToken'];
+            if (!$formProtection->validateToken($installToolEnableToken, 'installTool')) {
+                throw new \RuntimeException('Given form token was not valid', 1369161225);
+            }
+            $enableFileService->createInstallToolEnableFile();
+            // Install tool is open and valid, redirect to it
+            $response = $response->withStatus(303)->withHeader('Location', 'sysext/install/Start/Install.php?install[context]=backend');
+        } else {
+            // Show the "create enable install tool" button
+            /** @var StandaloneView $view */
+            $view = GeneralUtility::makeInstance(StandaloneView::class);
+            $view->setTemplatePathAndFilename(GeneralUtility::getFileAbsFileName(
+                'EXT:install/Resources/Private/Templates/BackendModule/ShowEnableInstallToolButton.html', false)
+            );
+            $token = $formProtection->generateToken('installTool');
+            $view->assign('installToolEnableToken', $token);
+            /** @var ModuleTemplate $moduleTemplate */
+            $moduleTemplate = GeneralUtility::makeInstance(ModuleTemplate::class);
+            $pageRenderer = $moduleTemplate->getPageRenderer();
+            $pageRenderer->addCssFile(
+                ExtensionManagementUtility::extRelPath('install') . 'Resources/Public/Css/BackendModule/ShowEnableInstallToolButton.css'
+            );
+            $moduleTemplate->setContent($view->render());
+            $response->getBody()->write($moduleTemplate->renderContent());
         }
-        $this->enableFileService->createInstallToolEnableFile();
-        $this->forward('index');
+        return $response;
     }
 
-    /**
-     * Redirect to specified URI
-     *
-     * @param string $uri
-     * @param string $_1 Dummy parameter to ensure compatible method signature
-     * @param string $_2 Dummy parameter to ensure compatible method signature
-     * @param array $_3 Dummy parameter to ensure compatible method signature
-     * @param int $_4 Dummy parameter to ensure compatible method signature
-     * @param int $_5 Dummy parameter to ensure compatible method signature
-     * @param int $_6 Dummy parameter to ensure compatible method signature
-     */
-    protected function redirect(
-        $uri,
-        $_1 = null,
-        $_2 = null,
-        array $_3 = null,
-        $_4 = null,
-        $_5 = 0,
-        $_6 = 303
-    ) {
-        \TYPO3\CMS\Core\Utility\HttpUtility::redirect($uri);
-    }
 }
diff --git a/typo3/sysext/install/Resources/Private/Layouts/BackendModule.html b/typo3/sysext/install/Resources/Private/Layouts/BackendModule.html
deleted file mode 100644 (file)
index 9a9199f..0000000
+++ /dev/null
@@ -1,25 +0,0 @@
-{namespace i=TYPO3\CMS\Install\ViewHelpers}
-
-<f:comment>
-       This layout is for the 'backend module' that only shows the 'Unlock the Install Tool' message
-       and then redirects to the step installation / install tool
-</f:comment>
-
-<i:be.container
-       pageTitle="Install tool"
-       addCssFiles="{
-               0:'{f:uri.resource(path:\'Css/BackendModule/ShowEnableInstallToolButton.css\')}'
-       }"
-       addJsFiles="{}"
->
-
-       <div id="typo3-docheader">
-               <div class="typo3-docheader-functions"></div>
-               <div class="typo3-docheader-buttons"></div>
-       </div>
-       <div id="typo3-docbody">
-               <div id="typo3-inner-docbody">
-                       <f:render section="Content" />
-               </div>
-       </div>
-</i:be.container>
diff --git a/typo3/sysext/install/Resources/Private/Templates/BackendModule/Index.html b/typo3/sysext/install/Resources/Private/Templates/BackendModule/Index.html
deleted file mode 100644 (file)
index 2995a4d..0000000
+++ /dev/null
@@ -1 +0,0 @@
-dummy
\ No newline at end of file
index 53c1f1e..1288489 100644 (file)
@@ -1,21 +1,16 @@
-{namespace i=TYPO3\CMS\Install\ViewHelpers}
-
-<f:layout name="BackendModule" />
-
-<f:section name="Content">
-       <f:form action="enableInstallTool" method="post" id="t3-install-form-unlock">
-               <f:form.hidden name="installToolEnableToken" value="{installToolEnableToken}" />
-               <div id="container">
-                       <f:be.infobox state="-1" title="{f:translate(key: 'LLL:EXT:install/Resources/Private/Language/BackendModule.xlf:confirmUnlockInstallToolTitle')}">
+<form action="" method="post" id="t3-install-form-unlock">
+       <input type="hidden" name="action" value="enableInstallTool" />
+       <input type="hidden" name="installToolEnableToken" value="{installToolEnableToken}" />
+       <div id="container">
+               <f:be.infobox state="-1" title="{f:translate(key: 'LLL:EXT:install/Resources/Private/Language/BackendModule.xlf:confirmUnlockInstallToolTitle')}">
+                       <f:translate
+                               key="LLL:EXT:install/Resources/Private/Language/BackendModule.xlf:confirmUnlockInstallToolMessage"
+                               />
+                       <button class="btn btn-info" value="enableInstallTool">
                                <f:translate
-                                       key="LLL:EXT:install/Resources/Private/Language/BackendModule.xlf:confirmUnlockInstallToolMessage"
+                                       key="LLL:EXT:install/Resources/Private/Language/BackendModule.xlf:confirmUnlockInstallToolButton"
                                        />
-                               <button class="btn btn-info" value="enableInstallTool">
-                                       <f:translate
-                                               key="LLL:EXT:install/Resources/Private/Language/BackendModule.xlf:confirmUnlockInstallToolButton"
-                                               />
-                               </button>
-                       </f:be.infobox>
-               </div>
-       </f:form>
-</f:section>
+                       </button>
+               </f:be.infobox>
+       </div>
+</form>
index 4f2ba51..945c7dd 100644 (file)
@@ -11,17 +11,21 @@ if (TYPO3_MODE === 'BE') {
         $GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['reports']['tx_reports']['status']['providers']['system'][] = \TYPO3\CMS\Install\Report\EnvironmentStatusReport::class;
     }
 
-    // Register backend module
-    \TYPO3\CMS\Extbase\Utility\ExtensionUtility::registerModule(
-        'TYPO3.CMS.Install',
+    \TYPO3\CMS\Core\Utility\ExtensionManagementUtility::addModule(
         'system',
-        'install', '', array(
-            'BackendModule' => 'index, showEnableInstallToolButton, enableInstallTool',
-        ),
+        'extinstall',
+        '',
+        '',
         array(
+            'routeTarget' => \TYPO3\CMS\Install\Controller\BackendModuleController::class . '::index',
             'access' => 'admin',
-            'icon' => 'EXT:install/Resources/Public/Icons/module-install.svg',
-            'labels' => 'LLL:EXT:install/Resources/Private/Language/BackendModule.xlf',
+            'name' => 'system_extinstall',
+            'labels' => array(
+                'tabs_images' => array(
+                    'tab' => 'EXT:install/Resources/Public/Icons/module-install.svg',
+                ),
+                'll_ref' => 'LLL:EXT:install/Resources/Private/Language/BackendModule.xlf',
+            ),
         )
     );
 }