Skip to content

Commit 89d9f0d

Browse files
committed
[TASK] fix PhpStan errors for TYPO3 13
1 parent f859f0c commit 89d9f0d

14 files changed

+134
-111
lines changed

Classes/Event/Indexing/AfterPageDocumentIsCreatedForIndexingEvent.php

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,10 @@
2020
use ApacheSolrForTypo3\Solr\IndexQueue\Item;
2121
use ApacheSolrForTypo3\Solr\System\Configuration\TypoScriptConfiguration;
2222
use ApacheSolrForTypo3\Solr\System\Solr\Document\Document;
23+
use Psr\Http\Message\ServerRequestInterface;
2324
use TYPO3\CMS\Core\Site\Entity\Site;
2425
use TYPO3\CMS\Core\Site\Entity\SiteLanguage;
26+
use TYPO3\CMS\Frontend\ContentObject\Exception\ContentRenderingException;
2527
use TYPO3\CMS\Frontend\Controller\TypoScriptFrontendController;
2628

2729
/**
@@ -39,7 +41,7 @@ public function __construct(
3941
private readonly Item $indexQueueItem,
4042
private readonly array $record,
4143
private readonly TypoScriptFrontendController $tsfe,
42-
private readonly TypoScriptConfiguration $configuration
44+
private readonly TypoScriptConfiguration $configuration,
4345
) {}
4446

4547
public function getDocument(): Document
@@ -62,14 +64,20 @@ public function getIndexingConfigurationName(): string
6264
return $this->indexQueueItem->getIndexingConfigurationName();
6365
}
6466

67+
/**
68+
* @throws ContentRenderingException
69+
*/
6570
public function getSite(): Site
6671
{
67-
return $this->tsfe->getSite();
72+
return clone $this->tsfe->cObj->getRequest()->getAttribute('site');
6873
}
6974

75+
/**
76+
* @throws ContentRenderingException
77+
*/
7078
public function getSiteLanguage(): SiteLanguage
7179
{
72-
return $this->tsfe->getLanguage();
80+
return $this->getSite()->getAttribute('language');
7381
}
7482

7583
public function getRecord(): array

Classes/Event/Indexing/BeforeDocumentIsProcessedForIndexingEvent.php

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
use ApacheSolrForTypo3\Solr\System\Solr\Document\Document;
2222
use TYPO3\CMS\Core\Site\Entity\Site;
2323
use TYPO3\CMS\Core\Site\Entity\SiteLanguage;
24+
use TYPO3\CMS\Frontend\ContentObject\Exception\ContentRenderingException;
2425
use TYPO3\CMS\Frontend\Controller\TypoScriptFrontendController;
2526

2627
/**
@@ -45,14 +46,20 @@ public function __construct(
4546
$this->documents[] = $this->document;
4647
}
4748

49+
/**
50+
* @throws ContentRenderingException
51+
*/
4852
public function getSite(): Site
4953
{
50-
return $this->tsfe->getSite();
54+
return clone $this->tsfe->cObj->getRequest()->getAttribute('site');
5155
}
5256

57+
/**
58+
* @throws ContentRenderingException
59+
*/
5360
public function getSiteLanguage(): SiteLanguage
5461
{
55-
return $this->tsfe->getLanguage();
62+
return clone $this->getSite()->getAttribute('language');
5663
}
5764

5865
public function getIndexQueueItem(): Item

Classes/Event/Indexing/BeforeDocumentsAreIndexedEvent.php

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
use ApacheSolrForTypo3\Solr\System\Solr\Document\Document;
2222
use TYPO3\CMS\Core\Site\Entity\Site;
2323
use TYPO3\CMS\Core\Site\Entity\SiteLanguage;
24+
use TYPO3\CMS\Frontend\ContentObject\Exception\ContentRenderingException;
2425
use TYPO3\CMS\Frontend\Controller\TypoScriptFrontendController;
2526

2627
/**
@@ -39,14 +40,20 @@ public function __construct(
3940
private readonly TypoScriptFrontendController $tsfe,
4041
) {}
4142

43+
/**
44+
* @throws ContentRenderingException
45+
*/
4246
public function getSite(): Site
4347
{
44-
return $this->tsfe->getSite();
48+
return clone $this->tsfe->cObj->getRequest()->getAttribute('site');
4549
}
4650

51+
/**
52+
* @throws ContentRenderingException
53+
*/
4754
public function getSiteLanguage(): SiteLanguage
4855
{
49-
return $this->tsfe->getLanguage();
56+
return clone $this->getSite()->getAttribute('language');
5057
}
5158

5259
public function getIndexQueueItem(): Item

Classes/Event/Indexing/BeforePageDocumentIsProcessedForIndexingEvent.php

Lines changed: 2 additions & 56 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,7 @@
1919

2020
use ApacheSolrForTypo3\Solr\IndexQueue\Item;
2121
use ApacheSolrForTypo3\Solr\System\Solr\Document\Document;
22-
use TYPO3\CMS\Core\Site\Entity\Site;
23-
use TYPO3\CMS\Core\Site\Entity\SiteLanguage;
22+
use Psr\Http\Message\ServerRequestInterface;
2423
use TYPO3\CMS\Frontend\Controller\TypoScriptFrontendController;
2524

2625
/**
@@ -29,59 +28,6 @@
2928
* Previously used with
3029
* $GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['solr']['Indexer']['indexPageAddDocuments']
3130
*/
32-
class BeforePageDocumentIsProcessedForIndexingEvent
31+
class BeforePageDocumentIsProcessedForIndexingEvent extends BeforeDocumentIsProcessedForIndexingEvent
3332
{
34-
/**
35-
* @var Document[]
36-
*/
37-
private array $documents = [];
38-
39-
public function __construct(
40-
private readonly Document $document,
41-
private readonly Item $indexQueueItem,
42-
private readonly TypoScriptFrontendController $tsfe,
43-
) {
44-
$this->documents[] = $this->document;
45-
}
46-
47-
public function getSite(): Site
48-
{
49-
return $this->tsfe->getSite();
50-
}
51-
52-
public function getSiteLanguage(): SiteLanguage
53-
{
54-
return $this->tsfe->getLanguage();
55-
}
56-
57-
public function getIndexQueueItem(): Item
58-
{
59-
return $this->indexQueueItem;
60-
}
61-
62-
public function getDocument(): Document
63-
{
64-
return $this->document;
65-
}
66-
67-
/**
68-
* @param Document[] $documents
69-
*/
70-
public function addDocuments(array $documents): void
71-
{
72-
$this->documents = array_merge($this->documents, $documents);
73-
}
74-
75-
/**
76-
* @return Document[]
77-
*/
78-
public function getDocuments(): array
79-
{
80-
return $this->documents;
81-
}
82-
83-
public function getTsfe(): TypoScriptFrontendController
84-
{
85-
return clone $this->tsfe;
86-
}
8733
}

Classes/IndexQueue/AbstractIndexer.php

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,9 @@
2222
use ApacheSolrForTypo3\Solr\ContentObject\Relation;
2323
use ApacheSolrForTypo3\Solr\FrontendEnvironment\Tsfe;
2424
use ApacheSolrForTypo3\Solr\System\Solr\Document\Document;
25+
use ApacheSolrForTypo3\Solr\System\Util\ArrayAccessor;
2526
use TYPO3\CMS\Core\Core\Environment;
27+
use TYPO3\CMS\Core\TypoScript\FrontendTypoScript;
2628
use TYPO3\CMS\Core\TypoScript\Parser\TypoScriptParser;
2729
use TYPO3\CMS\Core\Utility\GeneralUtility;
2830
use TYPO3\CMS\Core\Utility\MathUtility;
@@ -120,7 +122,7 @@ protected function resolveFieldValue(
120122
array $indexingConfiguration,
121123
string $solrFieldName,
122124
array $data,
123-
TypoScriptFrontendController $tsfe
125+
TypoScriptFrontendController $tsfe,
124126
): mixed {
125127
if (isset($indexingConfiguration[$solrFieldName . '.'])) {
126128
// configuration found => need to resolve a cObj
@@ -156,10 +158,12 @@ protected function resolveFieldValue(
156158
1
157159
));
158160

159-
// @todo: this must be solved differently
160-
$typoScriptParser = GeneralUtility::makeInstance(TypoScriptParser::class);
161+
/** @var ?FrontendTypoScript $frontendTypoScript */
162+
$frontendTypoScript = $tsfe->cObj->getRequest()->getAttribute('frontend.typoscript');
163+
$configurationAccess = new ArrayAccessor($frontendTypoScript?->getSetupArray(), '.', true);
161164
// $name and $conf is loaded with the referenced values.
162-
[$name, $conf] = $typoScriptParser->getVal($referencedTsPath, $GLOBALS['TYPO3_REQUEST']->getAttribute('frontend.typoscript')?->getSetupArray());
165+
$name = $configurationAccess->get($referencedTsPath);
166+
$conf = $configurationAccess->get($referencedTsPath . '.');
163167

164168
// need to change directory to make IMAGE content objects work in BE context
165169
// see http://blog.netzelf.de/lang/de/tipps-und-tricks/tslib_cobj-image-im-backend

Classes/IndexQueue/FrontendHelper/PageIndexer.php

Lines changed: 40 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -21,18 +21,20 @@
2121
use ApacheSolrForTypo3\Solr\Event\Indexing\AfterPageDocumentIsCreatedForIndexingEvent;
2222
use ApacheSolrForTypo3\Solr\Event\Indexing\BeforeDocumentsAreIndexedEvent;
2323
use ApacheSolrForTypo3\Solr\Event\Indexing\BeforePageDocumentIsProcessedForIndexingEvent;
24-
use ApacheSolrForTypo3\Solr\Exception;
24+
use ApacheSolrForTypo3\Solr\Exception as SolrException;
2525
use ApacheSolrForTypo3\Solr\FieldProcessor\Service;
2626
use ApacheSolrForTypo3\Solr\IndexQueue\Item;
2727
use ApacheSolrForTypo3\Solr\IndexQueue\PageIndexerRequest;
2828
use ApacheSolrForTypo3\Solr\IndexQueue\PageIndexerResponse;
2929
use ApacheSolrForTypo3\Solr\IndexQueue\Queue;
30+
use ApacheSolrForTypo3\Solr\NoSolrConnectionFoundException;
3031
use ApacheSolrForTypo3\Solr\System\Configuration\TypoScriptConfiguration;
3132
use ApacheSolrForTypo3\Solr\System\Logging\DebugWriter;
3233
use ApacheSolrForTypo3\Solr\System\Logging\SolrLogManager;
3334
use ApacheSolrForTypo3\Solr\System\Solr\Document\Document;
3435
use ApacheSolrForTypo3\Solr\System\Solr\SolrConnection;
3536
use ApacheSolrForTypo3\Solr\Util;
37+
use Doctrine\DBAL\Exception as DBALException;
3638
use Psr\EventDispatcher\EventDispatcherInterface;
3739
use Psr\Http\Message\ServerRequestInterface;
3840
use Psr\Log\LogLevel;
@@ -200,9 +202,16 @@ public function __invoke(AfterCacheableContentIsGeneratedEvent $event): void
200202

201203
/**
202204
* Index item
205+
*
206+
* @throws DBALException
207+
* @throws SolrException
208+
* @throws Throwable
203209
*/
204-
protected function index(Item $indexQueueItem, ServerRequestInterface $request, TypoScriptFrontendController $tsfe): void
205-
{
210+
protected function index(
211+
Item $indexQueueItem,
212+
ServerRequestInterface $request,
213+
TypoScriptFrontendController $tsfe,
214+
): void {
206215
/** @var PageArguments $pageArguments */
207216
$pageArguments = $request->getAttribute('routing');
208217
$pageInformation = $request->getAttribute('frontend.page.information');
@@ -218,7 +227,12 @@ protected function index(Item $indexQueueItem, ServerRequestInterface $request,
218227
$this->getAccessRootline(),
219228
$pageInformation->getMountPoint()
220229
);
221-
$document = $this->substitutePageDocument($document, $pageInformation->getPageRecord(), $indexQueueItem, $tsfe);
230+
$document = $this->substitutePageDocument(
231+
$document,
232+
$pageInformation->getPageRecord(),
233+
$indexQueueItem,
234+
$tsfe,
235+
);
222236

223237
$this->responseData['pageIndexed'] = (int)$this->indexPage($document, $indexQueueItem, $tsfe);
224238
$this->responseData['originalPageDocument'] = (array)$document;
@@ -236,14 +250,19 @@ protected function index(Item $indexQueueItem, ServerRequestInterface $request,
236250
/**
237251
* Gets the solr connection to use for indexing the page based on the
238252
* Index Queue item's properties.
253+
*
254+
* @throws DBALException
255+
* @throws NoSolrConnectionFoundException
256+
* @throws SolrException
257+
* @throws Throwable
239258
*/
240259
protected function getSolrConnection(Item $indexQueueItem, SiteLanguage $siteLanguage, bool $logExceptions): SolrConnection
241260
{
242261
$connectionManager = GeneralUtility::makeInstance(ConnectionManager::class);
243262
try {
244263
$solrConnection = $connectionManager->getConnectionByRootPageId($indexQueueItem->getRootPageUid(), $siteLanguage->getLanguageId());
245264
if (!$solrConnection->getWriteService()->ping()) {
246-
throw new Exception(
265+
throw new SolrException(
247266
'Could not connect to Solr server.',
248267
1323946472
249268
);
@@ -269,9 +288,12 @@ protected function getSolrConnection(Item $indexQueueItem, SiteLanguage $siteLan
269288

270289
/**
271290
* This method retrieves the item from the index queue, that is indexed in this request.
291+
*
292+
* @throws DBALException
272293
*/
273294
protected function getIndexQueueItem(): ?Item
274295
{
296+
/** @var Queue $indexQueue */
275297
$indexQueue = GeneralUtility::makeInstance(Queue::class);
276298
return $indexQueue->getItem($this->request->getParameter('item'));
277299
}
@@ -289,7 +311,13 @@ protected function substitutePageDocument(
289311
Item $indexQueueItem,
290312
TypoScriptFrontendController $tsfe,
291313
): Document {
292-
$event = new AfterPageDocumentIsCreatedForIndexingEvent($pageDocument, $indexQueueItem, $pageRecord, $tsfe, $this->configuration);
314+
$event = new AfterPageDocumentIsCreatedForIndexingEvent(
315+
$pageDocument,
316+
$indexQueueItem,
317+
$pageRecord,
318+
$tsfe,
319+
$this->configuration,
320+
);
293321
$event = $this->getEventDispatcher()->dispatch($event);
294322
return $event->getDocument();
295323
}
@@ -309,6 +337,9 @@ protected function getPageDocument(TypoScriptFrontendController $tsfe, PageInfor
309337
* Indexes a page.
310338
*
311339
* @return bool TRUE after successfully indexing the page, FALSE on error
340+
*
341+
* @throws DBALException
342+
* @throws SolrException
312343
*/
313344
protected function indexPage(
314345
Document $pageDocument,
@@ -336,6 +367,9 @@ protected function indexPage(
336367
* care of manipulating fields as defined in the field's configuration.
337368
*
338369
* @param Document[] $documents An array of documents to manipulate
370+
*
371+
* @throws SolrException
372+
* @throws DBALException
339373
*/
340374
protected function processDocuments(array $documents): void
341375
{

Classes/IndexQueue/PageIndexerRequest.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -366,11 +366,11 @@ protected function getUrl(string $url, array $headers, float $timeout): Response
366366
'options' => $options,
367367
]
368368
);
369-
} finally {
369+
} /* @todo: fix that properly or remove */ /*finally {
370370
if (isset($originalBackendUser)) {
371371
$GLOBALS['BE_USER'] = $originalBackendUser;
372372
}
373-
}
373+
}*/
374374
$response->getBody()->rewind();
375375
return $response;
376376
}

Classes/Middleware/SolrRoutingMiddleware.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -301,7 +301,7 @@ protected function retrievePageInformation(UriInterface $uri, Site $site): array
301301
sprintf(
302302
$message,
303303
$path,
304-
$this->language->getTwoLetterIsoCode(),
304+
$this->language->getLocale()->getLanguageCode(),
305305
$uri->getPath()
306306
)
307307
);

Classes/Report/SolrConfigurationStatus.php

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -149,18 +149,15 @@ protected function getRootPagesWithIndexingOff(): array
149149
if ($solrIsEnabledAndIndexingDisabled) {
150150
$rootPagesWithIndexingOff[] = $rootPage;
151151
}
152-
/** @phpstan-ignore-next-line */
153152
} catch (RuntimeException) {
154153
$rootPagesWithIndexingOff[] = $rootPage;
155-
/** @phpstan-ignore-next-line */
156-
} catch (ServiceUnavailableException $sue) {
154+
} /** @noinspection PhpRedundantCatchClauseInspection */ catch (ServiceUnavailableException $sue) {
157155
if ($sue->getCode() == 1294587218) {
158156
// No TypoScript template found, continue with next site
159157
$rootPagesWithIndexingOff[] = $rootPage;
160158
continue;
161159
}
162-
/** @phpstan-ignore-next-line */
163-
} catch (SiteNotFoundException $sue) {
160+
} /** @noinspection PhpRedundantCatchClauseInspection */ catch (SiteNotFoundException $sue) {
164161
if ($sue->getCode() == 1521716622) {
165162
// No site found, continue with next site
166163
$rootPagesWithIndexingOff[] = $rootPage;
@@ -188,8 +185,6 @@ protected function getRootPages(): array
188185

189186
/**
190187
* Checks if the solr plugin is enabled with plugin.tx_solr.enabled.
191-
*
192-
* @throws DBALException
193188
*/
194189
protected function getIsSolrEnabled(int $pageUid): bool
195190
{
@@ -198,8 +193,6 @@ protected function getIsSolrEnabled(int $pageUid): bool
198193

199194
/**
200195
* Checks if the indexing is enabled with config.index_enable
201-
*
202-
* @throws DBALException
203196
*/
204197
protected function getIsIndexingEnabled(int $pageUid): bool
205198
{

0 commit comments

Comments
 (0)