mirror of
https://github.com/Codappix/search_core.git
synced 2024-11-22 08:36:10 +01:00
BUGFIX: Fix broken getRecord method
Also add test covering method.
This commit is contained in:
parent
a8fdb8a44d
commit
2cd5debf97
2 changed files with 46 additions and 20 deletions
|
@ -22,6 +22,7 @@ namespace Codappix\SearchCore\Domain\Index;
|
|||
|
||||
use Codappix\SearchCore\Connection\ConnectionInterface;
|
||||
use TYPO3\CMS\Core\Database\ConnectionPool;
|
||||
use TYPO3\CMS\Core\Database\Query\QueryBuilder;
|
||||
use TYPO3\CMS\Core\Utility\GeneralUtility;
|
||||
|
||||
/**
|
||||
|
@ -53,21 +54,11 @@ class TcaIndexer extends AbstractIndexer
|
|||
*/
|
||||
protected function getRecords($offset, $limit)
|
||||
{
|
||||
$queryBuilder = $this->getDatabaseConnection()->getQueryBuilderForTable($this->tcaTableService->getTableName());
|
||||
$where = $this->tcaTableService->getWhereClause();
|
||||
$query = $queryBuilder->select(... $this->tcaTableService->getFields())
|
||||
->from($this->tcaTableService->getTableClause())
|
||||
->where($where->getStatement())
|
||||
->setParameters($where->getParameters())
|
||||
$records = $this->getQuery()
|
||||
->setFirstResult($offset)
|
||||
->setMaxResults($limit);
|
||||
|
||||
foreach ($this->tcaTableService->getJoins() as $join) {
|
||||
$query->from($join->getTable());
|
||||
$query->andWhere($join->getCondition());
|
||||
}
|
||||
|
||||
$records = $query->execute()->fetchAll();
|
||||
->setMaxResults($limit)
|
||||
->execute()
|
||||
->fetchAll();
|
||||
|
||||
if ($records === null) {
|
||||
return null;
|
||||
|
@ -88,12 +79,7 @@ class TcaIndexer extends AbstractIndexer
|
|||
*/
|
||||
protected function getRecord($identifier)
|
||||
{
|
||||
$record = $this->getDatabaseConnection()->exec_SELECTgetSingleRow(
|
||||
$this->tcaTableService->getFields(),
|
||||
$this->tcaTableService->getTableClause(),
|
||||
$this->tcaTableService->getWhereClause()
|
||||
. ' AND ' . $this->tcaTableService->getTableName() . '.uid = ' . (int) $identifier
|
||||
);
|
||||
$record = $this->getQuery()->execute()->fetch();
|
||||
|
||||
if ($record === false || $record === null) {
|
||||
throw new NoRecordFoundException(
|
||||
|
@ -114,6 +100,23 @@ class TcaIndexer extends AbstractIndexer
|
|||
return $this->tcaTableService->getTableName();
|
||||
}
|
||||
|
||||
protected function getQuery() : QueryBuilder
|
||||
{
|
||||
$queryBuilder = $this->getDatabaseConnection()->getQueryBuilderForTable($this->tcaTableService->getTableName());
|
||||
$where = $this->tcaTableService->getWhereClause();
|
||||
$query = $queryBuilder->select(... $this->tcaTableService->getFields())
|
||||
->from($this->tcaTableService->getTableClause())
|
||||
->where($where->getStatement())
|
||||
->setParameters($where->getParameters());
|
||||
|
||||
foreach ($this->tcaTableService->getJoins() as $join) {
|
||||
$query->from($join->getTable());
|
||||
$query->andWhere($join->getCondition());
|
||||
}
|
||||
|
||||
return $query;
|
||||
}
|
||||
|
||||
protected function getDatabaseConnection()
|
||||
{
|
||||
return GeneralUtility::makeInstance(ConnectionPool::class);
|
||||
|
|
|
@ -59,6 +59,29 @@ class IndexTcaTableTest extends AbstractFunctionalTestCase
|
|||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @test
|
||||
*/
|
||||
public function indexSingleBasicTtContent()
|
||||
{
|
||||
\TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance(ObjectManager::class)
|
||||
->get(IndexerFactory::class)
|
||||
->getIndexer('tt_content')
|
||||
->indexDocument(6)
|
||||
;
|
||||
|
||||
$response = $this->client->request('typo3content/_search?q=*:*');
|
||||
|
||||
$this->assertTrue($response->isOK(), 'Elastica did not answer with ok code.');
|
||||
$this->assertSame($response->getData()['hits']['total'], 1, 'Not exactly 1 document was indexed.');
|
||||
$this->assertArraySubset(
|
||||
['_source' => ['header' => 'indexed content element']],
|
||||
$response->getData()['hits']['hits'][0],
|
||||
false,
|
||||
'Record was not indexed.'
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @test
|
||||
* @expectedException \Codappix\SearchCore\Domain\Index\IndexingException
|
||||
|
|
Loading…
Reference in a new issue