Passed
Push — master ( ed38f6...30aafa )
by Timo
11:15
created

SolrSiteStrategy   A

Complexity

Total Complexity 2

Size/Duplication

Total Lines 20
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
wmc 2
eloc 9
dl 0
loc 20
rs 10
c 0
b 0
f 0

1 Method

Rating   Name   Duplication   Size   Complexity  
A buildPageIndexingUriFromPageItemAndLanguageId() 0 12 2
1
<?php declare(strict_types = 1);
2
3
namespace ApacheSolrForTypo3\Solr\Domain\Index\PageIndexer\Helper\UriBuilder;
4
5
/***************************************************************
6
 *  Copyright notice
7
 *
8
 *  (c) 2019 Timo Hund <[email protected]>
9
 *  All rights reserved
10
 *
11
 *  This script is part of the TYPO3 project. The TYPO3 project is
12
 *  free software; you can redistribute it and/or modify
13
 *  it under the terms of the GNU General Public License as published by
14
 *  the Free Software Foundation; either version 3 of the License, or
15
 *  (at your option) any later version.
16
 *
17
 *  The GNU General Public License can be found at
18
 *  http://www.gnu.org/copyleft/gpl.html.
19
 *  A copy is found in the textfile GPL.txt and important notices to the license
20
 *  from the author is found in LICENSE.txt distributed with these scripts.
21
 *
22
 *
23
 *  This script is distributed in the hope that it will be useful,
24
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
25
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
26
 *  GNU General Public License for more details.
27
 *
28
 *  This copyright notice MUST APPEAR in all copies of the script!
29
 ***************************************************************/
30
31
use ApacheSolrForTypo3\Solr\IndexQueue\Item;
32
33
/**
34
 * This class is used to build the indexing url based on the EXT:solr site.
35
 *
36
 * The EXT:solr site is the TYPO3 site where the domain record is located or an EXT:solr specific domain configuration
37
 * is located. EXT:solr uses this term "site" several years for the entry point.
38
 *
39
 * In TYPO3 9 "site's" have been introduced in TYPO3 and are managed with the "site management" for those sites
40
 * we build the indexing url in a different way since they have the pageId and languageId encoded in the speaking url by the core.
41
 *
42
 * @package ApacheSolrForTypo3\Solr\Domain\Index\PageIndexer\Helper\UriBuilder
43
 */
44
class SolrSiteStrategy extends AbstractUriStrategy
45
{
46
    /**
47
     * @param Item $item
48
     * @param int $language
49
     * @param string $mountPointParameter
50
     * @return string
51
     */
52
    protected function buildPageIndexingUriFromPageItemAndLanguageId(Item $item, int $language = 0, string $mountPointParameter  = '')
53
    {
54
        $scheme = 'http';
55
        $host = $item->getSite()->getDomain();
56
        $path = '/';
57
        $pageId = $item->getRecordUid();
58
59
        $pageIndexUri = $scheme . '://' . $host . $path . 'index.php?id=' . $pageId;
60
        $pageIndexUri .= ($mountPointParameter !== '') ? '&MP=' . $mountPointParameter : '';
61
        $pageIndexUri .= '&L=' . $language;
62
63
        return $pageIndexUri;
64
    }
65
}