|
1
|
|
|
<?php |
|
2
|
|
|
namespace ApacheSolrForTypo3\Solr\Middleware; |
|
3
|
|
|
|
|
4
|
|
|
/*************************************************************** |
|
5
|
|
|
* Copyright notice |
|
6
|
|
|
* |
|
7
|
|
|
* (c) 2019 Achim Fritz <[email protected]> |
|
8
|
|
|
* All rights reserved |
|
9
|
|
|
* |
|
10
|
|
|
* This script is part of the TYPO3 project. The TYPO3 project is |
|
11
|
|
|
* free software; you can redistribute it and/or modify |
|
12
|
|
|
* it under the terms of the GNU General Public License as published by |
|
13
|
|
|
* the Free Software Foundation; either version 3 of the License, or |
|
14
|
|
|
* (at your option) any later version. |
|
15
|
|
|
* |
|
16
|
|
|
* The GNU General Public License can be found at |
|
17
|
|
|
* http://www.gnu.org/copyleft/gpl.html. |
|
18
|
|
|
* A copy is found in the textfile GPL.txt and important notices to the license |
|
19
|
|
|
* from the author is found in LICENSE.txt distributed with these scripts. |
|
20
|
|
|
* |
|
21
|
|
|
* |
|
22
|
|
|
* This script is distributed in the hope that it will be useful, |
|
23
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
24
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
25
|
|
|
* GNU General Public License for more details. |
|
26
|
|
|
* |
|
27
|
|
|
* This copyright notice MUST APPEAR in all copies of the script! |
|
28
|
|
|
***************************************************************/ |
|
29
|
|
|
|
|
30
|
|
|
use ApacheSolrForTypo3\Solr\IndexQueue\PageIndexerRequest; |
|
31
|
|
|
use ApacheSolrForTypo3\Solr\IndexQueue\PageIndexerRequestHandler; |
|
32
|
|
|
use ApacheSolrForTypo3\Solr\System\Logging\SolrLogManager; |
|
33
|
|
|
use Psr\Http\Message\ResponseInterface; |
|
34
|
|
|
use Psr\Http\Message\ServerRequestInterface; |
|
35
|
|
|
use Psr\Http\Server\MiddlewareInterface; |
|
36
|
|
|
use Psr\Http\Server\RequestHandlerInterface; |
|
37
|
|
|
use TYPO3\CMS\Core\Http\NullResponse; |
|
38
|
|
|
use TYPO3\CMS\Core\Utility\GeneralUtility; |
|
39
|
|
|
|
|
40
|
|
|
/** |
|
41
|
|
|
* Class PageIndexerInitialization |
|
42
|
|
|
* @package ApacheSolrForTypo3\Solr\Middleware |
|
43
|
|
|
*/ |
|
44
|
|
|
class PageIndexerInitialization implements MiddlewareInterface |
|
45
|
|
|
{ |
|
46
|
|
|
|
|
47
|
|
|
/** |
|
48
|
|
|
* @param ServerRequestInterface $request |
|
49
|
|
|
* @param RequestHandlerInterface $handler |
|
50
|
|
|
* @return ResponseInterface |
|
51
|
|
|
*/ |
|
52
|
|
|
public function process(ServerRequestInterface $request, RequestHandlerInterface $handler): ResponseInterface |
|
53
|
|
|
{ |
|
54
|
|
|
if ($request->hasHeader(PageIndexerRequest::SOLR_INDEX_HEADER)) { |
|
55
|
|
|
// disable TSFE cache for TYPO3 v10 |
|
56
|
|
|
$request = $request->withAttribute('noCache', true); |
|
57
|
|
|
$jsonEncodedParameters = $request->getHeader(PageIndexerRequest::SOLR_INDEX_HEADER)[0]; |
|
58
|
|
|
$pageIndexerRequestHandler = GeneralUtility::makeInstance(PageIndexerRequestHandler::class, $jsonEncodedParameters); |
|
|
|
|
|
|
59
|
|
|
|
|
60
|
|
|
$pageIndexerRequest = $pageIndexerRequestHandler->getRequest(); |
|
61
|
|
|
if (!$pageIndexerRequest->isAuthenticated()) { |
|
62
|
|
|
$logger = GeneralUtility::makeInstance(SolrLogManager::class, self::class); |
|
63
|
|
|
$logger->log( |
|
64
|
|
|
SolrLogManager::ERROR, |
|
65
|
|
|
'Invalid Index Queue Frontend Request detected!', |
|
66
|
|
|
[ |
|
67
|
|
|
'page indexer request' => (array)$pageIndexerRequest, |
|
68
|
|
|
'index queue header' => $jsonEncodedParameters |
|
69
|
|
|
] |
|
70
|
|
|
); |
|
71
|
|
|
return new NullResponse('Invalid Index Queue Request!', 403); |
|
|
|
|
|
|
72
|
|
|
} |
|
73
|
|
|
$pageIndexerRequestHandler->run(); |
|
74
|
|
|
|
|
75
|
|
|
} |
|
76
|
|
|
|
|
77
|
|
|
return $handler->handle($request); |
|
78
|
|
|
} |
|
79
|
|
|
} |
|
80
|
|
|
|