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,100 @@
<?php
namespace WapplerSystems\Meilisearch\Task;
/***************************************************************
* Copyright notice
*
* (c) 2017 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!
***************************************************************/
use WapplerSystems\Meilisearch\Domain\Site\SiteRepository;
use WapplerSystems\Meilisearch\Domain\Site\Site;
use WapplerSystems\Meilisearch\System\Logging\SolrLogManager;
use TYPO3\CMS\Core\Utility\GeneralUtility;
use TYPO3\CMS\Scheduler\Task\AbstractTask;
/**
* Abstract scheduler task for solr scheduler tasks, contains the logic to
* retrieve the site, avoids serialization of site, when scheduler task is saved.
*/
abstract class AbstractMeilisearchTask extends AbstractTask {
/**
* The site this task is supposed to initialize the index queue for.
*
* @var Site
*/
protected $site;
/**
* The rootPageId of the site that should be reIndexed
*
* @var integer
*/
protected $rootPageId;
/**
* @return int
*/
public function getRootPageId()
{
return $this->rootPageId;
}
/**
* @param int $rootPageId
*/
public function setRootPageId($rootPageId)
{
$this->rootPageId = $rootPageId;
}
/**
* @return Site
*/
public function getSite()
{
if (!is_null($this->site)) {
return $this->site;
}
try {
/** @var $siteRepository SiteRepository */
$siteRepository = GeneralUtility::makeInstance(SiteRepository::class);
$this->site = $siteRepository->getSiteByRootPageId($this->rootPageId);
} catch (\InvalidArgumentException $e) {
$logger = GeneralUtility::makeInstance(SolrLogManager::class, /** @scrutinizer ignore-type */ __CLASS__);
$logger->log(SolrLogManager::ERROR, 'Scheduler task tried to get invalid site');
}
return $this->site;
}
/**
* @return array
*/
public function __sleep()
{
$properties = get_object_vars($this);
// avoid serialization of the site and logger object
unset($properties['site'], $properties['logger']);
return array_keys($properties);
}
}

View File

