[BUGFIX] Moved transferDeprecatedCurlSettings from Bootstrap to Setup 09/42209/7
authorMichael Oehlhof <typo3@oehlhof.de>
Sun, 2 Aug 2015 22:07:00 +0000 (00:07 +0200)
committerSusanne Moog <typo3@susannemoog.de>
Sat, 8 Aug 2015 15:14:58 +0000 (17:14 +0200)
Resolves: #54556
Releases: master
Change-Id: Id649033fc8e50833b9cdc15b8a37e25800463160
Reviewed-on: http://review.typo3.org/42209
Reviewed-by: Christian Kuhn <lolli@schwarzbu.ch>
Tested-by: Christian Kuhn <lolli@schwarzbu.ch>
Reviewed-by: Susanne Moog <typo3@susannemoog.de>
Tested-by: Susanne Moog <typo3@susannemoog.de>
typo3/sysext/core/Classes/Core/Bootstrap.php
typo3/sysext/core/Tests/Unit/Core/BootstrapTest.php
typo3/sysext/install/Classes/Service/SilentConfigurationUpgradeService.php
typo3/sysext/install/Tests/Unit/Service/SilentConfigurationUpgradeServiceTest.php [new file with mode: 0644]

index 8bdc82d..5eb1d54 100644 (file)
@@ -373,7 +373,6 @@ class Bootstrap {
                        ->defineDatabaseConstants()
                        ->defineUserAgentConstant()
                        ->registerExtDirectComponents()
-                       ->transferDeprecatedCurlSettings()
                        ->setCacheHashOptions()
                        ->setDefaultTimezone()
                        ->initializeL10nLocales()
@@ -561,30 +560,6 @@ class Bootstrap {
        }
 
        /**
-        * Parse old curl options and set new http ones instead
-        *
-        * @TODO: Move this functionality to the silent updater in the Install Tool
-        * @return Bootstrap
-        */
-       protected function transferDeprecatedCurlSettings() {
-               if (!empty($GLOBALS['TYPO3_CONF_VARS']['SYS']['curlProxyServer']) && empty($GLOBALS['TYPO3_CONF_VARS']['HTTP']['proxy_host'])) {
-                       $curlProxy = rtrim(preg_replace('#^https?://#', '', $GLOBALS['TYPO3_CONF_VARS']['SYS']['curlProxyServer']), '/');
-                       $proxyParts = GeneralUtility::revExplode(':', $curlProxy, 2);
-                       $GLOBALS['TYPO3_CONF_VARS']['HTTP']['proxy_host'] = $proxyParts[0];
-                       $GLOBALS['TYPO3_CONF_VARS']['HTTP']['proxy_port'] = $proxyParts[1];
-               }
-               if (!empty($GLOBALS['TYPO3_CONF_VARS']['SYS']['curlProxyUserPass']) && empty($GLOBALS['TYPO3_CONF_VARS']['HTTP']['proxy_user'])) {
-                       $userPassParts = explode(':', $GLOBALS['TYPO3_CONF_VARS']['SYS']['curlProxyUserPass'], 2);
-                       $GLOBALS['TYPO3_CONF_VARS']['HTTP']['proxy_user'] = $userPassParts[0];
-                       $GLOBALS['TYPO3_CONF_VARS']['HTTP']['proxy_password'] = $userPassParts[1];
-               }
-               if ($GLOBALS['TYPO3_CONF_VARS']['SYS']['curlUse']) {
-                       $GLOBALS['TYPO3_CONF_VARS']['HTTP']['adapter'] = 'curl';
-               }
-               return $this;
-       }
-
-       /**
         * Set cacheHash options
         *
         * @return Bootstrap
index 18755ea..aa7582a 100644 (file)
@@ -99,84 +99,4 @@ class BootstrapTest extends \TYPO3\CMS\Core\Tests\UnitTestCase {
                $bootstrapInstance->loadCachedTca();
        }
 
-       /**
-        * Dataprovider for transferDeprecatedCurlSettings
-        *
-        * @return array
-        */
-       public function curlProxySettingsToHttpSettingsMapping() {
-               return array(
-                       array('http://proxy:3128/', 'proxy', '3128'),
-                       array('http://proxy:3128', 'proxy', '3128'),
-                       array('proxy:3128', 'proxy', '3128'),
-                       array('https://proxy:3128/', 'proxy', '3128'),
-               );
-       }
-
-       /**
-        * @test
-        * @dataProvider curlProxySettingsToHttpSettingsMapping
-        */
-       public function transferDeprecatedCurlSettings($curlProxyServer, $proxyHost, $proxyPort) {
-               /** @var $bootstrapInstance \TYPO3\CMS\Core\Core\Bootstrap|\PHPUnit_Framework_MockObject_MockObject|\TYPO3\CMS\Core\Tests\AccessibleObjectInterface */
-               $bootstrapInstance = $this->getAccessibleMock(
-                       \TYPO3\CMS\Core\Core\Bootstrap::class,
-                       array('dummy'),
-                       array(),
-                       '',
-                       FALSE
-               );
-               $GLOBALS['TYPO3_CONF_VARS']['SYS']['curlProxyServer'] = $curlProxyServer;
-               $bootstrapInstance->_call('transferDeprecatedCurlSettings');
-               $this->assertEquals($proxyHost, $GLOBALS['TYPO3_CONF_VARS']['HTTP']['proxy_host']);
-               $this->assertEquals($proxyPort, $GLOBALS['TYPO3_CONF_VARS']['HTTP']['proxy_port']);
-       }
-
-       /**
-        * @test
-        */
-       public function curlProxyServerDoesNotOverwriteHttpSettings() {
-               /** @var $bootstrapInstance \TYPO3\CMS\Core\Core\Bootstrap|\PHPUnit_Framework_MockObject_MockObject|\TYPO3\CMS\Core\Tests\AccessibleObjectInterface */
-               $bootstrapInstance = $this->getAccessibleMock(
-                       \TYPO3\CMS\Core\Core\Bootstrap::class,
-                       array('dummy'),
-                       array(),
-                       '',
-                       FALSE
-               );
-
-               $GLOBALS['TYPO3_CONF_VARS']['SYS']['curlProxyServer'] = 'http://proxyOld:3128/';
-               $GLOBALS['TYPO3_CONF_VARS']['SYS']['curlProxyUserPass'] = 'userOld:passOld';
-               $GLOBALS['TYPO3_CONF_VARS']['HTTP']['proxy_host'] = 'proxyNew';
-               $GLOBALS['TYPO3_CONF_VARS']['HTTP']['proxy_port'] = '3128';
-               $GLOBALS['TYPO3_CONF_VARS']['HTTP']['proxy_user'] = 'userNew';
-               $GLOBALS['TYPO3_CONF_VARS']['HTTP']['proxy_pass'] = 'passNew';
-
-               $bootstrapInstance->_call('transferDeprecatedCurlSettings');
-               $this->assertEquals('http://proxyOld:3128/', $GLOBALS['TYPO3_CONF_VARS']['SYS']['curlProxyServer']);
-               $this->assertEquals('userOld:passOld', $GLOBALS['TYPO3_CONF_VARS']['SYS']['curlProxyUserPass']);
-               $this->assertEquals('proxyNew', $GLOBALS['TYPO3_CONF_VARS']['HTTP']['proxy_host']);
-               $this->assertEquals('3128', $GLOBALS['TYPO3_CONF_VARS']['HTTP']['proxy_port']);
-               $this->assertEquals('userNew', $GLOBALS['TYPO3_CONF_VARS']['HTTP']['proxy_user']);
-               $this->assertEquals('passNew', $GLOBALS['TYPO3_CONF_VARS']['HTTP']['proxy_pass']);
-       }
-
-       /**
-        * @test
-        */
-       public function curlAdapterUsedIfCurlUse() {
-               /** @var $bootstrapInstance \TYPO3\CMS\Core\Core\Bootstrap|\PHPUnit_Framework_MockObject_MockObject|\TYPO3\CMS\Core\Tests\AccessibleObjectInterface */
-               $bootstrapInstance = $this->getAccessibleMock(
-                       \TYPO3\CMS\Core\Core\Bootstrap::class,
-                       array('dummy'),
-                       array(),
-                       '',
-                       FALSE
-               );
-
-               $GLOBALS['TYPO3_CONF_VARS']['SYS']['curlUse'] = TRUE;
-               $bootstrapInstance->_call('transferDeprecatedCurlSettings');
-               $this->assertEquals('curl', $GLOBALS['TYPO3_CONF_VARS']['HTTP']['adapter']);
-       }
-
 }
