diff --git a/Classes/Domain/Index/TcaIndexer/RelationResolver.php b/Classes/Domain/Index/TcaIndexer/RelationResolver.php index 763589b..256a135 100644 --- a/Classes/Domain/Index/TcaIndexer/RelationResolver.php +++ b/Classes/Domain/Index/TcaIndexer/RelationResolver.php @@ -37,7 +37,8 @@ class RelationResolver implements Singleton { foreach (array_keys($record) as $column) { // TODO: Define / configure fields to exclude?! - if ($column === 'pid') { + if (in_array($column, ['pid', $service->getLanguageUidColumn()])) { + $record[$column] = (int) $record[$column]; continue; } diff --git a/Classes/Domain/Index/TcaIndexer/TcaTableService.php b/Classes/Domain/Index/TcaIndexer/TcaTableService.php index ee0a2d8..37b0c89 100644 --- a/Classes/Domain/Index/TcaIndexer/TcaTableService.php +++ b/Classes/Domain/Index/TcaIndexer/TcaTableService.php @@ -283,6 +283,15 @@ class TcaTableService implements TcaTableServiceInterface return $this->tca['columns'][$columnName]['config']; } + public function getLanguageUidColumn() : string + { + if (!isset($this->tca['ctrl']['languageField'])) { + return ''; + } + + return $this->tca['ctrl']['languageField']; + } + /** * Checks whether the given record was blacklisted by root line. * This can be configured by typoscript as whole root lines can be black listed. diff --git a/Classes/Domain/Index/TcaIndexer/TcaTableService76.php b/Classes/Domain/Index/TcaIndexer/TcaTableService76.php index f52027a..59d6136 100644 --- a/Classes/Domain/Index/TcaIndexer/TcaTableService76.php +++ b/Classes/Domain/Index/TcaIndexer/TcaTableService76.php @@ -290,6 +290,15 @@ class TcaTableService76 implements TcaTableServiceInterface return $this->tca['columns'][$columnName]['config']; } + public function getLanguageUidColumn() : string + { + if (!isset($this->tca['ctrl']['languageField'])) { + return ''; + } + + return $this->tca['ctrl']['languageField']; + } + /** * Checks whether the given record was blacklisted by root line. * This can be configured by typoscript as whole root lines can be black listed. diff --git a/Classes/Domain/Index/TcaIndexer/TcaTableServiceInterface.php b/Classes/Domain/Index/TcaIndexer/TcaTableServiceInterface.php index 0c9cfc4..e4ee7c5 100644 --- a/Classes/Domain/Index/TcaIndexer/TcaTableServiceInterface.php +++ b/Classes/Domain/Index/TcaIndexer/TcaTableServiceInterface.php @@ -41,4 +41,6 @@ interface TcaTableServiceInterface public function getRecords(int $offset, int $limit) : array; public function getRecord(int $identifier) : array; + + public function getLanguageUidColumn() : string; } diff --git a/Documentation/source/changelog.rst b/Documentation/source/changelog.rst index 8b1c649..37b42c6 100644 --- a/Documentation/source/changelog.rst +++ b/Documentation/source/changelog.rst @@ -5,8 +5,9 @@ Changelog :maxdepth: 1 :glob: - changelog/20180415-134-make-conent-fields-configurable - changelog/20180409-25-provide-sys-language-uid - changelog/20180408-131-respect-page-cache-clear - changelog/20180408-introduce-php70-type-hints - changelog/20180406-120-facet-configuration + changelog/20180410-148-keep-sys_language_uid + changelog/20180315-134-make-conent-fields-configurable + changelog/20180309-25-provide-sys-language-uid + changelog/20180308-131-respect-page-cache-clear + changelog/20180308-introduce-php70-type-hints + changelog/20180306-120-facet-configuration diff --git a/Documentation/source/changelog/20180406-120-facet-configuration.rst b/Documentation/source/changelog/20180306-120-facet-configuration.rst similarity index 93% rename from Documentation/source/changelog/20180406-120-facet-configuration.rst rename to Documentation/source/changelog/20180306-120-facet-configuration.rst index 0c2338f..88c36d0 100644 --- a/Documentation/source/changelog/20180406-120-facet-configuration.rst +++ b/Documentation/source/changelog/20180306-120-facet-configuration.rst @@ -1,5 +1,5 @@ -Breacking Change 120 "Pass facets configuration to Elasticsearch" -================================================================= +Breaking Change 120 "Pass facets configuration to Elasticsearch" +================================================================ In order to allow arbitrary facet configuration, we do not process the facet configuration anymore. Instead integrators are able to configure facets for search service "as is". We just pipe the diff --git a/Documentation/source/changelog/20180408-131-respect-page-cache-clear.rst b/Documentation/source/changelog/20180308-131-respect-page-cache-clear.rst similarity index 100% rename from Documentation/source/changelog/20180408-131-respect-page-cache-clear.rst rename to Documentation/source/changelog/20180308-131-respect-page-cache-clear.rst diff --git a/Documentation/source/changelog/20180408-introduce-php70-type-hints.rst b/Documentation/source/changelog/20180308-introduce-php70-type-hints.rst similarity index 82% rename from Documentation/source/changelog/20180408-introduce-php70-type-hints.rst rename to Documentation/source/changelog/20180308-introduce-php70-type-hints.rst index cc2dfe3..dae8b40 100644 --- a/Documentation/source/changelog/20180408-introduce-php70-type-hints.rst +++ b/Documentation/source/changelog/20180308-introduce-php70-type-hints.rst @@ -1,5 +1,5 @@ -Breacking Change "Introduce PHP 7.0 TypeHints" -============================================== +Breaking Change "Introduce PHP 7.0 TypeHints" +============================================= As PHP evolved, we now migrate the whole code base to use PHP 7.0 type hints. We do not use PHP 7.1 Type Hints, as some customers still need PHP 7.0 support. diff --git a/Documentation/source/changelog/20180409-25-provide-sys-language-uid.rst b/Documentation/source/changelog/20180309-25-provide-sys-language-uid.rst similarity index 91% rename from Documentation/source/changelog/20180409-25-provide-sys-language-uid.rst rename to Documentation/source/changelog/20180309-25-provide-sys-language-uid.rst index 3700ce0..5230b75 100644 --- a/Documentation/source/changelog/20180409-25-provide-sys-language-uid.rst +++ b/Documentation/source/changelog/20180309-25-provide-sys-language-uid.rst @@ -1,4 +1,4 @@ -FEATURE 25 "Respect multiple languages" - Provide sys_language_uid +Feature 25 "Respect multiple languages" - Provide sys_language_uid ================================================================== Previously we did not fetch ``sys_language_uid`` field from database. This prevented everyone from diff --git a/Documentation/source/changelog/20180415-134-make-conent-fields-configurable.rst b/Documentation/source/changelog/20180315-134-make-conent-fields-configurable.rst similarity index 88% rename from Documentation/source/changelog/20180415-134-make-conent-fields-configurable.rst rename to Documentation/source/changelog/20180315-134-make-conent-fields-configurable.rst index 7068119..2601a71 100644 --- a/Documentation/source/changelog/20180415-134-make-conent-fields-configurable.rst +++ b/Documentation/source/changelog/20180315-134-make-conent-fields-configurable.rst @@ -1,4 +1,4 @@ -FEATURE 134 "Enable indexing of tt_content records of CType Header" +Feature 134 "Enable indexing of tt_content records of CType Header" =================================================================== Before, only ``bodytext`` was used to generate content while indexing pages. diff --git a/Documentation/source/changelog/20180410-148-keep-sys_language_uid.rst b/Documentation/source/changelog/20180410-148-keep-sys_language_uid.rst new file mode 100644 index 0000000..d89a289 --- /dev/null +++ b/Documentation/source/changelog/20180410-148-keep-sys_language_uid.rst @@ -0,0 +1,10 @@ +Feature 148 "Cast sys_language_uid to int" +========================================== + +While resolving relations the configured language uid field, fetched from TCA, will +be casted to integer and returned immediately. + +This change prevents the bug mentioned in :issue:`148`, where `0` is casted to an +empty string, which makes filtering hard. + +See :issue:`148`. diff --git a/Tests/Functional/Indexing/TcaIndexerTest.php b/Tests/Functional/Indexing/TcaIndexerTest.php index d7ecc3a..85f36a6 100644 --- a/Tests/Functional/Indexing/TcaIndexerTest.php +++ b/Tests/Functional/Indexing/TcaIndexerTest.php @@ -103,11 +103,7 @@ class TcaIndexerTest extends AbstractFunctionalTestCase ->with( $this->stringContains('tt_content'), $this->callback(function ($documents) { - if ($this->isLegacyVersion()) { - return isset($documents[0]['sys_language_uid']) && $documents[0]['sys_language_uid'] === '2'; - } else { - return isset($documents[0]['sys_language_uid']) && $documents[0]['sys_language_uid'] === 2; - } + return isset($documents[0]['sys_language_uid']) && $documents[0]['sys_language_uid'] === 2; }) ); diff --git a/Tests/Unit/Domain/Index/TcaIndexer/RelationResolverTest.php b/Tests/Unit/Domain/Index/TcaIndexer/RelationResolverTest.php index c227c24..663f7ca 100644 --- a/Tests/Unit/Domain/Index/TcaIndexer/RelationResolverTest.php +++ b/Tests/Unit/Domain/Index/TcaIndexer/RelationResolverTest.php @@ -37,6 +37,59 @@ class RelationResolverTest extends AbstractUnitTestCase $this->subject = new RelationResolver(); } + /** + * @test + */ + public function sysLanguageUidZeroIsKept() + { + $record = [ + 'sys_language_uid' => '0', + ]; + $GLOBALS['TCA'] = [ + 'tt_content' => [ + 'columns' => [ + 'sys_language_uid' => [ + 'config' => [ + 'default' => 0, + 'items' => [ + [ + 'LLL:EXT:lang/Resources/Private/Language/locallang_general.xlf:LGL.allLanguages', + '-1', + 'flags-multiple', + ], + ], + 'renderType' => 'selectSingle', + 'special' => 'languages', + 'type' => 'select', + 'exclude' => '1', + 'label' => 'LLL:EXT:lang/Resources/Private/Language/locallang_general.xlf:LGL.language', + ], + ], + ], + ], + ]; + $tableServiceMock = $this->getMockBuilder(TcaTableServiceInterface::class)->getMock(); + $tableServiceMock->expects($this->any()) + ->method('getTableName') + ->willReturn('tt_content'); + $tableServiceMock->expects($this->any()) + ->method('getLanguageUidColumn') + ->willReturn('sys_language_uid'); + $tableServiceMock->expects($this->any()) + ->method('getColumnConfig') + ->willReturn($GLOBALS['TCA']['tt_content']['columns']['sys_language_uid']['config']); + + $this->subject->resolveRelationsForRecord($tableServiceMock, $record); + + $this->assertSame( + [ + 'sys_language_uid' => 0, + ], + $record, + 'sys_language_uid was not kept as zero.' + ); + } + /** * @test */