From 967c8897b05f9d78af925b1a5320765181222fc1 Mon Sep 17 00:00:00 2001
From: Susanne Moog <susanne.moog@typo3.org>
Date: Sun, 8 Apr 2018 09:50:32 +0200
Subject: [PATCH] [TASK] Streamline upgrade wizards that install extensions

Let the adminpanel and redirect upgrade wizards make use of
the abstract wizard for installing extensions,
which includes handling composer based installations.

Resolves: #84660
Releases: master
Change-Id: Iab7f3ed44945362a315a7f4d32497c6a1c70d779
Reviewed-on: https://review.typo3.org/56559
Tested-by: TYPO3com <no-reply@typo3.com>
Reviewed-by: Mathias Schreiber <mathias.schreiber@typo3.com>
Tested-by: Mathias Schreiber <mathias.schreiber@typo3.com>
Reviewed-by: Susanne Moog <susanne.moog@typo3.org>
Tested-by: Susanne Moog <susanne.moog@typo3.org>
---
 .../Classes/Updates/AdminPanelInstall.php     | 24 ++++-----
 .../Updates/RedirectsExtensionUpdate.php      | 54 ++++---------------
 2 files changed, 23 insertions(+), 55 deletions(-)

diff --git a/typo3/sysext/install/Classes/Updates/AdminPanelInstall.php b/typo3/sysext/install/Classes/Updates/AdminPanelInstall.php
index 8239285ae62a..105b8a0da38c 100644
--- a/typo3/sysext/install/Classes/Updates/AdminPanelInstall.php
+++ b/typo3/sysext/install/Classes/Updates/AdminPanelInstall.php
@@ -17,15 +17,11 @@ namespace TYPO3\CMS\Install\Updates;
  */
 
 use TYPO3\CMS\Core\Utility\ExtensionManagementUtility;
-use TYPO3\CMS\Core\Utility\GeneralUtility;
-use TYPO3\CMS\Extbase\Object\ObjectManager;
-use TYPO3\CMS\Extensionmanager\Exception\ExtensionManagerException;
-use TYPO3\CMS\Extensionmanager\Utility\InstallUtility;
 
 /**
  * Installs EXT:adminpanel
  */
