‪TYPO3CMS  ‪main
MigrateSiteSettingsConfigUpdate.php
Go to the documentation of this file.
1 <?php
2 
3 declare(strict_types=1);
4 
5 /*
6  * This file is part of the TYPO3 CMS project.
7  *
8  * It is free software; you can redistribute it and/or modify it under
9  * the terms of the GNU General Public License, either version 2
10  * of the License, or any later version.
11  *
12  * For the full copyright and license information, please read the
13  * LICENSE.txt file that was distributed with this source code.
14  *
15  * The TYPO3 project - inspiring people to share!
16  */
17 
19 
24 
31 #[UpgradeWizard('migrateSiteSettings')]
33 {
34  protected const ‪SETTINGS_FILENAME = 'settings.yaml';
35 
37  protected array ‪$sitePathsToMigrate = [];
38 
39  public function ‪__construct()
40  {
41  $this->siteConfiguration = GeneralUtility::makeInstance(SiteConfiguration::class);
42  $this->sitePathsToMigrate = $this->‪getSitePathsToMigrate();
43  }
44 
45  public function ‪getTitle(): string
46  {
47  return 'Migrate site settings to separate file';
48  }
49 
50  public function ‪getDescription(): string
51  {
52  return
53  'If site settings exist in a config.yaml file, this wizard migrates them to a dedicated settings.yaml file. ' .
54  'Please note that you should remove them from your existing config manually.';
55  }
56 
57  public function ‪executeUpdate(): bool
58  {
59  try {
60  foreach ($this->sitePathsToMigrate as ‪$siteIdentifier => $settings) {
61  $this->siteConfiguration->writeSettings(‪$siteIdentifier, $settings);
62  }
64  return false;
65  }
66  return true;
67  }
68 
72  public function ‪updateNecessary(): bool
73  {
74  return $this->sitePathsToMigrate !== [];
75  }
76 
77  public function ‪getPrerequisites(): array
78  {
79  return [];
80  }
81 
85  protected function ‪getSitePathsToMigrate(): array
86  {
87  $settingsCollection = [];
88  foreach ($this->siteConfiguration->getAllSiteConfigurationPaths() as ‪$siteIdentifier => $configurationPath) {
89  // Ensure site identifier is a string, even if it only consists of digits
91  // settings.yaml already exists, skip
92  if (file_exists($configurationPath . '/' . self::SETTINGS_FILENAME)) {
93  continue;
94  }
95  // Check if the site has any settings
96  ‪$siteConfiguration = $this->siteConfiguration->‪load(‪$siteIdentifier);
97  if (!isset(‪$siteConfiguration['settings'])) {
98  continue;
99  }
100  $settingsCollection[‪$siteIdentifier] = ‪$siteConfiguration['settings'];
101  }
102  return $settingsCollection;
103  }
104 }
‪TYPO3\CMS\Install\Updates\MigrateSiteSettingsConfigUpdate
Definition: MigrateSiteSettingsConfigUpdate.php:33
‪TYPO3\CMS\Core\Configuration\Exception\SiteConfigurationWriteException
Definition: SiteConfigurationWriteException.php:27
‪TYPO3\CMS\Install\Updates\MigrateSiteSettingsConfigUpdate\getTitle
‪getTitle()
Definition: MigrateSiteSettingsConfigUpdate.php:45
‪TYPO3\CMS\Install\Updates\MigrateSiteSettingsConfigUpdate\$siteConfiguration
‪SiteConfiguration $siteConfiguration
Definition: MigrateSiteSettingsConfigUpdate.php:36
‪TYPO3\CMS\Install\Updates\MigrateSiteSettingsConfigUpdate\SETTINGS_FILENAME
‪const SETTINGS_FILENAME
Definition: MigrateSiteSettingsConfigUpdate.php:34
‪TYPO3\CMS\Install\Attribute\UpgradeWizard
Definition: UpgradeWizard.php:25
‪TYPO3\CMS\Core\Configuration\SiteConfiguration
Definition: SiteConfiguration.php:47
‪TYPO3\CMS\Core\Configuration\SiteConfiguration\load
‪load(string $siteIdentifier)
Definition: SiteConfiguration.php:241
‪TYPO3\CMS\Install\Updates\MigrateSiteSettingsConfigUpdate\__construct
‪__construct()
Definition: MigrateSiteSettingsConfigUpdate.php:39
‪TYPO3\CMS\Install\Updates\MigrateSiteSettingsConfigUpdate\getSitePathsToMigrate
‪getSitePathsToMigrate()
Definition: MigrateSiteSettingsConfigUpdate.php:85
‪TYPO3\CMS\Install\Updates
Definition: LegacyClassesForIde.php:22
‪TYPO3\CMS\Install\Updates\MigrateSiteSettingsConfigUpdate\getPrerequisites
‪getPrerequisites()
Definition: MigrateSiteSettingsConfigUpdate.php:77
‪TYPO3\CMS\Install\Updates\MigrateSiteSettingsConfigUpdate\$sitePathsToMigrate
‪array $sitePathsToMigrate
Definition: MigrateSiteSettingsConfigUpdate.php:37
‪TYPO3\CMS\Install\Updates\UpgradeWizardInterface
Definition: UpgradeWizardInterface.php:24
‪TYPO3\CMS\Install\Updates\MigrateSiteSettingsConfigUpdate\executeUpdate
‪executeUpdate()
Definition: MigrateSiteSettingsConfigUpdate.php:57
‪TYPO3\CMS\Install\Updates\MigrateSiteSettingsConfigUpdate\getDescription
‪getDescription()
Definition: MigrateSiteSettingsConfigUpdate.php:50
‪TYPO3\CMS\Install\Updates\MigrateSiteSettingsConfigUpdate\updateNecessary
‪updateNecessary()
Definition: MigrateSiteSettingsConfigUpdate.php:72
‪TYPO3\CMS\Webhooks\Message\$siteIdentifier
‪identifier readonly int readonly array readonly string readonly string $siteIdentifier
Definition: PageModificationMessage.php:38
‪TYPO3\CMS\Core\Utility\GeneralUtility
Definition: GeneralUtility.php:52