Skip to content

Commit 3b44bd7

Browse files
authored
Merge pull request #223 from Novactive/feat-importexport-iterator-processor
Feat importexport iterator processor
2 parents 000e818 + a4bbc45 commit 3b44bd7

File tree

10 files changed

+136
-9
lines changed

10 files changed

+136
-9
lines changed

components/ImportExportBundle/bin/mdb-to-sqlite.bash

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ echo "Starting conversion in ${tmp_dir}"
1111
mkdir -p $tmp_dir
1212
mdb-schema $mdb_path sqlite > ${tmp_dir}/schema.sql
1313
mkdir -p ${tmp_dir}/sql
14-
for i in $( mdb-tables $mdb_path ); do mdb-export --quote="'" -D "%Y-%m-%d %H:%M:%S" -H -I sqlite $mdb_path $i > ${tmp_dir}/sql/$i.sql; done
14+
for i in $( mdb-tables $mdb_path ); do mdb-export -q "'" -D "%Y-%m-%d %H:%M:%S" -H -I sqlite $mdb_path $i > ${tmp_dir}/sql/$i.sql; done
1515
cat ${tmp_dir}/schema.sql | sqlite3 $sqlite_path
1616
for f in ${tmp_dir}/sql/* ; do (echo 'BEGIN;'; cat $f; echo 'COMMIT;') | sqlite3 $sqlite_path; done
1717
rm -rf $tmp_dir

components/ImportExportBundle/src/bundle/Resources/config/workflow/component.yaml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,3 +16,9 @@ services:
1616
tags:
1717
- { name: almaviacx.import_export.component, alias: processor.aggregator}
1818

19+
AlmaviaCX\Bundle\IbexaImportExport\Processor\Iterator\IteratorProcessor:
20+
arguments:
21+
$sourceResolver: '@AlmaviaCX\Bundle\IbexaImportExport\Item\Transformer\SourceResolver'
22+
tags:
23+
- { name: almaviacx.import_export.component, alias: processor.iterator}
24+

components/ImportExportBundle/src/bundle/Resources/views/themes/admin/import_export/job/view.html.twig

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@
7070
] %}
7171

7272
{% set information_headline_items %}
73-
{% if job.status != 3 %}
73+
{% if job.isRunning() %}
7474
<a
7575
href="{{ path('import_export.job.cancel', {'id': job.id}) }}"
7676
class="btn ibexa-btn ibexa-btn--ghost ibexa-btn--small"

components/ImportExportBundle/src/lib/Component/ComponentBuilder.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ public function __invoke(
2727
if ($runtimeProcessConfiguration) {
2828
$options->merge($runtimeProcessConfiguration);
2929
}
30-
$options->replaceComponentReferences($this);
30+
$options->replaceComponentReferences($this, $runtimeProcessConfiguration);
3131
$component->setOptions(
3232
$options
3333
);

components/ImportExportBundle/src/lib/Component/ComponentOptions.php

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -86,8 +86,11 @@ public function merge(ComponentOptions $overrideOptions): ComponentOptions
8686

8787
/**
8888
* @param callable(ComponentReference $componentReference): ComponentInterface $buildComponentCallback
89+
* @param ?ComponentOptions $runtimeProcessConfiguration
8990
*/
90-
public function replaceComponentReferences($buildComponentCallback): void
91-
{
91+
public function replaceComponentReferences(
92+
$buildComponentCallback,
93+
?ComponentOptions $runtimeProcessConfiguration = null
94+
): void {
9295
}
9396
}

components/ImportExportBundle/src/lib/Item/ValueTransformer/Utils/SlugTransformer.php

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,11 +18,18 @@ public function __construct(SlugConverter $slugConverter)
1818

1919
/**
2020
* @param string $value
21-
*
22-
* @return string
2321
*/
2422
public function transform($value, array $options = [])
2523
{
24+
if (is_array($value)) {
25+
$values = [];
26+
foreach ($value as $string) {
27+
$values[] = $this->slugConverter->convert($string);
28+
}
29+
30+
return $values;
31+
}
32+
2633
return $this->slugConverter->convert($value);
2734
}
2835
}

components/ImportExportBundle/src/lib/Job/Job.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -301,4 +301,9 @@ public function reset(): void
301301
$this->totalItemsCount = 0;
302302
$this->processedItemsCount = 0;
303303
}
304+
305+
public function isRunning(): bool
306+
{
307+
return self::STATUS_RUNNING === $this->status;
308+
}
304309
}

