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

tomasnorre / crawler / 29263197699

13 Jul 2026 03:40PM UTC coverage: 69.894% (-0.02%) from 69.912%
29263197699

push

github

web-flow
[BUGFIX] Replace deprecated TSFE with frontend page information (#1300)

4 of 6 new or added lines in 1 file covered. (66.67%)

1920 of 2747 relevant lines covered (69.89%)

3.19 hits per line

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

91.67
/Classes/Middleware/CrawlerInitialization.php
1
<?php
2

3
declare(strict_types=1);
4

5
namespace AOE\Crawler\Middleware;
6

7
/*
8
 * (c) 2022 Tomas Norre Mikkelsen <tomasnorre@gmail.com>
9
 *
10
 * This file is part of the TYPO3 Crawler Extension.
11
 *
12
 * It is free software; you can redistribute it and/or modify it under
13
 * the terms of the GNU General Public License, either version 2
14
 * of the License, or any later version.
15
 *
16
 * For the full copyright and license information, please read the
17
 * LICENSE.txt file that was distributed with this source code.
18
 *
19
 * The TYPO3 project - inspiring people to share!
20
 */
21

22
use Psr\Http\Message\ResponseInterface;
23
use Psr\Http\Message\ServerRequestInterface;
24
use Psr\Http\Server\MiddlewareInterface;
25
use Psr\Http\Server\RequestHandlerInterface;
26
use TYPO3\CMS\Core\Context\Context;
27
use TYPO3\CMS\Core\Context\Exception\AspectNotFoundException;
28
use TYPO3\CMS\Core\Error\Http\ServiceUnavailableException;
29
use TYPO3\CMS\Core\Utility\GeneralUtility;
30
use TYPO3\CMS\Frontend\Page\PageInformationCreationFailedException;
31
use TYPO3\CMS\Frontend\Page\PageInformationFactory;
32

33
/**
34
 * Evaluates HTTP headers and checks if Crawler should register itself.
35
 * Needs to be run after TSFE initialization AND Frontend User Authentication.
36
 *
37
 * Once done, the queue is fetched, and then the frontend request runs through.
38
 *
39
 * Finally, at the very end, if the crawler is still running, output the data and replace the response.
40
 *
41
 * @internal since v12.0.0
42
 */
43
class CrawlerInitialization implements MiddlewareInterface
44
{
45
    protected Context $context;
46

47
    public function __construct(
48
        private readonly PageInformationFactory $pageInformationFactory,
49
        ?Context $context = null,
50
    ) {
51
        $this->context = $context ?? GeneralUtility::makeInstance(Context::class);
2✔
52
    }
53

54
    /**
55
     * @throws AspectNotFoundException
56
     * @throws ServiceUnavailableException
57
     */
58
    #[\Override]
59
    public function process(ServerRequestInterface $request, RequestHandlerInterface $handler): ResponseInterface
60
    {
61
        $queueParameters = $request->getAttribute('tx_crawler');
3✔
62
        if ($queueParameters === null) {
3✔
63
            return $handler->handle($request);
1✔
64
        }
65

66
        $request = $request->withAttribute('tx_crawler', [
2✔
67
            'forceIndexing' => true,
2✔
68
            'running' => true,
2✔
69
            'parameters' => $queueParameters,
2✔
70
            'log' => ['User Groups: ' . ($queueParameters['feUserGroupList'] ?? '')],
2✔
71
        ]);
2✔
72

73
        // Execute the frontend request as is
74
        $response = $handler->handle($request);
2✔
75
        $noCache = !$request->getAttribute('frontend.cache.instruction')->isCachingAllowed();
2✔
76

77
        try {
78
            $pageInformation = $request->getAttribute(
2✔
79
                'frontend.page.information',
2✔
80
            ) ?? $this->pageInformationFactory->create($request);
2✔
NEW
81
        } catch (PageInformationCreationFailedException $exception) {
×
NEW
82
            return $exception->getResponse();
×
83
        }
84

85
        $crawlerData = $request->getAttribute('tx_crawler', []);
2✔
86
        $crawlerData['vars'] = [
2✔
87
            'id' => $pageInformation->getId(),
2✔
88
            'gr_list' => implode(',', $this->context->getAspect('frontend.user')->getGroupIds()),
2✔
89
            'no_cache' => $noCache,
2✔
90
        ];
2✔
91

92
        // Send log data for crawler (serialized content)
93
        return $response->withHeader('X-T3Crawler-Meta', serialize($crawlerData));
2✔
94
    }
95
}
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