-class AdminPanelInstall extends AbstractUpdate
+class AdminPanelInstall extends AbstractDownloadExtensionUpdate
 {
     /**
      * @var string
@@ -37,6 +33,15 @@ class AdminPanelInstall extends AbstractUpdate
      */
     protected $extensionKey = 'adminpanel';
 
+    protected $extensionDetails = [
+        'adminpanel' => [
+            'title' => 'TYPO3 Admin Panel',
+            'description' => 'The TYPO3 admin panel provides a panel with additional functionality in the frontend (Debugging, Caching, Preview...)',
+            'versionString' => '9.2',
+            'composerName' => 'typo3/cms-adminpanel',
+        ],
+    ];
+
     /**
      * Checks if an update is needed
      *
@@ -67,14 +72,9 @@ class AdminPanelInstall extends AbstractUpdate
      */
     public function performUpdate(array &$databaseQueries, &$customMessage): bool
     {
-        $objectManager = GeneralUtility::makeInstance(ObjectManager::class);
-        $extensionInstallUtility = $objectManager->get(InstallUtility::class);
-        try {
-            $extensionInstallUtility->install('adminpanel');
-            $updateSuccessful = true;
+        $updateSuccessful = $this->installExtension($this->extensionKey, $customMessage);
+        if ($updateSuccessful) {
             $this->markWizardAsDone();
-        } catch (ExtensionManagerException $e) {
-            $updateSuccessful = false;
         }
         return $updateSuccessful;
     }
diff --git a/typo3/sysext/install/Classes/Updates/RedirectsExtensionUpdate.php b/typo3/sysext/install/Classes/Updates/RedirectsExtensionUpdate.php
index 832d0ff2ffa8..97c08b0ada87 100644
--- a/typo3/sysext/install/Classes/Updates/RedirectsExtensionUpdate.php
+++ b/typo3/sysext/install/Classes/Updates/RedirectsExtensionUpdate.php
@@ -19,16 +19,12 @@ use Psr\Log\LoggerAwareInterface;
 use Psr\Log\LoggerAwareTrait;
 use TYPO3\CMS\Core\Database\ConnectionPool;
 use TYPO3\CMS\Core\Utility\GeneralUtility;
-use TYPO3\CMS\Extbase\Object\ObjectManager;
-use TYPO3\CMS\Extensionmanager\Exception\ExtensionManagerException;
-use TYPO3\CMS\Extensionmanager\Utility\InstallUtility;
-use TYPO3\CMS\Extensionmanager\Utility\ListUtility;
 
 /**
  * Installs EXT:redirect if sys_domain.redirectTo is filled, and migrates the values from redirectTo
  * to a proper sys_redirect entry.
  */
-class RedirectsExtensionUpdate extends AbstractUpdate implements LoggerAwareInterface
+class RedirectsExtensionUpdate extends AbstractDownloadExtensionUpdate implements LoggerAwareInterface
 {
     use LoggerAwareTrait;
 
@@ -38,9 +34,16 @@ class RedirectsExtensionUpdate extends AbstractUpdate implements LoggerAwareInte
     protected $title = 'Install system extension "redirects" if a sys_domain entry with redirectTo is necessary';
 
     /**
-     * @var string
+     * @var array
      */
-    protected $extensionKey = 'redirects';
+    protected $extensionDetails = [
+        'redirects' => [
+            'title' => 'Redirects',
+            'description' => 'Manage redirects for your TYPO3-based website',
+            'versionString' => '9.2',
+            'composerName' => 'typo3/cms-redirects',
+        ],
+    ];
 
     /**
      * Checks if an update is needed
@@ -76,7 +79,7 @@ class RedirectsExtensionUpdate extends AbstractUpdate implements LoggerAwareInte
     public function performUpdate(array &$databaseQueries, &$customMessage): bool
     {
         // Install the EXT:redirects extension if not happened yet
-        $installationSuccessful = $this->installExtension($this->extensionKey);
+        $installationSuccessful = $this->installExtension('redirects', $customMessage);
         if ($installationSuccessful) {
             // Migrate the database entries
             $this->migrateRedirectDomainsToSysRedirect();
@@ -114,41 +117,6 @@ class RedirectsExtensionUpdate extends AbstractUpdate implements LoggerAwareInte
         return false;
     }
 
-    /**
-     * This method can be called to install an extension following all proper processes
-     * (e.g. installing in extList, respecting priority, etc.)
-     *
-     * @param string $extensionKey
-     * @return bool
-     */
-    protected function installExtension(string $extensionKey): bool
-    {
-        $extensionInstalled = false;
-        /** @var $objectManager ObjectManager */
-        $objectManager = GeneralUtility::makeInstance(ObjectManager::class);
-
-        /** @var $extensionListUtility ListUtility */
-        $extensionListUtility = $objectManager->get(ListUtility::class);
-
-        $availableExtensions = $extensionListUtility->getAvailableExtensions();
-        $availableAndInstalledExtensions = $extensionListUtility->getAvailableAndInstalledExtensions($availableExtensions);
-
-        // Extension is not installed yet, install it
-        if (!isset($availableAndInstalledExtensions[$extensionKey]['installed']) || $availableAndInstalledExtensions[$extensionKey]['installed'] !== true) {
-            /** @var $extensionInstallUtility InstallUtility */
-            $extensionInstallUtility = $objectManager->get(InstallUtility::class);
-            try {
-                $extensionInstallUtility->install($extensionKey);
-                $extensionInstalled = true;
-            } catch (ExtensionManagerException $e) {
-                $this->logger->warning($e->getMessage());
-            }
-        } else {
-            $extensionInstalled = true;
-        }
-        return $extensionInstalled;
-    }
-
     /**
      * Move all sys_domain records with a "redirectTo" value filled (also deleted) to "sys_redirect" record
      */
-- 
GitLab