Merge branch 'develop' into feature/filter

This commit is contained in:
Daniel Siepmann 2017-06-27 15:02:25 +02:00
commit 18b7f2d8b1
10 changed files with 90 additions and 116 deletions

View file

@ -25,7 +25,6 @@ env:
- typo3DatabaseUsername="travis" - typo3DatabaseUsername="travis"
- typo3DatabasePassword="" - typo3DatabasePassword=""
matrix: matrix:
- TYPO3_VERSION="~6.2"
- TYPO3_VERSION="~7.6" - TYPO3_VERSION="~7.6"
- TYPO3_VERSION="~8" - TYPO3_VERSION="~8"
- TYPO3_VERSION="dev-master" - TYPO3_VERSION="dev-master"
@ -34,19 +33,11 @@ matrix:
fast_finish: true fast_finish: true
exclude: exclude:
# TYPO3 no longer supports 5.6 # TYPO3 no longer supports 5.6
- env: TYPO3_VERSION="~7.6"
php: 5.6
- env: TYPO3_VERSION="~8" - env: TYPO3_VERSION="~8"
php: 5.6 php: 5.6
- env: TYPO3_VERSION="dev-master" - env: TYPO3_VERSION="dev-master"
php: 5.6 php: 5.6
allow_failures: 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" - env: TYPO3_VERSION="~8"
php: 7.0 php: 7.0
- env: TYPO3_VERSION="~8" - env: TYPO3_VERSION="~8"

View file