@@ -0,0 +1,209 @@
<?php
namespace WapplerSystems\Meilisearch\Task;
/***************************************************************
* Copyright notice
*
* (c) 2009-2015 Ingo Renner <ingo@typo3.org>
* 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\Domain\Index\IndexService;
use WapplerSystems\Meilisearch\Domain\Site\Site;
use WapplerSystems\Meilisearch\System\Environment\CliEnvironment;
use TYPO3\CMS\Core\Core\Environment;
use TYPO3\CMS\Core\Utility\GeneralUtility;
use TYPO3\CMS\Scheduler\ProgressProviderInterface;
/**
* A worker indexing the items in the index queue. Needs to be set up as one
* task per root page.
*
* @author Ingo Renner <ingo@typo3.org>
*/
class IndexQueueWorkerTask extends AbstractMeilisearchTask implements ProgressProviderInterface
{
/**
* @var int
*/
protected $documentsToIndexLimit;
/**
* @var string
*/
protected $forcedWebRoot = '';
/**
* Works through the indexing queue and indexes the queued items into Solr.
*
* @return bool Returns TRUE on success, FALSE if no items were indexed or none were found.
*/
public function execute()
{
$cliEnvironment = null;
// Wrapped the CliEnvironment to avoid defining TYPO3_PATH_WEB since this
// should only be done in the case when running it from outside TYPO3 BE
// @see #921 and #934 on https://github.com/TYPO3-Solr
if (TYPO3_REQUESTTYPE & TYPO3_REQUESTTYPE_CLI) {
$cliEnvironment = GeneralUtility::makeInstance(CliEnvironment::class);
$cliEnvironment->backup();
$cliEnvironment->initialize($this->getWebRoot(), Environment::getPublicPath() . '/');
}
$site = $this->getSite();
$indexService = $this->getInitializedIndexService($site);
$indexService->indexItems($this->documentsToIndexLimit);
if (TYPO3_REQUESTTYPE & TYPO3_REQUESTTYPE_CLI) {
$cliEnvironment->restore();
}
$executionSucceeded = true;
return $executionSucceeded;
}
/**
* In the cli context TYPO3 has chance to determine the webroot.
* Since we need it for the TSFE related things we allow to set it
* in the scheduler task and use the ###PATH_typo3### marker in the
* setting to be able to define relative paths.
*
* @return string
*/
public function getWebRoot()
{
if ($this->forcedWebRoot !== '') {
return $this->replaceWebRootMarkers($this->forcedWebRoot);
}
return Environment::getPublicPath() . '/';
}
/**
* @param string $webRoot
* @return string
*/
protected function replaceWebRootMarkers($webRoot)
{
if (strpos($webRoot, '###PATH_typo3###') !== false) {
$webRoot = str_replace('###PATH_typo3###', Environment::getPublicPath() . '/typo3/', $webRoot);
}
if (strpos($webRoot, '###PATH_site###') !== false) {
$webRoot = str_replace('###PATH_site###', Environment::getPublicPath() . '/', $webRoot);
}
return $webRoot;
}
/**
* Returns some additional information about indexing progress, shown in
* the scheduler's task overview list.
*
* @return string Information to display
*/
public function getAdditionalInformation()
{
$site = $this->getSite();
if (is_null($site)) {
return 'Invalid site configuration for scheduler please re-create the task!';
}
$message = 'Site: ' . $site->getLabel();
/** @var $indexService \WapplerSystems\Meilisearch\Domain\Index\IndexService */
$indexService = $this->getInitializedIndexService($site);
$failedItemsCount = $indexService->getFailCount();
if ($failedItemsCount) {
$message .= ' Failures: ' . $failedItemsCount;
}
$message .= ' / Using webroot: ' . htmlspecialchars($this->getWebRoot());
return $message;
}
/**
* Gets the indexing progress.
*
* @return float Indexing progress as a two decimal precision float. f.e. 44.87
*/
public function getProgress()
{
$site = $this->getSite();
if (is_null($site)) {
return 0.0;
}
/** @var $indexService \WapplerSystems\Meilisearch\Domain\Index\IndexService */
$indexService = $this->getInitializedIndexService($site);
return $indexService->getProgress();
}
/**
* @return mixed
*/
public function getDocumentsToIndexLimit()
{
return $this->documentsToIndexLimit;
}
/**
* @param int $limit
*/
public function setDocumentsToIndexLimit($limit)
{
$this->documentsToIndexLimit = $limit;
}
/**
* @param string $forcedWebRoot
*/
public function setForcedWebRoot($forcedWebRoot)
{
$this->forcedWebRoot = $forcedWebRoot;
}
/**
* @return string
*/
public function getForcedWebRoot()
{
return $this->forcedWebRoot;
}
/**
* Returns the initialize IndexService instance.
*
* @param Site $site
* @return IndexService
* @internal param $Site
*/
protected function getInitializedIndexService(Site $site)
{
$indexService = GeneralUtility::makeInstance(IndexService::class, /** @scrutinizer ignore-type */ $site);
$indexService->setContextTask($this);
return $indexService;
}
}

View File

