[TASK] Move install update flags to system registry
[Packages/TYPO3.CMS.git] / typo3 / sysext / install / Classes / Updates / WizardDoneToRegistry.php
1 <?php
2 namespace TYPO3\CMS\Install\Updates;
3
4 /*
5 * This file is part of the TYPO3 CMS project.
6 *
7 * It is free software; you can redistribute it and/or modify it under
8 * the terms of the GNU General Public License, either version 2
9 * of the License, or any later version.
10 *
11 * For the full copyright and license information, please read the
12 * LICENSE.txt file that was distributed with this source code.
13 *
14 * The TYPO3 project - inspiring people to share!
15 */
16
17 use TYPO3\CMS\Core\Configuration\ConfigurationManager;
18 use TYPO3\CMS\Core\Registry;
19 use TYPO3\CMS\Core\Utility\GeneralUtility;
20
21 /**
22 * Move "wizard done" flags to system registry
23 */
24 class WizardDoneToRegistry extends AbstractUpdate
25 {
26 /**
27 * @var string
28 */
29 protected $title = 'Move "wizard done" flags from LocalConfiguration.php to system registry';
30
31 /**
32 * Checks if an update is needed
33 *
34 * @param string &$description The description for the update
35 * @return bool Whether an update is needed (TRUE) or not (FALSE)
36 */
37 public function checkForUpdate(&$description)
38 {
39 $result = false;
40 $description = 'Moves all "wizard done" flags from LocalConfiguration.php to system registry.';
41
42 try {
43 $wizardsDone = GeneralUtility::makeInstance(ConfigurationManager::class)->getLocalConfigurationValueByPath('INSTALL/wizardDone');
44
45 if (!empty($wizardsDone)) {
46 $result = true;
47 }
48 } catch (\RuntimeException $e) {
49 }
50
51 return $result;
52 }
53
54 /**
55 * Performs the accordant updates.
56 *
57 * @param array &$dbQueries Queries done in this update
58 * @param mixed &$customMessages Custom messages
59 * @return bool Whether everything went smoothly or not
60 */
61 public function performUpdate(array &$dbQueries, &$customMessages)
62 {
63 $configurationManager = GeneralUtility::makeInstance(ConfigurationManager::class);
64 $registry = GeneralUtility::makeInstance(Registry::class);
65 $wizardsDone = $configurationManager->getLocalConfigurationValueByPath('INSTALL/wizardDone');
66 $configurationKeysToRemove = [];
67
68 foreach ($wizardsDone as $wizardClassName => $value) {
69 $registry->set('installUpdate', $wizardClassName, $value);
70 $configurationKeysToRemove[] = 'INSTALL/wizardDone/' . $wizardClassName;
71 }
72
73 $configurationKeysToRemove[] = 'INSTALL/wizardDone';
74
75 $configurationManager->removeLocalConfigurationKeysByPath($configurationKeysToRemove);
76
77 $this->markWizardAsDone();
78 return true;
79 }
80 }