!!!|BUGFIX: Index media field of pages as relation uids

Always index media field of pages as array.
Index reference_uids for files.
This commit is contained in:
Daniel Siepmann 2017-12-12 11:26:46 +01:00
parent cd391abf10
commit 6423f510e2
Signed by: Daniel Siepmann
GPG key ID: 33D6629915560EF4
3 changed files with 117 additions and 0 deletions

View file

@ -71,6 +71,7 @@ class PagesIndexer extends TcaIndexer
} }
} }
$record['media'] = $this->fetchMediaForPage($record['uid']);
$content = $this->fetchContentForPage($record['uid']); $content = $this->fetchContentForPage($record['uid']);
if ($content !== []) { if ($content !== []) {
$record['content'] = $content['content']; $record['content'] = $content['content'];
@ -136,4 +137,24 @@ class PagesIndexer extends TcaIndexer
return $imageRelationUids; return $imageRelationUids;
} }
/**
* @param int $uid
* @return []
*/
protected function fetchMediaForPage($uid)
{
$imageRelationUids = [];
$imageRelations = $this->fileRepository->findByRelation(
'pages',
'media',
$uid
);
foreach ($imageRelations as $relation) {
$imageRelationUids[] = $relation->getUid();
}
return $imageRelationUids;
}
} }

View file

@ -205,4 +205,33 @@ class IndexTcaTableTest extends AbstractFunctionalTestCase
'Record was indexed with resolved category relation, but should not have any.' '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.'
);
}
} }

View file

@ -99,4 +99,71 @@
<colPos>0</colPos> <colPos>0</colPos>
<filelink_sorting>0</filelink_sorting> <filelink_sorting>0</filelink_sorting>
</tt_content> </tt_content>
<pages>
<uid>2</uid>
<pid>1</pid>
<title>Example page with </title>
<description>Used as abstract as no abstract is defined.</description>
<media>2</media>
</pages>
<sys_file_reference>
<uid>1</uid>
<pid>1</pid>
<uid_local>1</uid_local>
<uid_foreign>2</uid_foreign>
<tablenames>pages</tablenames>
<fieldname>media</fieldname>
<sorting_foreign>2</sorting_foreign>
<table_local>sys_file</table_local>
<l10n_diffsource></l10n_diffsource>
</sys_file_reference>
<sys_file_reference>
<uid>10</uid>
<pid>1</pid>
<uid_local>2</uid_local>
<uid_foreign>2</uid_foreign>
<tablenames>pages</tablenames>
<fieldname>media</fieldname>
<sorting_foreign>1</sorting_foreign>
<table_local>sys_file</table_local>
<l10n_diffsource></l10n_diffsource>
</sys_file_reference>
<sys_file>
<uid>1</uid>
<pid>0</pid>
<storage>1</storage>
<type>2</type>
<identifier>full/file/path.png</identifier>
<identifier_hash>94dd1f9645114cf1344438ac7188db972768f59f</identifier_hash>
<folder_hash>67887283a03f465f1004d1d43a157ee1f1c59be5</folder_hash>
<extension>png</extension>
<mime_type>image/png</mime_type>
<name>path2.png</name>
<sha1>c1dd34eb34d651ee6ca6ac52dea595db75d8e9d2</sha1>
<size>3044</size>
<creation_date>1432306303</creation_date>
<modification_date>1432306303</modification_date>
</sys_file>
<sys_file>
<uid>2</uid>
<pid>0</pid>
<storage>1</storage>
<type>2</type>
<identifier>full/file/path2.png</identifier>
<identifier_hash>94dd1f9645114cf1344438ac7188db972768f59f</identifier_hash>
<folder_hash>67887283a03f465f1004d1d43a157ee1f1c59be5</folder_hash>
<extension>png</extension>
<mime_type>image/png</mime_type>
<name>path2.png</name>
<sha1>c1dd34eb34d651ee6ca6ac52dea595db75d8e9d2</sha1>
<size>3044</size>
<creation_date>1432306303</creation_date>
<modification_date>1432306303</modification_date>
</sys_file>
</dataset> </dataset>