BUGFIX: Respect page uid of content records

Do not index content records of all pages while indexing pages in CMS
8.x.

We add same logic as for CMS 7.x, we extend the query to only fetch
records from current page.

Resolves: #135
This commit is contained in:
Daniel Siepmann 2018-03-14 21:32:42 +01:00
parent 8f65d858bb
commit a232ae0b36
Signed by: Daniel Siepmann
GPG key ID: 33D6629915560EF4
4 changed files with 45 additions and 13 deletions

View file

@ -79,8 +79,14 @@ class PagesIndexer extends TcaIndexer
protected function fetchContentForPage(int $uid) : array
{
if ($this->contentTableService instanceof TcaTableService) {
$contentElements = $this->contentTableService->getQuery()
->execute()->fetchAll();
$queryBuilder = $this->contentTableService->getQuery();
$queryBuilder->andWhere(
$queryBuilder->expr()->eq(
$this->contentTableService->getTableName() . '.pid',
$queryBuilder->createNamedParameter($uid, \PDO::PARAM_INT)
)
);
$contentElements = $queryBuilder->execute()->fetchAll();
} else {
$contentElements = $GLOBALS['TYPO3_DB']->exec_SELECTgetRows(
$this->contentTableService->getFields(),

View file

@ -50,11 +50,10 @@ class IndexTcaTableTest extends AbstractFunctionalTestCase
$response = $this->client->request('typo3content/_search?q=*:*');
$this->assertTrue($response->isOk(), 'Elastica did not answer with ok code.');
$this->assertSame($response->getData()['hits']['total'], 2, 'Not exactly 2 documents were indexed.');
$this->assertArraySubset(
['_source' => ['header' => 'indexed content element']],
$response->getData()['hits']['hits'][1],
false,
$this->assertSame($response->getData()['hits']['total'], 3, 'Not exactly 3 documents were indexed.');
$this->assertSame(
'indexed content element',
$response->getData()['hits']['hits'][2]['_source']['header'],
'Record was not indexed.'
);
}
@ -113,7 +112,7 @@ class IndexTcaTableTest extends AbstractFunctionalTestCase
$response = $this->client->request('typo3content/_search?q=*:*');
$this->assertTrue($response->isOk(), 'Elastica did not answer with ok code.');
$this->assertSame($response->getData()['hits']['total'], 2, 'Not exactly 2 documents were indexed.');
$this->assertSame($response->getData()['hits']['total'], 3, 'Not exactly 3 documents were indexed.');
}
/**
@ -136,7 +135,7 @@ class IndexTcaTableTest extends AbstractFunctionalTestCase
$response = $this->client->request('typo3content/_search?q=*:*');
$this->assertTrue($response->isOk(), 'Elastica did not answer with ok code.');
$this->assertSame($response->getData()['hits']['total'], 3, 'Not exactly 3 documents were indexed.');
$this->assertSame($response->getData()['hits']['total'], 4, 'Not exactly 4 documents were indexed.');
$response = $this->client->request('typo3content/_search?q=uid:11');
$this->assertArraySubset(
['_source' => ['header' => 'Also indexable record']],
@ -168,7 +167,7 @@ class IndexTcaTableTest extends AbstractFunctionalTestCase
$response = $this->client->request('typo3content/_search?q=*:*');
$this->assertTrue($response->isOk(), 'Elastica did not answer with ok code.');
$this->assertSame($response->getData()['hits']['total'], 4, 'Not exactly 4 documents were indexed.');
$this->assertSame($response->getData()['hits']['total'], 5, 'Not exactly 5 documents were indexed.');
$response = $this->client->request('typo3content/_search?q=uid:11');
$this->assertArraySubset(
@ -218,7 +217,7 @@ class IndexTcaTableTest extends AbstractFunctionalTestCase
;
$response = $this->client->request('typo3content/_search?q=*:*');
$this->assertSame($response->getData()['hits']['total'], 2, 'Not exactly 2 documents were indexed.');
$this->assertSame($response->getData()['hits']['total'], 3, 'Not exactly 3 documents were indexed.');
if ($this->isLegacyVersion()) {
$this->getDatabaseConnection()
@ -239,6 +238,6 @@ class IndexTcaTableTest extends AbstractFunctionalTestCase
;
$response = $this->client->request('typo3content/_search?q=*:*');
$this->assertSame($response->getData()['hits']['total'], 1, 'Not exactly 1 document is in index.');
$this->assertSame($response->getData()['hits']['total'], 2, 'Not exactly 2 document is in index.');
}
}

View file

@ -99,4 +99,31 @@
<colPos>0</colPos>
<filelink_sorting>0</filelink_sorting>
</tt_content>
<tt_content>
<uid>100</uid>
<pid>2</pid>
<tstamp>1480686370</tstamp>
<crdate>1480686370</crdate>
<hidden>0</hidden>
<sorting>72</sorting>
<CType>header</CType>
<header>Indexed on page 2</header>
<bodytext>This element is on a different page</bodytext>
<media>0</media>
<layout>0</layout>
<deleted>0</deleted>
<cols>0</cols>
<starttime>0</starttime>
<endtime>0</endtime>
<colPos>0</colPos>
<filelink_sorting>0</filelink_sorting>
</tt_content>
<pages>
<uid>2</uid>
<pid>1</pid>
<title>Second page with content</title>
<description>Used to check whether content is indexed only for parent page.</description>
</pages>
</dataset>

View file

@ -48,7 +48,7 @@ class PagesIndexerTest extends AbstractFunctionalTestCase
->with(
$this->stringContains($tableName),
$this->callback(function ($documents) {
return count($documents) === 1
return count($documents) === 2
&& isset($documents[0]['content']) && $documents[0]['content'] ===
'this is the content of header content element that should get indexed Some text in paragraph'
&& isset($documents[0]['search_abstract']) && $documents[0]['search_abstract'] ===