index 4d7c33e..c55f30a 100644 (file)
@@ -121,6 +121,7 @@ class SilentConfigurationUpgradeService {
                $this->configureBackendLoginSecurity();
                $this->configureSaltedPasswords();
                $this->setProxyAuthScheme();
+               $this->transferDeprecatedCurlSettings();
                $this->disableImageMagickAndGdlibIfImageProcessingIsDisabled();
                $this->disableImageMagickDetailSettingsIfImageMagickIsDisabled();
                $this->setImageMagickDetailSettings();
@@ -250,6 +251,68 @@ class SilentConfigurationUpgradeService {
        }
 
        /**
+        * Parse old curl options and set new http ones instead
+        *
+        * @return void
+        */
+       protected function transferDeprecatedCurlSettings() {
+               $changed = FALSE;
+               try {
+                       $curlProxyServer = $this->configurationManager->getLocalConfigurationValueByPath('SYS/curlProxyServer');
+               } catch (\RuntimeException $e) {
+                       $curlProxyServer = '';
+               }
+               try {
+                       $proxyHost = $this->configurationManager->getLocalConfigurationValueByPath('HTTP/proxy_host');
+               } catch (\RuntimeException $e) {
+                       $proxyHost = '';
+               }
+               if (!empty($curlProxyServer) && empty($proxyHost)) {
+                       $curlProxy = rtrim(preg_replace('#^https?://#', '', $curlProxyServer), '/');
+                       $proxyParts = GeneralUtility::revExplode(':', $curlProxy, 2);
+                       $this->configurationManager->setLocalConfigurationValueByPath('HTTP/proxy_host', $proxyParts[0]);
+                       $this->configurationManager->setLocalConfigurationValueByPath('HTTP/proxy_port', $proxyParts[1]);
+                       $changed = TRUE;
+               }
+
+               try {
+                       $curlProxyUserPass = $this->configurationManager->getLocalConfigurationValueByPath('SYS/curlProxyUserPass');
+               } catch (\RuntimeException $e) {
+                       $curlProxyUserPass = '';
+               }
+               try {
+                       $proxyUser = $this->configurationManager->getLocalConfigurationValueByPath('HTTP/proxy_user');
+               } catch (\RuntimeException $e) {
+                       $proxyUser = '';
+               }
+               if (!empty($curlProxyUserPass) && empty($proxyUser)) {
+                       $userPassParts = explode(':', $curlProxyUserPass, 2);
+                       $this->configurationManager->setLocalConfigurationValueByPath('HTTP/proxy_user', $userPassParts[0]);
+                       $this->configurationManager->setLocalConfigurationValueByPath('HTTP/proxy_password', $userPassParts[1]);
+                       $changed = TRUE;
+               }
+
+               try {
+                       $curlUse = $this->configurationManager->getLocalConfigurationValueByPath('SYS/curlUse');
+               } catch (\RuntimeException $e) {
+                       $curlUse = '';
+               }
+               try {
+                       $adapter = $this->configurationManager->getConfigurationValueByPath('HTTP/adapter');
+               } catch (\RuntimeException $e) {
+                       $adapter = '';
+               }
+               if (!empty($curlUse) && $adapter !== 'curl') {
+                       $GLOBALS['TYPO3_CONF_VARS']['HTTP']['adapter'] = 'curl';
+                       $this->configurationManager->setLocalConfigurationValueByPath('HTTP/adapter', 'curl');
+                       $changed = TRUE;
+               }
+               if ($changed) {
+                       $this->throwRedirectException();
+               }
+       }
+
+       /**
         * GFX/im and GFX/gdlib must be set to 0 if image_processing is disabled.
         *
         * "Configuration presets" in install tool is not type safe, so value
diff --git a/typo3/sysext/install/Tests/Unit/Service/SilentConfigurationUpgradeServiceTest.php b/typo3/sysext/install/Tests/Unit/Service/SilentConfigurationUpgradeServiceTest.php
new file mode 100644 (file)
index 0000000..fcbca61
--- /dev/null
@@ -0,0 +1,178 @@
+<?php
+namespace TYPO3\CMS\Install\Service;
+
+/*
+ * This file is part of the TYPO3 CMS project.
+ *
+ * It is free software; you can redistribute it and/or modify it under
+ * the terms of the GNU General Public License, either version 2
+ * of the License, or any later version.
+ *
+ * For the full copyright and license information, please read the
+ * LICENSE.txt file that was distributed with this source code.
+ *
+ * The TYPO3 project - inspiring people to share!
+ */
+
+use TYPO3\CMS\Install\Controller\Exception\RedirectException;
+
+/**
+ * Test case
+ */
+class SilentConfigurationUpgradeServiceTest extends \TYPO3\CMS\Core\Tests\UnitTestCase {
+
+       /**
+        * @var \TYPO3\CMS\Core\Configuration\ConfigurationManager|\PHPUnit_Framework_MockObject_MockObject
+        */
+       protected $configurationManager;
+
+       /**
+        * @param array $methods
+        */
+       protected function createConfigurationManagerWithMockedMethods(array $methods) {
+               $this->configurationManager = $this->getMock(
+                       \TYPO3\CMS\Core\Configuration\ConfigurationManager::class,
+                       $methods
+               );
+       }
+
+       /**
+        * Dataprovider for transferDeprecatedCurlSettings
+        *
+        * @return array
+        */
+       public function curlProxySettingsToHttpSettingsMapping() {
+               return array(
+                       array('http://proxy:3128/', 'proxy', '3128'),
+                       array('http://proxy:3128', 'proxy', '3128'),
+                       array('proxy:3128', 'proxy', '3128'),
+                       array('https://proxy:3128/', 'proxy', '3128'),
+               );
+       }
+
+       /**
+        * @test
+        * @dataProvider curlProxySettingsToHttpSettingsMapping
+        */
+       public function transferDeprecatedCurlSettings($curlProxyServer, $proxyHost, $proxyPort) {
+               /** @var $silentConfigurationUpgradeServiceInstance \TYPO3\CMS\Install\Service\SilentConfigurationUpgradeService|\PHPUnit_Framework_MockObject_MockObject|\TYPO3\CMS\Core\Tests\AccessibleObjectInterface */
+               $silentConfigurationUpgradeServiceInstance = $this->getAccessibleMock(
+                       \TYPO3\CMS\Install\Service\SilentConfigurationUpgradeService::class,
+                       array('dummy'),
+                       array(),
+                       '',
+                       FALSE
+               );
+
+               $currentLocalConfiguration = array(
+                       array('SYS/curlProxyServer',  $curlProxyServer),
+                       array('HTTP/proxy_host', ''),
+                       array('SYS/curlProxyUserPass',  ''),
+                       array('HTTP/proxy_user', ''),
+                       array('SYS/curlUse', FALSE)
+               );
+               $this->createConfigurationManagerWithMockedMethods(
+                       array(
+                               'getLocalConfigurationValueByPath',
+                               'setLocalConfigurationValueByPath',
+                       )
+               );
+               $this->configurationManager->expects($this->exactly(5))
+                       ->method('getLocalConfigurationValueByPath')
+                       ->will($this->returnValueMap($currentLocalConfiguration));
+               $this->configurationManager->expects($this->exactly(2))
+                       ->method('setLocalConfigurationValueByPath')
+                       ->withConsecutive(
+                               array('HTTP/proxy_host', $proxyHost),
+                               array('HTTP/proxy_port', $proxyPort)
+                       );
+
+               $this->setExpectedException('\TYPO3\CMS\Install\Controller\Exception\RedirectException');
+
+               $silentConfigurationUpgradeServiceInstance->_set('configurationManager', $this->configurationManager);
+
+               $silentConfigurationUpgradeServiceInstance->_call('transferDeprecatedCurlSettings');
+       }
+
+       /**
+        * @test
+        */
+       public function curlProxyServerDoesNotOverwriteHttpSettings() {
+               /** @var $silentConfigurationUpgradeServiceInstance \TYPO3\CMS\Install\Service\SilentConfigurationUpgradeService|\PHPUnit_Framework_MockObject_MockObject|\TYPO3\CMS\Core\Tests\AccessibleObjectInterface */
+               $silentConfigurationUpgradeServiceInstance = $this->getAccessibleMock(
+                       \TYPO3\CMS\Install\Service\SilentConfigurationUpgradeService::class,
+                       array('dummy'),
+                       array(),
+                       '',
+                       FALSE
+               );
+
+               $currentLocalConfiguration = array(
+                       array('SYS/curlProxyServer', 'http://proxyOld:3128/'),
+                       array('SYS/curlProxyUserPass', 'userOld:passOld'),
+                       array('HTTP/proxy_host', 'proxyNew'),
+                       array('HTTP/proxy_port', '3128'),
+                       array('HTTP/proxy_user', 'userNew'),
+                       array('HTTP/proxy_pass', 'passNew'),
+                       array('SYS/curlUse', FALSE)
+               );
+               $this->createConfigurationManagerWithMockedMethods(
+                       array(
+                               'getLocalConfigurationValueByPath',
+                               'setLocalConfigurationValueByPath',
+                       )
+               );
+               $this->configurationManager->expects($this->exactly(5))
+                       ->method('getLocalConfigurationValueByPath')
+                       ->will($this->returnValueMap($currentLocalConfiguration));
+               $this->configurationManager->expects($this->never())
+                       ->method('setLocalConfigurationValueByPath');
+
+               $silentConfigurationUpgradeServiceInstance->_set('configurationManager', $this->configurationManager);
+
+               $silentConfigurationUpgradeServiceInstance->_call('transferDeprecatedCurlSettings');
+       }
+
+       /**
+        * @test
+        */
+       public function curlAdapterUsedIfCurlUse() {
+               /** @var $silentConfigurationUpgradeServiceInstance \TYPO3\CMS\Install\Service\SilentConfigurationUpgradeService|\PHPUnit_Framework_MockObject_MockObject|\TYPO3\CMS\Core\Tests\AccessibleObjectInterface */
+               $silentConfigurationUpgradeServiceInstance = $this->getAccessibleMock(
+                       \TYPO3\CMS\Install\Service\SilentConfigurationUpgradeService::class,
+                       array('dummy'),
+                       array(),
+                       '',
+                       FALSE
+               );
+
+               $currentLocalConfiguration = array(
+                       array('SYS/curlProxyServer', ''),
+                       array('SYS/curlProxyUserPass', ''),
+                       array('HTTP/proxy_host', 'proxyNew'),
+                       array('HTTP/proxy_user', 'userNew'),
+                       array('SYS/curlUse', TRUE)
+               );
+               $this->createConfigurationManagerWithMockedMethods(
+                       array(
+                               'getLocalConfigurationValueByPath',
+                               'setLocalConfigurationValueByPath',
+                       )
+               );
+               $this->configurationManager->expects($this->exactly(5))
+                       ->method('getLocalConfigurationValueByPath')
+                       ->will($this->returnValueMap($currentLocalConfiguration));
+               $this->configurationManager->expects($this->once())
+                       ->method('setLocalConfigurationValueByPath')
+                       ->withConsecutive(
+                               array('HTTP/adapter', 'curl')
+                       );
+
+               $this->setExpectedException('\TYPO3\CMS\Install\Controller\Exception\RedirectException');
+
+               $silentConfigurationUpgradeServiceInstance->_set('configurationManager', $this->configurationManager);
+
+               $silentConfigurationUpgradeServiceInstance->_call('transferDeprecatedCurlSettings');
+       }
+
+}
\ No newline at end of file