first commit

This commit is contained in:
Sven Wappler
2021-04-17 00:26:33 +02:00
commit 866c63cc63
813 changed files with 100696 additions and 0 deletions

View File

@@ -0,0 +1,159 @@
<?php declare(strict_types = 1);
namespace WapplerSystems\Meilisearch\Domain\Index\PageIndexer\Helper\UriBuilder;
/***************************************************************
* Copyright notice
*
* (c) 2019 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.
* A copy is found in the textfile GPL.txt and important notices to the license
* from the author is found in LICENSE.txt distributed with these scripts.
*
*
* 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!
***************************************************************/
use WapplerSystems\Meilisearch\IndexQueue\Item;
use WapplerSystems\Meilisearch\IndexQueue\PageIndexerDataUrlModifier;
use WapplerSystems\Meilisearch\System\Logging\SolrLogManager;
use WapplerSystems\Meilisearch\System\Url\UrlHelper;
use TYPO3\CMS\Core\Utility\GeneralUtility;
/**
* Implementations of this class are able to build an indexing url for solr page indexing.
*/
abstract class AbstractUriStrategy
{
/**
* @var SolrLogManager|null|object
*/
protected $logger;
/**
* AbstractUriStrategy constructor.
* @param SolrLogManager|null $logger
*/
public function __construct(SolrLogManager $logger = null)
{
$this->logger = $logger ?? GeneralUtility::makeInstance(SolrLogManager::class, /** @scrutinizer ignore-type */ __CLASS__);
}
/**
* @param UrlHelper $urlHelper
* @param array $overrideConfiguration
* @return UrlHelper
*/
protected function applyTypoScriptOverridesOnIndexingUrl(UrlHelper $urlHelper, array $overrideConfiguration = []): UrlHelper
{
// check whether we should use ssl / https
if (!empty($overrideConfiguration['scheme'])) {
$urlHelper->setScheme($overrideConfiguration['scheme']);
}
// overwriting the host
if (!empty($overrideConfiguration['host'])) {
$urlHelper->setHost($overrideConfiguration['host']);
}
// overwriting the port
if (!empty($overrideConfiguration['port'])) {
$urlHelper->setPort($overrideConfiguration['port']);
}
// setting a path if TYPO3 is installed in a sub directory
if (!empty($overrideConfiguration['path'])) {
$urlHelper->setPath($overrideConfiguration['path']);
}
return $urlHelper;
}
/**
* @param Item $item
* @param int $language
* @param string $mountPointParameter
* @param array $options
* @return string
*/
public function getPageIndexingUriFromPageItemAndLanguageId(Item $item, int $language = 0, string $mountPointParameter = '', $options = []): string
{
$pageIndexUri = $this->buildPageIndexingUriFromPageItemAndLanguageId($item, $language, $mountPointParameter);
$urlHelper = GeneralUtility::makeInstance(UrlHelper::class, $pageIndexUri);
$overrideConfiguration = is_array($options['frontendDataHelper.']) ? $options['frontendDataHelper.'] : [];
$urlHelper = $this->applyTypoScriptOverridesOnIndexingUrl($urlHelper, $overrideConfiguration);
$dataUrl = $urlHelper->getUrl();
if (!GeneralUtility::isValidUrl($dataUrl)) {
$this->logger->log(
SolrLogManager::ERROR,
'Could not create a valid URL to get frontend data while trying to index a page.',
[
'item' => (array)$item,
'constructed URL' => $dataUrl,
'scheme' => $urlHelper->getScheme(),
'host' => $urlHelper->getHost(),
'path' => $urlHelper->getPath(),
'page ID' => $item->getRecordUid(),
'indexer options' => $options
]
);
throw new \RuntimeException(
'Could not create a valid URL to get frontend data while trying to index a page. Created URL: ' . $dataUrl,
1311080805
);
}
return $this->applyDataUrlModifier($item, $language, $dataUrl, $urlHelper);
}
/**
* @param Item $item
* @param int $language
* @param string $mountPointParameter
* @return mixed
*/
abstract protected function buildPageIndexingUriFromPageItemAndLanguageId(Item $item, int $language = 0, string $mountPointParameter = '');
/**
* @param Item $item
* @param int $language
* @param string $dataUrl
* @param UrlHelper $urlHelper
* @return string
*/
protected function applyDataUrlModifier(Item $item, int $language, $dataUrl, UrlHelper $urlHelper):string
{
if (empty($GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['solr']['IndexQueuePageIndexer']['dataUrlModifier'])) {
return $dataUrl;
}
$dataUrlModifier = GeneralUtility::makeInstance($GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['solr']['IndexQueuePageIndexer']['dataUrlModifier']);
if (!$dataUrlModifier instanceof PageIndexerDataUrlModifier) {
throw new \RuntimeException($GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['solr']['IndexQueuePageIndexer']['dataUrlModifier'] . ' is not an implementation of WapplerSystems\Meilisearch\IndexQueue\PageIndexerDataUrlModifier', 1290523345);
}
return $dataUrlModifier->modifyDataUrl($dataUrl,
[
'item' => $item, 'scheme' => $urlHelper->getScheme(), 'host' => $urlHelper->getHost(),
'path' => $urlHelper->getPath(), 'pageId' => $item->getRecordUid(), 'language' => $language
]
);
}
}

