search_core/Classes/Domain/Index/TcaIndexer.php

92 lines
2.8 KiB
PHP
Raw Normal View History

2016-12-09 13:19:35 +01:00
<?php
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.
*/
use Codappix\SearchCore\Configuration\ConfigurationContainerInterface;
use Codappix\SearchCore\Connection\ConnectionInterface;
use Codappix\SearchCore\Domain\Index\TcaIndexer\TcaTableServiceInterface;
2016-12-09 13:19:35 +01:00
/**
* Will index the given table using configuration from TCA.
*/
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
* @param ConfigurationContainerInterface $configuration
2016-12-09 13:19:35 +01:00
*/
public function __construct(
2018-03-14 20:08:53 +01:00
TcaTableServiceInterface $tcaTableService,
ConnectionInterface $connection,
ConfigurationContainerInterface $configuration
2016-12-09 13:19:35 +01:00
) {
parent::__construct($connection, $configuration);
2016-12-09 13:19:35 +01:00
$this->tcaTableService = $tcaTableService;
}
/**
* @return array|null
2016-12-09 13:19:35 +01:00
*/
protected function getRecords(int $offset, int $limit)
2016-12-09 13:19:35 +01:00
{
$records = $this->tcaTableService->getRecords($offset, $limit);
if ($records === []) {
return null;
}
2016-12-09 13:19:35 +01:00
$this->tcaTableService->filterRecordsByRootLineBlacklist($records);
2016-12-09 13:19:35 +01:00
foreach ($records as &$record) {
$this->tcaTableService->prepareRecord($record);
}
return $records;
}
/**
* @throws NoRecordFoundException If record could not be found.
*/
protected function getRecord(int $identifier) : array
{
$record = $this->tcaTableService->getRecord($identifier);
2017-08-21 12:10:34 +02:00
if ($record === []) {
throw new NoRecordFoundException(
'Record could not be fetched from database: "' . $identifier . '". Perhaps record is not active.',
1484225364
);
}
$this->tcaTableService->prepareRecord($record);
return $record;
}
protected function getDocumentName() : string
{
return $this->tcaTableService->getTableName();
}
2016-12-09 13:19:35 +01:00
}