dkd-kaehm /
ext-solr
| 1 | <?php |
||
| 2 | |||
| 3 | namespace ApacheSolrForTypo3\Solr\Domain\Site; |
||
| 4 | |||
| 5 | /*************************************************************** |
||
| 6 | * Copyright notice |
||
| 7 | * |
||
| 8 | * (c) 2011-2015 Ingo Renner <[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 | * |
||
| 20 | * This script is distributed in the hope that it will be useful, |
||
| 21 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
||
| 22 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
||
| 23 | * GNU General Public License for more details. |
||
| 24 | * |
||
| 25 | * This copyright notice MUST APPEAR in all copies of the script! |
||
| 26 | ***************************************************************/ |
||
| 27 | |||
| 28 | use ApacheSolrForTypo3\Solr\Domain\Index\Queue\RecordMonitor\Helper\ConfigurationAwareRecordService; |
||
| 29 | use ApacheSolrForTypo3\Solr\NoSolrConnectionFoundException; |
||
| 30 | use ApacheSolrForTypo3\Solr\System\Configuration\TypoScriptConfiguration; |
||
| 31 | use ApacheSolrForTypo3\Solr\System\Records\Pages\PagesRepository; |
||
| 32 | use TYPO3\CMS\Backend\Utility\BackendUtility; |
||
| 33 | use TYPO3\CMS\Core\Utility\GeneralUtility; |
||
| 34 | |||
| 35 | /** |
||
| 36 | * Base Clas for Typo3ManagedSite and LegacySite |
||
| 37 | */ |
||
| 38 | abstract class Site implements SiteInterface |
||
| 39 | { |
||
| 40 | /** |
||
| 41 | * @var TypoScriptConfiguration |
||
| 42 | */ |
||
| 43 | protected $configuration; |
||
| 44 | |||
| 45 | /** |
||
| 46 | * Root page record. |
||
| 47 | * |
||
| 48 | * @var array |
||
| 49 | */ |
||
| 50 | protected $rootPage = []; |
||
| 51 | /** |
||
| 52 | * @var string |
||
| 53 | */ |
||
| 54 | protected $domain; |
||
| 55 | |||
| 56 | /** |
||
| 57 | * @var string |
||
| 58 | */ |
||
| 59 | protected $siteHash; |
||
| 60 | |||
| 61 | /** |
||
| 62 | * @var PagesRepository |
||
| 63 | */ |
||
| 64 | protected $pagesRepository; |
||
| 65 | |||
| 66 | /** |
||
| 67 | * @var int |
||
| 68 | */ |
||
| 69 | protected $defaultLanguageId = 0; |
||
| 70 | |||
| 71 | /** |
||
| 72 | * @var int[] Available language ids |
||
| 73 | */ |
||
| 74 | protected $availableLanguageIds = []; |
||
| 75 | |||
| 76 | /** |
||
| 77 | * Takes an pagerecord and checks whether the page is marked as root page. |
||
| 78 | * |
||
| 79 | * @param array $page pagerecord |
||
| 80 | * @return bool true if the page is marked as root page, false otherwise |
||
| 81 | * @todo: move to SiteUtility? |
||
| 82 | */ |
||
| 83 | public static function isRootPage($page) |
||
| 84 | { |
||
| 85 | if ($page['is_siteroot']) { |
||
| 86 | return true; |
||
| 87 | } |
||
| 88 | |||
| 89 | return false; |
||
| 90 | } |
||
| 91 | |||
| 92 | /** |
||
| 93 | * Gets the site's root page ID (uid). |
||
| 94 | * |
||
| 95 | * @return int The site's root page ID. |
||
| 96 | */ |
||
| 97 | public function getRootPageId() |
||
| 98 | { |
||
| 99 | return (int)$this->rootPage['uid']; |
||
| 100 | } |
||
| 101 | |||
| 102 | /** |
||
| 103 | * Gets available language id's for this site |
||
| 104 | * |
||
| 105 | * @return int[] array or language id's |
||
| 106 | */ |
||
| 107 | public function getAvailableLanguageIds(): array { |
||
| 108 | return $this->availableLanguageIds; |
||
| 109 | } |
||
| 110 | |||
| 111 | /** |
||
| 112 | * Gets the site's label. The label is build from the the site title and root |
||
| 113 | * page ID (uid). |
||
| 114 | * |
||
| 115 | * @return string The site's label. |
||
| 116 | */ |
||
| 117 | public function getLabel() |
||
| 118 | { |
||
| 119 | $rootlineTitles = []; |
||
| 120 | $rootLine = BackendUtility::BEgetRootLine($this->rootPage['uid']); |
||
| 121 | // Remove last |
||
| 122 | array_pop($rootLine); |
||
| 123 | $rootLine = array_reverse($rootLine); |
||
| 124 | foreach ($rootLine as $rootLineItem) { |
||
| 125 | $rootlineTitles[] = $rootLineItem['title']; |
||
| 126 | } |
||
| 127 | return implode(' - ', $rootlineTitles) . ', Root Page ID: ' . $this->rootPage['uid']; |
||
| 128 | } |
||
| 129 | |||
| 130 | /** |
||
| 131 | * Gets the site's Solr TypoScript configuration (plugin.tx_solr.*) |
||
| 132 | * |
||
| 133 | * @return \ApacheSolrForTypo3\Solr\System\Configuration\TypoScriptConfiguration The Solr TypoScript configuration |
||
| 134 | */ |
||
| 135 | public function getSolrConfiguration() |
||
| 136 | { |
||
| 137 | return $this->configuration; |
||
| 138 | } |
||
| 139 | |||
| 140 | /** |
||
| 141 | * Gets the site's default language as configured in |
||
| 142 | * config.sys_language_uid. If sys_language_uid is not set, 0 is assumed to |
||
| 143 | * be the default. |
||
| 144 | * |
||
| 145 | * @return int The site's default language. |
||
| 146 | */ |
||
| 147 | public function getDefaultLanguage() |
||
| 148 | { |
||
| 149 | return $this->defaultLanguageId; |
||
| 150 | } |
||
| 151 | |||
| 152 | /** |
||
| 153 | * Generates a list of page IDs in this site. Attention, this includes |
||
| 154 | * all page types! Deleted pages are not included. |
||
| 155 | * |
||
| 156 | * @param int|string $rootPageId Page ID from where to start collection sub pages |
||
| 157 | * @param int $maxDepth Maximum depth to descend into the site tree |
||
| 158 | * @return array Array of pages (IDs) in this site |
||
| 159 | */ |
||
| 160 | public function getPages($rootPageId = 'SITE_ROOT', $maxDepth = 999) |
||
| 161 | { |
||
| 162 | $pageIds = []; |
||
| 163 | if ($rootPageId === 'SITE_ROOT') { |
||
| 164 | $rootPageId = (int)$this->rootPage['uid']; |
||
| 165 | $pageIds[] = $rootPageId; |
||
| 166 | } |
||
| 167 | |||
| 168 | $configurationAwareRecordService = GeneralUtility::makeInstance(ConfigurationAwareRecordService::class); |
||
| 169 | // Fetch configuration in order to be able to read initialPagesAdditionalWhereClause |
||
| 170 | $solrConfiguration = $this->getSolrConfiguration(); |
||
| 171 | $indexQueueConfigurationName = $configurationAwareRecordService->getIndexingConfigurationName('pages', $this->rootPage['uid'], $solrConfiguration); |
||
| 172 | if ($indexQueueConfigurationName === null) { |
||
| 173 | return $pageIds; |
||
| 174 | } |
||
| 175 | $initialPagesAdditionalWhereClause = $solrConfiguration->getInitialPagesAdditionalWhereClause($indexQueueConfigurationName); |
||
| 176 | return array_merge($pageIds, $this->pagesRepository->findAllSubPageIdsByRootPage($rootPageId, $maxDepth, $initialPagesAdditionalWhereClause)); |
||
|
0 ignored issues
–
show
Bug
introduced
by
Loading history...
|
|||
| 177 | } |
||
| 178 | |||
| 179 | |||
| 180 | /** |
||
| 181 | * Generates the site's unique Site Hash. |
||
| 182 | * |
||
| 183 | * The Site Hash is build from the site's main domain, the system encryption |
||
| 184 | * key, and the extension "tx_solr". These components are concatenated and |
||
| 185 | * sha1-hashed. |
||
| 186 | * |
||
| 187 | * @return string Site Hash. |
||
| 188 | */ |
||
| 189 | public function getSiteHash() |
||
| 190 | { |
||
| 191 | return $this->siteHash; |
||
| 192 | } |
||
| 193 | |||
| 194 | /** |
||
| 195 | * Gets the site's main domain. More specifically the first domain record in |
||
| 196 | * the site tree. |
||
| 197 | * |
||
| 198 | * @return string The site's main domain. |
||
| 199 | */ |
||
| 200 | public function getDomain() |
||
| 201 | { |
||
| 202 | return $this->domain; |
||
| 203 | } |
||
| 204 | |||
| 205 | /** |
||
| 206 | * Gets the site's root page. |
||
| 207 | * |
||
| 208 | * @return array The site's root page. |
||
| 209 | */ |
||
| 210 | public function getRootPage() |
||
| 211 | { |
||
| 212 | return $this->rootPage; |
||
| 213 | } |
||
| 214 | |||
| 215 | /** |
||
| 216 | * Gets the site's root page's title. |
||
| 217 | * |
||
| 218 | * @return string The site's root page's title |
||
| 219 | */ |
||
| 220 | public function getTitle() |
||
| 221 | { |
||
| 222 | return $this->rootPage['title']; |
||
| 223 | } |
||
| 224 | |||
| 225 | /** |
||
| 226 | * Retrieves the rootPageIds as an array from a set of sites. |
||
| 227 | * |
||
| 228 | * @param array $sites |
||
| 229 | * @return array |
||
| 230 | * @todo: move to SiteUtility? |
||
| 231 | */ |
||
| 232 | public static function getRootPageIdsFromSites(array $sites): array |
||
| 233 | { |
||
| 234 | $rootPageIds = []; |
||
| 235 | foreach ($sites as $site) { |
||
| 236 | $rootPageIds[] = (int)$site->getRootPageId(); |
||
| 237 | } |
||
| 238 | |||
| 239 | return $rootPageIds; |
||
| 240 | } |
||
| 241 | |||
| 242 | /** |
||
| 243 | * @return array |
||
| 244 | * @throws NoSolrConnectionFoundException |
||
| 245 | */ |
||
| 246 | public function getAllSolrConnectionConfigurations(): array { |
||
| 247 | $configs = []; |
||
| 248 | foreach ($this->getAvailableLanguageIds() as $languageId) { |
||
| 249 | try { |
||
| 250 | $configs[$languageId] = $this->getSolrConnectionConfiguration($languageId); |
||
| 251 | } catch (NoSolrConnectionFoundException $e) {} |
||
|
0 ignored issues
–
show
Coding Style
Comprehensibility
introduced
by
|
|||
| 252 | } |
||
| 253 | return $configs; |
||
| 254 | } |
||
| 255 | |||
| 256 | /** |
||
| 257 | * @param int $languageId |
||
| 258 | * @return array |
||
| 259 | */ |
||
| 260 | abstract function getSolrConnectionConfiguration(int $language = 0): array; |
||
| 261 | } |
||
| 262 |