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

tomasnorre / crawler / 18850473052

27 Oct 2025 05:38PM UTC coverage: 69.33% (-0.2%) from 69.481%
18850473052

Pull #1158

github

web-flow
Merge bd10b1ec2 into 9bc42f52b
Pull Request #1158: [TASK] Replace deprecated applicationData with request attributes

12 of 15 new or added lines in 1 file covered. (80.0%)

8 existing lines in 3 files now uncovered.

1935 of 2791 relevant lines covered (69.33%)

3.22 hits per line

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

83.33
/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\Information\Typo3Version;
30
use TYPO3\CMS\Core\Utility\GeneralUtility;
31

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

46
    public function __construct(?Context $context = null)
47
    {
48
        $this->context = $context ?? GeneralUtility::makeInstance(Context::class);
2✔
49
    }
50

51
    /**
52
     * @throws AspectNotFoundException
53
     * @throws ServiceUnavailableException
54
     */
55
    public function process(ServerRequestInterface $request, RequestHandlerInterface $handler): ResponseInterface
56
    {
57
        $queueParameters = $request->getAttribute('tx_crawler');
3✔
58
        if ($queueParameters === null) {
3✔
59
            return $handler->handle($request);
1✔
60
        }
61

62
        $request = $request->withAttribute('tx_crawler', [
2✔
63
            'forceIndexing' => true,
2✔
64
            'running' => true,
2✔
65
            'parameters' => $queueParameters,
2✔
66
            'log' => ['User Groups: ' . ($queueParameters['feUserGroupList'] ?? '')],
2✔
67
        ]);
2✔
68

69
        // Execute the frontend request as is
70
        $response = $handler->handle($request);
2✔
71

72
        $typo3Version = GeneralUtility::makeInstance(Typo3Version::class);
2✔
73
        if ($typo3Version->getMajorVersion() >= 13) {
2✔
74
            $noCache = !$request->getAttribute('frontend.cache.instruction')->isCachingAllowed();
2✔
75
        } else {
UNCOV
76
            $noCache = $GLOBALS['TSFE']->no_cache;
×
77
        }
78

79
        $crawlerData = $request->getAttribute('tx_crawler', []);
2✔
80
        $crawlerData['vars'] = [
2✔
81
            'id' => $GLOBALS['TSFE']->id,
2✔
82
            'gr_list' => implode(',', $this->context->getAspect('frontend.user')->getGroupIds()),
2✔
83
            'no_cache' => $noCache,
2✔
84
        ];
2✔
85

86
        $this->runPollSuccessHooks($crawlerData);
2✔
87

88
        // Send log data for crawler (serialized content)
89
        return $response->withHeader('X-T3Crawler-Meta', serialize($crawlerData));
2✔
90
    }
91

92
    /**
93
     * Required because some extensions (staticpub) might never be requested to run due to some Core side effects
94
     * and since this is considered as error the crawler should handle it properly
95
     */
96
    private function runPollSuccessHooks(array &$crawlerData): void
97
    {
98
        $procInstructions = $crawlerData['content']['parameters']['procInstructions'] ?? null;
2✔
99
        if (!is_array($procInstructions)) {
2✔
100
            return;
2✔
101
        }
102

103
        foreach ($GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['crawler']['pollSuccess'] ?? [] as $pollable) {
×
NEW
104
            if (in_array($pollable, $procInstructions, true)) {
×
NEW
105
                if (empty($crawlerData['success'][$pollable])) {
×
NEW
106
                    $crawlerData['errorlog'][] = 'Error: Pollable extension (' . $pollable . ') did not complete successfully.';
×
107
                }
108
            }
109
        }
110
    }
111
}
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