TYPO3 CMS  TYPO3_7-6
SilentConfigurationUpgradeService.php
Go to the documentation of this file.
1 <?php
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 
20 
33 {
37  protected $objectManager = null;
38 
42  protected $configurationManager = null;
43 
53  // #62402
54  'INSTALL/wizardDone/TYPO3\\CMS\\Install\\Updates\\ExtensionManagerTables',
55  'INSTALL/wizardDone/TYPO3\\CMS\\Install\\Updates\\FileIdentifierHashUpdate',
56  'INSTALL/wizardDone/TYPO3\\CMS\\Install\\Updates\\FilemountUpdateWizard',
57  'INSTALL/wizardDone/TYPO3\\CMS\\Install\\Updates\\FilePermissionUpdate',
58  'INSTALL/wizardDone/TYPO3\\CMS\\Install\\Updates\\FileTableSplittingUpdate',
59  'INSTALL/wizardDone/TYPO3\\CMS\\Install\\Updates\\InitUpdateWizard',
60  'INSTALL/wizardDone/TYPO3\\CMS\\Install\\Updates\\MediaFlexformUpdate',
61  'INSTALL/wizardDone/TYPO3\\CMS\\Install\\Updates\\ReferenceIntegrityUpdateWizard',
62  'INSTALL/wizardDone/TYPO3\\CMS\\Install\\Updates\\RteFileLinksUpdateWizard',
63  'INSTALL/wizardDone/TYPO3\\CMS\\Install\\Updates\\RteMagicImagesUpdateWizard',
64  'INSTALL/wizardDone/TYPO3\\CMS\\Install\\Updates\\TceformsUpdateWizard',
65  'INSTALL/wizardDone/TYPO3\\CMS\\Install\\Updates\\TtContentUploadsUpdateWizard',
66  'INSTALL/wizardDone/TYPO3\\CMS\\Install\\Updates\\TruncateSysFileProcessedFileTable',
67  // #68183
68  'INSTALL/wizardDone/TYPO3\\CMS\\Install\\Updates\\MigrateShortcutUrlsUpdate',
69  // #63818
70  'BE/staticFileEditPath',
71  // #64226
72  'BE/accessListRenderMode',
73  // #66431
74  'BE/loginNewsTitle',
75  // #24900
76  'SYS/compat_version',
77  // #64643
78  'GFX/enable_typo3temp_db_tracking',
79  // #48542
80  'GFX/TTFdpi',
81  // #64872
82  'SYS/useCachingFramework',
83  // #65912
84  'FE/allowedTempPaths',
85  // #66034
86  'FE/activateContentAdapter',
87  // #66902
88  'SYS/loginCopyrightShowVersion',
89  // #66903
90  'BE/RTEenabled',
91  // #66906
92  'GFX/png_to_gif',
93  // #67411
94  'SYS/caching/cacheConfigurations/cache_classes',
95  // #68178
96  'SYS/form_enctype',
97  // #69904
98  'BE/diff_path',
99  // #69930
100  'SYS/serverTimeZone',
101  // #70138
102  'BE/flexFormXMLincludeDiffBase',
103  // #71110
104  'BE/maxFileSize',
105  ];
106 
110  public function injectObjectManager(\TYPO3\CMS\Extbase\Object\ObjectManager $objectManager)
111  {
112  $this->objectManager = $objectManager;
113  }
114 
119  {
120  $this->configurationManager = $configurationManager;
121  }
122 
129  public function execute()
130  {
133  $this->configureSaltedPasswords();
134  $this->setProxyAuthScheme();
140  }
141 
151  {
152  $removed = $this->configurationManager->removeLocalConfigurationKeysByPath($this->obsoleteLocalConfigurationSettings);
153 
154  // If something was changed: Trigger a reload to have new values in next request
155  if ($removed) {
156  $this->throwRedirectException();
157  }
158  }
159 
167  protected function configureBackendLoginSecurity()
168  {
169  $rsaauthLoaded = ExtensionManagementUtility::isLoaded('rsaauth');
170  try {
171  $currentLoginSecurityLevelValue = $this->configurationManager->getLocalConfigurationValueByPath('BE/loginSecurityLevel');
172  if ($rsaauthLoaded && $currentLoginSecurityLevelValue !== 'rsa') {
173  $this->configurationManager->setLocalConfigurationValueByPath('BE/loginSecurityLevel', 'rsa');
174  $this->throwRedirectException();
175  } elseif (!$rsaauthLoaded && $currentLoginSecurityLevelValue !== 'normal') {
176  $this->configurationManager->setLocalConfigurationValueByPath('BE/loginSecurityLevel', 'normal');
177  $this->throwRedirectException();
178  }
179  } catch (\RuntimeException $e) {
180  // If an exception is thrown, the value is not set in LocalConfiguration
181  $this->configurationManager->setLocalConfigurationValueByPath('BE/loginSecurityLevel', $rsaauthLoaded ? 'rsa' : 'normal');
182  $this->throwRedirectException();
183  }
184  }
185 
192  protected function configureSaltedPasswords()
193  {
194  $defaultConfiguration = $this->configurationManager->getDefaultConfiguration();
195  $defaultExtensionConfiguration = unserialize($defaultConfiguration['EXT']['extConf']['saltedpasswords']);
196  try {
197  $extensionConfiguration = @unserialize($this->configurationManager->getLocalConfigurationValueByPath('EXT/extConf/saltedpasswords'));
198  } catch (\RuntimeException $e) {
199  $extensionConfiguration = [];
200  }
201  if (is_array($extensionConfiguration) && !empty($extensionConfiguration)) {
202  if (isset($extensionConfiguration['BE.']['enabled'])) {
203  if ($extensionConfiguration['BE.']['enabled']) {
204  unset($extensionConfiguration['BE.']['enabled']);
205  } else {
206  $extensionConfiguration['BE.'] = $defaultExtensionConfiguration['BE.'];
207  }
208  $this->configurationManager->setLocalConfigurationValueByPath(
209  'EXT/extConf/saltedpasswords',
210  serialize($extensionConfiguration)
211  );
212  $this->throwRedirectException();
213  }
214  } else {
215  $this->configurationManager->setLocalConfigurationValueByPath(
216  'EXT/extConf/saltedpasswords',
217  serialize($defaultExtensionConfiguration)
218  );
219  $this->throwRedirectException();
220  }
221  }
222 
231  protected function generateEncryptionKeyIfNeeded()
232  {
233  try {
234  $currentValue = $this->configurationManager->getLocalConfigurationValueByPath('SYS/encryptionKey');
235  } catch (\RuntimeException $e) {
236  // If an exception is thrown, the value is not set in LocalConfiguration
237  $currentValue = '';
238  }
239 
240  if (empty($currentValue)) {
241  $randomKey = GeneralUtility::getRandomHexString(96);
242  $this->configurationManager->setLocalConfigurationValueByPath('SYS/encryptionKey', $randomKey);
243  $this->throwRedirectException();
244  }
245  }
246 
254  protected function setProxyAuthScheme()
255  {
256  // Get current value from LocalConfiguration
257  try {
258  $currentValueInLocalConfiguration = $this->configurationManager->getLocalConfigurationValueByPath('HTTP/proxy_auth_scheme');
259  } catch (\RuntimeException $e) {
260  // If an exception is thrown, the value is not set in LocalConfiguration, so we don't need to do anything
261  return;
262  }
263  if ($currentValueInLocalConfiguration !== 'digest') {
264  $this->configurationManager->removeLocalConfigurationKeysByPath(['HTTP/proxy_auth_scheme']);
265  $this->throwRedirectException();
266  }
267  }
268 
274  protected function transferDeprecatedCurlSettings()
275  {
276  $changed = false;
277  try {
278  $curlProxyServer = $this->configurationManager->getLocalConfigurationValueByPath('SYS/curlProxyServer');
279  } catch (\RuntimeException $e) {
280  $curlProxyServer = '';
281  }
282  try {
283  $proxyHost = $this->configurationManager->getLocalConfigurationValueByPath('HTTP/proxy_host');
284  } catch (\RuntimeException $e) {
285  $proxyHost = '';
286  }
287  if (!empty($curlProxyServer) && empty($proxyHost)) {
288  $curlProxy = rtrim(preg_replace('#^https?://#', '', $curlProxyServer), '/');
289  $proxyParts = GeneralUtility::revExplode(':', $curlProxy, 2);
290  $this->configurationManager->setLocalConfigurationValueByPath('HTTP/proxy_host', $proxyParts[0]);
291  $this->configurationManager->setLocalConfigurationValueByPath('HTTP/proxy_port', $proxyParts[1]);
292  $changed = true;
293  }
294 
295  try {
296  $curlProxyUserPass = $this->configurationManager->getLocalConfigurationValueByPath('SYS/curlProxyUserPass');
297  } catch (\RuntimeException $e) {
298  $curlProxyUserPass = '';
299  }
300  try {
301  $proxyUser = $this->configurationManager->getLocalConfigurationValueByPath('HTTP/proxy_user');
302  } catch (\RuntimeException $e) {
303  $proxyUser = '';
304  }
305  if (!empty($curlProxyUserPass) && empty($proxyUser)) {
306  $userPassParts = explode(':', $curlProxyUserPass, 2);
307  $this->configurationManager->setLocalConfigurationValueByPath('HTTP/proxy_user', $userPassParts[0]);
308  $this->configurationManager->setLocalConfigurationValueByPath('HTTP/proxy_password', $userPassParts[1]);
309  $changed = true;
310  }
311 
312  try {
313  $curlUse = $this->configurationManager->getLocalConfigurationValueByPath('SYS/curlUse');
314  } catch (\RuntimeException $e) {
315  $curlUse = '';
316  }
317  try {
318  $adapter = $this->configurationManager->getConfigurationValueByPath('HTTP/adapter');
319  } catch (\RuntimeException $e) {
320  $adapter = '';
321  }
322  if (!empty($curlUse) && $adapter !== 'curl') {
323  $GLOBALS['TYPO3_CONF_VARS']['HTTP']['adapter'] = 'curl';
324  $this->configurationManager->setLocalConfigurationValueByPath('HTTP/adapter', 'curl');
325  $changed = true;
326  }
327  if ($changed) {
328  $this->throwRedirectException();
329  }
330  }
331 
342  {
343  $changedValues = [];
344  try {
345  $currentImageProcessingValue = $this->configurationManager->getLocalConfigurationValueByPath('GFX/image_processing');
346  } catch (\RuntimeException $e) {
347  $currentImageProcessingValue = $this->configurationManager->getDefaultConfigurationValueByPath('GFX/image_processing');
348  }
349  try {
350  $currentImValue = $this->configurationManager->getLocalConfigurationValueByPath('GFX/im');
351  } catch (\RuntimeException $e) {
352  $currentImValue = $this->configurationManager->getDefaultConfigurationValueByPath('GFX/im');
353  }
354  try {
355  $currentGdlibValue = $this->configurationManager->getLocalConfigurationValueByPath('GFX/gdlib');
356  } catch (\RuntimeException $e) {
357  $currentGdlibValue = $this->configurationManager->getDefaultConfigurationValueByPath('GFX/gdlib');
358  }
359  // If image processing is fully disabled, im and gdlib sub settings must be 0
360  if (!$currentImageProcessingValue) {
361  if ($currentImValue != 0) {
362  $changedValues['GFX/im'] = 0;
363  }
364  if ($currentGdlibValue != 0) {
365  $changedValues['GFX/gdlib'] = 0;
366  }
367  }
368  if (!empty($changedValues)) {
369  $this->configurationManager->setLocalConfigurationValuesByPathValuePairs($changedValues);
370  $this->throwRedirectException();
371  }
372  }
373 
385  {
386  $changedValues = [];
387  try {
388  $currentImValue = $this->configurationManager->getLocalConfigurationValueByPath('GFX/im');
389  } catch (\RuntimeException $e) {
390  $currentImValue = $this->configurationManager->getDefaultConfigurationValueByPath('GFX/im');
391  }
392  try {
393  $currentImPathValue = $this->configurationManager->getLocalConfigurationValueByPath('GFX/im_path');
394  } catch (\RuntimeException $e) {
395  $currentImPathValue = $this->configurationManager->getDefaultConfigurationValueByPath('GFX/im_path');
396  }
397  try {
398  $currentImPathLzwValue = $this->configurationManager->getLocalConfigurationValueByPath('GFX/im_path_lzw');
399  } catch (\RuntimeException $e) {
400  $currentImPathLzwValue = $this->configurationManager->getDefaultConfigurationValueByPath('GFX/im_path_lzw');
401  }
402  try {
403  $currentImageFileExtValue = $this->configurationManager->getLocalConfigurationValueByPath('GFX/imagefile_ext');
404  } catch (\RuntimeException $e) {
405  $currentImageFileExtValue = $this->configurationManager->getDefaultConfigurationValueByPath('GFX/imagefile_ext');
406  }
407  try {
408  $currentThumbnailsValue = $this->configurationManager->getLocalConfigurationValueByPath('GFX/thumbnails');
409  } catch (\RuntimeException $e) {
410  $currentThumbnailsValue = $this->configurationManager->getDefaultConfigurationValueByPath('GFX/thumbnails');
411  }
412  if (!$currentImValue) {
413  if ($currentImPathValue != '') {
414  $changedValues['GFX/im_path'] = '';
415  }
416  if ($currentImPathLzwValue != '') {
417  $changedValues['GFX/im_path_lzw'] = '';
418  }
419  if ($currentImageFileExtValue !== 'gif,jpg,jpeg,png') {
420  $changedValues['GFX/imagefile_ext'] = 'gif,jpg,jpeg,png';
421  }
422  if ($currentThumbnailsValue != 0) {
423  $changedValues['GFX/thumbnails'] = 0;
424  }
425  }
426  if (!empty($changedValues)) {
427  $this->configurationManager->setLocalConfigurationValuesByPathValuePairs($changedValues);
428  $this->throwRedirectException();
429  }
430  }
431 
442  protected function setImageMagickDetailSettings()
443  {
444  $changedValues = [];
445  try {
446  $currentIm5Value = $this->configurationManager->getLocalConfigurationValueByPath('GFX/im_version_5');
447  } catch (\RuntimeException $e) {
448  $currentIm5Value = $this->configurationManager->getDefaultConfigurationValueByPath('GFX/im_version_5');
449  }
450  try {
451  $currentImMaskValue = $this->configurationManager->getLocalConfigurationValueByPath('GFX/im_mask_temp_ext_gif');
452  } catch (\RuntimeException $e) {
453  $currentImMaskValue = $this->configurationManager->getDefaultConfigurationValueByPath('GFX/im_mask_temp_ext_gif');
454  }
455  try {
456  $currentIm5EffectsValue = $this->configurationManager->getLocalConfigurationValueByPath('GFX/im_v5effects');
457  } catch (\RuntimeException $e) {
458  $currentIm5EffectsValue = $this->configurationManager->getDefaultConfigurationValueByPath('GFX/im_v5effects');
459  }
460  if ((string)$currentIm5Value !== '') {
461  if ($currentImMaskValue != 1) {
462  $changedValues['GFX/im_mask_temp_ext_gif'] = 1;
463  }
464  if ($currentIm5Value === 'gm') {
465  if ($currentIm5EffectsValue != -1) {
466  $changedValues['GFX/im_v5effects'] = -1;
467  }
468  }
469  }
470  if (!empty($changedValues)) {
471  $this->configurationManager->setLocalConfigurationValuesByPathValuePairs($changedValues);
472  $this->throwRedirectException();
473  }
474  }
475 
481  protected function throwRedirectException()
482  {
483  throw new RedirectException(
484  'Configuration updated, reload needed',
485  1379024938
486  );
487  }
488 }
injectConfigurationManager(\TYPO3\CMS\Core\Configuration\ConfigurationManager $configurationManager)
injectObjectManager(\TYPO3\CMS\Extbase\Object\ObjectManager $objectManager)
static revExplode($delimiter, $string, $count=0)
if(TYPO3_MODE==='BE') $GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['t3lib/class.t3lib_tsfebeuserauth.php']['frontendEditingController']['default']