-
-
Notifications
You must be signed in to change notification settings - Fork 137
/
SilentConfigurationUpgrade.php
74 lines (67 loc) · 2.62 KB
/
SilentConfigurationUpgrade.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
<?php
declare(strict_types=1);
namespace Helhum\Typo3Console\Install\Upgrade;
/*
* This file is part of the TYPO3 Console 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
* LICENSE file that was distributed with this source code.
*
*/
use Helhum\Typo3Console\Typo3CompatibilityBridge;
use Symfony\Component\Console\Exception\RuntimeException;
use TYPO3\CMS\Core\Configuration\ConfigurationManager;
use TYPO3\CMS\Core\Configuration\ExtensionConfiguration;
use TYPO3\CMS\Core\Utility\GeneralUtility;
use TYPO3\CMS\Install\Service\Exception\ConfigurationChangedException;
use TYPO3\CMS\Install\Service\SilentConfigurationUpgradeService;
/**
* Used to migrate deprecated system configuration values to new values
* It is a wrapper around the TYPO3 class to properly handle redirect exceptions
*/
class SilentConfigurationUpgrade
{
/**
* @var ConfigurationManager
*/
private $configurationManager;
public function __construct(ConfigurationManager $configurationManager = null)
{
$this->configurationManager = $configurationManager ?: GeneralUtility::makeInstance(ConfigurationManager::class);
}
/**
* Call silent upgrade class, redirect to self if configuration was changed.
*
* @throws \UnexpectedValueException
* @throws RuntimeException
*/
public function executeSilentConfigurationUpgradesIfNeeded()
{
if (!file_exists(Typo3CompatibilityBridge::getSystemConfigurationFileLocation())) {
return;
}
$upgradeService = new SilentConfigurationUpgradeService($this->configurationManager);
$count = 0;
do {
try {
$count++;
$upgradeService->execute();
$redirect = false;
} catch (ConfigurationChangedException $e) {
$redirect = true;
$this->configurationManager->exportConfiguration();
if ($count > 20) {
throw new RuntimeException('Too many loops when silently upgrading configuration', 1493897404, $e);
}
}
} while ($redirect === true);
// We need to write the extension configuration for all active extensions ourselves
// as the core does not take care doing so (yet)
$extensionConfigurationService = new ExtensionConfiguration();
$extensionConfigurationService->synchronizeExtConfTemplateWithLocalConfigurationOfAllExtensions();
}
}