Passed
Push — master ( 8e4875...07bfbc )
by
unknown
12:19
created

SilentTemplateFileUpgradeService   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 42
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 5
eloc 10
dl 0
loc 42
rs 10
c 1
b 0
f 0

4 Methods

Rating   Name   Duplication   Size   Complexity  
A addBackendRoutingRewriteRules() 0 6 2
A throwTemplateFileChangedException() 0 5 1
A __construct() 0 3 1
A execute() 0 3 1
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
18
namespace TYPO3\CMS\Install\Service;
19
20
use TYPO3\CMS\Install\Service\Exception\TemplateFileChangedException;
21
22
/**
23
 * Execute "silent" upgrades for folder structure template files, if needed.
24
 *
25
 * Since the content of the template files may changed over time this class
26
 * performs the necessary content changes in those files already present in
27
 * the installation. It is called by the layout controller at an early point.
28
 *
29
 * Every change is encapsulated in one method and must throw a
30
 * TemplateFileChangedException if its content was updated.
31
 *
32
 * @internal This class is only meant to be used within EXT:install and is not part of the TYPO3 Core API.
33
 */
34
class SilentTemplateFileUpgradeService
35
{
36
    protected WebServerConfigurationFileService $webServerConfigurationFileService;
37
38
    public function __construct(WebServerConfigurationFileService $webServerConfigurationFileService)
39
    {
40
        $this->webServerConfigurationFileService = $webServerConfigurationFileService;
41
    }
42
43
    /**
44
     * Executed content changes. Single upgrade methods must throw a
45
     * TemplateFileChangedException if content of the file was updated.
46
     *
47
     * @throws TemplateFileChangedException
48
     */
49
    public function execute(): void
50
    {
51
        $this->addBackendRoutingRewriteRules();
52
    }
53
54
    /**
55
     * @throws TemplateFileChangedException
56
     */
57
    protected function addBackendRoutingRewriteRules(): void
58
    {
59
        $changed = $this->webServerConfigurationFileService->addWebServerSpecificBackendRoutingRewriteRules();
60
61
        if ($changed) {
62
            $this->throwTemplateFileChangedException();
63
        }
64
    }
65
66
    /**
67
     * Throw exception after template file content change to trigger a redirect.
68
     *
69
     * @throws TemplateFileChangedException
70
     */
71
    protected function throwTemplateFileChangedException(): void
72
    {
73
        throw new TemplateFileChangedException(
74
            'Template file updated, reload needed',
75
            1608286894
76
        );
77
    }
78
}
79