@@ -0,0 +1,180 @@
<?php
namespace WapplerSystems\Meilisearch\Task;
/***************************************************************
* Copyright notice
*
* (c) 2009-2015 Ingo Renner <ingo@typo3.org>
* 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\Backend\SiteSelectorField;
use WapplerSystems\Meilisearch\Domain\Site\SiteRepository;
use TYPO3\CMS\Core\Utility\GeneralUtility;
use TYPO3\CMS\Scheduler\AdditionalFieldProviderInterface;
use TYPO3\CMS\Scheduler\Controller\SchedulerModuleController;
use TYPO3\CMS\Scheduler\Task\AbstractTask;
use TYPO3\CMS\Scheduler\Task\Enumeration\Action;
/**
* Additional field provider for the index queue worker task
*
* @author Ingo Renner <ingo@typo3.org>
*/
class IndexQueueWorkerTaskAdditionalFieldProvider implements AdditionalFieldProviderInterface
{
/**
* SiteRepository
*
* @var SiteRepository
*/
protected $siteRepository;
public function __construct()
{
$this->siteRepository = GeneralUtility::makeInstance(SiteRepository::class);
}
/**
* Used to define fields to provide the TYPO3 site to index and number of
* items to index per run when adding or editing a task.
*
* @param array $taskInfo reference to the array containing the info used in the add/edit form
* @param AbstractTask $task when editing, reference to the current task object. Null when adding.
* @param SchedulerModuleController $schedulerModule : reference to the calling object (Scheduler's BE module)
* @return array Array containing all the information pertaining to the additional fields
* The array is multidimensional, keyed to the task class name and each field's id
* For each field it provides an associative sub-array with the following:
*/
public function getAdditionalFields(
array &$taskInfo,
$task,
SchedulerModuleController $schedulerModule
) {
/** @var $task IndexQueueWorkerTask */
$additionalFields = [];
$siteSelectorField = GeneralUtility::makeInstance(SiteSelectorField::class);
if (!$this->isTaskInstanceofIndexQueueWorkerTask($task)) {
return $additionalFields;
}
$currentAction = $schedulerModule->getCurrentAction();
if ($currentAction->equals(Action::ADD)) {
$taskInfo['site'] = null;
$taskInfo['documentsToIndexLimit'] = 50;
$taskInfo['forcedWebRoot'] = '';
}
if ($currentAction->equals(Action::EDIT)) {
$taskInfo['site'] = $this->siteRepository->getSiteByRootPageId($task->getRootPageId());
$taskInfo['documentsToIndexLimit'] = $task->getDocumentsToIndexLimit();
$taskInfo['forcedWebRoot'] = $task->getForcedWebRoot();
}
$additionalFields['site'] = [
'code' => $siteSelectorField->getAvailableSitesSelector('tx_scheduler[site]',
$taskInfo['site']),
'label' => 'LLL:EXT:meilisearch/Resources/Private/Language/locallang.xlf:field_site',
'cshKey' => '',
'cshLabel' => ''
];
$additionalFields['documentsToIndexLimit'] = [
'code' => '<input type="number" class="form-control" name="tx_scheduler[documentsToIndexLimit]" value="' . htmlspecialchars($taskInfo['documentsToIndexLimit']) . '" />',
'label' => 'LLL:EXT:meilisearch/Resources/Private/Language/locallang.xlf:indexqueueworker_field_documentsToIndexLimit',
'cshKey' => '',
'cshLabel' => ''
];
$additionalFields['forcedWebRoot'] = [
'code' => '<input type="text" class="form-control" name="tx_scheduler[forcedWebRoot]" value="' . htmlspecialchars($taskInfo['forcedWebRoot']) . '" />',
'label' => 'LLL:EXT:meilisearch/Resources/Private/Language/locallang.xlf:indexqueueworker_field_forcedWebRoot',
'cshKey' => '',
'cshLabel' => ''
];
return $additionalFields;
}
/**
* Checks any additional data that is relevant to this task. If the task
* class is not relevant, the method is expected to return TRUE
*
* @param array $submittedData reference to the array containing the data submitted by the user
* @param SchedulerModuleController $schedulerModule reference to the calling object (Scheduler's BE module)
* @return bool True if validation was ok (or selected class is not relevant), FALSE otherwise
*/
public function validateAdditionalFields(
array &$submittedData,
SchedulerModuleController $schedulerModule
) {
$result = false;
// validate site
$sites = $this->siteRepository->getAvailableSites();
if (array_key_exists($submittedData['site'], $sites)) {
$result = true;
}
// escape limit
$submittedData['documentsToIndexLimit'] = intval($submittedData['documentsToIndexLimit']);
return $result;
}
/**
* Saves any additional input into the current task object if the task
* class matches.
*
* @param array $submittedData array containing the data submitted by the user
* @param AbstractTask $task reference to the current task object
*/
public function saveAdditionalFields(
array $submittedData,
AbstractTask $task
) {
if (!$this->isTaskInstanceofIndexQueueWorkerTask($task)) {
return;
}
$task->setRootPageId($submittedData['site']);
$task->setDocumentsToIndexLimit($submittedData['documentsToIndexLimit']);
$task->setForcedWebRoot($submittedData['forcedWebRoot']);
}
/**
* Check that a task is an instance of IndexQueueWorkerTask
*
* @param AbstractTask $task
* @return boolean
* @throws \LogicException
*/
protected function isTaskInstanceofIndexQueueWorkerTask($task)
{
if ((!is_null($task)) && (!($task instanceof IndexQueueWorkerTask))) {
throw new \LogicException(
'$task must be an instance of IndexQueueWorkerTask, '
.'other instances are not supported.', 1487499814
);
}
return true;
}
}

