• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

eliashaeussler / typo3-sitemap-robots / 14101541190

27 Mar 2025 07:56AM UTC coverage: 92.035% (-8.0%) from 100.0%
14101541190

push

github

web-flow
Merge pull request #65 from thomasrawiel/feature/language-sitemaps

[feat] add option to inject sitemap language versions into robots.txt

52 of 61 new or added lines in 4 files covered. (85.25%)

104 of 113 relevant lines covered (92.04%)

3.07 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

76.32
/Classes/Updates/LegacySiteConfigurationParameterUpgradeWizard.php
1
<?php
2

3
declare(strict_types=1);
4

5
/*
6
 * This file is part of the TYPO3 CMS extension "sitemap_robots".
7
 *
8
 * Copyright (C) 2023-2025 Elias Häußler <elias@haeussler.dev>
9
 *
10
 * This program is free software: you can redistribute it and/or modify
11
 * it under the terms of the GNU General Public License as published by
12
 * the Free Software Foundation, either version 2 of the License, or
13
 * (at your option) any later version.
14
 *
15
 * This program is distributed in the hope that it will be useful,
16
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18
 * GNU General Public License for more details.
19
 *
20
 * You should have received a copy of the GNU General Public License
21
 * along with this program. If not, see <https://www.gnu.org/licenses/>.
22
 */
23

24
namespace EliasHaeussler\Typo3SitemapRobots\Updates;
25

26
use EliasHaeussler\Typo3SitemapRobots\Enum;
27
use TYPO3\CMS\Core;
28
use TYPO3\CMS\Install;
29

30
/**
31
 * LegacySiteConfigurationParameterUpgradeWizard
32
 *
33
 * @author Elias Häußler <elias@haeussler.dev>
34
 * @license GPL-2.0-or-later
35
 */
36
#[Install\Attribute\UpgradeWizard('sitemapRobotsLegacySiteConfigurationParameterUpgradeWizard')]
37
final class LegacySiteConfigurationParameterUpgradeWizard implements Install\Updates\UpgradeWizardInterface
38
{
39
    private readonly Core\Information\Typo3Version $typo3Version;
40

41
    public function __construct(
5✔
42
        private readonly Core\Configuration\SiteConfiguration $siteConfiguration,
43
    ) {
44
        $this->typo3Version = new Core\Information\Typo3Version();
5✔
45
    }
46

NEW
47
    public function getTitle(): string
×
48
    {
NEW
49
        return '[EXT:sitemap_robots] Migrate legacy site configuration parameter';
×
50
    }
51

NEW
52
    public function getDescription(): string
×
53
    {
NEW
54
        return 'Migrates legacy configuration values of the "sitemap_robots_inject" parameter within site configuration.';
×
55
    }
56

57
    public function executeUpdate(): bool
3✔
58
    {
59
        $outdatedSites = $this->fetchOutdatedSites();
3✔
60
        $successful = true;
3✔
61

62
        foreach ($outdatedSites as $identifier => $configuration) {
3✔
63
            /** @var bool $outdatedValue */
64
            $outdatedValue = $configuration['sitemap_robots_inject'];
2✔
65
            $migratedValue = Enum\EnhancementStrategy::fromConfiguration($outdatedValue);
2✔
66

67
            if ($migratedValue !== null) {
2✔
68
                $configuration['sitemap_robots_inject'] = $migratedValue->value;
1✔
69
            } else {
70
                $configuration['sitemap_robots_inject'] = '';
1✔
71
            }
72

73
            try {
74
                $this->writeMigratedSiteConfiguration($identifier, $configuration);
2✔
NEW
75
            } catch (Core\Configuration\Exception\SiteConfigurationWriteException) {
×
NEW
76
                $successful = false;
×
77
            }
78
        }
79

80
        return $successful;
3✔
81
    }
82

83
    public function updateNecessary(): bool
2✔
84
    {
85
        return $this->fetchOutdatedSites() !== [];
2✔
86
    }
87

NEW
88
    public function getPrerequisites(): array
×
89
    {
NEW
90
        return [];
×
91
    }
92

93
    /**
94
     * @return array<string, array<string, mixed>>
95
     */
96
    private function fetchOutdatedSites(): array
5✔
97
    {
98
        $allSites = $this->siteConfiguration->getAllExistingSites(false);
5✔
99
        $outdatedSites = [];
5✔
100

101
        foreach ($allSites as $site) {
5✔
102
            $siteIdentifier = $site->getIdentifier();
5✔
103
            /** @var array<string, mixed> $configuration */
104
            $configuration = $this->siteConfiguration->load($siteIdentifier);
5✔
105
            $configurationValue = $configuration['sitemap_robots_inject'] ?? null;
5✔
106

107
            if (is_bool($configurationValue)) {
5✔
108
                $outdatedSites[$siteIdentifier] = $configuration;
3✔
109
            }
110
        }
111

112
        return $outdatedSites;
5✔
113
    }
114

115
    /**
116
     * @param array<string, mixed> $configuration
117
     */
118
    private function writeMigratedSiteConfiguration(string $identifier, array $configuration): void
2✔
119
    {
120
        if ($this->typo3Version->getMajorVersion() >= 13) {
2✔
NEW
121
            $siteWriter = Core\Utility\GeneralUtility::makeInstance(Core\Configuration\SiteWriter::class);
×
122
        } else {
123
            // @todo Remove once support for TYPO3 v12 is dropped
124
            $siteWriter = $this->siteConfiguration;
2✔
125
        }
126

127
        $siteWriter->write($identifier, $configuration);
2✔
128
    }
129
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2025 Coveralls, Inc