components/ImportExportBundle/src/lib/Processor/Aggregator/ProcessorAggregatorOptions.php

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,10 @@ public function merge(ComponentOptions $overrideOptions): ComponentOptions
2727
/**
2828
* {@inheritDoc}
2929
*/
30-
public function replaceComponentReferences($buildComponentCallback): void
31-
{
30+
public function replaceComponentReferences(
31+
$buildComponentCallback,
32+
?ComponentOptions $runtimeProcessConfiguration = null
33+
): void {
3234
foreach ($this->processors as $key => $processor) {
3335
$this->processors[$key] = call_user_func(
3436
$buildComponentCallback,
Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace AlmaviaCX\Bundle\IbexaImportExport\Processor\Iterator;
6+
7+
use AlmaviaCX\Bundle\IbexaImportExport\Item\Transformer\SourceResolver;
8+
use AlmaviaCX\Bundle\IbexaImportExport\Monolog\WorkflowLoggerInterface;
9+
use AlmaviaCX\Bundle\IbexaImportExport\Processor\AbstractProcessor;
10+
use AlmaviaCX\Bundle\IbexaImportExport\Processor\ProcessorInterface;
11+
use Symfony\Component\Translation\TranslatableMessage;
12+
13+
class IteratorProcessor extends AbstractProcessor implements ProcessorInterface
14+
{
15+
protected SourceResolver $sourceResolver;
16+
17+
public function __construct(
18+
SourceResolver $sourceResolver
19+
) {
20+
$this->sourceResolver = $sourceResolver;
21+
}
22+
23+
public function processItem($item)
24+
{
25+
/** @var ProcessorInterface $processor */
26+
$processor = $this->getOption('processor', []);
27+
$source = $this->getOption('value', []);
28+
29+
$values = ($this->sourceResolver)($source, $item);
30+
if (!is_array($values)) {
31+
$values = [$values];
32+
}
33+
34+
foreach ($values as $value) {
35+
($processor)(
36+
[
37+
'iteration_value' => $value,
38+
'item' => $item,
39+
]
40+
);
41+
}
42+
43+
return $item;
44+
}
45+
46+
public static function getName()
47+
{
48+
return new TranslatableMessage(/* @Desc("Iterator") */ 'processor.iterator.name');
49+
}
50+
51+
public static function getOptionsType(): ?string
52+
{
53+
return IteratorProcessorOptions::class;
54+
}
55+
56+
public function setLogger(WorkflowLoggerInterface $logger): void
57+
{
58+
parent::setLogger($logger);
59+
$processor = $this->getOption('processor', []);
60+
$processor->setLogger($logger);
61+
}
62+
}
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace AlmaviaCX\Bundle\IbexaImportExport\Processor\Iterator;
6+
7+
use AlmaviaCX\Bundle\IbexaImportExport\Component\ComponentOptions;
8+
use AlmaviaCX\Bundle\IbexaImportExport\Component\ComponentReference;
9+
use AlmaviaCX\Bundle\IbexaImportExport\Processor\ProcessorInterface;
10+
use AlmaviaCX\Bundle\IbexaImportExport\Processor\ProcessorOptions;
11+
12+
/**
13+
* @property $value string|\AlmaviaCX\Bundle\IbexaImportExport\Item\Transformer\Source
14+
*/
15+
class IteratorProcessorOptions extends ProcessorOptions
16+
{
17+
protected ComponentReference|ProcessorInterface $processor;
18+
19+
/** @var string|\AlmaviaCX\Bundle\IbexaImportExport\Item\Transformer\Source */
20+
protected $value;
21+
22+
public function setProcessor(string $class, ?ComponentOptions $options = null): void
23+
{
24+
$this->processor = new ComponentReference($class, $options);
25+
}
26+
27+
/**
28+
* @param callable $buildComponentCallback
29+
* @param \AlmaviaCX\Bundle\IbexaImportExport\Reader\InputAwareReaderOptions|null $runtimeProcessConfiguration
30+
*/
31+
public function replaceComponentReferences(
32+
$buildComponentCallback,
33+
?ComponentOptions $runtimeProcessConfiguration = null
34+
): void {
35+
$options = $runtimeProcessConfiguration->processor ?? null;
36+
$this->processor = call_user_func(
37+
$buildComponentCallback,
38+
$this->processor,
39+
$options
40+
);
41+
}
42+
}

0 commit comments

Comments
 (0)