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

tomasnorre / crawler / 19907601717

03 Dec 2025 08:20PM UTC coverage: 68.82% (-0.7%) from 69.485%
19907601717

Pull #1237

github

web-flow
Merge 3969b3d6b into 837f2e25f
Pull Request #1237: [TASK] Add TYPO3 14 Support

1896 of 2755 relevant lines covered (68.82%)

3.16 hits per line

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

10.0
/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\Utility\GeneralUtility;
29

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

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

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

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

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

71
        $GLOBALS['TSFE']->applicationData['tx_crawler']['vars'] = [
×
72
            'id' => $GLOBALS['TSFE']->id,
×
73
            'gr_list' => implode(',', $this->context->getAspect('frontend.user')->getGroupIds()),
×
74
            'no_cache' => !$request->getAttribute('frontend.cache.instruction')->isCachingAllowed(),
×
75
        ];
×
76

77
        $this->runPollSuccessHooks();
×
78

79
        // Send log data for crawler (serialized content)
80
        return $response->withHeader('X-T3Crawler-Meta', serialize($GLOBALS['TSFE']->applicationData['tx_crawler']));
×
81
    }
82

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