FEATURE: Allow to copy a single field with CopyToProcessor

This commit is contained in:
Daniel Siepmann 2018-03-20 15:42:34 +01:00
parent 250a187cc6
commit 372cd48471
Signed by: Daniel Siepmann
GPG key ID: 33D6629915560EF4
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
{
$all = [];
$target = [];
$this->addArray($all, $record);
$all = array_filter($all);
$record[$configuration['to']] = implode(PHP_EOL, $all);
$from = $record;
if (isset($configuration['from'])) {
$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;
}

View file

@ -8,6 +8,10 @@ Possible Options:
``to``
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::
plugin.tx_searchcore.settings.indexing.tt_content.dataProcessing {
@ -17,7 +21,8 @@ Example::
}
2 = Codappix\SearchCore\DataProcessing\CopyToProcessor
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',
],
],
'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',
],
],
];
}
}