Merge pull request #144 from Codappix/feature/improve-copyto-dataprocessor

FEATURE: Allow to copy a single field with CopyToProcessor
This commit is contained in:
Daniel Siepmann 2018-03-22 13:37:53 +01:00 committed by GitHub
commit e18001e286
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 32 additions and 5 deletions

View file

@ -27,11 +27,21 @@ class CopyToProcessor implements ProcessorInterface
{ {
public function processData(array $record, array $configuration) : array public function processData(array $record, array $configuration) : array
{ {
$all = []; $target = [];
$this->addArray($all, $record); $from = $record;
$all = array_filter($all); if (isset($configuration['from'])) {
$record[$configuration['to']] = implode(PHP_EOL, $all); $from = $record[$configuration['from']];
}
if (is_array($from)) {
$this->addArray($target, $from);
} else {
$target[] = (string) $from;
}
$target = array_filter($target);
$record[$configuration['to']] = implode(PHP_EOL, $target);
return $record; return $record;
} }

View file

@ -8,6 +8,10 @@ Possible Options:
``to`` ``to``
Defines the field to copy the values into. All values not false will be copied at the moment. Defines the field to copy the values into. All values not false will be copied at the moment.
``from``
Optional, defines the field to copy, can only be one field.
If empty, all existing fields will be copied.
Example:: Example::
plugin.tx_searchcore.settings.indexing.tt_content.dataProcessing { plugin.tx_searchcore.settings.indexing.tt_content.dataProcessing {
@ -17,7 +21,8 @@ Example::
} }
2 = Codappix\SearchCore\DataProcessing\CopyToProcessor 2 = Codappix\SearchCore\DataProcessing\CopyToProcessor
2 { 2 {
to = spellcheck from = uid
to = backup_uid
} }
} }

View file

@ -80,6 +80,18 @@ class CopyToProcessorTest extends AbstractUnitTestCase
'new_field' => 'Some content like lorem' . PHP_EOL . 'Tag 1' . PHP_EOL . 'Tag 2', 'new_field' => 'Some content like lorem' . PHP_EOL . 'Tag 1' . PHP_EOL . 'Tag 2',
], ],
], ],
'Copy single field to new field' => [
'record' => [
'field 1' => 'Some content like lorem',
],
'configuration' => [
'to' => 'new_field',
],
'expectedData' => [
'field 1' => 'Some content like lorem',
'new_field' => 'Some content like lorem',
],
],
]; ];
} }
} }