[TASK] Fix CGL errors
[Packages/TYPO3.CMS.git] / typo3 / sysext / install / Classes / Updates / AccessRightParametersUpdate.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\Utility\GeneralUtility;
19
20 /**
21 * Move access right parameters from "BE" to "SYS" configuration section
22 */
23 class AccessRightParametersUpdate extends AbstractUpdate
24 {
25 /**
26 * @var string
27 */
28 protected $title = 'Move access right parameters configuration to "SYS" section';
29
30 /**
31 * @var array
32 */
33 protected $movedAccessRightConfigurationSettings = [
34 'BE/fileCreateMask' => 'SYS/fileCreateMask',
35 'BE/folderCreateMask' => 'SYS/folderCreateMask',
36 'BE/createGroup' => 'SYS/createGroup',
37 ];
38
39 /**
40 * Checks if an update is needed
41 *
42 * @param string &$description The description for the update
43 * @return bool Whether an update is needed (TRUE) or not (FALSE)
44 */
45 public function checkForUpdate(&$description)
46 {
47 $updateNeeded = false;
48
49 /** @var ConfigurationManager $configurationManager */
50 $configurationManager = GeneralUtility::makeInstance(ConfigurationManager::class);
51
52 // If the local configuration path can be accessed, the path is valid and the update wizard has to be executed
53 foreach ($this->movedAccessRightConfigurationSettings as $oldPath => $newPath) {
54 try {
55 $configurationManager->getLocalConfigurationValueByPath($oldPath);
56 $updateNeeded = true;
57 break;
58 } catch (\RuntimeException $e) {
59 }
60 }
61
62 $description = 'Some access right parameters were moved from the "BE" to the "SYS" configuration section. ' .
63 'The update wizards moves the settings to the new configuration destination.';
64
65 return $updateNeeded;
66 }
67
68 /**
69 * Performs the configuration update
70 *
71 * @param array &$databaseQueries Queries done in this update
72 * @param mixed &$customMessages Custom messages
73 * @return bool
74 */
75 public function performUpdate(array &$databaseQueries, &$customMessages)
76 {
77 /** @var ConfigurationManager $configurationManager */
78 $configurationManager = GeneralUtility::makeInstance(ConfigurationManager::class);
79 foreach ($this->movedAccessRightConfigurationSettings as $oldPath => $newPath) {
80 try {
81 $value = $configurationManager->getLocalConfigurationValueByPath($oldPath);
82 $configurationManager->setLocalConfigurationValueByPath($newPath, $value);
83 } catch (\RuntimeException $e) {
84 }
85 }
86 $configurationManager->removeLocalConfigurationKeysByPath(array_keys($this->movedAccessRightConfigurationSettings));
87
88 $this->markWizardAsDone();
89 return true;
90 }
91 }