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

eliashaeussler / typo3-warming / 17774573081

16 Sep 2025 05:54PM UTC coverage: 92.917% (+0.2%) from 92.759%
17774573081

Pull #959

github

eliashaeussler
[FEATURE] Run cache warmup after DataHandler cache clear
Pull Request #959: [FEATURE] Run cache warmup after DataHandler cache clear

80 of 83 new or added lines in 3 files covered. (96.39%)

1771 of 1906 relevant lines covered (92.92%)

14.24 hits per line

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

90.0
/Classes/Hook/DataHandlerClearCacheHook.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\Hook;
25

26
use EliasHaeussler\Typo3Warming\Configuration;
27
use EliasHaeussler\Typo3Warming\Queue;
28
use EliasHaeussler\Typo3Warming\ValueObject;
29
use Symfony\Component\DependencyInjection;
30
use TYPO3\CMS\Backend;
31
use TYPO3\CMS\Core;
32

33
/**
34
 * DataHandlerClearCacheHook
35
 *
36
 * @author Elias Häußler <elias@haeussler.dev>
37
 * @license GPL-2.0-or-later
38
 * @internal
39
 *
40
 * @phpstan-type HookParams array{table?: non-empty-string, uid?: positive-int, uid_page?: positive-int}
41
 */
42
#[DependencyInjection\Attribute\Autoconfigure(public: true)]
43
final readonly class DataHandlerClearCacheHook
44
{
45
    public function __construct(
10✔
46
        private Configuration\Configuration $configuration,
47
        private Queue\CacheWarmupQueue $queue,
48
    ) {}
10✔
49

50
    /**
51
     * @param HookParams $params
52
     */
53
    public function warmupPageCache(array $params): void
10✔
54
    {
55
        // Early return if hook is disabled
56
        if (!$this->configuration->runAfterCacheClear) {
10✔
57
            return;
2✔
58
        }
59

60
        [$pageUid, $languageIds] = $this->resolveCacheWarmupParameters($params);
8✔
61

62
        if ($pageUid !== null) {
8✔
63
            $this->queue->enqueue(new ValueObject\Request\PageWarmupRequest($pageUid, $languageIds));
7✔
64
        }
65
    }
66

67
    /**
68
     * @param HookParams $params
69
     * @return array{positive-int|null, array{0?: non-negative-int}}
70
     */
71
    private function resolveCacheWarmupParameters(array $params): array
8✔
72
    {
73
        $table = $params['table'] ?? null;
8✔
74
        $recordUid = $params['uid'] ?? null;
8✔
75

76
        // Early return if table or record uid is not available
77
        if ($table === null || $recordUid === null) {
8✔
78
            return [null, []];
1✔
79
        }
80

81
        if ($table === 'pages') {
7✔
82
            return [$recordUid, []];
3✔
83
        }
84

85
        $record = Backend\Utility\BackendUtility::getRecord($table, $recordUid);
4✔
86
        $pageUid = $params['uid_page'] ?? null;
4✔
87

88
        // Early return if record cannot be resolved
89
        if ($record === null) {
4✔
90
            return [$pageUid, []];
2✔
91
        }
92

93
        if (\class_exists(Core\Schema\TcaSchemaFactory::class)) {
2✔
94
            // @todo Use DI once support for TYPO3 v12 is dropped
95
            $tcaSchemaFactory = Core\Utility\GeneralUtility::makeInstance(Core\Schema\TcaSchemaFactory::class);
2✔
96
            $tcaSchema = $tcaSchemaFactory->has($table) ? $tcaSchemaFactory->get($table) : null;
2✔
97

98
            if ($tcaSchema?->isLanguageAware() === true) {
2✔
99
                $languageField = $tcaSchema->getCapability(Core\Schema\Capability\TcaSchemaCapability::Language)->getLanguageField()->getName();
2✔
100
            } else {
NEW
101
                $languageField = null;
×
102
            }
103
        } else {
104
            // @todo Remove once support for TYPO3 v12 is dropped
NEW
105
            $languageField = $GLOBALS['TCA'][$table]['ctrl']['languageField'] ?? null;
×
106
        }
107

108
        if ($languageField !== null) {
2✔
109
            $languageIds = [$record[$languageField] ?? 0];
2✔
110
        } else {
NEW
111
            $languageIds = [];
×
112
        }
113

114
        return [$pageUid, $languageIds];
2✔
115
    }
116
}
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

© 2026 Coveralls, Inc