View File

@@ -0,0 +1,149 @@
<?php
namespace WapplerSystems\Meilisearch\Task;
/***************************************************************
* Copyright notice
*
* (c) 2011-2015 Christoph Moeller <support@network-publishing.de>
* (c) 2012-2015 Ingo Renner <ingo@typo3.org>
*
* 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\ConnectionManager;
use WapplerSystems\Meilisearch\IndexQueue\Queue;
use TYPO3\CMS\Core\Utility\GeneralUtility;
/**
* Scheduler task to empty the indexes of a site and re-initialize the
* Solr Index Queue thus making the indexer re-index the site.
*
* @author Christoph Moeller <support@network-publishing.de>
*/
class ReIndexTask extends AbstractMeilisearchTask
{
/**
* Indexing configurations to re-initialize.
*
* @var array
*/
protected $indexingConfigurationsToReIndex = [];
/**
* Purges/commits all Solr indexes, initializes the Index Queue
* and returns TRUE if the execution was successful
*
* @return bool Returns TRUE on success, FALSE on failure.
*/
public function execute()
{
// clean up
$cleanUpResult = $this->cleanUpIndex();
// initialize for re-indexing
/** @var Queue $indexQueue */
$indexQueue = GeneralUtility::makeInstance(Queue::class);
$indexQueueInitializationResults = $indexQueue->getInitializationService()
->initializeBySiteAndIndexConfigurations($this->getSite(), $this->indexingConfigurationsToReIndex);
return ($cleanUpResult && !in_array(false, $indexQueueInitializationResults));
}
/**
* Removes documents of the selected types from the index.
*
* @return bool TRUE if clean up was successful, FALSE on error
*/
protected function cleanUpIndex()
{
$cleanUpResult = true;
$solrConfiguration = $this->getSite()->getSolrConfiguration();
$solrServers = GeneralUtility::makeInstance(ConnectionManager::class)->getConnectionsBySite($this->getSite());
$typesToCleanUp = [];
$enableCommitsSetting = $solrConfiguration->getEnableCommits();
foreach ($this->indexingConfigurationsToReIndex as $indexingConfigurationName) {
$type = $solrConfiguration->getIndexQueueTableNameOrFallbackToConfigurationName($indexingConfigurationName);
$typesToCleanUp[] = $type;
}
foreach ($solrServers as $solrServer) {
$deleteQuery = 'type:(' . implode(' OR ', $typesToCleanUp) . ')' . ' AND siteHash:' . $this->getSite()->getSiteHash();
$solrServer->getWriteService()->deleteByQuery($deleteQuery);
if (!$enableCommitsSetting) {
# Do not commit
continue;
}
$response = $solrServer->getWriteService()->commit(false, false, false);
if ($response->getHttpStatus() != 200) {
$cleanUpResult = false;
break;
}
}
return $cleanUpResult;
}
/**
* Gets the indexing configurations to re-index.
*
* @return array
*/
public function getIndexingConfigurationsToReIndex()
{
return $this->indexingConfigurationsToReIndex;
}
/**
* Sets the indexing configurations to re-index.
*
* @param array $indexingConfigurationsToReIndex
*/
public function setIndexingConfigurationsToReIndex(array $indexingConfigurationsToReIndex)
{
$this->indexingConfigurationsToReIndex = $indexingConfigurationsToReIndex;
}
/**
* This method is designed to return some additional information about the task,
* that may help to set it apart from other tasks from the same class
* This additional information is used - for example - in the Scheduler's BE module
* This method should be implemented in most task classes
*
* @return string Information to display
*/
public function getAdditionalInformation()
{
$site = $this->getSite();
if (is_null($site)) {
return 'Invalid site configuration for scheduler please re-create the task!';
}
$information = 'Site: ' . $this->getSite()->getLabel();
if (!empty($this->indexingConfigurationsToReIndex)) {
$information .= ', Indexing Configurations: ' . implode(', ',
$this->indexingConfigurationsToReIndex);
}
return $information;
}
}

