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

tomasnorre / crawler / 19710526688

26 Nov 2025 04:22PM UTC coverage: 69.231% (-0.3%) from 69.481%
19710526688

push

github

web-flow
!!! [TASK] Remove PHP 8.1 support (#1219)

1935 of 2795 relevant lines covered (69.23%)

3.21 hits per line

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

73.53
/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
use Psr\Http\Message\ResponseInterface;
22
use Psr\Http\Message\ServerRequestInterface;
23
use Psr\Http\Server\MiddlewareInterface;
24
use Psr\Http\Server\RequestHandlerInterface;
25
use TYPO3\CMS\Core\Context\Context;
26
use TYPO3\CMS\Core\Context\Exception\AspectNotFoundException;
27
use TYPO3\CMS\Core\Error\Http\ServiceUnavailableException;
28
use TYPO3\CMS\Core\Information\Typo3Version;
29
use TYPO3\CMS\Core\Utility\GeneralUtility;
30

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

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

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

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

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

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

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

84
        $this->runPollSuccessHooks();
2✔
85

86
        // Send log data for crawler (serialized content)
87
        return $response->withHeader('X-T3Crawler-Meta', serialize($GLOBALS['TSFE']->applicationData['tx_crawler']));
2✔
88
    }
89

90
    /**
91
     * Required because some extensions (staticpub) might never be requested to run due to some Core side effects
92
     * and since this is considered as error the crawler should handle it properly
93
     */
94
    private function runPollSuccessHooks(): void
95
    {
96
        if (!is_array(
2✔
97
            $GLOBALS['TSFE']->applicationData['tx_crawler']['content']['parameters']['procInstructions'] ?? false
2✔
98
        )) {
2✔
99
            return;
2✔
100
        }
101
        foreach ($GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['crawler']['pollSuccess'] ?? [] as $pollable) {
×
102
            if (in_array(
×
103
                $pollable,
×
104
                $GLOBALS['TSFE']->applicationData['tx_crawler']['content']['parameters']['procInstructions'],
×
105
                true
×
106
            )) {
×
107
                if (empty($GLOBALS['TSFE']->applicationData['tx_crawler']['success'][$pollable])) {
×
108
                    $GLOBALS['TSFE']->applicationData['tx_crawler']['errorlog'][] = 'Error: Pollable extension (' . $pollable . ') did not complete successfully.';
×
109
                }
110
            }
111
        }
112
    }
113
}
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