[BUGFIX] Fix problem with saving extension configuration in different tabs 80/16280/4
authorJan-Erik Revsbech <janerik@moc.net>
Thu, 8 Nov 2012 00:38:58 +0000 (01:38 +0100)
committerChristian Kuhn <lolli@schwarzbu.ch>
Fri, 25 Jan 2013 19:39:05 +0000 (20:39 +0100)
The new ConfigurationUtility is working internally with configuration as
valued array, but the existing configuration is serialized in the old
nested format. When merging these two, exising configuration was not
merged correctly, resulting in error where configuration set in other tabs
was lost when saving.

Change-Id: I9007a0f80974A72610b3afc1e1dc76f7cad31fca
Fixes: #42775
Releases: 6.0
Change-Id: I9007a0f80974a72610b3afc1e1dc76f7cad31fca
Reviewed-on: https://review.typo3.org/16280
Reviewed-by: Mattias Nilsson
Tested-by: Mattias Nilsson
Reviewed-by: Jan-Erik Revsbech
Tested-by: Jan-Erik Revsbech
Reviewed-by: Wouter Wolters
Tested-by: Wouter Wolters
Reviewed-by: Stefan Neufeind
Tested-by: Stefan Neufeind
Reviewed-by: Sebastian Michaelsen
Tested-by: Sebastian Michaelsen
Reviewed-by: Francois Suter
Tested-by: Francois Suter
Reviewed-by: Christian Kuhn
Tested-by: Christian Kuhn
typo3/sysext/extensionmanager/Classes/Utility/ConfigurationUtility.php
typo3/sysext/extensionmanager/Tests/Unit/Utility/ConfigurationUtilityTest.php

index f412443..eecb8c4 100644 (file)
@@ -85,7 +85,7 @@ class ConfigurationUtility implements \TYPO3\CMS\Core\SingletonInterface {
        }
 
        /**
-        * Get current configuration of an extension
+        * Get current configuration of an extension. Will return the configuration as a valued object
         *
         * @param string $extensionKey
         * @return array
@@ -95,6 +95,7 @@ class ConfigurationUtility implements \TYPO3\CMS\Core\SingletonInterface {
                $defaultConfig = $this->configurationItemRepository->createArrayFromConstants(\TYPO3\CMS\Core\Utility\GeneralUtility::getUrl(PATH_site . $extension['siteRelPath'] . '/ext_conf_template.txt'), $extension);
                $currentExtensionConfig = unserialize($GLOBALS['TYPO3_CONF_VARS']['EXT']['extConf'][$extensionKey]);
                $currentExtensionConfig = is_array($currentExtensionConfig) ? $currentExtensionConfig : array();
+               $currentExtensionConfig = $this->convertNestedToValuedConfiguration($currentExtensionConfig);
                $currentFullConfiguration = \TYPO3\CMS\Core\Utility\GeneralUtility::array_merge_recursive_overrule($defaultConfig, $currentExtensionConfig);
                return $currentFullConfiguration;
        }
@@ -118,7 +119,24 @@ class ConfigurationUtility implements \TYPO3\CMS\Core\SingletonInterface {
                return $nestedConfiguration;
        }
 
+       /**
+        * Convert a nested configuration to a valued configuration
+        *
+        * array('first.' => array('second' => 1))
+        * will become
+        * array('first.second' => array('value' => 1)
+        * @param array $nestedConfiguration
+        * @return array
+        */
+       public function convertNestedToValuedConfiguration(array $nestedConfiguration) {
+               $flatExtensionConfig = \TYPO3\CMS\Core\Utility\ArrayUtility::flatten($nestedConfiguration);
+               $valuedCurrentExtensionConfig = array();
+               foreach ($flatExtensionConfig as $key => $value) {
+                       $valuedCurrentExtensionConfig[$key]['value'] = $value;
+               }
+               return $valuedCurrentExtensionConfig;
+       }
 }
 
 