View File

@@ -0,0 +1,255 @@
<?php
namespace WapplerSystems\Meilisearch\Task;
/***************************************************************
* Copyright notice
*
* (c) 2011-2015 Christoph Moeller <support@network-publishing.de>
* (c) 2012-2015 Ingo Renner <ingo@typo3.org>
*
* 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\Backend\IndexingConfigurationSelectorField;
use WapplerSystems\Meilisearch\Backend\SiteSelectorField;
use WapplerSystems\Meilisearch\Domain\Site\SiteRepository;
use WapplerSystems\Meilisearch\Domain\Site\Site;
use TYPO3\CMS\Core\Page\PageRenderer;
use TYPO3\CMS\Core\Utility\GeneralUtility;
use TYPO3\CMS\Scheduler\AdditionalFieldProviderInterface;
use TYPO3\CMS\Scheduler\Controller\SchedulerModuleController;
use TYPO3\CMS\Scheduler\Task\AbstractTask;
use TYPO3\CMS\Scheduler\Task\Enumeration\Action;
/**
* Adds an additional field to specify the Solr server to initialize the index queue for
*
* @author Christoph Moeller <support@network-publishing.de>
*/
class ReIndexTaskAdditionalFieldProvider implements AdditionalFieldProviderInterface
{
/**
* Task information
*
* @var array
*/
protected $taskInformation;
/**
* Scheduler task
*
* @var AbstractTask|ReIndexTask|NULL
*/
protected $task = null;
/**
* Scheduler Module
*
* @var SchedulerModuleController
*/
protected $schedulerModule;
/**
* Selected site
*
* @var Site
*/
protected $site = null;
/**
* SiteRepository
*
* @var SiteRepository
*/
protected $siteRepository;
/**
* @var PageRenderer
*/
protected $pageRenderer = null;
/**
* ReIndexTaskAdditionalFieldProvider constructor.
*/
public function __construct()
{
$this->siteRepository = GeneralUtility::makeInstance(SiteRepository::class);
}
/**
* @param array $taskInfo
* @param \TYPO3\CMS\Scheduler\Task\AbstractTask|NULL $task
* @param \TYPO3\CMS\Scheduler\Controller\SchedulerModuleController $schedulerModule
*/
protected function initialize(
array $taskInfo = [],
AbstractTask $task = null,
SchedulerModuleController $schedulerModule
) {
/** @var $task ReIndexTask */
$this->taskInformation = $taskInfo;
$this->task = $task;
$this->schedulerModule = $schedulerModule;
$currentAction = $schedulerModule->getCurrentAction();
if ($currentAction->equals(Action::EDIT)) {
$this->site = $this->siteRepository->getSiteByRootPageId($task->getRootPageId());
}
}
/**
* Used to define fields to provide the Solr server address when adding
* or editing a task.
*
* @param array $taskInfo reference to the array containing the info used in the add/edit form
* @param AbstractTask $task when editing, reference to the current task object. Null when adding.
* @param SchedulerModuleController $schedulerModule reference to the calling object (Scheduler's BE module)
* @return array Array containing all the information pertaining to the additional fields
* The array is multidimensional, keyed to the task class name and each field's id
* For each field it provides an associative sub-array with the following:
*/
public function getAdditionalFields(
array &$taskInfo,
$task,
SchedulerModuleController $schedulerModule
) {
$additionalFields = [];
if (!$this->isTaskInstanceofReIndexTask($task)) {
return $additionalFields;
}
$this->initialize($taskInfo, $task, $schedulerModule);
$siteSelectorField = GeneralUtility::makeInstance(SiteSelectorField::class);
$additionalFields['site'] = [
'code' => $siteSelectorField->getAvailableSitesSelector('tx_scheduler[site]',
$this->site),
'label' => 'LLL:EXT:meilisearch/Resources/Private/Language/locallang.xlf:field_site',
'cshKey' => '',
'cshLabel' => ''
];
$additionalFields['indexingConfigurations'] = [
'code' => $this->getIndexingConfigurationSelector(),
'label' => 'Index Queue configurations to re-index',
'cshKey' => '',
'cshLabel' => ''
];
return $additionalFields;
}
protected function getIndexingConfigurationSelector()
{
$selectorMarkup = 'Please select a site first.';
$this->getPageRenderer()->addCssFile('../typo3conf/ext/solr/Resources/Css/Backend/indexingconfigurationselectorfield.css');
if (is_null($this->site)) {
return $selectorMarkup;
}
$selectorField = GeneralUtility::makeInstance(IndexingConfigurationSelectorField::class, /** @scrutinizer ignore-type */ $this->site);
$selectorField->setFormElementName('tx_scheduler[indexingConfigurations]');
$selectorField->setSelectedValues($this->task->getIndexingConfigurationsToReIndex());
$selectorMarkup = $selectorField->render();
return $selectorMarkup;
}
/**
* Checks any additional data that is relevant to this task. If the task
* class is not relevant, the method is expected to return TRUE
*
* @param array $submittedData reference to the array containing the data submitted by the user
* @param SchedulerModuleController $schedulerModule reference to the calling object (Scheduler's BE module)
* @return bool True if validation was ok (or selected class is not relevant), FALSE otherwise
*/
public function validateAdditionalFields(
array &$submittedData,
SchedulerModuleController $schedulerModule
) {
$result = false;
// validate site
$sites = $this->siteRepository->getAvailableSites();
if (array_key_exists($submittedData['site'], $sites)) {
$result = true;
}
return $result;
}
/**
* Saves any additional input into the current task object if the task
* class matches.
*
* @param array $submittedData array containing the data submitted by the user
* @param AbstractTask $task reference to the current task object
*/
public function saveAdditionalFields(
array $submittedData,
AbstractTask $task
) {
/** @var $task ReIndexTask */
if (!$this->isTaskInstanceofReIndexTask($task)) {
return;
}
$task->setRootPageId($submittedData['site']);
$indexingConfigurations = [];
if (!empty($submittedData['indexingConfigurations'])) {
$indexingConfigurations = $submittedData['indexingConfigurations'];
}
$task->setIndexingConfigurationsToReIndex($indexingConfigurations);
}
/**
* @return PageRenderer
*/
protected function getPageRenderer()
{
if (!isset($this->pageRenderer)) {
$this->pageRenderer = GeneralUtility::makeInstance(PageRenderer::class);
}
return $this->pageRenderer;
}
/**
* Check that a task is an instance of ReIndexTask
*
* @param AbstractTask $task
* @return boolean
* @throws \LogicException
*/
protected function isTaskInstanceofReIndexTask($task)
{
if ((!is_null($task)) && (!($task instanceof ReIndexTask))) {
throw new \LogicException(
'$task must be an instance of ReIndexTask, '
. 'other instances are not supported.', 1487500366
);
}
return true;
}
}