first commit

This commit is contained in:
Sven Wappler
2021-04-17 21:20:54 +02:00
parent c93ec9492a
commit cadcc8edb4
406 changed files with 4917 additions and 5157 deletions

View File

@@ -26,7 +26,7 @@ namespace WapplerSystems\Meilisearch\IndexQueue\FrontendHelper;
use WapplerSystems\Meilisearch\IndexQueue\PageIndexerRequest;
use WapplerSystems\Meilisearch\IndexQueue\PageIndexerResponse;
use WapplerSystems\Meilisearch\System\Logging\SolrLogManager;
use WapplerSystems\Meilisearch\System\Logging\MeilisearchLogManager;
use TYPO3\CMS\Core\Utility\GeneralUtility;
use TYPO3\CMS\Frontend\Controller\TypoScriptFrontendController;
@@ -59,7 +59,7 @@ abstract class AbstractFrontendHelper implements FrontendHelper
protected $action = null;
/**
* @var SolrLogManager
* @var MeilisearchLogManager
*/
protected $logger = null;
@@ -99,11 +99,11 @@ abstract class AbstractFrontendHelper implements FrontendHelper
) {
$this->request = $request;
$this->response = $response;
$this->logger = GeneralUtility::makeInstance(SolrLogManager::class, /** @scrutinizer ignore-type */ __CLASS__);
$this->logger = GeneralUtility::makeInstance(MeilisearchLogManager::class, /** @scrutinizer ignore-type */ __CLASS__);
if ($request->getParameter('loggingEnabled')) {
$this->logger->log(
SolrLogManager::INFO,
MeilisearchLogManager::INFO,
'Page indexer request received',
[
'request' => (array)$request,

View File

@@ -45,7 +45,7 @@ class AuthorizationService extends AbstractAuthenticationService
*
* @var string
*/
const SOLR_INDEXER_USERNAME = '__SolrIndexerUser__';
const SOLR_INDEXER_USERNAME = '__MeilisearchIndexerUser__';
/**
* Gets a fake frontend user record to allow access to protected pages.
@@ -115,7 +115,7 @@ class AuthorizationService extends AbstractAuthenticationService
$groupData[] = [
'uid' => $groupId,
'pid' => 0,
'title' => '__SolrIndexerGroup__',
'title' => '__MeilisearchIndexerGroup__',
'TSconfig' => ''
];
}

View File

@@ -29,7 +29,7 @@ use WapplerSystems\Meilisearch\IndexQueue\AbstractIndexer;
use WapplerSystems\Meilisearch\IndexQueue\InvalidFieldNameException;
use WapplerSystems\Meilisearch\SubstitutePageIndexer;
use WapplerSystems\Meilisearch\System\Configuration\TypoScriptConfiguration;
use WapplerSystems\Meilisearch\System\Solr\Document\Document;
use WapplerSystems\Meilisearch\System\Meilisearch\Document\Document;
use WapplerSystems\Meilisearch\Util;
use TYPO3\CMS\Core\Utility\GeneralUtility;
use TYPO3\CMS\Frontend\ContentObject\ContentObjectRenderer;
@@ -57,7 +57,7 @@ class PageFieldMappingIndexer implements SubstitutePageIndexer
*/
public function __construct(TypoScriptConfiguration $configuration = null)
{
$this->configuration = $configuration == null ? Util::getSolrConfiguration() : $configuration;
$this->configuration = $configuration == null ? Util::getMeilisearchConfiguration() : $configuration;
}
/**
@@ -75,7 +75,7 @@ class PageFieldMappingIndexer implements SubstitutePageIndexer
* plugin.tx_meilisearch.index.queue.pages.fields.
*
* @param Document $pageDocument The original page document.
* @return Document A Apache Solr Document object that replace the default page document
* @return Document A Meilisearch Document object that replace the default page document
*/
public function getPageDocument(Document $pageDocument)
{
@@ -131,16 +131,16 @@ class PageFieldMappingIndexer implements SubstitutePageIndexer
* Allows to put the page record through cObj processing if wanted / needed.
* Otherwise the plain page record field value is used.
*
* @param string $solrFieldName The Solr field name to resolve the value from the item's record
* @param string $meilisearchFieldName The Meilisearch field name to resolve the value from the item's record
* @return string The resolved string value to be indexed
*/
protected function resolveFieldValue($solrFieldName, Document $pageDocument)
protected function resolveFieldValue($meilisearchFieldName, Document $pageDocument)
{
$pageRecord = $GLOBALS['TSFE']->page;
$pageIndexingConfiguration = $this->configuration->getIndexQueueFieldsConfigurationByConfigurationName($this->pageIndexingConfigurationName);
if (isset($pageIndexingConfiguration[$solrFieldName . '.'])) {
if (isset($pageIndexingConfiguration[$meilisearchFieldName . '.'])) {
$pageRecord = AbstractIndexer::addVirtualContentFieldToRecord($pageDocument, $pageRecord);
// configuration found => need to resolve a cObj
@@ -148,15 +148,15 @@ class PageFieldMappingIndexer implements SubstitutePageIndexer
$contentObject->start($pageRecord, 'pages');
$fieldValue = $contentObject->cObjGetSingle(
$pageIndexingConfiguration[$solrFieldName],
$pageIndexingConfiguration[$solrFieldName . '.']
$pageIndexingConfiguration[$meilisearchFieldName],
$pageIndexingConfiguration[$meilisearchFieldName . '.']
);
if (AbstractIndexer::isSerializedValue($pageIndexingConfiguration, $solrFieldName)) {
if (AbstractIndexer::isSerializedValue($pageIndexingConfiguration, $meilisearchFieldName)) {
$fieldValue = unserialize($fieldValue);
}
} else {
$fieldValue = $pageRecord[$pageIndexingConfiguration[$solrFieldName]];
$fieldValue = $pageRecord[$pageIndexingConfiguration[$meilisearchFieldName]];
}
return $fieldValue;

View File

@@ -29,9 +29,9 @@ use WapplerSystems\Meilisearch\Access\Rootline;
use WapplerSystems\Meilisearch\ConnectionManager;
use WapplerSystems\Meilisearch\IndexQueue\Item;
use WapplerSystems\Meilisearch\IndexQueue\Queue;
use WapplerSystems\Meilisearch\NoSolrConnectionFoundException;
use WapplerSystems\Meilisearch\System\Logging\SolrLogManager;
use WapplerSystems\Meilisearch\System\Solr\SolrConnection;
use WapplerSystems\Meilisearch\NoMeilisearchConnectionFoundException;
use WapplerSystems\Meilisearch\System\Logging\MeilisearchLogManager;
use WapplerSystems\Meilisearch\System\Meilisearch\MeilisearchConnection;
use WapplerSystems\Meilisearch\Typo3PageIndexer;
use WapplerSystems\Meilisearch\Util;
use Exception;
@@ -91,7 +91,7 @@ class PageIndexer extends AbstractFrontendHelper implements SingletonInterface
$GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['tslib/class.tslib_fe.php']['pageIndexing'][__CLASS__] = $pageIndexingHookRegistration;
// indexes fields defined in plugin.tx_meilisearch.index.queue.pages.fields
$GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['solr']['Indexer']['indexPageSubstitutePageDocument'][PageFieldMappingIndexer::class] = PageFieldMappingIndexer::class;
$GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['meilisearch']['Indexer']['indexPageSubstitutePageDocument'][PageFieldMappingIndexer::class] = PageFieldMappingIndexer::class;
$this->registerAuthorizationService();
}
@@ -170,13 +170,13 @@ class PageIndexer extends AbstractFrontendHelper implements SingletonInterface
$overrulingPriority = $this->getHighestAuthenticationServicePriority() + 1;
ExtensionManagementUtility::addService(
'solr', // extension key
'meilisearch', // extension key
'auth', // service type
AuthorizationService::class,
// service key
[// service meta data
'title' => 'Solr Indexer Authorization',
'description' => 'Authorizes the Solr Index Queue indexer to access protected pages.',
'title' => 'Meilisearch Indexer Authorization',
'description' => 'Authorizes the Meilisearch Index Queue indexer to access protected pages.',
'subtype' => 'getUserFE,authUserFE,getGroupsFE',
@@ -187,7 +187,7 @@ class PageIndexer extends AbstractFrontendHelper implements SingletonInterface
'os' => '',
'exec' => '',
'classFile' => ExtensionManagementUtility::extPath('solr') . 'Classes/IndexQueue/FrontendHelper/AuthorizationService.php',
'classFile' => ExtensionManagementUtility::extPath('meilisearch') . 'Classes/IndexQueue/FrontendHelper/AuthorizationService.php',
'className' => AuthorizationService::class,
]
);
@@ -263,16 +263,16 @@ class PageIndexer extends AbstractFrontendHelper implements SingletonInterface
*/
public function hook_indexContent(TypoScriptFrontendController $page)
{
$this->logger = GeneralUtility::makeInstance(SolrLogManager::class, /** @scrutinizer ignore-type */ __CLASS__);
$this->logger = GeneralUtility::makeInstance(MeilisearchLogManager::class, /** @scrutinizer ignore-type */ __CLASS__);
$this->page = $page;
$configuration = Util::getSolrConfiguration();
$configuration = Util::getMeilisearchConfiguration();
$logPageIndexed = $configuration->getLoggingIndexingPageIndexed();
if (!$this->page->config['config']['index_enable']) {
if ($logPageIndexed) {
$this->logger->log(
SolrLogManager::ERROR,
MeilisearchLogManager::ERROR,
'Indexing is disabled. Set config.index_enable = 1 .'
);
}
@@ -285,32 +285,32 @@ class PageIndexer extends AbstractFrontendHelper implements SingletonInterface
throw new UnexpectedValueException('Can not get index queue item', 1482162337);
}
$solrConnection = $this->getSolrConnection($indexQueueItem);
$meilisearchConnection = $this->getMeilisearchConnection($indexQueueItem);
/** @var $indexer Typo3PageIndexer */
$indexer = GeneralUtility::makeInstance(Typo3PageIndexer::class, /** @scrutinizer ignore-type */ $page);
$indexer->setSolrConnection($solrConnection);
$indexer->setMeilisearchConnection($meilisearchConnection);
$indexer->setPageAccessRootline($this->getAccessRootline());
$indexer->setPageUrl($this->generatePageUrl());
$indexer->setMountPointParameter($GLOBALS['TSFE']->MP);
$indexer->setIndexQueueItem($indexQueueItem);
$this->responseData['pageIndexed'] = (int)$indexer->indexPage();
$this->responseData['originalPageDocument'] = (array)$indexer->getPageSolrDocument();
$this->responseData['solrConnection'] = [
$this->responseData['originalPageDocument'] = (array)$indexer->getPageMeilisearchDocument();
$this->responseData['meilisearchConnection'] = [
'rootPage' => $indexQueueItem->getRootPageUid(),
'sys_language_uid' => Util::getLanguageUid(),
'solr' => (string)$solrConnection->getNode('write')
'meilisearch' => (string)$meilisearchConnection->getNode('write')
];
$documentsSentToSolr = $indexer->getDocumentsSentToSolr();
foreach ($documentsSentToSolr as $document) {
$this->responseData['documentsSentToSolr'][] = (array)$document;
$documentsSentToMeilisearch = $indexer->getDocumentsSentToMeilisearch();
foreach ($documentsSentToMeilisearch as $document) {
$this->responseData['documentsSentToMeilisearch'][] = (array)$document;
}
} catch (Exception $e) {
if ($configuration->getLoggingExceptions()) {
$this->logger->log(
SolrLogManager::ERROR,
MeilisearchLogManager::ERROR,
'Exception while trying to index page ' . $page->id,
[
$e->__toString()
@@ -321,7 +321,7 @@ class PageIndexer extends AbstractFrontendHelper implements SingletonInterface
if ($logPageIndexed) {
$success = $this->responseData['pageIndexed'] ? 'Success' : 'Failed';
$severity = $this->responseData['pageIndexed'] ? SolrLogManager::NOTICE : SolrLogManager::ERROR;
$severity = $this->responseData['pageIndexed'] ? MeilisearchLogManager::NOTICE : MeilisearchLogManager::ERROR;
$this->logger->log(
$severity,
@@ -332,14 +332,14 @@ class PageIndexer extends AbstractFrontendHelper implements SingletonInterface
}
/**
* Gets the solr connection to use for indexing the page based on the
* Gets the meilisearch connection to use for indexing the page based on the
* Index Queue item's properties.
*
* @param Item $indexQueueItem
* @return SolrConnection Solr server connection
* @throws NoSolrConnectionFoundException
* @return MeilisearchConnection Meilisearch server connection
* @throws NoMeilisearchConnectionFoundException
*/
protected function getSolrConnection(Item $indexQueueItem)
protected function getMeilisearchConnection(Item $indexQueueItem)
{
/** @var $connectionManager ConnectionManager */
$connectionManager = GeneralUtility::makeInstance(ConnectionManager::class);

View File

@@ -24,7 +24,7 @@ namespace WapplerSystems\Meilisearch\IndexQueue\FrontendHelper;
* This copyright notice MUST APPEAR in all copies of the script!
***************************************************************/
use WapplerSystems\Meilisearch\System\Logging\SolrLogManager;
use WapplerSystems\Meilisearch\System\Logging\MeilisearchLogManager;
use TYPO3\CMS\Core\SingletonInterface;
use TYPO3\CMS\Core\Utility\GeneralUtility;
use TYPO3\CMS\Frontend\ContentObject\ContentObjectPostInitHookInterface;
@@ -66,7 +66,7 @@ class UserGroupDetector extends AbstractFrontendHelper implements
protected $frontendGroups = [];
/**
* @var \WapplerSystems\Meilisearch\System\Logging\SolrLogManager
* @var \WapplerSystems\Meilisearch\System\Logging\MeilisearchLogManager
*/
protected $logger = null;
@@ -202,7 +202,7 @@ class UserGroupDetector extends AbstractFrontendHelper implements
} else {
if ($this->request->getParameter('loggingEnabled')) {
$this->logger->log(
SolrLogManager::INFO,
MeilisearchLogManager::INFO,
'Access restriction found',
[
'groups' => $frontendGroups,