4cad8be3652b5ca3df82710c1d463c7feae07068
[Packages/TYPO3.CMS.git] / typo3 / sysext / install / Classes / Service / SilentConfigurationUpgradeService.php
1 <?php
2 namespace TYPO3\CMS\Install\Service;
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\Crypto\Random;
19 use TYPO3\CMS\Core\Utility\Exception\MissingArrayPathException;
20 use TYPO3\CMS\Core\Utility\ExtensionManagementUtility;
21 use TYPO3\CMS\Core\Utility\GeneralUtility;
22 use TYPO3\CMS\Install\Service\Exception\ConfigurationChangedException;
23
24 /**
25 * Execute "silent" LocalConfiguration upgrades if needed.
26 *
27 * Some LocalConfiguration settings are obsolete or changed over time.
28 * This class handles upgrades of these settings. It is called by
29 * the step controller at an early point.
30 *
31 * Every change is encapsulated in one method an must throw a ConfigurationChangedException
32 * if new data is written to LocalConfiguration. This is caught by above
33 * step controller to initiate a redirect and start again with adapted configuration.
34 */
35 class SilentConfigurationUpgradeService
36 {
37 /**
38 * @var \TYPO3\CMS\Core\Configuration\ConfigurationManager
39 */
40 protected $configurationManager;
41
42 /**
43 * List of obsolete configuration options in LocalConfiguration to be removed
44 * Example:
45 * // #forge-ticket
46 * 'BE/somesetting',
47 *
48 * @var array
49 */
50 protected $obsoleteLocalConfigurationSettings = [
51 // #72400
52 'BE/spriteIconGenerator_handler',
53 // #72417
54 'SYS/lockingMode',
55 // #72473
56 'FE/secureFormmail',
57 'FE/strictFormmail',
58 'FE/formmailMaxAttachmentSize',
59 // #72337
60 'SYS/t3lib_cs_utils',
61 'SYS/t3lib_cs_convMethod',
62 // #72604
63 'SYS/maxFileNameLength',
64 // #72602
65 'BE/unzip_path',
66 // #72615
67 'BE/notificationPrefix',
68 // #72616
69 'BE/XCLASS',
70 'FE/XCLASS',
71 // #43085
72 'GFX/image_processing',
73 // #70056
74 'SYS/curlUse',
75 'SYS/curlProxyNTLM',
76 'SYS/curlProxyServer',
77 'SYS/curlProxyTunnel',
78 'SYS/curlProxyUserPass',
79 'SYS/curlTimeout',
80 // #75355
81 'BE/niceFlexFormXMLtags',
82 'BE/compactFlexFormXML',
83 // #75625
84 'SYS/clearCacheSystem',
85 // #77411
86 'SYS/caching/cacheConfigurations/extbase_typo3dbbackend_tablecolumns',
87 // #77460
88 'SYS/caching/cacheConfigurations/extbase_typo3dbbackend_queries',
89 // #79513
90 'FE/lockHashKeyWords',
91 'BE/lockHashKeyWords',
92 // #78835
93 'SYS/cookieHttpOnly',
94 // #71095
95 'BE/lang',
96 // #80050
97 'FE/cHashIncludePageId',
98 // #80711
99 'FE/noPHPscriptInclude',
100 'FE/maxSessionDataSize',
101 // #82162
102 'SYS/enable_errorDLOG',
103 'SYS/enable_exceptionDLOG',
104 // #82377
105 'EXT/allowSystemInstall',
106 // #82421
107 'SYS/sqlDebug',
108 'SYS/no_pconnect',
109 'SYS/setDBinit',
110 'SYS/dbClientCompress',
111 // #82430
112 'SYS/syslogErrorReporting',
113 // #82639
114 'SYS/enable_DLOG',
115 'SC_OPTIONS/t3lib/class.t3lib_userauth.php/writeDevLog',
116 'SC_OPTIONS/t3lib/class.t3lib_userauth.php/writeDevLogBE',
117 'SC_OPTIONS/t3lib/class.t3lib_userauth.php/writeDevLogFE',
118 // #82438
119 'SYS/enableDeprecationLog',
120 // #82680
121 'GFX/png_truecolor',
122 // #82803
123 'FE/content_doktypes',
124 // #83081
125 'BE/fileExtensions',
126 // #83768
127 'SYS/doNotCheckReferer',
128 // #83878
129 'SYS/isInitialInstallationInProgress',
130 'SYS/isInitialDatabaseImportDone',
131 // #84810
132 'BE/explicitConfirmationOfTranslation',
133 ];
134
135 public function __construct(ConfigurationManager $configurationManager = null)
136 {
137 $this->configurationManager = $configurationManager ?: GeneralUtility::makeInstance(ConfigurationManager::class);
138 }
139
140 /**
141 * Executed configuration upgrades. Single upgrade methods must throw a
142 * ConfigurationChangedException if something was written to LocalConfiguration.
143 */
144 public function execute()
145 {
146 $this->generateEncryptionKeyIfNeeded();
147 $this->configureBackendLoginSecurity();
148 $this->migrateImageProcessorSetting();
149 $this->transferHttpSettings();
150 $this->disableImageMagickDetailSettingsIfImageMagickIsDisabled();
151 $this->setImageMagickDetailSettings();
152 $this->migrateThumbnailsPngSetting();
153 $this->migrateLockSslSetting();
154 $this->migrateDatabaseConnectionSettings();
155 $this->migrateDatabaseConnectionCharset();
156 $this->migrateDatabaseDriverOptions();
157 $this->migrateLangDebug();
158 $this->migrateCacheHashOptions();
159 $this->migrateExceptionErrors();
160 $this->migrateDisplayErrorsSetting();
161
162 // Should run at the end to prevent that obsolete settings are removed before migration
163 $this->removeObsoleteLocalConfigurationSettings();
164 }
165
166 /**
167 * Some settings in LocalConfiguration vanished in DefaultConfiguration
168 * and have no impact on the core anymore.
169 * To keep the configuration clean, those old settings are just silently
170 * removed from LocalConfiguration if set.
171 */
172 protected function removeObsoleteLocalConfigurationSettings()
173 {
174 $removed = $this->configurationManager->removeLocalConfigurationKeysByPath($this->obsoleteLocalConfigurationSettings);
175
176 // If something was changed: Trigger a reload to have new values in next request
177 if ($removed) {
178 $this->throwConfigurationChangedException();
179 }
180 }
181
182 /**
183 * Backend login security is set to rsa if rsaauth
184 * is installed (but not used) otherwise the default value "normal" has to be used.
185 * This forces either 'normal' or 'rsa' to be set in LocalConfiguration.
186 */
187 protected function configureBackendLoginSecurity()
188 {
189 $rsaauthLoaded = ExtensionManagementUtility::isLoaded('rsaauth');
190 try {
191 $currentLoginSecurityLevelValue = $this->configurationManager->getLocalConfigurationValueByPath('BE/loginSecurityLevel');
192 if ($rsaauthLoaded && $currentLoginSecurityLevelValue !== 'rsa') {
193 $this->configurationManager->setLocalConfigurationValueByPath('BE/loginSecurityLevel', 'rsa');
194 $this->throwConfigurationChangedException();
195 } elseif (!$rsaauthLoaded && $currentLoginSecurityLevelValue !== 'normal') {
196 $this->configurationManager->setLocalConfigurationValueByPath('BE/loginSecurityLevel', 'normal');
197 $this->throwConfigurationChangedException();
198 }
199 } catch (MissingArrayPathException $e) {
200 // If an exception is thrown, the value is not set in LocalConfiguration
201 $this->configurationManager->setLocalConfigurationValueByPath(
202 'BE/loginSecurityLevel',
203 $rsaauthLoaded ? 'rsa' : 'normal'
204 );
205 $this->throwConfigurationChangedException();
206 }
207 }
208
209 /**
210 * The encryption key is crucial for securing form tokens
211 * and the whole TYPO3 link rendering later on. A random key is set here in
212 * LocalConfiguration if it does not exist yet. This might possible happen
213 * during upgrading and will happen during first install.
214 */
215 protected function generateEncryptionKeyIfNeeded()
216 {
217 try {
218 $currentValue = $this->configurationManager->getLocalConfigurationValueByPath('SYS/encryptionKey');
219 } catch (MissingArrayPathException $e) {
220 // If an exception is thrown, the value is not set in LocalConfiguration
221 $currentValue = '';
222 }
223
224 if (empty($currentValue)) {
225 $randomKey = GeneralUtility::makeInstance(Random::class)->generateRandomHexString(96);
226 $this->configurationManager->setLocalConfigurationValueByPath('SYS/encryptionKey', $randomKey);
227 $this->throwConfigurationChangedException();
228 }
229 }
230
231 /**
232 * Parse old curl and HTTP options and set new HTTP options, related to Guzzle
233 */
234 protected function transferHttpSettings()
235 {
236 $changed = false;
237 $newParameters = [];
238 $obsoleteParameters = [];
239
240 // Remove / migrate options to new options
241 try {
242 // Check if the adapter option is set, if so, set it to the parameters that are obsolete
243 $this->configurationManager->getLocalConfigurationValueByPath('HTTP/adapter');
244 $obsoleteParameters[] = 'HTTP/adapter';
245 } catch (MissingArrayPathException $e) {
246 // Migration done already
247 }
248 try {
249 $newParameters['HTTP/version'] = $this->configurationManager->getLocalConfigurationValueByPath('HTTP/protocol_version');
250 $obsoleteParameters[] = 'HTTP/protocol_version';
251 } catch (MissingArrayPathException $e) {
252 // Migration done already
253 }
254 try {
255 $this->configurationManager->getLocalConfigurationValueByPath('HTTP/ssl_verify_host');
256 $obsoleteParameters[] = 'HTTP/ssl_verify_host';
257 } catch (MissingArrayPathException $e) {
258 // Migration done already
259 }
260 try {
261 $legacyUserAgent = $this->configurationManager->getLocalConfigurationValueByPath('HTTP/userAgent');
262 $newParameters['HTTP/headers/User-Agent'] = $legacyUserAgent;
263 $obsoleteParameters[] = 'HTTP/userAgent';
264 } catch (MissingArrayPathException $e) {
265 // Migration done already
266 }
267
268 // Redirects
269 try {
270 $legacyFollowRedirects = $this->configurationManager->getLocalConfigurationValueByPath('HTTP/follow_redirects');
271 $obsoleteParameters[] = 'HTTP/follow_redirects';
272 } catch (MissingArrayPathException $e) {
273 $legacyFollowRedirects = '';
274 }
275 try {
276 $legacyMaximumRedirects = $this->configurationManager->getLocalConfigurationValueByPath('HTTP/max_redirects');
277 $obsoleteParameters[] = 'HTTP/max_redirects';
278 } catch (MissingArrayPathException $e) {
279 $legacyMaximumRedirects = '';
280 }
281 try {
282 $legacyStrictRedirects = $this->configurationManager->getLocalConfigurationValueByPath('HTTP/strict_redirects');
283 $obsoleteParameters[] = 'HTTP/strict_redirects';
284 } catch (MissingArrayPathException $e) {
285 $legacyStrictRedirects = '';
286 }
287
288 // Check if redirects have been disabled
289 if ($legacyFollowRedirects !== '' && (bool)$legacyFollowRedirects === false) {
290 $newParameters['HTTP/allow_redirects'] = false;
291 } elseif ($legacyMaximumRedirects !== '' || $legacyStrictRedirects !== '') {
292 $newParameters['HTTP/allow_redirects'] = [];
293 if ($legacyMaximumRedirects !== '' && (int)$legacyMaximumRedirects !== 5) {
294 $newParameters['HTTP/allow_redirects']['max'] = (int)$legacyMaximumRedirects;
295 }
296 if ($legacyStrictRedirects !== '' && (bool)$legacyStrictRedirects === true) {
297 $newParameters['HTTP/allow_redirects']['strict'] = true;
298 }
299 // defaults are used, no need to set the option in LocalConfiguration.php
300 if (empty($newParameters['HTTP/allow_redirects'])) {
301 unset($newParameters['HTTP/allow_redirects']);
302 }
303 }
304
305 // Migrate Proxy settings
306 try {
307 // Currently without protocol or port
308 $legacyProxyHost = $this->configurationManager->getLocalConfigurationValueByPath('HTTP/proxy_host');
309 $obsoleteParameters[] = 'HTTP/proxy_host';
310 } catch (MissingArrayPathException $e) {
311 $legacyProxyHost = '';
312 }
313 try {
314 $legacyProxyPort = $this->configurationManager->getLocalConfigurationValueByPath('HTTP/proxy_port');
315 $obsoleteParameters[] = 'HTTP/proxy_port';
316 } catch (MissingArrayPathException $e) {
317 $legacyProxyPort = '';
318 }
319 try {
320 $legacyProxyUser = $this->configurationManager->getLocalConfigurationValueByPath('HTTP/proxy_user');
321 $obsoleteParameters[] = 'HTTP/proxy_user';
322 } catch (MissingArrayPathException $e) {
323 $legacyProxyUser = '';
324 }
325 try {
326 $legacyProxyPassword = $this->configurationManager->getLocalConfigurationValueByPath('HTTP/proxy_password');
327 $obsoleteParameters[] = 'HTTP/proxy_password';
328 } catch (MissingArrayPathException $e) {
329 $legacyProxyPassword = '';
330 }
331 // Auth Scheme: Basic, digest etc.
332 try {
333 $legacyProxyAuthScheme = $this->configurationManager->getLocalConfigurationValueByPath('HTTP/proxy_auth_scheme');
334 $obsoleteParameters[] = 'HTTP/proxy_auth_scheme';
335 } catch (MissingArrayPathException $e) {
336 $legacyProxyAuthScheme = '';
337 }
338
339 if ($legacyProxyHost !== '') {
340 $proxy = 'http://';
341 if ($legacyProxyAuthScheme !== '' && $legacyProxyUser !== '' && $legacyProxyPassword !== '') {
342 $proxy .= $legacyProxyUser . ':' . $legacyProxyPassword . '@';
343 }
344 $proxy .= $legacyProxyHost;
345 if ($legacyProxyPort !== '') {
346 $proxy .= ':' . $legacyProxyPort;
347 }
348 $newParameters['HTTP/proxy'] = $proxy;
349 }
350
351 // Verify peers
352 // see http://docs.guzzlephp.org/en/latest/request-options.html#verify
353 try {
354 $legacySslVerifyPeer = $this->configurationManager->getLocalConfigurationValueByPath('HTTP/ssl_verify_peer');
355 $obsoleteParameters[] = 'HTTP/ssl_verify_peer';
356 } catch (MissingArrayPathException $e) {
357 $legacySslVerifyPeer = '';
358 }
359
360 // Directory holding multiple Certificate Authority files
361 try {
362 $legacySslCaPath = $this->configurationManager->getLocalConfigurationValueByPath('HTTP/ssl_capath');
363 $obsoleteParameters[] = 'HTTP/ssl_capath';
364 } catch (MissingArrayPathException $e) {
365 $legacySslCaPath = '';
366 }
367 // Certificate Authority file to verify the peer with (use when ssl_verify_peer is TRUE)
368 try {
369 $legacySslCaFile = $this->configurationManager->getLocalConfigurationValueByPath('HTTP/ssl_cafile');
370 $obsoleteParameters[] = 'HTTP/ssl_cafile';
371 } catch (MissingArrayPathException $e) {
372 $legacySslCaFile = '';
373 }
374 if ($legacySslVerifyPeer !== '') {
375 if ($legacySslCaFile !== '' && $legacySslCaPath !== '') {
376 $newParameters['HTTP/verify'] = $legacySslCaPath . $legacySslCaFile;
377 } elseif ((bool)$legacySslVerifyPeer === false) {
378 $newParameters['HTTP/verify'] = false;
379 }
380 }
381
382 // SSL Key + Passphrase
383 // Name of a file containing local certificate
384 try {
385 $legacySslLocalCert = $this->configurationManager->getLocalConfigurationValueByPath('HTTP/ssl_local_cert');
386 $obsoleteParameters[] = 'HTTP/ssl_local_cert';
387 } catch (MissingArrayPathException $e) {
388 $legacySslLocalCert = '';
389 }
390
391 // Passphrase with which local certificate was encoded
392 try {
393 $legacySslPassphrase = $this->configurationManager->getLocalConfigurationValueByPath('HTTP/ssl_passphrase');
394 $obsoleteParameters[] = 'HTTP/ssl_passphrase';
395 } catch (MissingArrayPathException $e) {
396 $legacySslPassphrase = '';
397 }
398
399 if ($legacySslLocalCert !== '') {
400 if ($legacySslPassphrase !== '') {
401 $newParameters['HTTP/ssl_key'] = [
402 $legacySslLocalCert,
403 $legacySslPassphrase
404 ];
405 } else {
406 $newParameters['HTTP/ssl_key'] = $legacySslLocalCert;
407 }
408 }
409
410 // Update the LocalConfiguration file if obsolete parameters or new parameters are set
411 if (!empty($obsoleteParameters)) {
412 $this->configurationManager->removeLocalConfigurationKeysByPath($obsoleteParameters);
413 $changed = true;
414 }
415 if (!empty($newParameters)) {
416 $this->configurationManager->setLocalConfigurationValuesByPathValuePairs($newParameters);
417 $changed = true;
418 }
419 if ($changed) {
420 $this->throwConfigurationChangedException();
421 }
422 }
423
424 /**
425 * Detail configuration of Image Magick settings must be cleared
426 * if Image Magick handling is disabled.
427 *
428 * "Configuration presets" in install tool is not type safe, so value
429 * comparisons here are not type safe too, to not trigger changes to
430 * LocalConfiguration again.
431 */
432 protected function disableImageMagickDetailSettingsIfImageMagickIsDisabled()
433 {
434 $changedValues = [];
435 try {
436 $currentImValue = $this->configurationManager->getLocalConfigurationValueByPath('GFX/processor_enabled');
437 } catch (MissingArrayPathException $e) {
438 $currentImValue = $this->configurationManager->getDefaultConfigurationValueByPath('GFX/processor_enabled');
439 }
440
441 try {
442 $currentImPathValue = $this->configurationManager->getLocalConfigurationValueByPath('GFX/processor_path');
443 } catch (MissingArrayPathException $e) {
444 $currentImPathValue = $this->configurationManager->getDefaultConfigurationValueByPath('GFX/processor_path');
445 }
446
447 try {
448 $currentImPathLzwValue = $this->configurationManager->getLocalConfigurationValueByPath('GFX/processor_path_lzw');
449 } catch (MissingArrayPathException $e) {
450 $currentImPathLzwValue = $this->configurationManager->getDefaultConfigurationValueByPath('GFX/processor_path_lzw');
451 }
452
453 try {
454 $currentImageFileExtValue = $this->configurationManager->getLocalConfigurationValueByPath('GFX/imagefile_ext');
455 } catch (MissingArrayPathException $e) {
456 $currentImageFileExtValue = $this->configurationManager->getDefaultConfigurationValueByPath('GFX/imagefile_ext');
457 }
458
459 try {
460 $currentThumbnailsValue = $this->configurationManager->getLocalConfigurationValueByPath('GFX/thumbnails');
461 } catch (MissingArrayPathException $e) {
462 $currentThumbnailsValue = $this->configurationManager->getDefaultConfigurationValueByPath('GFX/thumbnails');
463 }
464
465 if (!$currentImValue) {
466 if ($currentImPathValue != '') {
467 $changedValues['GFX/processor_path'] = '';
468 }
469 if ($currentImPathLzwValue != '') {
470 $changedValues['GFX/processor_path_lzw'] = '';
471 }
472 if ($currentImageFileExtValue !== 'gif,jpg,jpeg,png') {
473 $changedValues['GFX/imagefile_ext'] = 'gif,jpg,jpeg,png';
474 }
475 if ($currentThumbnailsValue != 0) {
476 $changedValues['GFX/thumbnails'] = 0;
477 }
478 }
479 if (!empty($changedValues)) {
480 $this->configurationManager->setLocalConfigurationValuesByPathValuePairs($changedValues);
481 $this->throwConfigurationChangedException();
482 }
483 }
484
485 /**
486 * Detail configuration of Image Magick and Graphics Magick settings
487 * depending on main values.
488 *
489 * "Configuration presets" in install tool is not type safe, so value
490 * comparisons here are not type safe too, to not trigger changes to
491 * LocalConfiguration again.
492 */
493 protected function setImageMagickDetailSettings()
494 {
495 $changedValues = [];
496 try {
497 $currentProcessorValue = $this->configurationManager->getLocalConfigurationValueByPath('GFX/processor');
498 } catch (MissingArrayPathException $e) {
499 $currentProcessorValue = $this->configurationManager->getDefaultConfigurationValueByPath('GFX/processor');
500 }
501
502 try {
503 $currentProcessorMaskValue = $this->configurationManager->getLocalConfigurationValueByPath('GFX/processor_allowTemporaryMasksAsPng');
504 } catch (MissingArrayPathException $e) {
505 $currentProcessorMaskValue = $this->configurationManager->getDefaultConfigurationValueByPath('GFX/processor_allowTemporaryMasksAsPng');
506 }
507
508 try {
509 $currentProcessorEffectsValue = $this->configurationManager->getLocalConfigurationValueByPath('GFX/processor_effects');
510 } catch (MissingArrayPathException $e) {
511 $currentProcessorEffectsValue = $this->configurationManager->getDefaultConfigurationValueByPath('GFX/processor_effects');
512 }
513
514 if ((string)$currentProcessorValue !== '') {
515 if ($currentProcessorMaskValue != 0) {
516 $changedValues['GFX/processor_allowTemporaryMasksAsPng'] = 0;
517 }
518 }
519 if (!empty($changedValues)) {
520 $this->configurationManager->setLocalConfigurationValuesByPathValuePairs($changedValues);
521 $this->throwConfigurationChangedException();
522 }
523 }
524
525 /**
526 * Migrate the definition of the image processor from the configuration value
527 * im_version_5 to the setting processor.
528 */
529 protected function migrateImageProcessorSetting()
530 {
531 $changedSettings = [];
532 $settingsToRename = [
533 'GFX/im' => 'GFX/processor_enabled',
534 'GFX/im_version_5' => 'GFX/processor',
535 'GFX/im_v5effects' => 'GFX/processor_effects',
536 'GFX/im_path' => 'GFX/processor_path',
537 'GFX/im_path_lzw' => 'GFX/processor_path_lzw',
538 'GFX/im_mask_temp_ext_gif' => 'GFX/processor_allowTemporaryMasksAsPng',
539 'GFX/im_noScaleUp' => 'GFX/processor_allowUpscaling',
540 'GFX/im_noFramePrepended' => 'GFX/processor_allowFrameSelection',
541 'GFX/im_stripProfileCommand' => 'GFX/processor_stripColorProfileCommand',
542 'GFX/im_useStripProfileByDefault' => 'GFX/processor_stripColorProfileByDefault',
543 'GFX/colorspace' => 'GFX/processor_colorspace',
544 ];
545
546 foreach ($settingsToRename as $oldPath => $newPath) {
547 try {
548 $value = $this->configurationManager->getLocalConfigurationValueByPath($oldPath);
549 $this->configurationManager->setLocalConfigurationValueByPath($newPath, $value);
550 $changedSettings[$oldPath] = true;
551 } catch (MissingArrayPathException $e) {
552 // If an exception is thrown, the value is not set in LocalConfiguration
553 $changedSettings[$oldPath] = false;
554 }
555 }
556
557 if (!empty($changedSettings['GFX/im_version_5'])) {
558 $currentProcessorValue = $this->configurationManager->getLocalConfigurationValueByPath('GFX/im_version_5');
559 $newProcessorValue = $currentProcessorValue === 'gm' ? 'GraphicsMagick' : 'ImageMagick';
560 $this->configurationManager->setLocalConfigurationValueByPath('GFX/processor', $newProcessorValue);
561 }
562
563 if (!empty($changedSettings['GFX/im_noScaleUp'])) {
564 $currentProcessorValue = $this->configurationManager->getLocalConfigurationValueByPath('GFX/im_noScaleUp');
565 $newProcessorValue = !$currentProcessorValue;
566 $this->configurationManager->setLocalConfigurationValueByPath(
567 'GFX/processor_allowUpscaling',
568 $newProcessorValue
569 );
570 }
571
572 if (!empty($changedSettings['GFX/im_noFramePrepended'])) {
573 $currentProcessorValue = $this->configurationManager->getLocalConfigurationValueByPath('GFX/im_noFramePrepended');
574 $newProcessorValue = !$currentProcessorValue;
575 $this->configurationManager->setLocalConfigurationValueByPath(
576 'GFX/processor_allowFrameSelection',
577 $newProcessorValue
578 );
579 }
580
581 if (!empty($changedSettings['GFX/im_mask_temp_ext_gif'])) {
582 $currentProcessorValue = $this->configurationManager->getLocalConfigurationValueByPath('GFX/im_mask_temp_ext_gif');
583 $newProcessorValue = !$currentProcessorValue;
584 $this->configurationManager->setLocalConfigurationValueByPath(
585 'GFX/processor_allowTemporaryMasksAsPng',
586 $newProcessorValue
587 );
588 }
589
590 if (!empty(array_filter($changedSettings))) {
591 $this->configurationManager->removeLocalConfigurationKeysByPath(array_keys($changedSettings));
592 $this->throwConfigurationChangedException();
593 }
594 }
595
596 /**
597 * Throw exception after configuration change to trigger a redirect.
598 *
599 * @throws ConfigurationChangedException
600 */
601 protected function throwConfigurationChangedException()
602 {
603 throw new ConfigurationChangedException(
604 'Configuration updated, reload needed',
605 1379024938
606 );
607 }
608
609 /**
610 * Migrate the configuration value thumbnails_png to a boolean value.
611 */
612 protected function migrateThumbnailsPngSetting()
613 {
614 $changedValues = [];
615 try {
616 $currentThumbnailsPngValue = $this->configurationManager->getLocalConfigurationValueByPath('GFX/thumbnails_png');
617 } catch (MissingArrayPathException $e) {
618 $currentThumbnailsPngValue = $this->configurationManager->getDefaultConfigurationValueByPath('GFX/thumbnails_png');
619 }
620
621 if (is_int($currentThumbnailsPngValue) && $currentThumbnailsPngValue > 0) {
622 $changedValues['GFX/thumbnails_png'] = true;
623 }
624 if (!empty($changedValues)) {
625 $this->configurationManager->setLocalConfigurationValuesByPathValuePairs($changedValues);
626 $this->throwConfigurationChangedException();
627 }
628 }
629
630 /**
631 * Migrate the configuration setting BE/lockSSL to boolean if set in the LocalConfiguration.php file
632 */
633 protected function migrateLockSslSetting()
634 {
635 try {
636 $currentOption = $this->configurationManager->getLocalConfigurationValueByPath('BE/lockSSL');
637 // check if the current option is an integer/string and if it is active
638 if (!is_bool($currentOption) && (int)$currentOption > 0) {
639 $this->configurationManager->setLocalConfigurationValueByPath('BE/lockSSL', true);
640 $this->throwConfigurationChangedException();
641 }
642 } catch (MissingArrayPathException $e) {
643 // no change inside the LocalConfiguration.php found, so nothing needs to be modified
644 }
645 }
646
647 /**
648 * Move the database connection settings to a "Default" connection
649 */
650 protected function migrateDatabaseConnectionSettings()
651 {
652 $confManager = $this->configurationManager;
653
654 $newSettings = [];
655 $removeSettings = [];
656
657 try {
658 $value = $confManager->getLocalConfigurationValueByPath('DB/username');
659 $removeSettings[] = 'DB/username';
660 $newSettings['DB/Connections/Default/user'] = $value;
661 } catch (MissingArrayPathException $e) {
662 // Old setting does not exist, do nothing
663 }
664
665 try {
666 $value = $confManager->getLocalConfigurationValueByPath('DB/password');
667 $removeSettings[] = 'DB/password';
668 $newSettings['DB/Connections/Default/password'] = $value;
669 } catch (MissingArrayPathException $e) {
670 // Old setting does not exist, do nothing
671 }
672
673 try {
674 $value = $confManager->getLocalConfigurationValueByPath('DB/host');
675 $removeSettings[] = 'DB/host';
676 $newSettings['DB/Connections/Default/host'] = $value;
677 } catch (MissingArrayPathException $e) {
678 // Old setting does not exist, do nothing
679 }
680
681 try {
682 $value = $confManager->getLocalConfigurationValueByPath('DB/port');
683 $removeSettings[] = 'DB/port';
684 $newSettings['DB/Connections/Default/port'] = $value;
685 } catch (MissingArrayPathException $e) {
686 // Old setting does not exist, do nothing
687 }
688
689 try {
690 $value = $confManager->getLocalConfigurationValueByPath('DB/socket');
691 $removeSettings[] = 'DB/socket';
692 // Remove empty socket connects
693 if (!empty($value)) {
694 $newSettings['DB/Connections/Default/unix_socket'] = $value;
695 }
696 } catch (MissingArrayPathException $e) {
697 // Old setting does not exist, do nothing
698 }
699
700 try {
701 $value = $confManager->getLocalConfigurationValueByPath('DB/database');
702 $removeSettings[] = 'DB/database';
703 $newSettings['DB/Connections/Default/dbname'] = $value;
704 } catch (MissingArrayPathException $e) {
705 // Old setting does not exist, do nothing
706 }
707
708 try {
709 $value = (bool)$confManager->getLocalConfigurationValueByPath('SYS/dbClientCompress');
710 $removeSettings[] = 'SYS/dbClientCompress';
711 if ($value) {
712 $newSettings['DB/Connections/Default/driverOptions'] = [
713 'flags' => MYSQLI_CLIENT_COMPRESS,
714 ];
715 }
716 } catch (MissingArrayPathException $e) {
717 // Old setting does not exist, do nothing
718 }
719
720 try {
721 $value = (bool)$confManager->getLocalConfigurationValueByPath('SYS/no_pconnect');
722 $removeSettings[] = 'SYS/no_pconnect';
723 if (!$value) {
724 $newSettings['DB/Connections/Default/persistentConnection'] = true;
725 }
726 } catch (MissingArrayPathException $e) {
727 // Old setting does not exist, do nothing
728 }
729
730 try {
731 $value = $confManager->getLocalConfigurationValueByPath('SYS/setDBinit');
732 $removeSettings[] = 'SYS/setDBinit';
733 $newSettings['DB/Connections/Default/initCommands'] = $value;
734 } catch (MissingArrayPathException $e) {
735 // Old setting does not exist, do nothing
736 }
737
738 try {
739 $confManager->getLocalConfigurationValueByPath('DB/Connections/Default/charset');
740 } catch (MissingArrayPathException $e) {
741 // If there is no charset option yet, add it.
742 $newSettings['DB/Connections/Default/charset'] = 'utf8';
743 }
744
745 try {
746 $confManager->getLocalConfigurationValueByPath('DB/Connections/Default/driver');
747 } catch (MissingArrayPathException $e) {
748 // Use the mysqli driver by default if no value has been provided yet
749 $newSettings['DB/Connections/Default/driver'] = 'mysqli';
750 }
751
752 // Add new settings and remove old ones
753 if (!empty($newSettings)) {
754 $confManager->setLocalConfigurationValuesByPathValuePairs($newSettings);
755 }
756 if (!empty($removeSettings)) {
757 $confManager->removeLocalConfigurationKeysByPath($removeSettings);
758 }
759
760 // Throw redirect if something was changed
761 if (!empty($newSettings) || !empty($removeSettings)) {
762 $this->throwConfigurationChangedException();
763 }
764 }
765
766 /**
767 * Migrate the configuration setting DB/Connections/Default/charset to 'utf8' as
768 * 'utf-8' is not supported by all MySQL versions.
769 */
770 protected function migrateDatabaseConnectionCharset()
771 {
772 $confManager = $this->configurationManager;
773 try {
774 $driver = $confManager->getLocalConfigurationValueByPath('DB/Connections/Default/driver');
775 $charset = $confManager->getLocalConfigurationValueByPath('DB/Connections/Default/charset');
776 if (in_array($driver, ['mysqli', 'pdo_mysql', 'drizzle_pdo_mysql'], true) && $charset === 'utf-8') {
777 $confManager->setLocalConfigurationValueByPath('DB/Connections/Default/charset', 'utf8');
778 $this->throwConfigurationChangedException();
779 }
780 } catch (MissingArrayPathException $e) {
781 // no incompatible charset configuration found, so nothing needs to be modified
782 }
783 }
784
785 /**
786 * Migrate the configuration setting DB/Connections/Default/driverOptions to array type.
787 */
788 protected function migrateDatabaseDriverOptions()
789 {
790 $confManager = $this->configurationManager;
791 try {
792 $options = $confManager->getLocalConfigurationValueByPath('DB/Connections/Default/driverOptions');
793 if (!is_array($options)) {
794 $confManager->setLocalConfigurationValueByPath(
795 'DB/Connections/Default/driverOptions',
796 ['flags' => (int)$options]
797 );
798 }
799 } catch (MissingArrayPathException $e) {
800 // no driver options found, nothing needs to be modified
801 }
802 }
803
804 /**
805 * Migrate the configuration setting BE/lang/debug if set in the LocalConfiguration.php file
806 */
807 protected function migrateLangDebug()
808 {
809 $confManager = $this->configurationManager;
810 try {
811 $currentOption = $confManager->getLocalConfigurationValueByPath('BE/lang/debug');
812 // check if the current option is set and boolean
813 if (isset($currentOption) && is_bool($currentOption)) {
814 $confManager->setLocalConfigurationValueByPath('BE/languageDebug', $currentOption);
815 }
816 } catch (MissingArrayPathException $e) {
817 // no change inside the LocalConfiguration.php found, so nothing needs to be modified
818 }
819 }
820
821 /**
822 * Migrate single cache hash related options under "FE" into "FE/cacheHash"
823 */
824 protected function migrateCacheHashOptions()
825 {
826 $confManager = $this->configurationManager;
827 $removeSettings = [];
828 $newSettings = [];
829
830 try {
831 $value = $confManager->getLocalConfigurationValueByPath('FE/cHashOnlyForParameters');
832 $removeSettings[] = 'FE/cHashOnlyForParameters';
833 $newSettings['FE/cacheHash/cachedParametersWhiteList'] = GeneralUtility::trimExplode(',', $value, true);
834 } catch (MissingArrayPathException $e) {
835 // Migration done already
836 }
837
838 try {
839 $value = $confManager->getLocalConfigurationValueByPath('FE/cHashExcludedParameters');
840 $removeSettings[] = 'FE/cHashExcludedParameters';
841 $newSettings['FE/cacheHash/excludedParameters'] = GeneralUtility::trimExplode(',', $value, true);
842 } catch (MissingArrayPathException $e) {
843 // Migration done already
844 }
845
846 try {
847 $value = $confManager->getLocalConfigurationValueByPath('FE/cHashRequiredParameters');
848 $removeSettings[] = 'FE/cHashRequiredParameters';
849 $newSettings['FE/cacheHash/requireCacheHashPresenceParameters'] = GeneralUtility::trimExplode(',', $value, true);
850 } catch (MissingArrayPathException $e) {
851 // Migration done already
852 }
853
854 try {
855 $value = $confManager->getLocalConfigurationValueByPath('FE/cHashExcludedParametersIfEmpty');
856 $removeSettings[] = 'FE/cHashExcludedParametersIfEmpty';
857 if (trim($value) === '*') {
858 $newSettings['FE/cacheHash/excludeAllEmptyParameters'] = true;
859 } else {
860 $newSettings['FE/cacheHash/excludedParametersIfEmpty'] = GeneralUtility::trimExplode(',', $value, true);
861 }
862 } catch (MissingArrayPathException $e) {
863 // Migration done already
864 }
865
866 // Add new settings and remove old ones
867 if (!empty($newSettings)) {
868 $confManager->setLocalConfigurationValuesByPathValuePairs($newSettings);
869 }
870 if (!empty($removeSettings)) {
871 $confManager->removeLocalConfigurationKeysByPath($removeSettings);
872 }
873
874 // Throw redirect if something was changed
875 if (!empty($newSettings) || !empty($removeSettings)) {
876 $this->throwConfigurationChangedException();
877 }
878 }
879
880 /**
881 * Migrate SYS/exceptionalErrors to not contain E_USER_DEPRECATED
882 */
883 protected function migrateExceptionErrors()
884 {
885 $confManager = $this->configurationManager;
886 try {
887 $currentOption = (int)$confManager->getLocalConfigurationValueByPath('SYS/exceptionalErrors');
888 // make sure E_USER_DEPRECATED is not part of the exceptionalErrors
889 if ($currentOption & E_USER_DEPRECATED) {
890 $confManager->setLocalConfigurationValueByPath('SYS/exceptionalErrors', $currentOption & ~E_USER_DEPRECATED);
891 }
892 } catch (MissingArrayPathException $e) {
893 // no change inside the LocalConfiguration.php found, so nothing needs to be modified
894 }
895 }
896
897 /**
898 * Migrate SYS/displayErrors to not contain 2
899 */
900 protected function migrateDisplayErrorsSetting()
901 {
902 $confManager = $this->configurationManager;
903 try {
904 $currentOption = (int)$confManager->getLocalConfigurationValueByPath('SYS/displayErrors');
905 // make sure displayErrors is set to 2
906 if ($currentOption === 2) {
907 $confManager->setLocalConfigurationValueByPath('SYS/displayErrors', -1);
908 }
909 } catch (MissingArrayPathException $e) {
910 // no change inside the LocalConfiguration.php found, so nothing needs to be modified
911 }
912 }
913 }