mirror of
https://github.com/Codappix/search_core.git
synced 2024-11-01 03:16:11 +01:00
Merge pull request #144 from Codappix/feature/improve-copyto-dataprocessor
FEATURE: Allow to copy a single field with CopyToProcessor
This commit is contained in:
commit
e18001e286
3 changed files with 32 additions and 5 deletions
|
@ -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;
|
||||||
}
|
}
|
||||||
|
|
|
@ -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
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -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',
|
||||||
|
],
|
||||||
|
],
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue