From 687ba8075d75ef094ea5d6996d74396718d2b201 Mon Sep 17 00:00:00 2001 From: Daniel Siepmann Date: Thu, 11 May 2017 12:39:56 +0200 Subject: [PATCH 1/8] TASK: Migrate RelationResolver to FormEngine * Replace old implementation for TYPO3 6.x with new one for rewritten form engine in 7.x and up. --- .../Index/TcaIndexer/RelationResolver.php | 142 ++++++++---------- .../TcaIndexer/RelationResolverTest.php | 6 +- 2 files changed, 69 insertions(+), 79 deletions(-) diff --git a/Classes/Domain/Index/TcaIndexer/RelationResolver.php b/Classes/Domain/Index/TcaIndexer/RelationResolver.php index 2dd5dd7..4f7ff21 100644 --- a/Classes/Domain/Index/TcaIndexer/RelationResolver.php +++ b/Classes/Domain/Index/TcaIndexer/RelationResolver.php @@ -25,6 +25,9 @@ use TYPO3\CMS\Core\SingletonInterface as Singleton; use TYPO3\CMS\Core\Utility\GeneralUtility; use TYPO3\CMS\Extbase\Utility\LocalizationUtility; +use TYPO3\CMS\Backend\Form\FormDataCompiler; +use TYPO3\CMS\Backend\Form\FormDataGroup\TcaDatabaseRecord; + /** * Resolves relations from TCA using TCA. * @@ -33,12 +36,6 @@ use TYPO3\CMS\Extbase\Utility\LocalizationUtility; */ class RelationResolver implements Singleton { - /** - * @var \TYPO3\CMS\Backend\Form\DataPreprocessor - * @inject - */ - protected $formEngine; - /** * Resolve relations for the given record. * @@ -47,12 +44,14 @@ class RelationResolver implements Singleton */ public function resolveRelationsForRecord(TcaTableService $service, array &$record) { - $preprocessedData = $this->formEngine->renderRecordRaw( - $service->getTableName(), - $record['uid'], - $record['pid'], - $record - ); + $formData = GeneralUtility::makeInstance(FormDataCompiler::class, GeneralUtility::makeInstance(TcaDatabaseRecord::class)) + ->compile([ + 'tableName' => $service->getTableName(), + 'vanillaUid' => (int)$record['uid'], + 'command' => 'edit', + ]); + + $record = $formData['databaseRow']; foreach (array_keys($record) as $column) { try { @@ -62,41 +61,35 @@ class RelationResolver implements Singleton continue; } - if (! $this->isRelation($config)) { + if (! $this->isRelation($config) || !is_array($formData['processedTca']['columns'][$column])) { continue; } - $record[$column] = $this->resolveValue($preprocessedData[$column], $config); + $record[$column] = $this->resolveValue($record[$column], $formData['processedTca']['columns'][$column]); } } /** * Resolve the given value from TYPO3 API response. * - * As FormEngine uses an internal format, we resolve it to a usable format - * for indexing. - * - * TODO: Unittest to break as soon as TYPO3 api has changed, so we know - * exactly that we need to tackle this place. - * * @param string $value The value from FormEngine to resolve. - * @param array $config The tca config of the relation. + * @param array $tcaColumn The tca config of the relation. * * @return array|string */ - protected function resolveValue($value, array $config) + protected function resolveValue($value, array $tcaColumn) { if ($value === '' || $value === '0') { return ''; } - if (strpos($value, '|') !== false) { - return $this->resolveSelectValue($value); + if ($tcaColumn['config']['type'] === 'select') { + return $this->resolveSelectValue($value, $tcaColumn); } - if (strpos($value, ',') !== false) { - return $this->resolveInlineValue($value, $config['foreign_table']); + if ($tcaColumn['config']['type'] === 'group' && strpos($value, '|') !== false) { + return $this->resolveForeignDbValue($value); } - if ($config['type'] === 'select' && is_array($config['items'])) { - return $this->resolveSelectItemValue($value, $config['items']); + if ($tcaColumn['config']['type'] === 'inline') { + return $this->resolveInlineValue($tcaColumn); } return ''; @@ -117,62 +110,55 @@ class RelationResolver implements Singleton /** * Resolves internal representation of select to array of labels. * - * @param string $value + * @param array $value + * @param array $tcaColumn * @return array */ - protected function resolveSelectValue($value) + protected function resolveSelectValue(array $values, array $tcaColumn) { - $newValue = []; + $resolvedValues = []; - foreach (GeneralUtility::trimExplode(',', $value) as $value) { - $value = substr($value, strpos($value, '|') + 1); - $value = rawurldecode($value); - $newValue[] = $value; - } - - return $newValue; - } - - /** - * @param string $value - * @param string $table - * - * @return array - */ - protected function resolveInlineValue($value, $table) - { - $newValue = []; - $records = $GLOBALS['TYPO3_DB']->exec_SELECTgetRows('*', $table, 'uid in (' . $value . ')'); - if ($records === null) { - return $newValue; - } - - foreach ($records as $record) { - $newValue[] = BackendUtility::getRecordTitle($table, $record); - } - - return $newValue; - } - - /** - * @param string $value - * @param array $items - * - * @return string - */ - protected function resolveSelectItemValue($value, array $items) - { - foreach ($items as $item) { - if ($item[1] === $value) { - $newValue = LocalizationUtility::translate($item[0], ''); - - if ($newValue === null) { - return ''; - } - return $newValue; + foreach ($tcaColumn['config']['items'] as $item) { + if (in_array($item[1], $values)) { + $resolvedValues[] = $item[0]; } } - return ''; + if ($tcaColumn['config']['renderType'] === 'selectSingle' || $tcaColumn['config']['maxitems'] === 1) { + return current($resolvedValues); + } + + return $resolvedValues; + } + + /** + * @param string $value + * + * @return array + */ + protected function resolveForeignDbValue($value) + { + $titles = []; + + foreach (explode(',', urldecode($value)) as $title) { + $titles[] = explode('|', $title)[1]; + } + + return $titles; + } + + /** + * @param array $tcaColumn + * @return array + */ + protected function resolveInlineValue(array $tcaColumn) + { + $titles = []; + + foreach ($tcaColumn['children'] as $selected) { + $titles[] = $selected['recordTitle']; + } + + return $titles; } } diff --git a/Tests/Functional/Indexing/TcaIndexer/RelationResolverTest.php b/Tests/Functional/Indexing/TcaIndexer/RelationResolverTest.php index 0010e30..360cacd 100644 --- a/Tests/Functional/Indexing/TcaIndexer/RelationResolverTest.php +++ b/Tests/Functional/Indexing/TcaIndexer/RelationResolverTest.php @@ -37,6 +37,10 @@ class RelationResolverTest extends AbstractFunctionalTestCase $objectManager = GeneralUtility::makeInstance(ObjectManager::class); $table = 'sys_file'; + // Only by adding the field to showitem, it will be processed by FormEngine. + // We use this field to test inline relations, as there is only one alternative. + $GLOBALS['TCA']['sys_file']['types'][1]['showitem'] .= ',metadata'; + $subject = $objectManager->get(TcaTableService::class, $table); $record = BackendUtility::getRecord($table, 1); $subject->prepareRecord($record); @@ -109,8 +113,8 @@ class RelationResolverTest extends AbstractFunctionalTestCase $this->assertEquals( [ - 'Category 2', 'Category 1', + 'Category 2', ], $record['categories'], 'Foreign mm select relation was not resolved as expected.' From f9ec3ada4eb3379cf7194598ff9c734d8bb19e52 Mon Sep 17 00:00:00 2001 From: Daniel Siepmann Date: Thu, 11 May 2017 12:45:11 +0200 Subject: [PATCH 2/8] TASK: Adjust travis to no longer test TYPO3 6.x --- .travis.yml | 9 --------- 1 file changed, 9 deletions(-) diff --git a/.travis.yml b/.travis.yml index e583e51..79bf8f9 100644 --- a/.travis.yml +++ b/.travis.yml @@ -16,7 +16,6 @@ env: - typo3DatabaseUsername="travis" - typo3DatabasePassword="" matrix: - - TYPO3_VERSION="~6.2" - TYPO3_VERSION="~7.6" - TYPO3_VERSION="~8" - TYPO3_VERSION="dev-master" @@ -25,19 +24,11 @@ matrix: fast_finish: true exclude: # TYPO3 no longer supports 5.6 - - env: TYPO3_VERSION="~7.6" - php: 5.6 - env: TYPO3_VERSION="~8" php: 5.6 - env: TYPO3_VERSION="dev-master" php: 5.6 allow_failures: - # 7 and 8 are not working due to current relation resolving. - # See: https://github.com/DanielSiepmann/search_core/projects/1 - - env: TYPO3_VERSION="~7.6" - php: 7.0 - - env: TYPO3_VERSION="~7.6" - php: 7.1 - env: TYPO3_VERSION="~8" php: 7.0 - env: TYPO3_VERSION="~8" From eba74ebb934174a14536400ab4cf8c49ef0ad7bd Mon Sep 17 00:00:00 2001 From: Daniel Siepmann Date: Thu, 11 May 2017 12:50:31 +0200 Subject: [PATCH 3/8] TASK: Make test work with TYPO3 7.x * Do not overwrite base ts setup, keep it and add test specific. * Adjust order of labels. --- .../Connection/Elasticsearch/IndexTcaTableTest.php | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/Tests/Functional/Connection/Elasticsearch/IndexTcaTableTest.php b/Tests/Functional/Connection/Elasticsearch/IndexTcaTableTest.php index 9f9b50b..5e0c1a7 100644 --- a/Tests/Functional/Connection/Elasticsearch/IndexTcaTableTest.php +++ b/Tests/Functional/Connection/Elasticsearch/IndexTcaTableTest.php @@ -98,7 +98,10 @@ class IndexTcaTableTest extends AbstractFunctionalTestCase */ public function indexingRespectsUserWhereClause() { - $this->setUpFrontendRootPage(1, ['EXT:search_core/Tests/Functional/Fixtures/Indexing/UserWhereClause.ts']); + $this->setUpFrontendRootPage(1, array_merge( + parent::getTypoScriptFilesForFrontendRootPage(), + ['EXT:search_core/Tests/Functional/Fixtures/Indexing/UserWhereClause.ts'] + )); $this->importDataSet('Tests/Functional/Fixtures/Indexing/UserWhereClause.xml'); \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance(ObjectManager::class) @@ -147,7 +150,7 @@ class IndexTcaTableTest extends AbstractFunctionalTestCase ['_source' => [ 'uid' => '9', 'CType' => 'Header', // Testing items - 'categories' => ['Category 2', 'Category 1'], // Testing mm (with sorting) + 'categories' => ['Category 1', 'Category 2'], // Testing mm (with sorting) ]], $response->getData()['hits']['hits'][0], false, From b829a3525a9f5e8f56a08922e4cc1a0f6a58e234 Mon Sep 17 00:00:00 2001 From: Daniel Siepmann Date: Thu, 11 May 2017 13:49:35 +0200 Subject: [PATCH 4/8] TASK: Finish TYPO3 update * Mark 6.2 as not supported. --- Documentation/source/readme.rst | 2 -- Makefile | 2 +- composer.json | 2 +- typo3_src | 1 + 4 files changed, 3 insertions(+), 4 deletions(-) create mode 160000 typo3_src diff --git a/Documentation/source/readme.rst b/Documentation/source/readme.rst index cc341c9..ec5e0e0 100644 --- a/Documentation/source/readme.rst +++ b/Documentation/source/readme.rst @@ -23,8 +23,6 @@ This is still a very early alpha version. More information can be taken from Git We are also focusing on Code Quality and Testing through `travis ci`_, `scrutinizer`_ and `codacy`_. -TYPO3 7 is not supported yet, see :project:`1`. - .. _current issues: https://github.com/DanielSiepmann/search_core/issues .. _current projects: https://github.com/DanielSiepmann/search_core/projects .. _travis ci: https://travis-ci.org/DanielSiepmann/search_core diff --git a/Makefile b/Makefile index 2520ab0..589dd7d 100644 --- a/Makefile +++ b/Makefile @@ -3,7 +3,7 @@ current_dir := $(dir $(mkfile_path)) TYPO3_WEB_DIR := $(current_dir).Build/Web # Allow different versions on travis -TYPO3_VERSION ?= ~6.2 +TYPO3_VERSION ?= ~7.6 typo3DatabaseName ?= "searchcore_test" typo3DatabaseUsername ?= "dev" typo3DatabasePassword ?= "dev" diff --git a/composer.json b/composer.json index be5051e..a705315 100644 --- a/composer.json +++ b/composer.json @@ -17,7 +17,7 @@ }, "require" : { "php": ">=5.6.0", - "typo3/cms": "~6.2", + "typo3/cms": "~7.6", "ruflin/elastica": "~3.2" }, "require-dev": { diff --git a/typo3_src b/typo3_src new file mode 160000 index 0000000..3a18913 --- /dev/null +++ b/typo3_src @@ -0,0 +1 @@ +Subproject commit 3a189135b36f5efb7aa07aca5b01b5438efa1b30 From 0f2ae732d7ffce36e9f4bd209dae8b9049d4a828 Mon Sep 17 00:00:00 2001 From: Daniel Siepmann Date: Thu, 11 May 2017 14:30:06 +0200 Subject: [PATCH 5/8] TASK: Remove added submodule --- typo3_src | 1 - 1 file changed, 1 deletion(-) delete mode 160000 typo3_src diff --git a/typo3_src b/typo3_src deleted file mode 160000 index 3a18913..0000000 --- a/typo3_src +++ /dev/null @@ -1 +0,0 @@ -Subproject commit 3a189135b36f5efb7aa07aca5b01b5438efa1b30 From ea1e3640dd1d4623bef4ad79fce7ae615ccf3599 Mon Sep 17 00:00:00 2001 From: Daniel Siepmann Date: Thu, 11 May 2017 14:30:17 +0200 Subject: [PATCH 6/8] TASK: Fix CGL --- .../Domain/Index/TcaIndexer/RelationResolver.php | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/Classes/Domain/Index/TcaIndexer/RelationResolver.php b/Classes/Domain/Index/TcaIndexer/RelationResolver.php index 4f7ff21..69eb4a2 100644 --- a/Classes/Domain/Index/TcaIndexer/RelationResolver.php +++ b/Classes/Domain/Index/TcaIndexer/RelationResolver.php @@ -44,13 +44,14 @@ class RelationResolver implements Singleton */ public function resolveRelationsForRecord(TcaTableService $service, array &$record) { - $formData = GeneralUtility::makeInstance(FormDataCompiler::class, GeneralUtility::makeInstance(TcaDatabaseRecord::class)) - ->compile([ - 'tableName' => $service->getTableName(), - 'vanillaUid' => (int)$record['uid'], - 'command' => 'edit', - ]); - + $formData = GeneralUtility::makeInstance( + FormDataCompiler::class, + GeneralUtility::makeInstance(TcaDatabaseRecord::class) + )->compile([ + 'tableName' => $service->getTableName(), + 'vanillaUid' => (int)$record['uid'], + 'command' => 'edit', + ]); $record = $formData['databaseRow']; foreach (array_keys($record) as $column) { From d26172b5cbef40c74bbcbaa1297b380dace4a2dc Mon Sep 17 00:00:00 2001 From: Daniel Siepmann Date: Tue, 6 Jun 2017 11:45:23 +0200 Subject: [PATCH 7/8] BUGFIX: Adjust emconf * Fix TYPO3 Version constraint. * Adjust author. --- ext_emconf.php | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/ext_emconf.php b/ext_emconf.php index 0b68b51..3aab0c7 100644 --- a/ext_emconf.php +++ b/ext_emconf.php @@ -6,7 +6,7 @@ $EM_CONF[$_EXTKEY] = [ 'category' => 'be', 'constraints' => [ 'depends' => [ - 'typo3' => '6.2.0-6.2.99', + 'typo3' => '7.6.0-7.6.99', 'php' => '5.6.0-7.99.99' ], 'conflicts' => [], @@ -18,7 +18,7 @@ $EM_CONF[$_EXTKEY] = [ ], 'state' => 'alpha', 'clearCacheOnLoad' => 1, - 'author' => 'Justus Leon Moroni', - 'author_email' => 'developer@leonmrni.com', + 'author' => 'Daniel Siepmann', + 'author_email' => 'coding@daniel-siepmann.de', 'version' => '1.0.0', ]; From 9a482381c049164d160be650edda2d1e5d0dbc70 Mon Sep 17 00:00:00 2001 From: Daniel Siepmann Date: Tue, 13 Jun 2017 15:36:56 +0200 Subject: [PATCH 8/8] TASK: Upgrade phpunit to latest stable 5.7 * To make use of new features. * To reduce cost of later migrations. * Migrate deprecated calls from lower TYPO3 api. --- .../Hooks/DataHandler/AbstractDataHandlerTest.php | 13 ++++--------- Tests/Functional/Indexing/TcaIndexerTest.php | 14 +++++--------- composer.json | 2 +- 3 files changed, 10 insertions(+), 19 deletions(-) diff --git a/Tests/Functional/Hooks/DataHandler/AbstractDataHandlerTest.php b/Tests/Functional/Hooks/DataHandler/AbstractDataHandlerTest.php index 7a7569e..a26021d 100644 --- a/Tests/Functional/Hooks/DataHandler/AbstractDataHandlerTest.php +++ b/Tests/Functional/Hooks/DataHandler/AbstractDataHandlerTest.php @@ -41,15 +41,10 @@ abstract class AbstractDataHandlerTest extends AbstractFunctionalTestCase $objectManager = GeneralUtility::makeInstance(ObjectManager::class); - $this->subject = $this->getAccessibleMock( - DataHandlerService::class, - [ - 'add', - 'update', - 'delete', - ], - [$objectManager->get(ConfigurationContainerInterface::class)] - ); + $this->subject = $this->getMockBuilder(DataHandlerService::class) + ->setConstructorArgs([$objectManager->get(ConfigurationContainerInterface::class)]) + ->setMethods(['add', 'update', 'delete']) + ->getMock(); // This way TYPO3 will use our mock instead of a new instance. $GLOBALS['T3_VAR']['getUserObj']['&' . DataHandlerHook::class] = new DataHandlerHook($this->subject); diff --git a/Tests/Functional/Indexing/TcaIndexerTest.php b/Tests/Functional/Indexing/TcaIndexerTest.php index e3af23b..056af39 100644 --- a/Tests/Functional/Indexing/TcaIndexerTest.php +++ b/Tests/Functional/Indexing/TcaIndexerTest.php @@ -44,15 +44,11 @@ class TcaIndexerTest extends AbstractFunctionalTestCase $objectManager->get(RelationResolver::class), $objectManager->get(ConfigurationContainerInterface::class) ); - $connection = $this->getAccessibleMock( - Elasticsearch::class, - [ - 'addDocuments', - ], - [], - '', - false - ); + + $connection = $this->getMockBuilder(Elasticsearch::class) + ->setMethods(['addDocuments']) + ->disableOriginalConstructor() + ->getMock(); $connection->expects($this->once()) ->method('addDocuments') diff --git a/composer.json b/composer.json index a705315..debb71f 100644 --- a/composer.json +++ b/composer.json @@ -21,7 +21,7 @@ "ruflin/elastica": "~3.2" }, "require-dev": { - "phpunit/phpunit": "~4.8.0" + "phpunit/phpunit": "~5.7.0" }, "config": { "optimize-autoloader": true,