[BUGFIX] Use class name to mark upgrade wizards done 97/58197/4
authorHelmut Hummel <typo3@helhum.io>
Thu, 6 Sep 2018 10:15:24 +0000 (12:15 +0200)
committerAnja Leichsenring <aleichsenring@ab-softlab.de>
Thu, 13 Sep 2018 19:08:14 +0000 (21:08 +0200)
To make the registry for done wizards consistent and stay backwards
compatible once all upgrade wizards are converted to use the
new interface, always store the class name of the wizard
instead of its identifier in the registry.

Additionally we now add checks for valid identifiers
to all API methods that receive one.

Releases: master
Resolves: #86165
Change-Id: I402852c90f5a8d3d0a05bacbd961a4bb4cb86d1e
Reviewed-on: https://review.typo3.org/58197
Tested-by: TYPO3com <no-reply@typo3.com>
Reviewed-by: Susanne Moog <susanne.moog@typo3.org>
Tested-by: Susanne Moog <susanne.moog@typo3.org>
Reviewed-by: Wouter Wolters <typo3@wouterwolters.nl>
Reviewed-by: Anja Leichsenring <aleichsenring@ab-softlab.de>
Tested-by: Anja Leichsenring <aleichsenring@ab-softlab.de>
typo3/sysext/install/Classes/Command/UpgradeWizardListCommand.php
typo3/sysext/install/Classes/Command/UpgradeWizardRunCommand.php
typo3/sysext/install/Classes/Service/UpgradeWizardsService.php

index c53d8db..093a2d4 100644 (file)
@@ -23,7 +23,6 @@ use Symfony\Component\Console\Output\OutputInterface;
 use Symfony\Component\Console\Style\SymfonyStyle;
 use TYPO3\CMS\Core\Authentication\CommandLineUserAuthentication;
 use TYPO3\CMS\Core\Core\Bootstrap;
-use TYPO3\CMS\Core\Registry;
 use TYPO3\CMS\Core\Utility\GeneralUtility;
 use TYPO3\CMS\Install\Service\UpgradeWizardsService;
 use TYPO3\CMS\Install\Updates\ChattyInterface;
@@ -132,14 +131,8 @@ class UpgradeWizardListCommand extends Command
      */
     protected function getWizard(string $className, string $identifier, $all = false): ?UpgradeWizardInterface
     {
-        $registry = GeneralUtility::makeInstance(Registry::class);
-        $markedDoneInRegistry = $registry->get(
-            'installUpdate',
-            $identifier,
-            false
-        );
         // already done
-        if (!$all && $markedDoneInRegistry) {
+        if (!$all && $this->upgradeWizardsService->isWizardDone($identifier)) {
             return null;
         }
 
index 10ed7e6..d48bc8e 100644 (file)
@@ -24,7 +24,6 @@ use Symfony\Component\Console\Question\ConfirmationQuestion;
 use Symfony\Component\Console\Style\SymfonyStyle;
 use TYPO3\CMS\Core\Authentication\CommandLineUserAuthentication;
 use TYPO3\CMS\Core\Core\Bootstrap;
-use TYPO3\CMS\Core\Registry;
 use TYPO3\CMS\Core\Utility\GeneralUtility;
 use TYPO3\CMS\Install\Service\UpgradeWizardsService;
 use TYPO3\CMS\Install\Updates\ChattyInterface;
@@ -132,14 +131,8 @@ class UpgradeWizardRunCommand extends Command
      */
     protected function getWizard(string $className, string $identifier): ?UpgradeWizardInterface
     {
-        $registry = GeneralUtility::makeInstance(Registry::class);
-        $markedDoneInRegistry = $registry->get(
-            'installUpdate',
-            $identifier,
-            false
-        );
         // already done
-        if ($markedDoneInRegistry) {
+        if ($this->upgradeWizardsService->isWizardDone($identifier)) {
             return null;
         }
 
index 0a420e3..53b1a19 100644 (file)
@@ -125,9 +125,12 @@ class UpgradeWizardsService
      *
      * @param string $identifier Wizard or RowUpdater identifier
      * @return bool True if wizard has been marked as undone
+     * @throws \RuntimeException
      */
     public function markWizardUndone(string $identifier): bool
     {
+        $this->assertIdentifierIsValid($identifier);
+
         $registry = GeneralUtility::makeInstance(Registry::class);
         $aWizardHasBeenMarkedUndone = false;
         $wizardsDoneList = $this->listOfWizardsDone();
@@ -318,15 +321,8 @@ class UpgradeWizardsService
      */
     public function getWizardUserInput(string $identifier): array
     {
-        // Validate identifier exists in upgrade wizard list
-        if (empty($identifier)
-            || !array_key_exists($identifier, $GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['ext/install']['update'])
-        ) {
-            throw new \RuntimeException(
-                'No valid wizard identifier given',
-                1502721731
-            );
-        }
+        $this->assertIdentifierIsValid($identifier);
+
         $class = $GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['ext/install']['update'][$identifier];
         $updateObject = GeneralUtility::makeInstance($class);
         $wizardHtml = '';
@@ -378,14 +374,8 @@ class UpgradeWizardsService
      */
     public function executeWizard(string $identifier, int $showDatabaseQueries = null): FlashMessageQueue
     {
-        if (empty($identifier)
-            || !array_key_exists($identifier, $GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['ext/install']['update'])
-        ) {
-            throw new \RuntimeException(
-                'No valid wizard identifier given',
-                1502721732
-            );
-        }
+        $this->assertIdentifierIsValid($identifier);
+
         $class = $GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['ext/install']['update'][$identifier];
         $updateObject = GeneralUtility::makeInstance($class);
 
@@ -478,10 +468,14 @@ class UpgradeWizardsService
      * Writes the info in LocalConfiguration.php
      *
      * @param string $identifier
+     * @throws \RuntimeException
      */
     public function markWizardAsDone(string $identifier): void
     {
-        GeneralUtility::makeInstance(Registry::class)->set('installUpdate', $identifier, 1);
+        $this->assertIdentifierIsValid($identifier);
+
+        $class = $GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['ext/install']['update'][$identifier];
+        GeneralUtility::makeInstance(Registry::class)->set('installUpdate', $class, 1);
     }
 
     /**
@@ -489,9 +483,26 @@ class UpgradeWizardsService
      *
      * @param string $identifier
      * @return bool TRUE if wizard has been done before, FALSE otherwise
+     * @throws \RuntimeException
      */
     public function isWizardDone(string $identifier): bool
     {
-        return (bool)GeneralUtility::makeInstance(Registry::class)->get('installUpdate', $identifier, false);
+        $this->assertIdentifierIsValid($identifier);
+
+        $class = $GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['ext/install']['update'][$identifier];
+        return (bool)GeneralUtility::makeInstance(Registry::class)->get('installUpdate', $class, false);
+    }
+
+    /**
+     * Validate identifier exists in upgrade wizard list
+     *
+     * @param string $identifier
+     * @throws \RuntimeException
+     */
+    protected function assertIdentifierIsValid(string $identifier): void
+    {
+        if ($identifier === '' || !isset($GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['ext/install']['update'][$identifier])) {
+            throw new \RuntimeException('No valid wizard identifier given', 1502721731);
+        }
     }
 }