2016-12-09 13:19:35 +01:00
|
|
|
<?php
|
2018-10-02 16:25:05 +02:00
|
|
|
|
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;
|
2018-03-13 17:28:50 +01:00
|
|
|
use Codappix\SearchCore\Domain\Index\TcaIndexer\TcaTableServiceInterface;
|
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
|
|
|
{
|
|
|
|
/**
|
2018-03-14 20:08:53 +01:00
|
|
|
* @var TcaTableServiceInterface
|
2016-12-09 13:19:35 +01:00
|
|
|
*/
|
|
|
|
protected $tcaTableService;
|
|
|
|
|
|
|
|
/**
|
2018-03-14 20:08:53 +01:00
|
|
|
* @param TcaTableServiceInterface $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(
|
2018-03-14 20:08:53 +01:00
|
|
|
TcaTableServiceInterface $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;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2018-10-02 16:25:05 +02:00
|
|
|
* @param integer $offset
|
|
|
|
* @param integer $limit
|
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
|
|
|
{
|
2018-03-13 17:28:50 +01:00
|
|
|
$records = $this->tcaTableService->getRecords($offset, $limit);
|
|
|
|
if ($records === []) {
|
2017-01-26 14:57:23 +01:00
|
|
|
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
|
|
|
|
|
|
|
/**
|
2018-10-02 16:25:05 +02:00
|
|
|
* @param integer $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
|
|
|
*/
|
2018-10-02 16:25:05 +02:00
|
|
|
protected function getRecord(int $identifier): array
|
2016-12-12 13:33:07 +01:00
|
|
|
{
|
2018-03-13 17:28:50 +01:00
|
|
|
$record = $this->tcaTableService->getRecord($identifier);
|
|
|
|
if ($record === []) {
|
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
|
|
|
|
2018-10-02 16:25:05 +02:00
|
|
|
/**
|
|
|
|
* @return string
|
|
|
|
*/
|
|
|
|
protected function getDocumentName(): string
|
2017-07-04 12:12:36 +02:00
|
|
|
{
|
|
|
|
return $this->tcaTableService->getTableName();
|
|
|
|
}
|
2018-10-25 14:01:57 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
* @param string $identifier
|
|
|
|
* @return string
|
|
|
|
*/
|
|
|
|
public function getIdentifier($identifier): string
|
|
|
|
{
|
|
|
|
return $this->getDocumentName() . '-' . $identifier;
|
|
|
|
}
|
2016-12-09 13:19:35 +01:00
|
|
|
}
|