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;
|
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
|
|
|
) {
|
2018-03-06 17:40:49 +01:00
|
|
|
parent::__construct($connection, $configuration);
|
2016-12-09 13:19:35 +01:00
|
|
|
$this->tcaTableService = $tcaTableService;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2016-12-13 10:38:49 +01:00
|
|
|
* @return array|null
|
2016-12-09 13:19:35 +01:00
|
|
|
*/
|
2018-03-06 17:40:49 +01:00
|
|
|
protected function getRecords(int $offset, int $limit)
|
2016-12-09 13:19:35 +01:00
|
|
|
{
|
|
|
|
$records = $GLOBALS['TYPO3_DB']->exec_SELECTgetRows(
|
|
|
|
$this->tcaTableService->getFields(),
|
2016-12-13 10:38:49 +01:00
|
|
|
$this->tcaTableService->getTableClause(),
|
2016-12-09 13:19:35 +01:00
|
|
|
$this->tcaTableService->getWhereClause(),
|
|
|
|
'',
|
|
|
|
'',
|
|
|
|
(int) $offset . ',' . (int) $limit
|
|
|
|
);
|
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
|
|
|
|
|
|
|
/**
|
2017-01-12 14:26:09 +01:00
|
|
|
* @throws NoRecordFoundException If record could not be found.
|
2016-12-12 13:33:07 +01:00
|
|
|
*/
|
2018-03-06 17:40:49 +01:00
|
|
|
protected function getRecord(int $identifier) : array
|
2016-12-12 13:33:07 +01:00
|
|
|
{
|
|
|
|
$record = $GLOBALS['TYPO3_DB']->exec_SELECTgetSingleRow(
|
|
|
|
$this->tcaTableService->getFields(),
|
2016-12-13 10:38:49 +01:00
|
|
|
$this->tcaTableService->getTableClause(),
|
|
|
|
$this->tcaTableService->getWhereClause()
|
|
|
|
. ' AND ' . $this->tcaTableService->getTableName() . '.uid = ' . (int) $identifier
|
2016-12-12 13:33:07 +01:00
|
|
|
);
|
2017-01-12 14:26:09 +01:00
|
|
|
|
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 12:12:36 +02:00
|
|
|
|
2018-03-06 17:40:49 +01:00
|
|
|
protected function getDocumentName() : string
|
2017-07-04 12:12:36 +02:00
|
|
|
{
|
|
|
|
return $this->tcaTableService->getTableName();
|
|
|
|
}
|
2016-12-09 13:19:35 +01:00
|
|
|
}
|