2021-04-17 00:26:33 +02:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace WapplerSystems\Meilisearch\Domain\Site;
|
|
|
|
|
|
|
|
/***************************************************************
|
|
|
|
* Copyright notice
|
|
|
|
*
|
|
|
|
* (c) 2019 Frans Saris <frans.saris@beech.it> & Timo Hund <timo.hund@dkd.de>
|
|
|
|
* All rights reserved
|
|
|
|
*
|
|
|
|
* This script is part of the TYPO3 project. The TYPO3 project is
|
|
|
|
* free software; you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
* the Free Software Foundation; either version 3 of the License, or
|
|
|
|
* (at your option) any later version.
|
|
|
|
*
|
|
|
|
* The GNU General Public License can be found at
|
|
|
|
* http://www.gnu.org/copyleft/gpl.html.
|
|
|
|
*
|
|
|
|
* This script is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* This copyright notice MUST APPEAR in all copies of the script!
|
|
|
|
***************************************************************/
|
|
|
|
|
2021-04-17 21:20:54 +02:00
|
|
|
use WapplerSystems\Meilisearch\NoMeilisearchConnectionFoundException;
|
2021-04-17 00:26:33 +02:00
|
|
|
use WapplerSystems\Meilisearch\System\Configuration\TypoScriptConfiguration;
|
|
|
|
use WapplerSystems\Meilisearch\System\Records\Pages\PagesRepository;
|
|
|
|
use TYPO3\CMS\Core\Context\LanguageAspectFactory;
|
|
|
|
use TYPO3\CMS\Core\Utility\GeneralUtility;
|
|
|
|
use TYPO3\CMS\Core\Site\Entity\Site as Typo3Site;
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Class Typo3ManagedSite
|
|
|
|
*/
|
|
|
|
class Typo3ManagedSite extends Site
|
|
|
|
{
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @var Typo3Site
|
|
|
|
*/
|
|
|
|
protected $typo3SiteObject;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @var array
|
|
|
|
*/
|
2021-04-17 21:20:54 +02:00
|
|
|
protected $meilisearchConnectionConfigurations;
|
2021-04-17 00:26:33 +02:00
|
|
|
|
|
|
|
|
|
|
|
public function __construct(
|
|
|
|
TypoScriptConfiguration $configuration,
|
2021-04-17 21:20:54 +02:00
|
|
|
array $page, $domain, $siteHash, PagesRepository $pagesRepository = null, $defaultLanguageId = 0, $availableLanguageIds = [], array $meilisearchConnectionConfigurations = [], Typo3Site $typo3SiteObject = null)
|
2021-04-17 00:26:33 +02:00
|
|
|
{
|
|
|
|
$this->configuration = $configuration;
|
|
|
|
$this->rootPage = $page;
|
|
|
|
$this->domain = $domain;
|
|
|
|
$this->siteHash = $siteHash;
|
|
|
|
$this->pagesRepository = $pagesRepository ?? GeneralUtility::makeInstance(PagesRepository::class);
|
|
|
|
$this->defaultLanguageId = $defaultLanguageId;
|
|
|
|
$this->availableLanguageIds = $availableLanguageIds;
|
2021-04-17 21:20:54 +02:00
|
|
|
$this->meilisearchConnectionConfigurations = $meilisearchConnectionConfigurations;
|
2021-04-17 00:26:33 +02:00
|
|
|
$this->typo3SiteObject = $typo3SiteObject;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @param int $language
|
|
|
|
* @return array
|
2021-04-17 21:20:54 +02:00
|
|
|
* @throws NoMeilisearchConnectionFoundException
|
2021-04-17 00:26:33 +02:00
|
|
|
*/
|
2021-04-17 21:20:54 +02:00
|
|
|
public function getMeilisearchConnectionConfiguration(int $language = 0): array
|
2021-04-17 00:26:33 +02:00
|
|
|
{
|
2021-04-17 21:20:54 +02:00
|
|
|
if (!is_array($this->meilisearchConnectionConfigurations[$language])) {
|
|
|
|
/* @var $noMeilisearchConnectionException NoMeilisearchConnectionFoundException */
|
|
|
|
$noMeilisearchConnectionException = GeneralUtility::makeInstance(
|
|
|
|
NoMeilisearchConnectionFoundException::class,
|
|
|
|
/** @scrutinizer ignore-type */ 'Could not find a Meilisearch connection for root page [' . $this->getRootPageId() . '] and language [' . $language . '].',
|
2021-04-17 00:26:33 +02:00
|
|
|
/** @scrutinizer ignore-type */ 1552491117
|
|
|
|
);
|
2021-04-17 21:20:54 +02:00
|
|
|
$noMeilisearchConnectionException->setRootPageId($this->getRootPageId());
|
|
|
|
$noMeilisearchConnectionException->setLanguageId($language);
|
2021-04-17 00:26:33 +02:00
|
|
|
|
2021-04-17 21:20:54 +02:00
|
|
|
throw $noMeilisearchConnectionException;
|
2021-04-17 00:26:33 +02:00
|
|
|
}
|
|
|
|
|
2021-04-17 21:20:54 +02:00
|
|
|
return $this->meilisearchConnectionConfigurations[$language];
|
2021-04-17 00:26:33 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Returns \TYPO3\CMS\Core\Site\Entity\Site
|
|
|
|
*
|
|
|
|
* @return Typo3Site
|
|
|
|
*/
|
|
|
|
public function getTypo3SiteObject(): Typo3Site
|
|
|
|
{
|
|
|
|
return $this->typo3SiteObject;
|
|
|
|
}
|
|
|
|
}
|