[TASK] Get rid of ObjectManager in install tool
[Packages/TYPO3.CMS.git] / typo3 / sysext / install / Classes / Controller / Action / Tool / Configuration.php
1 <?php
2 namespace TYPO3\CMS\Install\Controller\Action\Tool;
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 use TYPO3\CMS\Install\Configuration\FeatureManager;
20 use TYPO3\CMS\Install\Controller\Action;
21
22 /**
23 * Show configuration features and handle presets
24 */
25 class Configuration extends Action\AbstractAction
26 {
27 /**
28 * @var \TYPO3\CMS\Install\Configuration\FeatureManager
29 */
30 protected $featureManager;
31
32 /**
33 * @var \TYPO3\CMS\Core\Configuration\ConfigurationManager
34 */
35 protected $configurationManager;
36
37 /**
38 * @param FeatureManager $featureManager
39 * @param ConfigurationManager $configurationManager
40 */
41 public function __construct(FeatureManager $featureManager = null, ConfigurationManager $configurationManager = null)
42 {
43 $this->featureManager = $featureManager ?: GeneralUtility::makeInstance(FeatureManager::class);
44 $this->configurationManager = $configurationManager ?: GeneralUtility::makeInstance(ConfigurationManager::class);
45 }
46
47 /**
48 * Executes the tool
49 *
50 * @return string Rendered content
51 */
52 protected function executeAction()
53 {
54 $actionMessages = array();
55 if (isset($this->postValues['set']['activate'])) {
56 $actionMessages[] = $this->activate();
57 $this->activate();
58 }
59 $this->view->assign('actionMessages', $actionMessages);
60
61 $postValues = is_array($this->postValues['values']) ? $this->postValues['values'] : array();
62 $this->view->assign('features', $this->featureManager->getInitializedFeatures($postValues));
63
64 return $this->view->render();
65 }
66
67 /**
68 * Configure selected feature presets to be active
69 *
70 * @return \TYPO3\CMS\Install\Status\StatusInterface
71 */
72 protected function activate()
73 {
74 $configurationValues = $this->featureManager->getConfigurationForSelectedFeaturePresets($this->postValues['values']);
75
76 if (!empty($configurationValues)) {
77 $this->configurationManager->setLocalConfigurationValuesByPathValuePairs($configurationValues);
78 /** @var $message \TYPO3\CMS\Install\Status\StatusInterface */
79 $message = GeneralUtility::makeInstance(\TYPO3\CMS\Install\Status\OkStatus::class);
80 $message->setTitle('Configuration written');
81 $messageBody = array();
82 foreach ($configurationValues as $configurationKey => $configurationValue) {
83 $messageBody[] = '\'' . $configurationKey . '\' => \'' . $configurationValue . '\'';
84 }
85 $message->setMessage(implode(LF, $messageBody));
86 } else {
87 /** @var $message \TYPO3\CMS\Install\Status\StatusInterface */
88 $message = GeneralUtility::makeInstance(\TYPO3\CMS\Install\Status\InfoStatus::class);
89 $message->setTitle('No configuration change selected');
90 }
91 return $message;
92 }
93 }