[TASK] Use fully qualified name resolution in PHP 5.5
[Packages/TYPO3.CMS.git] / typo3 / sysext / extensionmanager / Classes / Controller / ConfigurationController.php
1 <?php
2 namespace TYPO3\CMS\Extensionmanager\Controller;
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\Extensionmanager\Domain\Model\Extension;
18 use TYPO3\CMS\Extensionmanager\Exception\ExtensionManagerException;
19
20 /**
21 * Controller for configuration related actions.
22 *
23 * @author Susanne Moog <typo3@susannemoog.de>
24 */
25 class ConfigurationController extends AbstractController {
26
27 /**
28 * @var \TYPO3\CMS\Extensionmanager\Domain\Repository\ConfigurationItemRepository
29 * @inject
30 */
31 protected $configurationItemRepository;
32
33 /**
34 * @var \TYPO3\CMS\Extensionmanager\Domain\Repository\ExtensionRepository
35 * @inject
36 */
37 protected $extensionRepository;
38
39 /**
40 * Show the extension configuration form. The whole form field handling is done
41 * in the corresponding view helper
42 *
43 * @param array $extension Extension information, must contain at least the key
44 * @throws \TYPO3\CMS\Extensionmanager\Exception\ExtensionManagerException
45 * @return void
46 */
47 public function showConfigurationFormAction(array $extension) {
48 if (!isset($extension['key'])) {
49 throw new ExtensionManagerException('Extension key not found.', 1359206803);
50 }
51 $extKey = $extension['key'];
52 $configuration = $this->configurationItemRepository->findByExtensionKey($extKey);
53 if ($configuration) {
54 $this->view
55 ->assign('configuration', $configuration)
56 ->assign('extension', $extension);
57 } else {
58 /** @var Extension $extension */
59 $extension = $this->extensionRepository->findOneByCurrentVersionByExtensionKey($extKey);
60 // Extension has no configuration and is a distribution
61 if ($extension->getCategory() === Extension::DISTRIBUTION_CATEGORY) {
62 $this->redirect('welcome', 'Distribution', NULL, array('extension' => $extension->getUid()));
63 }
64 throw new ExtensionManagerException('The extension ' . $extKey . ' has no configuration.');
65 }
66 }
67
68 /**
69 * Save configuration and redirects back to form
70 * or to the welcome page of a distribution
71 *
72 * @param array $config The new extension configuration
73 * @param string $extensionKey The extension key
74 * @return void
75 */
76 public function saveAction(array $config, $extensionKey) {
77 $this->saveConfiguration($config, $extensionKey);
78 /** @var Extension $extension */
79 $extension = $this->extensionRepository->findOneByCurrentVersionByExtensionKey($extensionKey);
80 // Different handling for distribution installation
81 if ($extension instanceof Extension &&
82 $extension->getCategory() === Extension::DISTRIBUTION_CATEGORY
83 ) {
84 $this->redirect('welcome', 'Distribution', NULL, array('extension' => $extension->getUid()));
85 } else {
86 $this->redirect('showConfigurationForm', NULL, NULL, array('extension' => array('key' => $extensionKey)));
87 }
88 }
89
90 /**
91 * Saves new configuration and redirects back to list
92 *
93 * @param array $config
94 * @param string $extensionKey
95 * @return void
96 */
97 public function saveAndCloseAction(array $config, $extensionKey) {
98 $this->saveConfiguration($config, $extensionKey);
99 $this->redirect('index', 'List');
100 }
101
102
103 /**
104 * Emits a signal after the configuration file was written
105 *
106 * @param string $extensionKey
107 * @param array $newConfiguration
108 * @return void
109 */
110 protected function emitAfterExtensionConfigurationWriteSignal($extensionKey, array $newConfiguration) {
111 $this->signalSlotDispatcher->dispatch(__CLASS__, 'afterExtensionConfigurationWrite', array($extensionKey, $newConfiguration, $this));
112 }
113
114 /**
115 * Merge and save new configuration
116 *
117 * @param array $config
118 * @param $extensionKey
119 * @return void
120 */
121 protected function saveConfiguration(array $config, $extensionKey) {
122 /** @var $configurationUtility \TYPO3\CMS\Extensionmanager\Utility\ConfigurationUtility */
123 $configurationUtility = $this->objectManager->get(\TYPO3\CMS\Extensionmanager\Utility\ConfigurationUtility::class);
124 $newConfiguration = $configurationUtility->getCurrentConfiguration($extensionKey);
125 \TYPO3\CMS\Core\Utility\ArrayUtility::mergeRecursiveWithOverrule($newConfiguration, $config);
126 $configurationUtility->writeConfiguration(
127 $configurationUtility->convertValuedToNestedConfiguration($newConfiguration),
128 $extensionKey
129 );
130 $this->emitAfterExtensionConfigurationWriteSignal($extensionKey, $newConfiguration);
131 }
132
133 }