2016-12-09 13:19:35 +01:00
|
|
|
<?php
|
2017-07-06 23:48:47 +02:00
|
|
|
namespace Codappix\SearchCore\Domain\Service;
|
2016-12-09 13:19:35 +01:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Copyright (C) 2016 Daniel Siepmann <coding@daniel-siepmann.de>
|
|
|
|
*
|
|
|
|
* This program 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 2
|
|
|
|
* of the License, or (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This program 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.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this program; if not, write to the Free Software
|
|
|
|
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
|
|
|
|
* 02110-1301, USA.
|
|
|
|
*/
|
|
|
|
|
2017-07-06 23:48:47 +02:00
|
|
|
use Codappix\SearchCore\Configuration\ConfigurationContainerInterface;
|
|
|
|
use Codappix\SearchCore\Domain\Index\IndexerFactory;
|
2018-03-06 17:40:49 +01:00
|
|
|
use Codappix\SearchCore\Domain\Index\IndexerInterface;
|
2017-07-06 23:48:47 +02:00
|
|
|
use Codappix\SearchCore\Domain\Index\NoMatchingIndexerException;
|
|
|
|
use Codappix\SearchCore\Domain\Index\TcaIndexer;
|
2016-12-09 13:19:35 +01:00
|
|
|
use TYPO3\CMS\Core\SingletonInterface as Singleton;
|
2016-12-15 14:02:40 +01:00
|
|
|
use TYPO3\CMS\Core\Utility\GeneralUtility;
|
2016-12-09 13:19:35 +01:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Handles all data related things like updates, deletes and inserts.
|
|
|
|
*
|
|
|
|
* This is the place to add mappings of further parts to adjust the data before
|
|
|
|
* sending ot to connection.
|
2016-12-14 19:34:35 +01:00
|
|
|
*
|
2016-12-15 09:24:43 +01:00
|
|
|
* TODO: Probably a candidate for deletion. Currently this class makes use of
|
|
|
|
* extbase DI. We have to resolve this somehow.
|
2016-12-15 14:02:40 +01:00
|
|
|
*
|
|
|
|
* I think we keep it for easier testing and DI.
|
2016-12-09 13:19:35 +01:00
|
|
|
*/
|
|
|
|
class DataHandler implements Singleton
|
|
|
|
{
|
|
|
|
/**
|
2016-12-15 14:02:40 +01:00
|
|
|
* TODO: Only inject on first use?!
|
|
|
|
*
|
2017-07-06 23:48:47 +02:00
|
|
|
* @var \Codappix\SearchCore\Connection\ConnectionInterface
|
2016-12-09 13:19:35 +01:00
|
|
|
* @inject
|
|
|
|
*/
|
|
|
|
protected $connection;
|
|
|
|
|
2016-12-12 13:33:07 +01:00
|
|
|
/**
|
2017-07-04 12:12:36 +02:00
|
|
|
* @var IndexerFactory
|
2016-12-12 13:33:07 +01:00
|
|
|
*/
|
|
|
|
protected $indexerFactory;
|
|
|
|
|
2016-12-15 14:02:40 +01:00
|
|
|
/**
|
|
|
|
* @var ConfigurationContainerInterface
|
|
|
|
*/
|
|
|
|
protected $configuration;
|
|
|
|
|
2016-12-09 13:19:35 +01:00
|
|
|
/**
|
|
|
|
* @var \TYPO3\CMS\Core\Log\Logger
|
|
|
|
*/
|
|
|
|
protected $logger;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Inject log manager to get concrete logger from it.
|
|
|
|
*
|
|
|
|
* @param \TYPO3\CMS\Core\Log\LogManager $logManager
|
|
|
|
*/
|
|
|
|
public function injectLogger(\TYPO3\CMS\Core\Log\LogManager $logManager)
|
|
|
|
{
|
|
|
|
$this->logger = $logManager->getLogger(__CLASS__);
|
|
|
|
}
|
|
|
|
|
2016-12-15 14:02:40 +01:00
|
|
|
/**
|
|
|
|
* @param ConfigurationContainerInterface $configuration
|
2017-07-04 12:12:36 +02:00
|
|
|
* @param IndexerFactory $indexerFactory
|
2016-12-15 14:02:40 +01:00
|
|
|
*/
|
2017-07-04 12:12:36 +02:00
|
|
|
public function __construct(ConfigurationContainerInterface $configuration, IndexerFactory $indexerFactory)
|
2016-12-15 14:02:40 +01:00
|
|
|
{
|
|
|
|
$this->configuration = $configuration;
|
2017-07-04 12:12:36 +02:00
|
|
|
$this->indexerFactory = $indexerFactory;
|
2016-12-15 14:02:40 +01:00
|
|
|
}
|
|
|
|
|
2018-03-06 17:40:49 +01:00
|
|
|
public function update(string $table, array $record)
|
2016-12-09 13:19:35 +01:00
|
|
|
{
|
2016-12-12 13:33:07 +01:00
|
|
|
$this->logger->debug('Record received for update.', [$table, $record]);
|
2017-07-04 12:12:36 +02:00
|
|
|
$this->getIndexer($table)->indexDocument($record['uid']);
|
2016-12-09 13:19:35 +01:00
|
|
|
}
|
|
|
|
|
2018-03-06 17:40:49 +01:00
|
|
|
public function delete(string $table, string $identifier)
|
2016-12-09 13:19:35 +01:00
|
|
|
{
|
2016-12-12 13:33:07 +01:00
|
|
|
$this->logger->debug('Record received for delete.', [$table, $identifier]);
|
2016-12-15 09:17:58 +01:00
|
|
|
$this->connection->deleteDocument($table, $identifier);
|
2016-12-09 13:19:35 +01:00
|
|
|
}
|
2017-07-04 12:12:36 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
* @throws NoMatchingIndexerException
|
|
|
|
*/
|
2018-03-06 17:40:49 +01:00
|
|
|
protected function getIndexer(string $table) : IndexerInterface
|
2017-07-04 12:12:36 +02:00
|
|
|
{
|
|
|
|
return $this->indexerFactory->getIndexer($table);
|
|
|
|
}
|
|
|
|
|
2018-03-06 17:58:19 +01:00
|
|
|
public function supportsTable(string $table) : bool
|
2017-07-04 12:12:36 +02:00
|
|
|
{
|
|
|
|
try {
|
|
|
|
$this->getIndexer($table);
|
|
|
|
return true;
|
|
|
|
} catch (NoMatchingIndexerException $e) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
2016-12-09 13:19:35 +01:00
|
|
|
}
|