TYPO3 CMS  TYPO3_8-7
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 
22 
35 {
40 
50  // #72400
51  'BE/spriteIconGenerator_handler',
52  // #72417
53  'SYS/lockingMode',
54  // #72473
55  'FE/secureFormmail',
56  'FE/strictFormmail',
57  'FE/formmailMaxAttachmentSize',
58  // #72337
59  'SYS/t3lib_cs_utils',
60  'SYS/t3lib_cs_convMethod',
61  // #72604
62  'SYS/maxFileNameLength',
63  // #72602
64  'BE/unzip_path',
65  // #72615
66  'BE/notificationPrefix',
67  // #72616
68  'BE/XCLASS',
69  'FE/XCLASS',
70  // #43085
71  'GFX/image_processing',
72  // #70056
73  'SYS/curlUse',
74  'SYS/curlProxyNTLM',
75  'SYS/curlProxyServer',
76  'SYS/curlProxyTunnel',
77  'SYS/curlProxyUserPass',
78  'SYS/curlTimeout',
79  // #75355
80  'BE/niceFlexFormXMLtags',
81  'BE/compactFlexFormXML',
82  // #75625
83  'SYS/clearCacheSystem',
84  // #77411
85  'SYS/caching/cacheConfigurations/extbase_typo3dbbackend_tablecolumns',
86  // #77460
87  'SYS/caching/cacheConfigurations/extbase_typo3dbbackend_queries',
88  // #79513
89  'FE/lockHashKeyWords',
90  'BE/lockHashKeyWords',
91  // #78835
92  'SYS/cookieHttpOnly',
93  // #71095
94  'BE/lang',
95  // #80050
96  'FE/cHashIncludePageId',
97  ];
98 
100  {
101  $this->configurationManager = $configurationManager ?: GeneralUtility::makeInstance(ConfigurationManager::class);
102  }
103 
108  public function execute()
109  {
114  $this->transferHttpSettings();
118  $this->migrateLockSslSetting();
122  $this->migrateLangDebug();
124 
125  // Should run at the end to prevent that obsolete settings are removed before migration
127  }
128 
136  {
137  $removed = $this->configurationManager->removeLocalConfigurationKeysByPath($this->obsoleteLocalConfigurationSettings);
138 
139  // If something was changed: Trigger a reload to have new values in next request
140  if ($removed) {
141  $this->throwRedirectException();
142  }
143  }
144 
150  protected function configureBackendLoginSecurity()
151  {
152  $rsaauthLoaded = ExtensionManagementUtility::isLoaded('rsaauth');
153  try {
154  $currentLoginSecurityLevelValue = $this->configurationManager->getLocalConfigurationValueByPath('BE/loginSecurityLevel');
155  if ($rsaauthLoaded && $currentLoginSecurityLevelValue !== 'rsa') {
156  $this->configurationManager->setLocalConfigurationValueByPath('BE/loginSecurityLevel', 'rsa');
157  $this->throwRedirectException();
158  } elseif (!$rsaauthLoaded && $currentLoginSecurityLevelValue !== 'normal') {
159  $this->configurationManager->setLocalConfigurationValueByPath('BE/loginSecurityLevel', 'normal');
160  $this->throwRedirectException();
161  }
162  } catch (\RuntimeException $e) {
163  // If an exception is thrown, the value is not set in LocalConfiguration
164  $this->configurationManager->setLocalConfigurationValueByPath(
165  'BE/loginSecurityLevel',
166  $rsaauthLoaded ? 'rsa' : 'normal'
167  );
168  $this->throwRedirectException();
169  }
170  }
171 
178  protected function configureFrontendLoginSecurity()
179  {
180  $rsaauthLoaded = ExtensionManagementUtility::isLoaded('rsaauth');
181  try {
182  $currentLoginSecurityLevelValue = $this->configurationManager->getLocalConfigurationValueByPath('FE/loginSecurityLevel');
183  if (!$rsaauthLoaded && $currentLoginSecurityLevelValue !== 'normal') {
184  $this->configurationManager->setLocalConfigurationValueByPath('FE/loginSecurityLevel', 'normal');
185  $this->throwRedirectException();
186  }
187  } catch (\RuntimeException $e) {
188  // no value set, just ignore
189  }
190  }
191 
198  protected function generateEncryptionKeyIfNeeded()
199  {
200  try {
201  $currentValue = $this->configurationManager->getLocalConfigurationValueByPath('SYS/encryptionKey');
202  } catch (\RuntimeException $e) {
203  // If an exception is thrown, the value is not set in LocalConfiguration
204  $currentValue = '';
205  }
206 
207  if (empty($currentValue)) {
208  $randomKey = GeneralUtility::makeInstance(Random::class)->generateRandomHexString(96);
209  $this->configurationManager->setLocalConfigurationValueByPath('SYS/encryptionKey', $randomKey);
210  $this->throwRedirectException();
211  }
212  }
213 
217  protected function transferHttpSettings()
218  {
219  $changed = false;
220  $newParameters = [];
221  $obsoleteParameters = [];
222 
223  // Remove / migrate options to new options
224  try {
225  // Check if the adapter option is set, if so, set it to the parameters that are obsolete
226  $this->configurationManager->getLocalConfigurationValueByPath('HTTP/adapter');
227  $obsoleteParameters[] = 'HTTP/adapter';
228  } catch (\RuntimeException $e) {
229  }
230  try {
231  $newParameters['HTTP/version'] = $this->configurationManager->getLocalConfigurationValueByPath('HTTP/protocol_version');
232  $obsoleteParameters[] = 'HTTP/protocol_version';
233  } catch (\RuntimeException $e) {
234  }
235  try {
236  $this->configurationManager->getLocalConfigurationValueByPath('HTTP/ssl_verify_host');
237  $obsoleteParameters[] = 'HTTP/ssl_verify_host';
238  } catch (\RuntimeException $e) {
239  }
240  try {
241  $legacyUserAgent = $this->configurationManager->getLocalConfigurationValueByPath('HTTP/userAgent');
242  $newParameters['HTTP/headers/User-Agent'] = $legacyUserAgent;
243  $obsoleteParameters[] = 'HTTP/userAgent';
244  } catch (\RuntimeException $e) {
245  }
246 
247  // Redirects
248  try {
249  $legacyFollowRedirects = $this->configurationManager->getLocalConfigurationValueByPath('HTTP/follow_redirects');
250  $obsoleteParameters[] = 'HTTP/follow_redirects';
251  } catch (\RuntimeException $e) {
252  $legacyFollowRedirects = '';
253  }
254  try {
255  $legacyMaximumRedirects = $this->configurationManager->getLocalConfigurationValueByPath('HTTP/max_redirects');
256  $obsoleteParameters[] = 'HTTP/max_redirects';
257  } catch (\RuntimeException $e) {
258  $legacyMaximumRedirects = '';
259  }
260  try {
261  $legacyStrictRedirects = $this->configurationManager->getLocalConfigurationValueByPath('HTTP/strict_redirects');
262  $obsoleteParameters[] = 'HTTP/strict_redirects';
263  } catch (\RuntimeException $e) {
264  $legacyStrictRedirects = '';
265  }
266 
267  // Check if redirects have been disabled
268  if ($legacyFollowRedirects !== '' && (bool)$legacyFollowRedirects === false) {
269  $newParameters['HTTP/allow_redirects'] = false;
270  } elseif ($legacyMaximumRedirects !== '' || $legacyStrictRedirects !== '') {
271  $newParameters['HTTP/allow_redirects'] = [];
272  if ($legacyMaximumRedirects !== '' && (int)$legacyMaximumRedirects !== 5) {
273  $newParameters['HTTP/allow_redirects']['max'] = (int)$legacyMaximumRedirects;
274  }
275  if ($legacyStrictRedirects !== '' && (bool)$legacyStrictRedirects === true) {
276  $newParameters['HTTP/allow_redirects']['strict'] = true;
277  }
278  // defaults are used, no need to set the option in LocalConfiguration.php
279  if (empty($newParameters['HTTP/allow_redirects'])) {
280  unset($newParameters['HTTP/allow_redirects']);
281  }
282  }
283 
284  // Migrate Proxy settings
285  try {
286  // Currently without protocol or port
287  $legacyProxyHost = $this->configurationManager->getLocalConfigurationValueByPath('HTTP/proxy_host');
288  $obsoleteParameters[] = 'HTTP/proxy_host';
289  } catch (\RuntimeException $e) {
290  $legacyProxyHost = '';
291  }
292  try {
293  $legacyProxyPort = $this->configurationManager->getLocalConfigurationValueByPath('HTTP/proxy_port');
294  $obsoleteParameters[] = 'HTTP/proxy_port';
295  } catch (\RuntimeException $e) {
296  $legacyProxyPort = '';
297  }
298  try {
299  $legacyProxyUser = $this->configurationManager->getLocalConfigurationValueByPath('HTTP/proxy_user');
300  $obsoleteParameters[] = 'HTTP/proxy_user';
301  } catch (\RuntimeException $e) {
302  $legacyProxyUser = '';
303  }
304  try {
305  $legacyProxyPassword = $this->configurationManager->getLocalConfigurationValueByPath('HTTP/proxy_password');
306  $obsoleteParameters[] = 'HTTP/proxy_password';
307  } catch (\RuntimeException $e) {
308  $legacyProxyPassword = '';
309  }
310  // Auth Scheme: Basic, digest etc.
311  try {
312  $legacyProxyAuthScheme = $this->configurationManager->getLocalConfigurationValueByPath('HTTP/proxy_auth_scheme');
313  $obsoleteParameters[] = 'HTTP/proxy_auth_scheme';
314  } catch (\RuntimeException $e) {
315  $legacyProxyAuthScheme = '';
316  }
317 
318  if ($legacyProxyHost !== '') {
319  $proxy = 'http://';
320  if ($legacyProxyAuthScheme !== '' && $legacyProxyUser !== '' && $legacyProxyPassword !== '') {
321  $proxy .= $legacyProxyUser . ':' . $legacyProxyPassword . '@';
322  }
323  $proxy .= $legacyProxyHost;
324  if ($legacyProxyPort !== '') {
325  $proxy .= ':' . $legacyProxyPort;
326  }
327  $newParameters['HTTP/proxy'] = $proxy;
328  }
329 
330  // Verify peers
331  // see http://docs.guzzlephp.org/en/latest/request-options.html#verify
332  try {
333  $legacySslVerifyPeer = $this->configurationManager->getLocalConfigurationValueByPath('HTTP/ssl_verify_peer');
334  $obsoleteParameters[] = 'HTTP/ssl_verify_peer';
335  } catch (\RuntimeException $e) {
336  $legacySslVerifyPeer = '';
337  }
338 
339  // Directory holding multiple Certificate Authority files
340  try {
341  $legacySslCaPath = $this->configurationManager->getLocalConfigurationValueByPath('HTTP/ssl_capath');
342  $obsoleteParameters[] = 'HTTP/ssl_capath';
343  } catch (\RuntimeException $e) {
344  $legacySslCaPath = '';
345  }
346  // Certificate Authority file to verify the peer with (use when ssl_verify_peer is TRUE)
347  try {
348  $legacySslCaFile = $this->configurationManager->getLocalConfigurationValueByPath('HTTP/ssl_cafile');
349  $obsoleteParameters[] = 'HTTP/ssl_cafile';
350  } catch (\RuntimeException $e) {
351  $legacySslCaFile = '';
352  }
353  if ($legacySslVerifyPeer !== '') {
354  if ($legacySslCaFile !== '' && $legacySslCaPath !== '') {
355  $newParameters['HTTP/verify'] = $legacySslCaPath . $legacySslCaFile;
356  } elseif ((bool)$legacySslVerifyPeer === false) {
357  $newParameters['HTTP/verify'] = false;
358  }
359  }
360 
361  // SSL Key + Passphrase
362  // Name of a file containing local certificate
363  try {
364  $legacySslLocalCert = $this->configurationManager->getLocalConfigurationValueByPath('HTTP/ssl_local_cert');
365  $obsoleteParameters[] = 'HTTP/ssl_local_cert';
366  } catch (\RuntimeException $e) {
367  $legacySslLocalCert = '';
368  }
369 
370  // Passphrase with which local certificate was encoded
371  try {
372  $legacySslPassphrase = $this->configurationManager->getLocalConfigurationValueByPath('HTTP/ssl_passphrase');
373  $obsoleteParameters[] = 'HTTP/ssl_passphrase';
374  } catch (\RuntimeException $e) {
375  $legacySslPassphrase = '';
376  }
377 
378  if ($legacySslLocalCert !== '') {
379  if ($legacySslPassphrase !== '') {
380  $newParameters['HTTP/ssl_key'] = [
381  $legacySslLocalCert,
382  $legacySslPassphrase
383  ];
384  } else {
385  $newParameters['HTTP/ssl_key'] = $legacySslLocalCert;
386  }
387  }
388 
389  // Update the LocalConfiguration file if obsolete parameters or new parameters are set
390  if (!empty($obsoleteParameters)) {
391  $this->configurationManager->removeLocalConfigurationKeysByPath($obsoleteParameters);
392  $changed = true;
393  }
394  if (!empty($newParameters)) {
395  $this->configurationManager->setLocalConfigurationValuesByPathValuePairs($newParameters);
396  $changed = true;
397  }
398  if ($changed) {
399  $this->throwRedirectException();
400  }
401  }
402 
412  {
413  $changedValues = [];
414  try {
415  $currentImValue = $this->configurationManager->getLocalConfigurationValueByPath('GFX/processor_enabled');
416  } catch (\RuntimeException $e) {
417  $currentImValue = $this->configurationManager->getDefaultConfigurationValueByPath('GFX/processor_enabled');
418  }
419 
420  try {
421  $currentImPathValue = $this->configurationManager->getLocalConfigurationValueByPath('GFX/processor_path');
422  } catch (\RuntimeException $e) {
423  $currentImPathValue = $this->configurationManager->getDefaultConfigurationValueByPath('GFX/processor_path');
424  }
425 
426  try {
427  $currentImPathLzwValue = $this->configurationManager->getLocalConfigurationValueByPath('GFX/processor_path_lzw');
428  } catch (\RuntimeException $e) {
429  $currentImPathLzwValue = $this->configurationManager->getDefaultConfigurationValueByPath('GFX/processor_path_lzw');
430  }
431 
432  try {
433  $currentImageFileExtValue = $this->configurationManager->getLocalConfigurationValueByPath('GFX/imagefile_ext');
434  } catch (\RuntimeException $e) {
435  $currentImageFileExtValue = $this->configurationManager->getDefaultConfigurationValueByPath('GFX/imagefile_ext');
436  }
437 
438  try {
439  $currentThumbnailsValue = $this->configurationManager->getLocalConfigurationValueByPath('GFX/thumbnails');
440  } catch (\RuntimeException $e) {
441  $currentThumbnailsValue = $this->configurationManager->getDefaultConfigurationValueByPath('GFX/thumbnails');
442  }
443 
444  if (!$currentImValue) {
445  if ($currentImPathValue != '') {
446  $changedValues['GFX/processor_path'] = '';
447  }
448  if ($currentImPathLzwValue != '') {
449  $changedValues['GFX/processor_path_lzw'] = '';
450  }
451  if ($currentImageFileExtValue !== 'gif,jpg,jpeg,png') {
452  $changedValues['GFX/imagefile_ext'] = 'gif,jpg,jpeg,png';
453  }
454  if ($currentThumbnailsValue != 0) {
455  $changedValues['GFX/thumbnails'] = 0;
456  }
457  }
458  if (!empty($changedValues)) {
459  $this->configurationManager->setLocalConfigurationValuesByPathValuePairs($changedValues);
460  $this->throwRedirectException();
461  }
462  }
463 
472  protected function setImageMagickDetailSettings()
473  {
474  $changedValues = [];
475  try {
476  $currentProcessorValue = $this->configurationManager->getLocalConfigurationValueByPath('GFX/processor');
477  } catch (\RuntimeException $e) {
478  $currentProcessorValue = $this->configurationManager->getDefaultConfigurationValueByPath('GFX/processor');
479  }
480 
481  try {
482  $currentProcessorMaskValue = $this->configurationManager->getLocalConfigurationValueByPath('GFX/processor_allowTemporaryMasksAsPng');
483  } catch (\RuntimeException $e) {
484  $currentProcessorMaskValue = $this->configurationManager->getDefaultConfigurationValueByPath('GFX/processor_allowTemporaryMasksAsPng');
485  }
486 
487  if ((string)$currentProcessorValue !== '') {
488  if ($currentProcessorMaskValue != 0) {
489  $changedValues['GFX/processor_allowTemporaryMasksAsPng'] = 0;
490  }
491  }
492  if (!empty($changedValues)) {
493  $this->configurationManager->setLocalConfigurationValuesByPathValuePairs($changedValues);
494  $this->throwRedirectException();
495  }
496  }
497 
502  protected function migrateImageProcessorSetting()
503  {
504  $changedSettings = [];
505  $settingsToRename = [
506  'GFX/im' => 'GFX/processor_enabled',
507  'GFX/im_version_5' => 'GFX/processor',
508  'GFX/im_v5effects' => 'GFX/processor_effects',
509  'GFX/im_path' => 'GFX/processor_path',
510  'GFX/im_path_lzw' => 'GFX/processor_path_lzw',
511  'GFX/im_mask_temp_ext_gif' => 'GFX/processor_allowTemporaryMasksAsPng',
512  'GFX/im_noScaleUp' => 'GFX/processor_allowUpscaling',
513  'GFX/im_noFramePrepended' => 'GFX/processor_allowFrameSelection',
514  'GFX/im_stripProfileCommand' => 'GFX/processor_stripColorProfileCommand',
515  'GFX/im_useStripProfileByDefault' => 'GFX/processor_stripColorProfileByDefault',
516  'GFX/colorspace' => 'GFX/processor_colorspace',
517  ];
518 
519  foreach ($settingsToRename as $oldPath => $newPath) {
520  try {
521  $value = $this->configurationManager->getLocalConfigurationValueByPath($oldPath);
522  $this->configurationManager->setLocalConfigurationValueByPath($newPath, $value);
523  $changedSettings[$oldPath] = true;
524  } catch (\RuntimeException $e) {
525  // If an exception is thrown, the value is not set in LocalConfiguration
526  $changedSettings[$oldPath] = false;
527  }
528  }
529 
530  if (!empty($changedSettings['GFX/im_version_5'])) {
531  $currentProcessorValue = $this->configurationManager->getLocalConfigurationValueByPath('GFX/im_version_5');
532  $newProcessorValue = $currentProcessorValue === 'gm' ? 'GraphicsMagick' : 'ImageMagick';
533  $this->configurationManager->setLocalConfigurationValueByPath('GFX/processor', $newProcessorValue);
534  }
535 
536  if (!empty($changedSettings['GFX/im_noScaleUp'])) {
537  $currentProcessorValue = $this->configurationManager->getLocalConfigurationValueByPath('GFX/im_noScaleUp');
538  $newProcessorValue = !$currentProcessorValue;
539  $this->configurationManager->setLocalConfigurationValueByPath(
540  'GFX/processor_allowUpscaling',
541  $newProcessorValue
542  );
543  }
544 
545  if (!empty($changedSettings['GFX/im_noFramePrepended'])) {
546  $currentProcessorValue = $this->configurationManager->getLocalConfigurationValueByPath('GFX/im_noFramePrepended');
547  $newProcessorValue = !$currentProcessorValue;
548  $this->configurationManager->setLocalConfigurationValueByPath(
549  'GFX/processor_allowFrameSelection',
550  $newProcessorValue
551  );
552  }
553 
554  if (!empty($changedSettings['GFX/im_mask_temp_ext_gif'])) {
555  $currentProcessorValue = $this->configurationManager->getLocalConfigurationValueByPath('GFX/im_mask_temp_ext_gif');
556  $newProcessorValue = !$currentProcessorValue;
557  $this->configurationManager->setLocalConfigurationValueByPath(
558  'GFX/processor_allowTemporaryMasksAsPng',
559  $newProcessorValue
560  );
561  }
562 
563  if (!empty(array_filter($changedSettings))) {
564  $this->configurationManager->removeLocalConfigurationKeysByPath(array_keys($changedSettings));
565  $this->throwRedirectException();
566  }
567  }
568 
574  protected function throwRedirectException()
575  {
576  throw new RedirectException(
577  'Configuration updated, reload needed',
578  1379024938
579  );
580  }
581 
585  protected function migrateThumbnailsPngSetting()
586  {
587  $changedValues = [];
588  try {
589  $currentThumbnailsPngValue = $this->configurationManager->getLocalConfigurationValueByPath('GFX/thumbnails_png');
590  } catch (\RuntimeException $e) {
591  $currentThumbnailsPngValue = $this->configurationManager->getDefaultConfigurationValueByPath('GFX/thumbnails_png');
592  }
593 
594  if (is_int($currentThumbnailsPngValue) && $currentThumbnailsPngValue > 0) {
595  $changedValues['GFX/thumbnails_png'] = true;
596  }
597  if (!empty($changedValues)) {
598  $this->configurationManager->setLocalConfigurationValuesByPathValuePairs($changedValues);
599  $this->throwRedirectException();
600  }
601  }
602 
606  protected function migrateLockSslSetting()
607  {
608  try {
609  $currentOption = $this->configurationManager->getLocalConfigurationValueByPath('BE/lockSSL');
610  // check if the current option is an integer/string and if it is active
611  if (!is_bool($currentOption) && (int)$currentOption > 0) {
612  $this->configurationManager->setLocalConfigurationValueByPath('BE/lockSSL', true);
613  $this->throwRedirectException();
614  }
615  } catch (\RuntimeException $e) {
616  // no change inside the LocalConfiguration.php found, so nothing needs to be modified
617  }
618  }
619 
624  {
625  $confManager = $this->configurationManager;
626 
627  $newSettings = [];
628  $removeSettings = [];
629 
630  try {
631  $value = $confManager->getLocalConfigurationValueByPath('DB/username');
632  $removeSettings[] = 'DB/username';
633  $newSettings['DB/Connections/Default/user'] = $value;
634  } catch (\RuntimeException $e) {
635  // Old setting does not exist, do nothing
636  }
637 
638  try {
639  $value= $confManager->getLocalConfigurationValueByPath('DB/password');
640  $removeSettings[] = 'DB/password';
641  $newSettings['DB/Connections/Default/password'] = $value;
642  } catch (\RuntimeException $e) {
643  // Old setting does not exist, do nothing
644  }
645 
646  try {
647  $value = $confManager->getLocalConfigurationValueByPath('DB/host');
648  $removeSettings[] = 'DB/host';
649  $newSettings['DB/Connections/Default/host'] = $value;
650  } catch (\RuntimeException $e) {
651  // Old setting does not exist, do nothing
652  }
653 
654  try {
655  $value = $confManager->getLocalConfigurationValueByPath('DB/port');
656  $removeSettings[] = 'DB/port';
657  $newSettings['DB/Connections/Default/port'] = $value;
658  } catch (\RuntimeException $e) {
659  // Old setting does not exist, do nothing
660  }
661 
662  try {
663  $value = $confManager->getLocalConfigurationValueByPath('DB/socket');
664  $removeSettings[] = 'DB/socket';
665  // Remove empty socket connects
666  if (!empty($value)) {
667  $newSettings['DB/Connections/Default/unix_socket'] = $value;
668  }
669  } catch (\RuntimeException $e) {
670  // Old setting does not exist, do nothing
671  }
672 
673  try {
674  $value = $confManager->getLocalConfigurationValueByPath('DB/database');
675  $removeSettings[] = 'DB/database';
676  $newSettings['DB/Connections/Default/dbname'] = $value;
677  } catch (\RuntimeException $e) {
678  // Old setting does not exist, do nothing
679  }
680 
681  try {
682  $value = (bool)$confManager->getLocalConfigurationValueByPath('SYS/dbClientCompress');
683  $removeSettings[] = 'SYS/dbClientCompress';
684  if ($value) {
685  $newSettings['DB/Connections/Default/driverOptions'] = [
686  'flags' => MYSQLI_CLIENT_COMPRESS,
687  ];
688  }
689  } catch (\RuntimeException $e) {
690  // Old setting does not exist, do nothing
691  }
692 
693  try {
694  $value = (bool)$confManager->getLocalConfigurationValueByPath('SYS/no_pconnect');
695  $removeSettings[] = 'SYS/no_pconnect';
696  if (!$value) {
697  $newSettings['DB/Connections/Default/persistentConnection'] = true;
698  }
699  } catch (\RuntimeException $e) {
700  // Old setting does not exist, do nothing
701  }
702 
703  try {
704  $value = $confManager->getLocalConfigurationValueByPath('SYS/setDBinit');
705  $removeSettings[] = 'SYS/setDBinit';
706  $newSettings['DB/Connections/Default/initCommands'] = $value;
707  } catch (\RuntimeException $e) {
708  // Old setting does not exist, do nothing
709  }
710 
711  try {
712  $confManager->getLocalConfigurationValueByPath('DB/Connections/Default/charset');
713  } catch (\RuntimeException $e) {
714  // If there is no charset option yet, add it.
715  $newSettings['DB/Connections/Default/charset'] = 'utf8';
716  }
717 
718  try {
719  $confManager->getLocalConfigurationValueByPath('DB/Connections/Default/driver');
720  } catch (\RuntimeException $e) {
721  // Use the mysqli driver by default if no value has been provided yet
722  $newSettings['DB/Connections/Default/driver'] = 'mysqli';
723  }
724 
725  // Add new settings and remove old ones
726  if (!empty($newSettings)) {
727  $confManager->setLocalConfigurationValuesByPathValuePairs($newSettings);
728  }
729  if (!empty($removeSettings)) {
730  $confManager->removeLocalConfigurationKeysByPath($removeSettings);
731  }
732 
733  // Throw redirect if something was changed
734  if (!empty($newSettings) || !empty($removeSettings)) {
735  $this->throwRedirectException();
736  }
737  }
738 
743  protected function migrateDatabaseConnectionCharset()
744  {
745  $confManager = $this->configurationManager;
746  try {
747  $driver = $confManager->getLocalConfigurationValueByPath('DB/Connections/Default/driver');
748  $charset = $confManager->getLocalConfigurationValueByPath('DB/Connections/Default/charset');
749  if (in_array($driver, ['mysqli', 'pdo_mysql', 'drizzle_pdo_mysql'], true) && $charset === 'utf-8') {
750  $confManager->setLocalConfigurationValueByPath('DB/Connections/Default/charset', 'utf8');
751  $this->throwRedirectException();
752  }
753  } catch (\RuntimeException $e) {
754  // no incompatible charset configuration found, so nothing needs to be modified
755  }
756  }
757 
761  protected function migrateDatabaseDriverOptions()
762  {
763  $confManager = $this->configurationManager;
764  try {
765  $options = $confManager->getLocalConfigurationValueByPath('DB/Connections/Default/driverOptions');
766  if (!is_array($options)) {
767  $confManager->setLocalConfigurationValueByPath(
768  'DB/Connections/Default/driverOptions',
769  ['flags' => (int)$options]
770  );
771  }
772  } catch (\RuntimeException $e) {
773  // no driver options found, nothing needs to be modified
774  }
775  }
776 
780  protected function migrateLangDebug()
781  {
782  $confManager = $this->configurationManager;
783  try {
784  $currentOption = $confManager->getLocalConfigurationValueByPath('BE/lang/debug');
785  // check if the current option is set and boolean
786  if (isset($currentOption) && is_bool($currentOption)) {
787  $confManager->setLocalConfigurationValueByPath('BE/languageDebug', $currentOption);
788  }
789  } catch (\RuntimeException $e) {
790  // no change inside the LocalConfiguration.php found, so nothing needs to be modified
791  }
792  }
793 
797  protected function migrateDisplayErrorsSetting()
798  {
799  $confManager = $this->configurationManager;
800  try {
801  $currentOption = (int)$confManager->getLocalConfigurationValueByPath('SYS/displayErrors');
802  // make sure displayErrors is set to 2
803  if ($currentOption === 2) {
804  $confManager->setLocalConfigurationValueByPath('SYS/displayErrors', -1);
805  }
806  } catch (\RuntimeException $e) {
807  // no change inside the LocalConfiguration.php found, so nothing needs to be modified
808  }
809  }
810 }
static makeInstance($className,... $constructorArguments)