diff --git a/Classes/Domain/Index/TcaIndexer/PagesIndexer.php b/Classes/Domain/Index/TcaIndexer/PagesIndexer.php index d666410..b5ddf56 100644 --- a/Classes/Domain/Index/TcaIndexer/PagesIndexer.php +++ b/Classes/Domain/Index/TcaIndexer/PagesIndexer.php @@ -71,6 +71,7 @@ class PagesIndexer extends TcaIndexer } } + $record['media'] = $this->fetchMediaForPage($record['uid']); $content = $this->fetchContentForPage($record['uid']); if ($content !== []) { $record['content'] = $content['content']; @@ -122,13 +123,29 @@ class PagesIndexer extends TcaIndexer * @return array */ protected function getContentElementImages($uidOfContentElement) + { + return $this->fetchSysFileReferenceUids($uidOfContentElement, 'tt_content', 'image'); + } + + /** + * @param int $uid + * @return [] + */ + protected function fetchMediaForPage($uid) + { + return $this->fetchSysFileReferenceUids($uid, 'pages', 'media'); + } + + /** + * @param int $uid + * @param string $tablename + * @param string $fieldname + * @return [] + */ + protected function fetchSysFileReferenceUids($uid, $tablename, $fieldname) { $imageRelationUids = []; - $imageRelations = $this->fileRepository->findByRelation( - 'tt_content', - 'image', - $uidOfContentElement - ); + $imageRelations = $this->fileRepository->findByRelation($tablename, $fieldname, $uid); foreach ($imageRelations as $relation) { $imageRelationUids[] = $relation->getUid(); diff --git a/Tests/Functional/Connection/Elasticsearch/IndexTcaTableTest.php b/Tests/Functional/Connection/Elasticsearch/IndexTcaTableTest.php index 02e6ca3..4267d79 100644 --- a/Tests/Functional/Connection/Elasticsearch/IndexTcaTableTest.php +++ b/Tests/Functional/Connection/Elasticsearch/IndexTcaTableTest.php @@ -205,4 +205,33 @@ class IndexTcaTableTest extends AbstractFunctionalTestCase 'Record was indexed with resolved category relation, but should not have any.' ); } + + /** + * @test + */ + public function indexPagesMedia() + { + \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance(ObjectManager::class) + ->get(IndexerFactory::class) + ->getIndexer('pages') + ->indexAllDocuments() + ; + + $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' => [ + 'media' => [ + 10, 1 + ] + ] + ], + $response->getData()['hits']['hits'][0], + false, + 'Record was not indexed.' + ); + } } diff --git a/Tests/Functional/Fixtures/Indexing/IndexTcaTable.xml b/Tests/Functional/Fixtures/Indexing/IndexTcaTable.xml index 3692135..aa2a8fa 100644 --- a/Tests/Functional/Fixtures/Indexing/IndexTcaTable.xml +++ b/Tests/Functional/Fixtures/Indexing/IndexTcaTable.xml @@ -99,4 +99,71 @@ 0 0 + + + 2 + 1 + Example page with + Used as abstract as no abstract is defined. + 2 + + + + 1 + 1 + 1 + 2 + pages + media + 2 + sys_file + + + + + + 10 + 1 + 2 + 2 + pages + media + 1 + sys_file + + + + + + 1 + 0 + 1 + 2 + full/file/path.png + 94dd1f9645114cf1344438ac7188db972768f59f + 67887283a03f465f1004d1d43a157ee1f1c59be5 + png + image/png + path2.png + c1dd34eb34d651ee6ca6ac52dea595db75d8e9d2 + 3044 + 1432306303 + 1432306303 + + + 2 + 0 + 1 + 2 + full/file/path2.png + 94dd1f9645114cf1344438ac7188db972768f59f + 67887283a03f465f1004d1d43a157ee1f1c59be5 + png + image/png + path2.png + c1dd34eb34d651ee6ca6ac52dea595db75d8e9d2 + 3044 + 1432306303 + 1432306303 + diff --git a/Tests/Functional/Indexing/PagesIndexerTest.php b/Tests/Functional/Indexing/PagesIndexerTest.php index 244413d..bf5a35f 100644 --- a/Tests/Functional/Indexing/PagesIndexerTest.php +++ b/Tests/Functional/Indexing/PagesIndexerTest.php @@ -1,5 +1,5 @@ @@ -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'] === diff --git a/Tests/Functional/Indexing/TcaIndexer/RelationResolverTest.php b/Tests/Functional/Indexing/TcaIndexer/RelationResolverTest.php index a491677..62c5158 100644 --- a/Tests/Functional/Indexing/TcaIndexer/RelationResolverTest.php +++ b/Tests/Functional/Indexing/TcaIndexer/RelationResolverTest.php @@ -1,5 +1,5 @@ diff --git a/Tests/Functional/Indexing/TcaIndexerTest.php b/Tests/Functional/Indexing/TcaIndexerTest.php index edf1a74..ff89318 100644 --- a/Tests/Functional/Indexing/TcaIndexerTest.php +++ b/Tests/Functional/Indexing/TcaIndexerTest.php @@ -1,5 +1,5 @@