@ -25,6 +25,9 @@ use TYPO3\CMS\Core\SingletonInterface as Singleton;
use TYPO3\CMS\Core\Utility\GeneralUtility; use TYPO3\CMS\Core\Utility\GeneralUtility;
use TYPO3\CMS\Extbase\Utility\LocalizationUtility; 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. * Resolves relations from TCA using TCA.
* *
@ -33,12 +36,6 @@ use TYPO3\CMS\Extbase\Utility\LocalizationUtility;
*/ */
class RelationResolver implements Singleton class RelationResolver implements Singleton
{ {
/**
* @var \TYPO3\CMS\Backend\Form\DataPreprocessor
* @inject
*/
protected $formEngine;
/** /**
* Resolve relations for the given record. * Resolve relations for the given record.
* *
@ -47,12 +44,15 @@ class RelationResolver implements Singleton
*/ */
public function resolveRelationsForRecord(TcaTableService $service, array &$record) public function resolveRelationsForRecord(TcaTableService $service, array &$record)
{ {
$preprocessedData = $this->formEngine->renderRecordRaw( $formData = GeneralUtility::makeInstance(
$service->getTableName(), FormDataCompiler::class,
$record['uid'], GeneralUtility::makeInstance(TcaDatabaseRecord::class)
$record['pid'], )->compile([
$record 'tableName' => $service->getTableName(),
); 'vanillaUid' => (int)$record['uid'],
'command' => 'edit',
]);
$record = $formData['databaseRow'];
foreach (array_keys($record) as $column) { foreach (array_keys($record) as $column) {
try { try {
@ -62,41 +62,35 @@ class RelationResolver implements Singleton
continue; continue;
} }
if (! $this->isRelation($config)) { if (! $this->isRelation($config) || !is_array($formData['processedTca']['columns'][$column])) {
continue; 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. * 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 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>|string * @return array<String>|string
*/ */
protected function resolveValue($value, array $config) protected function resolveValue($value, array $tcaColumn)
{ {
if ($value === '' || $value === '0') { if ($value === '' || $value === '0') {
return ''; return '';
} }
if (strpos($value, '|') !== false) { if ($tcaColumn['config']['type'] === 'select') {
return $this->resolveSelectValue($value); return $this->resolveSelectValue($value, $tcaColumn);
} }
if (strpos($value, ',') !== false) { if ($tcaColumn['config']['type'] === 'group' && strpos($value, '|') !== false) {
return $this->resolveInlineValue($value, $config['foreign_table']); return $this->resolveForeignDbValue($value);
} }
if ($config['type'] === 'select' && is_array($config['items'])) { if ($tcaColumn['config']['type'] === 'inline') {
return $this->resolveSelectItemValue($value, $config['items']); return $this->resolveInlineValue($tcaColumn);
} }
return ''; return '';
@ -117,62 +111,55 @@ class RelationResolver implements Singleton
/** /**
* Resolves internal representation of select to array of labels. * Resolves internal representation of select to array of labels.
* *
* @param string $value * @param array $value
* @param array $tcaColumn
* @return array * @return array
*/ */
protected function resolveSelectValue($value) protected function resolveSelectValue(array $values, array $tcaColumn)
{ {
$newValue = []; $resolvedValues = [];
foreach (GeneralUtility::trimExplode(',', $value) as $value) { foreach ($tcaColumn['config']['items'] as $item) {
$value = substr($value, strpos($value, '|') + 1); if (in_array($item[1], $values)) {
$value = rawurldecode($value); $resolvedValues[] = $item[0];
$newValue[] = $value; }
} }
return $newValue; if ($tcaColumn['config']['renderType'] === 'selectSingle' || $tcaColumn['config']['maxitems'] === 1) {
return current($resolvedValues);
}
return $resolvedValues;
} }
/** /**
* @param string $value * @param string $value
* @param string $table
* *
* @return array * @return array
*/ */
protected function resolveInlineValue($value, $table) protected function resolveForeignDbValue($value)
{ {
$newValue = []; $titles = [];
$records = $GLOBALS['TYPO3_DB']->exec_SELECTgetRows('*', $table, 'uid in (' . $value . ')');
if ($records === null) { foreach (explode(',', urldecode($value)) as $title) {
return $newValue; $titles[] = explode('|', $title)[1];
} }
foreach ($records as $record) { return $titles;
$newValue[] = BackendUtility::getRecordTitle($table, $record);
}
return $newValue;
} }
/** /**
* @param string $value * @param array $tcaColumn
* @param array $items * @return array
*
* @return string
*/ */
protected function resolveSelectItemValue($value, array $items) protected function resolveInlineValue(array $tcaColumn)
{ {
foreach ($items as $item) { $titles = [];
if ($item[1] === $value) {
$newValue = LocalizationUtility::translate($item[0], '');
if ($newValue === null) { foreach ($tcaColumn['children'] as $selected) {
return ''; $titles[] = $selected['recordTitle'];
}
return $newValue;
}
} }
return ''; return $titles;
} }
} }

View file

@ -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`_. 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 issues: https://github.com/DanielSiepmann/search_core/issues
.. _current projects: https://github.com/DanielSiepmann/search_core/projects .. _current projects: https://github.com/DanielSiepmann/search_core/projects
.. _travis ci: https://travis-ci.org/DanielSiepmann/search_core .. _travis ci: https://travis-ci.org/DanielSiepmann/search_core

View file

@ -3,7 +3,7 @@ current_dir := $(dir $(mkfile_path))
TYPO3_WEB_DIR := $(current_dir).Build/Web TYPO3_WEB_DIR := $(current_dir).Build/Web
# Allow different versions on travis # Allow different versions on travis
TYPO3_VERSION ?= ~6.2 TYPO3_VERSION ?= ~7.6
typo3DatabaseName ?= "searchcore_test" typo3DatabaseName ?= "searchcore_test"
typo3DatabaseUsername ?= "dev" typo3DatabaseUsername ?= "dev"
typo3DatabasePassword ?= "dev" typo3DatabasePassword ?= "dev"

View file

@ -98,7 +98,10 @@ class IndexTcaTableTest extends AbstractFunctionalTestCase
*/ */
public function indexingRespectsUserWhereClause() 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'); $this->importDataSet('Tests/Functional/Fixtures/Indexing/UserWhereClause.xml');
\TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance(ObjectManager::class) \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance(ObjectManager::class)
@ -147,7 +150,7 @@ class IndexTcaTableTest extends AbstractFunctionalTestCase
['_source' => [ ['_source' => [
'uid' => '9', 'uid' => '9',
'CType' => 'Header', // Testing items '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], $response->getData()['hits']['hits'][0],
false, false,

View file

@ -41,15 +41,10 @@ abstract class AbstractDataHandlerTest extends AbstractFunctionalTestCase
$objectManager = GeneralUtility::makeInstance(ObjectManager::class); $objectManager = GeneralUtility::makeInstance(ObjectManager::class);
$this->subject = $this->getAccessibleMock( $this->subject = $this->getMockBuilder(DataHandlerService::class)
DataHandlerService::class, ->setConstructorArgs([$objectManager->get(ConfigurationContainerInterface::class)])
[ ->setMethods(['add', 'update', 'delete'])
'add', ->getMock();
'update',
'delete',
],
[$objectManager->get(ConfigurationContainerInterface::class)]
);
// This way TYPO3 will use our mock instead of a new instance. // This way TYPO3 will use our mock instead of a new instance.
$GLOBALS['T3_VAR']['getUserObj']['&' . DataHandlerHook::class] = new DataHandlerHook($this->subject); $GLOBALS['T3_VAR']['getUserObj']['&' . DataHandlerHook::class] = new DataHandlerHook($this->subject);

View file

@ -37,6 +37,10 @@ class RelationResolverTest extends AbstractFunctionalTestCase
$objectManager = GeneralUtility::makeInstance(ObjectManager::class); $objectManager = GeneralUtility::makeInstance(ObjectManager::class);
$table = 'sys_file'; $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); $subject = $objectManager->get(TcaTableService::class, $table);
$record = BackendUtility::getRecord($table, 1); $record = BackendUtility::getRecord($table, 1);
$subject->prepareRecord($record); $subject->prepareRecord($record);
@ -109,8 +113,8 @@ class RelationResolverTest extends AbstractFunctionalTestCase
$this->assertEquals( $this->assertEquals(
[ [
'Category 2',
'Category 1', 'Category 1',
'Category 2',
], ],
$record['categories'], $record['categories'],
'Foreign mm select relation was not resolved as expected.' 'Foreign mm select relation was not resolved as expected.'

View file

@ -44,15 +44,11 @@ class TcaIndexerTest extends AbstractFunctionalTestCase
$objectManager->get(RelationResolver::class), $objectManager->get(RelationResolver::class),
$objectManager->get(ConfigurationContainerInterface::class) $objectManager->get(ConfigurationContainerInterface::class)
); );
$connection = $this->getAccessibleMock(
Elasticsearch::class, $connection = $this->getMockBuilder(Elasticsearch::class)
[ ->setMethods(['addDocuments'])
'addDocuments', ->disableOriginalConstructor()
], ->getMock();
[],
'',
false
);
$connection->expects($this->once()) $connection->expects($this->once())
->method('addDocuments') ->method('addDocuments')

View file

@ -17,11 +17,11 @@
}, },
"require" : { "require" : {
"php": ">=5.6.0", "php": ">=5.6.0",
"typo3/cms": "~6.2", "typo3/cms": "~7.6",
"ruflin/elastica": "~3.2" "ruflin/elastica": "~3.2"
}, },
"require-dev": { "require-dev": {
"phpunit/phpunit": "~4.8.0" "phpunit/phpunit": "~5.7.0"
}, },
"config": { "config": {
"optimize-autoloader": true, "optimize-autoloader": true,

View file

@ -6,7 +6,7 @@ $EM_CONF[$_EXTKEY] = [
'category' => 'be', 'category' => 'be',
'constraints' => [ 'constraints' => [
'depends' => [ 'depends' => [
'typo3' => '6.2.0-6.2.99', 'typo3' => '7.6.0-7.6.99',
'php' => '5.6.0-7.99.99' 'php' => '5.6.0-7.99.99'
], ],
'conflicts' => [], 'conflicts' => [],
@ -18,7 +18,7 @@ $EM_CONF[$_EXTKEY] = [
], ],
'state' => 'alpha', 'state' => 'alpha',
'clearCacheOnLoad' => 1, 'clearCacheOnLoad' => 1,
'author' => 'Justus Leon Moroni', 'author' => 'Daniel Siepmann',
'author_email' => 'developer@leonmrni.com', 'author_email' => 'coding@daniel-siepmann.de',
'version' => '1.0.0', 'version' => '1.0.0',
]; ];