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

eliashaeussler / typo3-warming / 14431906128

13 Apr 2025 05:54PM UTC coverage: 91.301% (-0.2%) from 91.486%
14431906128

Pull #839

github

eliashaeussler
[!!!][TASK] Convert `AccessUtility` to `WarmupPermissionGuard`
Pull Request #839: [!!!][TASK] Convert `AccessUtility` to `WarmupPermissionGuard`

55 of 60 new or added lines in 4 files covered. (91.67%)

5 existing lines in 2 files now uncovered.

1123 of 1230 relevant lines covered (91.3%)

8.8 hits per line

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

95.65
/Classes/Controller/FetchSitesController.php
1
<?php
2

3
declare(strict_types=1);
4

5
/*
6
 * This file is part of the TYPO3 CMS extension "warming".
7
 *
8
 * Copyright (C) 2021-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\Typo3Warming\Controller;
25

26
use EliasHaeussler\Typo3SitemapLocator;
27
use EliasHaeussler\Typo3Warming\Configuration;
28
use EliasHaeussler\Typo3Warming\Crawler;
29
use EliasHaeussler\Typo3Warming\Http;
30
use EliasHaeussler\Typo3Warming\Security;
31
use EliasHaeussler\Typo3Warming\Utility;
32
use EliasHaeussler\Typo3Warming\ValueObject;
33
use Psr\Http\Message;
34
use Symfony\Component\DependencyInjection;
35
use TYPO3\CMS\Backend;
36
use TYPO3\CMS\Core;
37

38
/**
39
 * FetchSitesController
40
 *
41
 * @author Elias Häußler <elias@haeussler.dev>
42
 * @license GPL-2.0-or-later
43
 */
44
#[DependencyInjection\Attribute\Autoconfigure(public: true)]
45
final class FetchSitesController
46
{
47
    public function __construct(
6✔
48
        private readonly Configuration\Configuration $configuration,
49
        private readonly Crawler\Strategy\CrawlingStrategyFactory $crawlingStrategyFactory,
50
        private readonly Core\Imaging\IconFactory $iconFactory,
51
        private readonly Http\Message\ResponseFactory $responseFactory,
52
        private readonly Core\Site\SiteFinder $siteFinder,
53
        private readonly Typo3SitemapLocator\Sitemap\SitemapLocator $sitemapLocator,
54
        private readonly Security\WarmupPermissionGuard $accessGuard,
55
    ) {}
6✔
56

57
    /**
58
     * @throws Typo3SitemapLocator\Exception\BaseUrlIsNotSupported
59
     * @throws Typo3SitemapLocator\Exception\SitemapIsMissing
60
     */
61
    public function __invoke(): Message\ResponseInterface
6✔
62
    {
63
        $siteGroups = [];
6✔
64

65
        foreach (array_filter($this->siteFinder->getAllSites(), $this->accessGuard->canWarmupCacheOfSite(...)) as $site) {
6✔
66
            $row = Backend\Utility\BackendUtility::getRecord('pages', $site->getRootPageId(), '*', ' AND hidden = 0');
6✔
67

68
            if (!\is_array($row)) {
6✔
69
                continue;
70
            }
71

72
            $siteGroup = $this->createSiteGroup($site, $row);
6✔
73

74
            if ($siteGroup !== null) {
6✔
75
                $siteGroups[] = $siteGroup;
6✔
76
            }
77
        }
78

79
        return $this->responseFactory->htmlTemplate('Modal/SitesModal', [
6✔
80
            'siteGroups' => $siteGroups,
6✔
81
            'userAgent' => $this->configuration->getUserAgent(),
6✔
82
            'configuration' => [
6✔
83
                'limit' => $this->configuration->getLimit(),
6✔
84
                'strategy' => $this->configuration->getStrategy(),
6✔
85
            ],
6✔
86
            'availableStrategies' => array_keys($this->crawlingStrategyFactory->getAll()),
6✔
87
            'isAdmin' => Utility\BackendUtility::getBackendUser()->isAdmin(),
6✔
88
        ]);
6✔
89
    }
90

91
    /**
92
     * @param array<string, mixed> $page
93
     * @throws Typo3SitemapLocator\Exception\BaseUrlIsNotSupported
94
     * @throws Typo3SitemapLocator\Exception\SitemapIsMissing
95
     */
96
    private function createSiteGroup(Core\Site\Entity\Site $site, array $page): ?ValueObject\Modal\SiteGroup
6✔
97
    {
98
        $items = [];
6✔
99

100
        // Check all available languages for possible sitemaps
101
        foreach ($this->sitemapLocator->locateAllBySite($site) as $i => $sitemaps) {
6✔
102
            foreach ($sitemaps as $sitemap) {
6✔
103
                $siteLanguage = $sitemap->getSiteLanguage();
6✔
104
                $url = null;
6✔
105

106
                // Check if sitemap exists
107
                if ($this->sitemapLocator->isValidSitemap($sitemap)) {
6✔
108
                    $url = (string)$sitemap->getUri();
6✔
109
                }
110

111
                $items[] = new ValueObject\Modal\SiteGroupItem(
6✔
112
                    $siteLanguage,
6✔
113
                    $siteLanguage === $site->getDefaultLanguage(),
6✔
114
                    $url,
6✔
115
                );
6✔
116
            }
117
        }
118

119
        // Early return if no languages are available
120
        if ($items === []) {
6✔
UNCOV
121
            return null;
×
122
        }
123

124
        return new ValueObject\Modal\SiteGroup(
6✔
125
            $site,
6✔
126
            $this->resolvePageTitle($site, $page),
6✔
127
            $this->iconFactory->getIconForRecord('pages', $page)->getIdentifier(),
6✔
128
            $items,
6✔
129
        );
6✔
130
    }
131

132
    /**
133
     * @param array<string, mixed> $page
134
     */
135
    private function resolvePageTitle(Core\Site\Entity\Site $site, array $page): string
6✔
136
    {
137
        $websiteTitle = $site->getConfiguration()['websiteTitle'] ?? null;
6✔
138

139
        if (\is_string($websiteTitle) && trim($websiteTitle) !== '') {
6✔
UNCOV
140
            return $websiteTitle;
×
141
        }
142

143
        return Backend\Utility\BackendUtility::getRecordTitle('pages', $page);
6✔
144
    }
145
}
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