BUGFIX: Fix broken getRecord method

Also add test covering method.
This commit is contained in:
Daniel Siepmann 2017-07-07 16:44:57 +02:00
parent a8fdb8a44d
commit 2cd5debf97
Signed by: Daniel Siepmann
GPG key ID: 33D6629915560EF4
2 changed files with 46 additions and 20 deletions

View file

@ -22,6 +22,7 @@ namespace Codappix\SearchCore\Domain\Index;
use Codappix\SearchCore\Connection\ConnectionInterface; use Codappix\SearchCore\Connection\ConnectionInterface;
use TYPO3\CMS\Core\Database\ConnectionPool; use TYPO3\CMS\Core\Database\ConnectionPool;
use TYPO3\CMS\Core\Database\Query\QueryBuilder;
use TYPO3\CMS\Core\Utility\GeneralUtility; use TYPO3\CMS\Core\Utility\GeneralUtility;
/** /**
@ -53,21 +54,11 @@ class TcaIndexer extends AbstractIndexer
*/ */
protected function getRecords($offset, $limit) protected function getRecords($offset, $limit)
{ {
$queryBuilder = $this->getDatabaseConnection()->getQueryBuilderForTable($this->tcaTableService->getTableName()); $records = $this->getQuery()
$where = $this->tcaTableService->getWhereClause();
$query = $queryBuilder->select(... $this->tcaTableService->getFields())
->from($this->tcaTableService->getTableClause())
->where($where->getStatement())
->setParameters($where->getParameters())
->setFirstResult($offset) ->setFirstResult($offset)
->setMaxResults($limit); ->setMaxResults($limit)
->execute()
foreach ($this->tcaTableService->getJoins() as $join) { ->fetchAll();
$query->from($join->getTable());
$query->andWhere($join->getCondition());
}
$records = $query->execute()->fetchAll();
if ($records === null) { if ($records === null) {
return null; return null;
@ -88,12 +79,7 @@ class TcaIndexer extends AbstractIndexer
*/ */
protected function getRecord($identifier) protected function getRecord($identifier)
{ {
$record = $this->getDatabaseConnection()->exec_SELECTgetSingleRow( $record = $this->getQuery()->execute()->fetch();
$this->tcaTableService->getFields(),
$this->tcaTableService->getTableClause(),
$this->tcaTableService->getWhereClause()
. ' AND ' . $this->tcaTableService->getTableName() . '.uid = ' . (int) $identifier
);
if ($record === false || $record === null) { if ($record === false || $record === null) {
throw new NoRecordFoundException( throw new NoRecordFoundException(
@ -114,6 +100,23 @@ class TcaIndexer extends AbstractIndexer
return $this->tcaTableService->getTableName(); 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() protected function getDatabaseConnection()
{ {
return GeneralUtility::makeInstance(ConnectionPool::class); return GeneralUtility::makeInstance(ConnectionPool::class);

View file

@ -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 * @test
* @expectedException \Codappix\SearchCore\Domain\Index\IndexingException * @expectedException \Codappix\SearchCore\Domain\Index\IndexingException