View File

@@ -0,0 +1,85 @@
<?php declare(strict_types = 1);
namespace WapplerSystems\Meilisearch\Domain\Index\PageIndexer\Helper\UriBuilder;
/***************************************************************
* Copyright notice
*
* (c) 2019 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.
* A copy is found in the textfile GPL.txt and important notices to the license
* from the author is found in LICENSE.txt distributed with these scripts.
*
*
* 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!
***************************************************************/
use WapplerSystems\Meilisearch\IndexQueue\Item;
use WapplerSystems\Meilisearch\System\Logging\SolrLogManager;
use TYPO3\CMS\Core\Exception\SiteNotFoundException;
use TYPO3\CMS\Core\Routing\InvalidRouteArgumentsException;
use TYPO3\CMS\Core\Site\SiteFinder;
use TYPO3\CMS\Core\Utility\GeneralUtility;
/**
* This class is used to build the indexing url for a TYPO3 site that is managed with the TYPO3 site management.
*
* These sites have the pageId and language information encoded in the speaking url.
*/
class TYPO3SiteStrategy extends AbstractUriStrategy
{
/**
* @var SiteFinder
*/
protected $siteFinder = null;
/**
* TYPO3SiteStrategy constructor.
* @param SolrLogManager|null $logger
* @param SiteFinder|null $siteFinder
*/
public function __construct(SolrLogManager $logger = null, SiteFinder $siteFinder = null)
{
parent::__construct($logger);
$this->siteFinder = $siteFinder ?? GeneralUtility::makeInstance(SiteFinder::class);
}
/**
* @param Item $item
* @param int $language
* @param string $mountPointParameter
* @return string
* @throws SiteNotFoundException
* @throws InvalidRouteArgumentsException
*/
protected function buildPageIndexingUriFromPageItemAndLanguageId(Item $item, int $language = 0, string $mountPointParameter = '')
{
$site = $this->siteFinder->getSiteByPageId((int)$item->getRecordUid());
$parameters = [];
if ($language > 0) {
$parameters['_language'] = $language;
};
if ($mountPointParameter !== '') {
$parameters['MP'] = $mountPointParameter;
}
$pageIndexUri = (string)$site->getRouter()->generateUri($item->getRecord(), $parameters);
return $pageIndexUri;
}
}

View File

@@ -0,0 +1,61 @@
<?php declare(strict_types = 1);
namespace WapplerSystems\Meilisearch\Domain\Index\PageIndexer\Helper;
/***************************************************************
* Copyright notice
*
* (c) 2019 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.
* A copy is found in the textfile GPL.txt and important notices to the license
* from the author is found in LICENSE.txt distributed with these scripts.
*
*
* 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!
***************************************************************/
use WapplerSystems\Meilisearch\Domain\Index\PageIndexer\Helper\UriBuilder\AbstractUriStrategy;
use WapplerSystems\Meilisearch\Domain\Index\PageIndexer\Helper\UriBuilder\TYPO3SiteStrategy;
use WapplerSystems\Meilisearch\System\Util\SiteUtility;
use TYPO3\CMS\Core\Utility\GeneralUtility;
/**
* This class is responsible to retrieve an "UriStrategy" the can build uri's for the site where the
* passed page belongs to.
*
* This can be:
* * A TYPO3 site managed with site management
* * A TYPO3 site without site management where the url is build by EXT:meilisearch with L and id param and information from the domain
* record or solr specific configuration.
*/
class UriStrategyFactory
{
/**
* @param integer $pageId
* @oaram array $overrideConfiguration
* @return AbstractUriStrategy
* @throws \Exception
*/
public function getForPageId(int $pageId): AbstractUriStrategy
{
if (!SiteUtility::getIsSiteManagedSite($pageId)) {
throw new \Exception('Site of page with uid ' . $pageId . ' is not a TYPO3 managed site');
}
return GeneralUtility::makeInstance(TYPO3SiteStrategy::class);
}
}