2016-12-09 13:19:35 +01:00
|
|
|
<?php
|
2017-07-06 23:48:47 +02:00
|
|
|
namespace Codappix\SearchCore\Domain\Index;
|
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-13 12:51:36 +02:00
|
|
|
use Codappix\SearchCore\Configuration\ConfigurationContainerInterface;
|
2017-07-06 23:48:47 +02:00
|
|
|
use Codappix\SearchCore\Connection\ConnectionInterface;
|
2017-07-07 14:44:32 +02:00
|
|
|
use TYPO3\CMS\Core\Database\ConnectionPool;
|
2017-07-07 16:44:57 +02:00
|
|
|
use TYPO3\CMS\Core\Database\Query\QueryBuilder;
|
2017-07-07 14:44:32 +02:00
|
|
|
use TYPO3\CMS\Core\Utility\GeneralUtility;
|
2016-12-09 13:19:35 +01:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Will index the given table using configuration from TCA.
|
|
|
|
*/
|
2017-07-04 12:12:36 +02:00
|
|
|
class TcaIndexer extends AbstractIndexer
|
2016-12-09 13:19:35 +01:00
|
|
|
{
|
|
|
|
/**
|
|
|
|
* @var TcaIndexer\TcaTableService
|
|
|
|
*/
|
|
|
|
protected $tcaTableService;
|
|
|
|
|
|
|
|
/**
|
2016-12-09 14:07:38 +01:00
|
|
|
* @param TcaIndexer\TcaTableService $tcaTableService
|
2016-12-09 13:19:35 +01:00
|
|
|
* @param ConnectionInterface $connection
|
2017-07-13 12:51:36 +02:00
|
|
|
* @param ConfigurationContainerInterface $configuration
|
2016-12-09 13:19:35 +01:00
|
|
|
*/
|
|
|
|
public function __construct(
|
|
|
|
TcaIndexer\TcaTableService $tcaTableService,
|
2017-07-13 12:51:36 +02:00
|
|
|
ConnectionInterface $connection,
|
|
|
|
ConfigurationContainerInterface $configuration
|
2016-12-09 13:19:35 +01:00
|
|
|
) {
|
|
|
|
$this->tcaTableService = $tcaTableService;
|
|
|
|
$this->connection = $connection;
|
2017-07-13 12:51:36 +02:00
|
|
|
$this->configuration = $configuration;
|
2016-12-09 13:19:35 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @param int $offset
|
|
|
|
* @param int $limit
|
2016-12-13 10:38:49 +01:00
|
|
|
* @return array|null
|
2016-12-09 13:19:35 +01:00
|
|
|
*/
|
|
|
|
protected function getRecords($offset, $limit)
|
|
|
|
{
|
2017-07-07 16:44:57 +02:00
|
|
|
$records = $this->getQuery()
|
2017-07-07 14:44:32 +02:00
|
|
|
->setFirstResult($offset)
|
2017-07-07 16:44:57 +02:00
|
|
|
->setMaxResults($limit)
|
|
|
|
->execute()
|
|
|
|
->fetchAll();
|
2017-07-07 14:44:32 +02:00
|
|
|
|
2017-01-26 14:57:23 +01:00
|
|
|
if ($records === null) {
|
|
|
|
return null;
|
|
|
|
}
|
2016-12-09 13:19:35 +01:00
|
|
|
|
2017-01-26 14:57:23 +01:00
|
|
|
$this->tcaTableService->filterRecordsByRootLineBlacklist($records);
|
2016-12-09 13:19:35 +01:00
|
|
|
foreach ($records as &$record) {
|
|
|
|
$this->tcaTableService->prepareRecord($record);
|
|
|
|
}
|
|
|
|
|
|
|
|
return $records;
|
|
|
|
}
|
2016-12-12 13:33:07 +01:00
|
|
|
|
|
|
|
/**
|
|
|
|
* @param int $identifier
|
|
|
|
* @return array
|
2017-01-12 14:26:09 +01:00
|
|
|
* @throws NoRecordFoundException If record could not be found.
|
2016-12-12 13:33:07 +01:00
|
|
|
*/
|
|
|
|
protected function getRecord($identifier)
|
|
|
|
{
|
2017-08-21 12:10:34 +02:00
|
|
|
$query = $this->getQuery();
|
|
|
|
$query = $query->andWhere($this->tcaTableService->getTableName() . '.uid = ' . (int) $identifier);
|
|
|
|
$record = $query->execute()->fetch();
|
|
|
|
|
2017-05-11 09:16:24 +02:00
|
|
|
if ($record === false || $record === null) {
|
2017-01-12 14:26:09 +01:00
|
|
|
throw new NoRecordFoundException(
|
|
|
|
'Record could not be fetched from database: "' . $identifier . '". Perhaps record is not active.',
|
|
|
|
1484225364
|
|
|
|
);
|
|
|
|
}
|
2016-12-12 13:33:07 +01:00
|
|
|
$this->tcaTableService->prepareRecord($record);
|
|
|
|
|
|
|
|
return $record;
|
|
|
|
}
|
2017-07-04 10:12:47 +02:00
|
|
|
|
2017-07-04 12:12:36 +02:00
|
|
|
/**
|
|
|
|
* @return string
|
|
|
|
*/
|
|
|
|
protected function getDocumentName()
|
|
|
|
{
|
|
|
|
return $this->tcaTableService->getTableName();
|
|
|
|
}
|
2017-07-07 11:58:15 +02:00
|
|
|
|
2017-08-04 13:01:33 +02:00
|
|
|
protected function getQuery($tcaTableService = null) : QueryBuilder
|
2017-07-07 16:44:57 +02:00
|
|
|
{
|
2017-08-04 13:01:33 +02:00
|
|
|
if ($tcaTableService === null) {
|
|
|
|
$tcaTableService = $this->tcaTableService;
|
|
|
|
}
|
|
|
|
$queryBuilder = $this->getDatabaseConnection()->getQueryBuilderForTable($tcaTableService->getTableName());
|
|
|
|
$where = $tcaTableService->getWhereClause();
|
|
|
|
$query = $queryBuilder->select(... $tcaTableService->getFields())
|
|
|
|
->from($tcaTableService->getTableClause())
|
2017-07-07 16:44:57 +02:00
|
|
|
->where($where->getStatement())
|
|
|
|
->setParameters($where->getParameters());
|
|
|
|
|
2017-08-04 13:01:33 +02:00
|
|
|
foreach ($tcaTableService->getJoins() as $join) {
|
2017-07-07 16:44:57 +02:00
|
|
|
$query->from($join->getTable());
|
|
|
|
$query->andWhere($join->getCondition());
|
|
|
|
}
|
|
|
|
|
|
|
|
return $query;
|
|
|
|
}
|
|
|
|
|
2017-07-04 10:12:47 +02:00
|
|
|
protected function getDatabaseConnection()
|
|
|
|
{
|
2017-07-07 14:44:32 +02:00
|
|
|
return GeneralUtility::makeInstance(ConnectionPool::class);
|
2017-07-04 10:12:47 +02:00
|
|
|
}
|
2016-12-09 13:19:35 +01:00
|
|
|
}
|