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

eliashaeussler / typo3-warming / 17710663153

14 Sep 2025 11:40AM UTC coverage: 90.136% (-2.6%) from 92.759%
17710663153

Pull #959

github

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

21 of 83 new or added lines in 3 files covered. (25.3%)

1718 of 1906 relevant lines covered (90.14%)

13.09 hits per line

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

0.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
{
NEW
45
    public function __construct(
×
46
        private Configuration\Configuration $configuration,
47
        private Queue\CacheWarmupQueue $queue,
NEW
48
    ) {}
×
49

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

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

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

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

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

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

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

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

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

NEW
98
            if ($tcaSchema->isLanguageAware()) {
×
NEW
99
                $languageField = $tcaSchema->getCapability(Core\Schema\Capability\TcaSchemaCapability::Language)->getLanguageField()->getName();
×
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

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

NEW
114
        return [$pageUid, $languageIds];
×
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