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

eliashaeussler / typo3-warming / 14522580517

17 Apr 2025 06:42PM UTC coverage: 92.149% (+0.4%) from 91.748%
14522580517

push

github

web-flow
Merge pull request #793 from eliashaeussler/feature/exclude-sites

145 of 146 new or added lines in 10 files covered. (99.32%)

1209 of 1312 relevant lines covered (92.15%)

9.33 hits per line

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

97.5
/Classes/Domain/Repository/SiteRepository.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\Domain\Repository;
25

26
use EliasHaeussler\Typo3Warming\Security;
27
use TYPO3\CMS\Core;
28

29
/**
30
 * SiteRepository
31
 *
32
 * @author Elias Häußler <elias@haeussler.dev>
33
 * @license GPL-2.0-or-later
34
 */
35
final class SiteRepository
36
{
37
    public function __construct(
38✔
38
        private readonly Core\Site\SiteFinder $siteFinder,
39
        private readonly Security\WarmupPermissionGuard $permissionGuard,
40
    ) {}
38✔
41

42
    /**
43
     * @return array<string, Core\Site\Entity\Site>
44
     */
45
    public function findAll(): array
25✔
46
    {
47
        $sites = $this->siteFinder->getAllSites();
25✔
48
        $resolvedSites = [];
25✔
49

50
        foreach ($sites as $site) {
25✔
51
            if ($this->isAccessible($site)) {
25✔
52
                $resolvedSites[$site->getIdentifier()] = $site;
22✔
53
            }
54

55
        }
56

57
        return $resolvedSites;
25✔
58
    }
59

60
    public function countAll(): int
22✔
61
    {
62
        return count($this->findAll());
22✔
63
    }
64

65
    /**
66
     * @param non-negative-int $rootPageId
67
     */
68
    public function findOneByRootPageId(int $rootPageId): ?Core\Site\Entity\Site
4✔
69
    {
70
        try {
71
            $site = $this->siteFinder->getSiteByRootPageId($rootPageId);
4✔
72
        } catch (Core\Exception\SiteNotFoundException) {
1✔
73
            return null;
1✔
74
        }
75

76
        if ($this->isAccessible($site)) {
3✔
77
            return $site;
1✔
78
        }
79

80
        return null;
2✔
81
    }
82

83
    /**
84
     * @param non-negative-int $pageId
85
     */
86
    public function findOneByPageId(int $pageId): ?Core\Site\Entity\Site
15✔
87
    {
88
        try {
89
            $site = $this->siteFinder->getSiteByPageId($pageId);
15✔
90
        } catch (Core\Exception\SiteNotFoundException) {
2✔
91
            return null;
2✔
92
        }
93

94
        if ($this->isAccessible($site)) {
13✔
95
            return $site;
10✔
96
        }
97

98
        return null;
3✔
99
    }
100

101
    public function findOneByIdentifier(string $identifier): ?Core\Site\Entity\Site
18✔
102
    {
103
        try {
104
            $site = $this->siteFinder->getSiteByIdentifier($identifier);
18✔
105
        } catch (Core\Exception\SiteNotFoundException) {
1✔
106
            return null;
1✔
107
        }
108

109
        if ($this->isAccessible($site)) {
17✔
110
            return $site;
15✔
111
        }
112

113
        return null;
2✔
114
    }
115

116
    private function isAccessible(Core\Site\Entity\Site $site): bool
34✔
117
    {
118
        $context = Security\Context\PermissionContext::forCurrentBackendUser();
34✔
119

120
        return !$this->isExcluded($site) && $this->permissionGuard->canWarmupCacheOfSite($site, $context);
34✔
121
    }
122

123
    private function isExcluded(Core\Site\Entity\Site $site): bool
34✔
124
    {
125
        $configuration = $site->getConfiguration();
34✔
126

127
        if (!isset($configuration['warming_exclude'])) {
34✔
NEW
128
            return false;
×
129
        }
130

131
        return (bool)$configuration['warming_exclude'];
34✔
132
    }
133
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE TRIAL · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc