Failed Conditions
Push — release-11.5.x ( 71e6eb...3bfdb1 )
by Markus
27:37
created

TYPO3SiteStrategy   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 44
Duplicated Lines 0 %

Test Coverage

Coverage 0%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 4
eloc 11
dl 0
loc 44
ccs 0
cts 11
cp 0
rs 10
c 1
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 6 1
A buildPageIndexingUriFromPageItemAndLanguageId() 0 17 3
1
<?php
2
3
declare(strict_types=1);
4
5
/*
6
 * This file is part of the TYPO3 CMS project.
7
 *
8
 * It is free software; you can redistribute it and/or modify it under
9
 * the terms of the GNU General Public License, either version 2
10
 * of the License, or any later version.
11
 *
12
 * For the full copyright and license information, please read the
13
 * LICENSE.txt file that was distributed with this source code.
14
 *
15
 * The TYPO3 project - inspiring people to share!
16
 */
17
18
namespace ApacheSolrForTypo3\Solr\Domain\Index\PageIndexer\Helper\UriBuilder;
19
20
use ApacheSolrForTypo3\Solr\IndexQueue\Item;
21
use ApacheSolrForTypo3\Solr\System\Logging\SolrLogManager;
22
use TYPO3\CMS\Core\Exception\SiteNotFoundException;
23
use TYPO3\CMS\Core\Site\SiteFinder;
24
use TYPO3\CMS\Core\Utility\GeneralUtility;
25
26
/**
27
 * This class is used to build the indexing url for a TYPO3 site that is managed with the TYPO3 site management.
28
 *
29
 * These sites have the pageId and language information encoded in the speaking url.
30
 */
31
class TYPO3SiteStrategy extends AbstractUriStrategy
32
{
33
    /**
34
     * @var SiteFinder
35
     */
36
    protected SiteFinder $siteFinder;
37
38
    /**
39
     * TYPO3SiteStrategy constructor.
40
     * @param SolrLogManager|null $logger
41
     * @param SiteFinder|null $siteFinder
42
     */
43
    public function __construct(
44
        SolrLogManager $logger = null,
45
        SiteFinder $siteFinder = null
46
    ) {
47
        parent::__construct($logger);
48
        $this->siteFinder = $siteFinder ?? GeneralUtility::makeInstance(SiteFinder::class);
49
    }
50
51
    /**
52
     * @param Item $item
53
     * @param int $language
54
     * @param string $mountPointParameter
55
     * @return string
56
     * @throws SiteNotFoundException
57
     */
58
    protected function buildPageIndexingUriFromPageItemAndLanguageId(
59
        Item $item,
60
        int $language = 0,
61
        string $mountPointParameter = ''
62
    ): string {
63
        $site = $this->siteFinder->getSiteByPageId((int)$item->getRecordUid());
64
        $parameters = [];
65
66
        if ($language > 0) {
67
            $parameters['_language'] = $language;
68
        }
69
70
        if ($mountPointParameter !== '') {
71
            $parameters['MP'] = $mountPointParameter;
72
        }
73
74
        return (string)$site->getRouter()->generateUri($item->getRecord(), $parameters);
75
    }
76
}
77