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

tomasnorre / crawler / 3696698329

pending completion
3696698329

Pull #988

github

GitHub
Merge d1d32bd2d into 3f94d6a4e
Pull Request #988: [WIP][FEATURE] Setup new Backend Module

417 of 417 new or added lines in 9 files covered. (100.0%)

1601 of 2523 relevant lines covered (63.46%)

3.23 hits per line

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

73.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\Http\Response;
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
class CrawlerInitialization implements MiddlewareInterface
39
{
40
    protected Context $context;
41

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

47
    /**
48
     * @throws \TYPO3\CMS\Core\Context\Exception\AspectNotFoundException
49
     * @throws \TYPO3\CMS\Core\Error\Http\ServiceUnavailableException
50
     */
51
    public function process(ServerRequestInterface $request, RequestHandlerInterface $handler): ResponseInterface
52
    {
53
        $queueParameters = $request->getAttribute('tx_crawler');
3✔
54
        if ($queueParameters === null) {
3✔
55
            return $handler->handle($request);
1✔
56
        }
57

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

65
        // Execute the frontend request as is
66
        $response = $handler->handle($request);
2✔
67

68
        $GLOBALS['TSFE']->applicationData['tx_crawler']['vars'] = [
2✔
69
            'id' => $GLOBALS['TSFE']->id,
2✔
70
            'gr_list' => implode(',', $this->context->getAspect('frontend.user')->getGroupIds()),
2✔
71
            'no_cache' => $GLOBALS['TSFE']->no_cache,
2✔
72
        ];
2✔
73

74
        $this->runPollSuccessHooks();
2✔
75

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

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