-?>
\ No newline at end of file
+?>
index 967863e..f0124f4 100644 (file)
@@ -126,7 +126,87 @@ class ConfigurationUtilityTest extends \TYPO3\CMS\Extbase\Tests\Unit\BaseTestCas
                );
        }
 
-}
+       /**
+        * @param array $configuration
+        * @param array $expected
+        * @test
+        * @dataProvider convertNestedToValuedConfigurationDataProvider
+        */
+       public function convertNestedToValuedConfiguration(array $configuration, array $expected) {
+               /** @var $fixture \TYPO3\CMS\Extensionmanager\Utility\ConfigurationUtility */
+               $fixture = $this->objectManager->get('TYPO3\\CMS\\Extensionmanager\\Utility\\ConfigurationUtility');
+               $this->assertEquals($expected, $fixture->convertNestedToValuedConfiguration($configuration));
+       }
 
+       /**
+        * @return array
+        */
+       public function convertNestedToValuedConfigurationDataProvider() {
+               return array(
+                       'plain array' => array(
+                               array(
+                                       'first' => 'value1',
+                                       'second' => 'value2'
+                               ),
+                               array(
+                                       'first' => array('value' => 'value1'),
+                                       'second' => array('value' => 'value2'),
+                               )
+                       ),
+                       'two levels' => array(
+                               array(
+                                       'first.' => array('firstSub' => 'value1'),
+                                       'second.' => array('firstSub' => 'value2'),
+                               ),
+                               array(
+                                       'first.firstSub' => array('value' => 'value1'),
+                                       'second.firstSub' => array('value' => 'value2'),
+                               )
+                       ),
+                       'three levels' => array(
+                               array(
+                                       'first.' => array('firstSub.' => array('firstSubSub' => 'value1')),
+                                       'second.' => array('firstSub.' => array('firstSubSub' => 'value2'))
+                               ),
+                               array(
+                                       'first.firstSub.firstSubSub' => array('value' => 'value1'),
+                                       'second.firstSub.firstSubSub' => array('value' => 'value2'),
+                               )
+                       ),
+                       'mixed' => array(
+                               array(
+                                       'first.' => array('firstSub' => 'value1'),
+                                       'second.' => array('firstSub.' => array('firstSubSub' => 'value2')),
+                                       'third' => 'value3'
+                               ),
+                               array(
+                                       'first.firstSub' => array('value' => 'value1'),
+                                       'second.firstSub.firstSubSub' => array('value' => 'value2'),
+                                       'third' => array('value' => 'value3')
+                               )
+                       )
+               );
+       }
 
-?>
\ No newline at end of file
+       /**
+        * @test
+        */
+       public function thatGetCurrentConfigurationReturnsCorrectExtensionConfigurationAsValuedConfiguration() {
+               $mockedConfigurationItemRepository = $this->getAccessibleMock('\TYPO3\CMS\Extensionmanager\Domain\Repository\ConfigurationItemRepository', array(
+                       'createArrayFromConstants'
+               ));
+               $mockedConfigurationItemRepository->expects($this->any())
+                       ->method('createArrayFromConstants')
+                       ->will($this->returnValue(array()));
+               $GLOBALS['TYPO3_LOADED_EXT']['MY_DUMMY_EXT']= array();
+               $GLOBALS['TYPO3_CONF_VARS']['EXT']['extConf']['MY_DUMMY_EXT'] = serialize(array('key1' => 'value1', 'key2.' => array('subkey1' => 'value2')));
+               $configurationUtility = $this->objectManager->get('TYPO3\\CMS\\Extensionmanager\\Utility\\ConfigurationUtility');
+               $configurationUtility->injectConfigurationItemRepository($mockedConfigurationItemRepository);
+
+               $configuration = $configurationUtility->getCurrentConfiguration('MY_DUMMY_EXT');
+               $this->assertEquals('value1', $configuration['key1']['value']);
+               $this->assertEquals('value2', $configuration['key2.subkey1']['value']);
+       }
+
+}
+?>