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

eliashaeussler / typo3-warming / 14429819143

13 Apr 2025 01:13PM UTC coverage: 90.562% (-0.9%) from 91.486%
14429819143

Pull #793

github

eliashaeussler
[!!!][FEATURE] Allow to exclude sites and languages from warming

Resolves: #777
Pull Request #793: [!!!][FEATURE] Allow to exclude sites and languages from warming

116 of 135 new or added lines in 10 files covered. (85.93%)

7 existing lines in 3 files now uncovered.

1161 of 1282 relevant lines covered (90.56%)

8.47 hits per line

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

90.48
/Classes/Http/Message/PageUriBuilder.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\Http\Message;
25

26
use EliasHaeussler\Typo3Warming\Domain;
27
use Psr\Http\Message;
28
use TYPO3\CMS\Core;
29

30
/**
31
 * PageUriBuilder
32
 *
33
 * @author Elias Häußler <elias@haeussler.dev>
34
 * @license GPL-2.0-or-later
35
 */
36
final class PageUriBuilder
37
{
38
    public function __construct(
8✔
39
        private readonly Core\Domain\Repository\PageRepository $pageRepository,
40
        private readonly Domain\Repository\SiteRepository $siteRepository,
41
        private readonly Domain\Repository\SiteLanguageRepository $siteLanguageRepository,
42
    ) {}
8✔
43

44
    /**
45
     * @param positive-int $pageId
46
     * @throws Core\Exception\SiteNotFoundException
47
     */
48
    public function build(int $pageId, ?int $languageId = null): ?Message\UriInterface
5✔
49
    {
50
        $page = $this->pageRepository->getPage($pageId);
5✔
51

52
        // Early return if page does not exist
53
        if ($page === []) {
5✔
54
            return null;
1✔
55
        }
56

57
        // Resolve site
58
        $site = $this->siteRepository->findOneByPageId($pageId);
4✔
59

60
        // Early return if site is inaccessible
61
        if ($site === null) {
4✔
NEW
62
            return null;
×
63
        }
64

65
        // Resolve site language
66
        $siteLanguage = $this->siteLanguageRepository->findOneByLanguageId(
4✔
67
            $site,
4✔
68
            $languageId ?? $site->getDefaultLanguage()->getLanguageId(),
4✔
69
        );
4✔
70

71
        // Early return if site language is inaccessible
72
        if ($siteLanguage === null) {
4✔
NEW
73
            return null;
×
74
        }
75

76
        // Check if page is suitable for language
77
        if ($siteLanguage->getLanguageId() > 0) {
4✔
78
            $languageAspect = Core\Context\LanguageAspectFactory::createFromSiteLanguage($siteLanguage);
2✔
79
            $page = $this->pageRepository->getLanguageOverlay('pages', $page, $languageAspect);
2✔
80

81
            if ($page === null || !$this->pageRepository->isPageSuitableForLanguage($page, $languageAspect)) {
2✔
82
                return null;
1✔
83
            }
84
        }
85

86
        return $site->getRouter()->generateUri((string)$pageId, ['_language' => $siteLanguage]);
3✔
87
    }
88
}
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