first commit
This commit is contained in:
114
Classes/System/Configuration/ConfigurationManager.php
Normal file
114
Classes/System/Configuration/ConfigurationManager.php
Normal file
@@ -0,0 +1,114 @@
|
||||
<?php
|
||||
namespace WapplerSystems\Meilisearch\System\Configuration;
|
||||
|
||||
/***************************************************************
|
||||
* Copyright notice
|
||||
*
|
||||
* (c) 2010-2016 Timo Schmidt <timo.schmidt@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!
|
||||
***************************************************************/
|
||||
|
||||
use TYPO3\CMS\Core\SingletonInterface;
|
||||
use TYPO3\CMS\Core\Utility\GeneralUtility;
|
||||
|
||||
/**
|
||||
* Configuration manager old the configuration instance.
|
||||
* Singleton
|
||||
*
|
||||
* @author Timo Schmidt <timo.schmidt@dkd.de>
|
||||
*/
|
||||
class ConfigurationManager implements SingletonInterface
|
||||
{
|
||||
/**
|
||||
* TypoScript Configurations
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $typoScriptConfigurations = [];
|
||||
|
||||
/**
|
||||
* Resets the state of the configuration manager.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function reset()
|
||||
{
|
||||
$this->typoScriptConfigurations = [];
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieves the TypoScriptConfiguration object from an configuration array, pageId, languageId and TypoScript
|
||||
* path that is used in in the current context.
|
||||
*
|
||||
* @param array $configurationArray
|
||||
* @param int $contextPageId
|
||||
* @param int $contextLanguageId
|
||||
* @param string $contextTypoScriptPath
|
||||
* @return TypoScriptConfiguration
|
||||
*/
|
||||
public function getTypoScriptConfiguration(array $configurationArray = null, $contextPageId = null, $contextLanguageId = 0, $contextTypoScriptPath = '')
|
||||
{
|
||||
if ($configurationArray == null) {
|
||||
if (isset($this->typoScriptConfigurations['default'])) {
|
||||
$configurationArray = $this->typoScriptConfigurations['default'];
|
||||
} else {
|
||||
if (!empty($GLOBALS['TSFE']->tmpl->setup) && is_array($GLOBALS['TSFE']->tmpl->setup)) {
|
||||
$configurationArray = $GLOBALS['TSFE']->tmpl->setup;
|
||||
$this->typoScriptConfigurations['default'] = $configurationArray;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (!is_array($configurationArray)) {
|
||||
$configurationArray = [];
|
||||
}
|
||||
|
||||
if (!isset($configurationArray['plugin.']['tx_meilisearch.'])) {
|
||||
$configurationArray['plugin.']['tx_meilisearch.'] = [];
|
||||
}
|
||||
|
||||
if ($contextPageId === null && !empty($GLOBALS['TSFE']->id)) {
|
||||
$contextPageId = $GLOBALS['TSFE']->id;
|
||||
}
|
||||
|
||||
$hash = md5(serialize($configurationArray)) . '-' . $contextPageId . '-' . $contextLanguageId . '-' . $contextTypoScriptPath;
|
||||
if (isset($this->typoScriptConfigurations[$hash])) {
|
||||
return $this->typoScriptConfigurations[$hash];
|
||||
}
|
||||
|
||||
$this->typoScriptConfigurations[$hash] = $this->getTypoScriptConfigurationInstance($configurationArray, $contextPageId);
|
||||
return $this->typoScriptConfigurations[$hash];
|
||||
}
|
||||
|
||||
/**
|
||||
* This method is used to build the TypoScriptConfiguration.
|
||||
*
|
||||
* @param array $configurationArray
|
||||
* @param int|null $contextPageId
|
||||
* @return object
|
||||
*/
|
||||
protected function getTypoScriptConfigurationInstance(array $configurationArray = null, $contextPageId = null)
|
||||
{
|
||||
return GeneralUtility::makeInstance(
|
||||
TypoScriptConfiguration::class,
|
||||
/** @scrutinizer ignore-type */ $configurationArray,
|
||||
/** @scrutinizer ignore-type */ $contextPageId
|
||||
);
|
||||
}
|
||||
}
|
117
Classes/System/Configuration/ConfigurationPageResolver.php
Normal file
117
Classes/System/Configuration/ConfigurationPageResolver.php
Normal file
@@ -0,0 +1,117 @@
|
||||
<?php
|
||||
namespace WapplerSystems\Meilisearch\System\Configuration;
|
||||
|
||||
/***************************************************************
|
||||
* Copyright notice
|
||||
*
|
||||
* (c) 2010-2016 Timo Schmidt <timo.schmidt@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!
|
||||
***************************************************************/
|
||||
|
||||
use WapplerSystems\Meilisearch\System\Cache\TwoLevelCache;
|
||||
use WapplerSystems\Meilisearch\System\Records\SystemTemplate\SystemTemplateRepository;
|
||||
use TYPO3\CMS\Core\Utility\GeneralUtility;
|
||||
use TYPO3\CMS\Core\Utility\RootlineUtility;
|
||||
use TYPO3\CMS\Frontend\Page\PageRepository;
|
||||
|
||||
/**
|
||||
* This class is responsible to find the closest page id from the rootline where
|
||||
* a typoscript template is stored on.
|
||||
*
|
||||
* @author Timo Hund <timo.hund@dkd.de>
|
||||
*/
|
||||
class ConfigurationPageResolver
|
||||
{
|
||||
|
||||
/**
|
||||
* @var SystemTemplateRepository
|
||||
*/
|
||||
protected $systemTemplateRepository;
|
||||
|
||||
/**
|
||||
* @var TwoLevelCache
|
||||
*/
|
||||
protected $twoLevelCache;
|
||||
|
||||
/**
|
||||
* @var TwoLevelCache
|
||||
*/
|
||||
protected $runtimeCache;
|
||||
|
||||
/**
|
||||
* ConfigurationPageResolver constructor.
|
||||
* @param PageRepository|null $pageRepository
|
||||
* @param TwoLevelCache|null $twoLevelCache
|
||||
* @param SystemTemplateRepository $systemTemplateRepository
|
||||
*/
|
||||
public function __construct(PageRepository $pageRepository = null, TwoLevelCache $twoLevelCache = null, SystemTemplateRepository $systemTemplateRepository = null)
|
||||
{
|
||||
$this->runtimeCache = $twoLevelCache ?? GeneralUtility::makeInstance(TwoLevelCache::class, /** @scrutinizer ignore-type */ 'cache_runtime');
|
||||
$this->systemTemplateRepository = $systemTemplateRepository ?? GeneralUtility::makeInstance(SystemTemplateRepository::class);
|
||||
}
|
||||
|
||||
/**
|
||||
* This method fetches the rootLine and calculates the id of the closest template in the rootLine.
|
||||
* The result is stored in the runtime cache.
|
||||
*
|
||||
* @param integer $startPageId
|
||||
* @return integer
|
||||
*/
|
||||
public function getClosestPageIdWithActiveTemplate($startPageId)
|
||||
{
|
||||
if ($startPageId === 0) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
$cacheId = 'ConfigurationPageResolver' . '_' . 'getClosestPageIdWithActiveTemplate' . '_' . $startPageId;
|
||||
$methodResult = $this->runtimeCache->get($cacheId);
|
||||
if (!empty($methodResult)) {
|
||||
return $methodResult;
|
||||
}
|
||||
|
||||
$methodResult = $this->calculateClosestPageIdWithActiveTemplate($startPageId);
|
||||
$this->runtimeCache->set($cacheId, $methodResult);
|
||||
|
||||
return $methodResult;
|
||||
}
|
||||
|
||||
/**
|
||||
* This method fetches the rootLine and calculates the id of the closest template in the rootLine.
|
||||
*
|
||||
* @param integer $startPageId
|
||||
* @return int
|
||||
*/
|
||||
protected function calculateClosestPageIdWithActiveTemplate($startPageId)
|
||||
{
|
||||
|
||||
$rootlineUtility = GeneralUtility::makeInstance(RootlineUtility::class, $startPageId);
|
||||
try {
|
||||
$rootline = $rootlineUtility->get();
|
||||
} catch (\RuntimeException $e) {
|
||||
return $startPageId;
|
||||
}
|
||||
|
||||
$closestPageIdWithTemplate = $this->systemTemplateRepository->findOneClosestPageIdWithActiveTemplateByRootLine($rootline);
|
||||
if ($closestPageIdWithTemplate === 0) {
|
||||
return $startPageId;
|
||||
}
|
||||
|
||||
return (int)$closestPageIdWithTemplate;
|
||||
}
|
||||
}
|
130
Classes/System/Configuration/ExtensionConfiguration.php
Normal file
130
Classes/System/Configuration/ExtensionConfiguration.php
Normal file
@@ -0,0 +1,130 @@
|
||||
<?php
|
||||
namespace WapplerSystems\Meilisearch\System\Configuration;
|
||||
|
||||
/***************************************************************
|
||||
* Copyright notice
|
||||
*
|
||||
* (c) 2017- Timo Schmidt <timo.schmidt@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!
|
||||
***************************************************************/
|
||||
|
||||
use TYPO3\CMS\Core\Utility\GeneralUtility;
|
||||
|
||||
/**
|
||||
* This class encapsulates the access to the extension configuration.
|
||||
*
|
||||
* @author Timo Hund <timo.hund@dkd.de>
|
||||
*/
|
||||
class ExtensionConfiguration
|
||||
{
|
||||
/**
|
||||
* Extension Configuration
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $configuration = [];
|
||||
|
||||
/**
|
||||
* ExtensionConfiguration constructor.
|
||||
* @param array $configurationToUse
|
||||
*/
|
||||
public function __construct($configurationToUse = [])
|
||||
{
|
||||
if (empty($configurationToUse)) {
|
||||
$this->configuration = GeneralUtility::makeInstance(\TYPO3\CMS\Core\Configuration\ExtensionConfiguration::class)->get('meilisearch');
|
||||
} else {
|
||||
$this->configuration = $configurationToUse;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Get configuration for useConfigurationFromClosestTemplate
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function getIsUseConfigurationFromClosestTemplateEnabled()
|
||||
{
|
||||
return (bool)$this->getConfigurationOrDefaultValue('useConfigurationFromClosestTemplate', false);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get configuration for useConfigurationTrackRecordsOutsideSiteroot
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function getIsUseConfigurationTrackRecordsOutsideSiteroot()
|
||||
{
|
||||
return (bool)$this->getConfigurationOrDefaultValue('useConfigurationTrackRecordsOutsideSiteroot', true);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get configuration for allowSelfSignedCertificates
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function getIsSelfSignedCertificatesEnabled()
|
||||
{
|
||||
return (bool)$this->getConfigurationOrDefaultValue('allowSelfSignedCertificates', false);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get configuration for useConfigurationMonitorTables
|
||||
*
|
||||
* @return array of tableName
|
||||
*/
|
||||
public function getIsUseConfigurationMonitorTables()
|
||||
{
|
||||
$monitorTables = [];
|
||||
$monitorTablesList = $this->getConfigurationOrDefaultValue('useConfigurationMonitorTables', '');
|
||||
|
||||
if (empty($monitorTablesList)) {
|
||||
return $monitorTables;
|
||||
}
|
||||
|
||||
return GeneralUtility::trimExplode(',', $monitorTablesList);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get configuration for allowLegacySiteMode
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function getIsAllowLegacySiteModeEnabled(): bool
|
||||
{
|
||||
trigger_error('solr:deprecation: Method getIsAllowLegacySiteModeEnabled is deprecated since EXT:meilisearch 11 and will be removed in 12. Since EXT:meilisearch 10 legacy site handling is deprecated and was removed in EXT:meilisearch 11.', E_USER_DEPRECATED);
|
||||
|
||||
//@todo throw exception if set to true and log deprecation
|
||||
$legacyModeIsActive = $this->getConfigurationOrDefaultValue('allowLegacySiteMode', false);
|
||||
if($legacyModeIsActive === true) {
|
||||
throw new \InvalidArgumentException("Legacy mode is not supported anymore, please migrate your system to use sitehandling now!");
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $key
|
||||
* @param mixed $defaultValue
|
||||
* @return mixed
|
||||
*/
|
||||
protected function getConfigurationOrDefaultValue($key, $defaultValue)
|
||||
{
|
||||
return isset($this->configuration[$key]) ? $this->configuration[$key] : $defaultValue;
|
||||
}
|
||||
}
|
2251
Classes/System/Configuration/TypoScriptConfiguration.php
Normal file
2251
Classes/System/Configuration/TypoScriptConfiguration.php
Normal file
File diff suppressed because it is too large
Load Diff
Reference in New Issue
Block a user