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

eliashaeussler / typo3-warming / 15509771334

07 Jun 2025 04:43PM UTC coverage: 86.535% (-4.1%) from 90.617%
15509771334

Pull #871

github

eliashaeussler
[FEATURE] Collect url metadata during cache warmup
Pull Request #871: [FEATURE] Collect url metadata during cache warmup

104 of 188 new or added lines in 9 files covered. (55.32%)

1 existing line in 1 file now uncovered.

1446 of 1671 relevant lines covered (86.54%)

9.25 hits per line

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

68.0
/Classes/EventListener/UrlMetadataListener.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\EventListener;
25

26
use EliasHaeussler\CacheWarmup;
27
use EliasHaeussler\Typo3Warming\Http;
28
use GuzzleHttp\Exception;
29

30
/**
31
 * UrlMetadataListener
32
 *
33
 * @author Elias Häußler <elias@haeussler.dev>
34
 * @license GPL-2.0-or-later
35
 */
36
final readonly class UrlMetadataListener
37
{
38
    public function __construct(
4✔
39
        private Http\Message\UrlMetadataFactory $urlMetadataFactory,
40
    ) {}
4✔
41

42
    // @todo Enable attribute once support for TYPO3 v12 is dropped
43
    // #[\TYPO3\CMS\Core\Attribute\AsEventListener('eliashaeussler/typo3-warming/url-metadata/on-success')]
NEW
44
    public function onSuccess(CacheWarmup\Event\Crawler\UrlCrawlingSucceeded $event): void
×
45
    {
NEW
46
        $metadata = $this->urlMetadataFactory->createFromResponse($event->response());
×
47

NEW
48
        if ($metadata !== null) {
×
NEW
49
            $result = CacheWarmup\Result\CrawlingResult::createSuccessful(
×
NEW
50
                $event->result()->getUri(),
×
NEW
51
                $this->extendResultData($event->result(), $metadata),
×
NEW
52
            );
×
53

NEW
54
            $event->setResult($result);
×
55
        }
56
    }
57

58
    // @todo Enable attribute once support for TYPO3 v12 is dropped
59
    // #[\TYPO3\CMS\Core\Attribute\AsEventListener('eliashaeussler/typo3-warming/url-metadata/on-failure')]
60
    public function onFailure(CacheWarmup\Event\Crawler\UrlCrawlingFailed $event): void
4✔
61
    {
62
        $metadata = null;
4✔
63
        $exception = $event->exception();
4✔
64

65
        if ($exception instanceof Exception\RequestException && ($response = $exception->getResponse()) !== null) {
4✔
66
            $metadata = $this->urlMetadataFactory->createFromResponse($response);
4✔
67
        }
68

69
        if ($metadata !== null) {
4✔
70
            $result = CacheWarmup\Result\CrawlingResult::createFailed(
4✔
71
                $event->result()->getUri(),
4✔
72
                $this->extendResultData($event->result(), $metadata),
4✔
73
            );
4✔
74

75
            $event->setResult($result);
4✔
76
        }
77
    }
78

79
    /**
80
     * @return array<string, mixed>
81
     */
82
    private function extendResultData(
4✔
83
        CacheWarmup\Result\CrawlingResult $result,
84
        Http\Message\UrlMetadata $metadata,
85
    ): array {
86
        $data = $result->getData();
4✔
87
        $data['urlMetadata'] = $metadata;
4✔
88

89
        return $data;
4✔
90
    }
91
}
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