From 2395335483c833fb22c42341b78586febe92ae2d Mon Sep 17 00:00:00 2001 From: Dominik Pfaffenbauer Date: Mon, 31 May 2021 13:00:19 +0200 Subject: [PATCH 01/65] fix: latest change in ProcessManager, change args passing --- .../ProcessManager/ExportDefinitionProcess.php | 9 +++++++-- .../ProcessManager/ImportDefinitionProcess.php | 9 +++++++-- 2 files changed, 14 insertions(+), 4 deletions(-) diff --git a/src/DataDefinitionsBundle/ProcessManager/ExportDefinitionProcess.php b/src/DataDefinitionsBundle/ProcessManager/ExportDefinitionProcess.php index 351a5762..c0c77dbc 100644 --- a/src/DataDefinitionsBundle/ProcessManager/ExportDefinitionProcess.php +++ b/src/DataDefinitionsBundle/ProcessManager/ExportDefinitionProcess.php @@ -31,8 +31,13 @@ public function run(ExecutableInterface $executable, array $params = null) $settings['params'] = (array)$params; } - $settings['command'] = sprintf('data-definitions:export -d %s -p "%s"', $settings['definition'], - addslashes(json_encode($settings['params']))); + $settings['command'] = [ + 'data-definitions:export', + '-d', + $settings['definition'], + '-p', + json_encode($settings['params']), + ]; $executable->setSettings($settings); diff --git a/src/DataDefinitionsBundle/ProcessManager/ImportDefinitionProcess.php b/src/DataDefinitionsBundle/ProcessManager/ImportDefinitionProcess.php index 960cf47d..dfcb9567 100644 --- a/src/DataDefinitionsBundle/ProcessManager/ImportDefinitionProcess.php +++ b/src/DataDefinitionsBundle/ProcessManager/ImportDefinitionProcess.php @@ -32,8 +32,13 @@ public function run(ExecutableInterface $executable, array $params = null) $params->userId = $currentUser->getId(); } - $settings['command'] = sprintf('data-definitions:import -d %s -p "%s"', $settings['definition'], - addslashes(json_encode($params))); + $settings['command'] = [ + 'data-definitions:import', + '-d', + $settings['definition'], + '-p', + json_encode($params), + ]; $executable->setSettings($settings); From 7b41ec687a7a9ed6be8a19191b2bb091d721841b Mon Sep 17 00:00:00 2001 From: Tomasz Januszewicz Date: Thu, 22 Jul 2021 16:20:07 +0200 Subject: [PATCH 02/65] Added note-in-version while products imported --- src/DataDefinitionsBundle/Importer/Importer.php | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/DataDefinitionsBundle/Importer/Importer.php b/src/DataDefinitionsBundle/Importer/Importer.php index e145c00d..d18ff6b8 100644 --- a/src/DataDefinitionsBundle/Importer/Importer.php +++ b/src/DataDefinitionsBundle/Importer/Importer.php @@ -371,9 +371,11 @@ private function importRow( } if ($shouldSave) { + $params['versionNote'] = sprintf('%s - %s', $definition->getId(), $definition->getName()); + $object->setUserModification($params['userId'] ?? 0); $object->setOmitMandatoryCheck($definition->getOmitMandatoryCheck()); - $object->save(); + $object->save($params); $this->eventDispatcher->dispatch( $definition, From 52e83cfd973414e1b8685cb8fca607c14ea01f4e Mon Sep 17 00:00:00 2001 From: Tomasz Januszewicz Date: Tue, 17 Aug 2021 20:23:25 +0200 Subject: [PATCH 03/65] Adding object persister to importer. --- docs/import/persister.md | 14 +++++++++ .../Controller/ImportDefinitionController.php | 7 +++++ .../DataDefinitionsBundle.php | 2 ++ .../PersisterRegistryCompilerPass.php | 21 +++++++++++++ .../DataDefinitionsExtension.php | 5 +++ .../Form/Type/ImportDefinitionType.php | 1 + .../Form/Type/PersisterChoiceType.php | 31 +++++++++++++++++++ .../Importer/Importer.php | 26 +++++++++++++++- .../Model/ImportDefinition.php | 15 +++++++++ .../Model/ImportDefinitionInterface.php | 10 ++++++ .../Persister/Persister.php | 20 ++++++++++++ .../Persister/PersisterInterface.php | 13 ++++++++ .../Resources/config/services.yml | 12 +++++++ .../Resources/config/services/forms.yml | 5 +++ .../public/pimcore/js/import/item.js | 15 +++++++++ .../public/pimcore/js/import/panel.js | 17 +++++++++- .../Resources/translations/admin.en.yml | 1 + 17 files changed, 213 insertions(+), 2 deletions(-) create mode 100644 docs/import/persister.md create mode 100644 src/DataDefinitionsBundle/DependencyInjection/Compiler/PersisterRegistryCompilerPass.php create mode 100644 src/DataDefinitionsBundle/Form/Type/PersisterChoiceType.php create mode 100644 src/DataDefinitionsBundle/Persister/Persister.php create mode 100644 src/DataDefinitionsBundle/Persister/PersisterInterface.php diff --git a/docs/import/persister.md b/docs/import/persister.md new file mode 100644 index 00000000..37b7f464 --- /dev/null +++ b/docs/import/persister.md @@ -0,0 +1,14 @@ +## Persister +A persister takes care about the save process. It basically saves objects. Following Persisters are currently available: + +- `Persister` saves objects + +To create your own persister you need to implement `Wvision\Bundle\DataDefinitionsBundle\Persister\PersisterInterface` +and add a new service: + +```yml +acme_bundle.data_definitions.my_persister: + class: AcmeBundle\DataDefinitions\MyPersister + tags: + - { name: data_definitions.persister, type: my-persister } +``` \ No newline at end of file diff --git a/src/DataDefinitionsBundle/Controller/ImportDefinitionController.php b/src/DataDefinitionsBundle/Controller/ImportDefinitionController.php index 16c3019e..0e69864a 100644 --- a/src/DataDefinitionsBundle/Controller/ImportDefinitionController.php +++ b/src/DataDefinitionsBundle/Controller/ImportDefinitionController.php @@ -41,6 +41,7 @@ public function getConfigAction(): JsonResponse $setters = $this->getConfigSetters(); $filters = $this->getConfigFilters(); $runners = $this->getConfigRunners(); + $persisters = $this->getConfigPersisters(); $importRuleConditions = $this->getImportRuleConditions(); $importRuleActions = $this->getImportRuleActions(); @@ -52,6 +53,7 @@ public function getConfigAction(): JsonResponse 'setter' => array_keys($setters), 'filters' => array_keys($filters), 'runner' => array_keys($runners), + 'persister' => array_keys($persisters), 'import_rules' => [ 'conditions' => array_keys($importRuleConditions), 'actions' => array_keys($importRuleActions) @@ -290,6 +292,11 @@ protected function getConfigRunners(): array return $this->container->getParameter('data_definitions.runners'); } + protected function getConfigPersisters(): array + { + return $this->container->getParameter('data_definitions.persisters'); + } + protected function getImportRuleConditions(): array { return $this->container->getParameter('data_definitions.import_rule.conditions'); diff --git a/src/DataDefinitionsBundle/DataDefinitionsBundle.php b/src/DataDefinitionsBundle/DataDefinitionsBundle.php index df2c8ab7..8b217f41 100644 --- a/src/DataDefinitionsBundle/DataDefinitionsBundle.php +++ b/src/DataDefinitionsBundle/DataDefinitionsBundle.php @@ -37,6 +37,7 @@ use Wvision\Bundle\DataDefinitionsBundle\DependencyInjection\Compiler\ImportRuleConditionPass; use Wvision\Bundle\DataDefinitionsBundle\DependencyInjection\Compiler\InterpreterRegistryCompilerPass; use Wvision\Bundle\DataDefinitionsBundle\DependencyInjection\Compiler\LoaderRegistryCompilerPass; +use Wvision\Bundle\DataDefinitionsBundle\DependencyInjection\Compiler\PersisterRegistryCompilerPass; use Wvision\Bundle\DataDefinitionsBundle\DependencyInjection\Compiler\ProviderRegistryCompilerPass; use Wvision\Bundle\DataDefinitionsBundle\DependencyInjection\Compiler\RunnerRegistryCompilerPass; use Wvision\Bundle\DataDefinitionsBundle\DependencyInjection\Compiler\SetterRegistryCompilerPass; @@ -76,6 +77,7 @@ public function build(ContainerBuilder $builder): void $builder->addCompilerPass(new ExportRunnerRegistryCompilerPass()); $builder->addCompilerPass(new ImportRuleConditionPass()); $builder->addCompilerPass(new ImportRuleActionPass()); + $builder->addCompilerPass(new PersisterRegistryCompilerPass()); } public function getVersion(): string diff --git a/src/DataDefinitionsBundle/DependencyInjection/Compiler/PersisterRegistryCompilerPass.php b/src/DataDefinitionsBundle/DependencyInjection/Compiler/PersisterRegistryCompilerPass.php new file mode 100644 index 00000000..bd42ff99 --- /dev/null +++ b/src/DataDefinitionsBundle/DependencyInjection/Compiler/PersisterRegistryCompilerPass.php @@ -0,0 +1,21 @@ +registerForAutoconfiguration(SetterInterface::class) ->addTag(SetterRegistryCompilerPass::SETTER_TAG); + $container + ->registerForAutoconfiguration(PersisterInterface::class) + ->addTag(PersisterRegistryCompilerPass::PERSISTER_TAG); } } diff --git a/src/DataDefinitionsBundle/Form/Type/ImportDefinitionType.php b/src/DataDefinitionsBundle/Form/Type/ImportDefinitionType.php index 342ada00..9f452136 100644 --- a/src/DataDefinitionsBundle/Form/Type/ImportDefinitionType.php +++ b/src/DataDefinitionsBundle/Form/Type/ImportDefinitionType.php @@ -49,6 +49,7 @@ public function buildForm(FormBuilderInterface $builder, array $options): void ->add('cleaner', CleanerChoiceType::class) ->add('filter', FilterChoiceType::class) ->add('runner', RunnerChoiceType::class) + ->add('persister', PersisterChoiceType::class) ->add('name', TextType::class) ->add('objectPath', TextType::class) ->add('key', TextType::class) diff --git a/src/DataDefinitionsBundle/Form/Type/PersisterChoiceType.php b/src/DataDefinitionsBundle/Form/Type/PersisterChoiceType.php new file mode 100644 index 00000000..08560172 --- /dev/null +++ b/src/DataDefinitionsBundle/Form/Type/PersisterChoiceType.php @@ -0,0 +1,31 @@ +persisters = $persisters; + } + + public function configureOptions(OptionsResolver $resolver): void + { + $resolver->setDefaults([ + 'choices' => array_flip($this->persisters), + ]); + } + + public function getParent(): ?string + { + return ChoiceType::class; + } +} diff --git a/src/DataDefinitionsBundle/Importer/Importer.php b/src/DataDefinitionsBundle/Importer/Importer.php index d18ff6b8..8b0601f6 100644 --- a/src/DataDefinitionsBundle/Importer/Importer.php +++ b/src/DataDefinitionsBundle/Importer/Importer.php @@ -44,6 +44,7 @@ use Wvision\Bundle\DataDefinitionsBundle\Provider\ImportDataSet; use Wvision\Bundle\DataDefinitionsBundle\Provider\ImportDataSetInterface; use Wvision\Bundle\DataDefinitionsBundle\Provider\ImportProviderInterface; +use Wvision\Bundle\DataDefinitionsBundle\Persister\PersisterInterface; use Wvision\Bundle\DataDefinitionsBundle\Runner\RunnerInterface; use Wvision\Bundle\DataDefinitionsBundle\Runner\SaveRunnerInterface; use Wvision\Bundle\DataDefinitionsBundle\Runner\SetterRunnerInterface; @@ -58,6 +59,7 @@ final class Importer implements ImporterInterface private ServiceRegistryInterface $setterRegistry; private ServiceRegistryInterface $cleanerRegistry; private ServiceRegistryInterface $loaderRegistry; + private ServiceRegistryInterface $persisterRegistry; private EventDispatcherInterface $eventDispatcher; private LoggerInterface $logger; private Factory $modelFactory; @@ -72,6 +74,7 @@ public function __construct( ServiceRegistryInterface $setterRegistry, ServiceRegistryInterface $cleanerRegistry, ServiceRegistryInterface $loaderRegistry, + ServiceRegistryInterface $persisterRegistry, EventDispatcherInterface $eventDispatcher, LoggerInterface $logger, Factory $modelFactory, @@ -84,6 +87,7 @@ public function __construct( $this->setterRegistry = $setterRegistry; $this->cleanerRegistry = $cleanerRegistry; $this->loaderRegistry = $loaderRegistry; + $this->persisterRegistry = $persisterRegistry; $this->eventDispatcher = $eventDispatcher; $this->logger = $logger; $this->modelFactory = $modelFactory; @@ -375,7 +379,8 @@ private function importRow( $object->setUserModification($params['userId'] ?? 0); $object->setOmitMandatoryCheck($definition->getOmitMandatoryCheck()); - $object->save($params); + + $this->saveObject($object, $definition, $params); $this->eventDispatcher->dispatch( $definition, @@ -578,4 +583,23 @@ private function createKey(ImportDefinitionInterface $definition, array $data): return $definition->getKey(); } + + private function saveObject(Concrete $object, ImportDefinitionInterface $definition, array $params): void + { + $persister = null; + + if ($definition->getPersister()) { + $persister = $this->persisterRegistry->get($definition->getPersister()); + } + + if (!$persister instanceof PersisterInterface) { + $persister = $this->persisterRegistry->get('persister'); + } + + if ($persister instanceof LoggerAwareInterface) { + $persister->setLogger($this->logger); + } + + $persister->persist($object, $definition, $params); + } } diff --git a/src/DataDefinitionsBundle/Model/ImportDefinition.php b/src/DataDefinitionsBundle/Model/ImportDefinition.php index 55e70a88..438f43ba 100644 --- a/src/DataDefinitionsBundle/Model/ImportDefinition.php +++ b/src/DataDefinitionsBundle/Model/ImportDefinition.php @@ -78,6 +78,11 @@ class ImportDefinition extends AbstractDataDefinition implements ImportDefinitio */ public $forceLoadObject = false; + /** + * @var string + */ + public $persister; + public static function getById($id) { $definitionEntry = new ImportDefinition(); @@ -210,4 +215,14 @@ public function setForceLoadObject($forceLoadObject) { $this->forceLoadObject = $forceLoadObject; } + + public function getPersister() + { + return $this->persister; + } + + public function setPersister($persister) + { + $this->persister = $persister; + } } diff --git a/src/DataDefinitionsBundle/Model/ImportDefinitionInterface.php b/src/DataDefinitionsBundle/Model/ImportDefinitionInterface.php index d6124256..814fd49c 100644 --- a/src/DataDefinitionsBundle/Model/ImportDefinitionInterface.php +++ b/src/DataDefinitionsBundle/Model/ImportDefinitionInterface.php @@ -137,4 +137,14 @@ public function getCreateVersion(); * @param boolean $createVersion */ public function setCreateVersion($createVersion); + + /** + * @return mixed + */ + public function getPersister(); + + /** + * @param string $persister + */ + public function setPersister($persister); } diff --git a/src/DataDefinitionsBundle/Persister/Persister.php b/src/DataDefinitionsBundle/Persister/Persister.php new file mode 100644 index 00000000..81ce3c18 --- /dev/null +++ b/src/DataDefinitionsBundle/Persister/Persister.php @@ -0,0 +1,20 @@ +save(); + } +} diff --git a/src/DataDefinitionsBundle/Persister/PersisterInterface.php b/src/DataDefinitionsBundle/Persister/PersisterInterface.php new file mode 100644 index 00000000..28965240 --- /dev/null +++ b/src/DataDefinitionsBundle/Persister/PersisterInterface.php @@ -0,0 +1,13 @@ + Date: Wed, 18 Aug 2021 11:21:45 +0200 Subject: [PATCH 04/65] Revert accidental delete. --- .../Resources/public/pimcore/js/import/panel.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/DataDefinitionsBundle/Resources/public/pimcore/js/import/panel.js b/src/DataDefinitionsBundle/Resources/public/pimcore/js/import/panel.js index 7ab6bbf9..0943b337 100755 --- a/src/DataDefinitionsBundle/Resources/public/pimcore/js/import/panel.js +++ b/src/DataDefinitionsBundle/Resources/public/pimcore/js/import/panel.js @@ -168,7 +168,7 @@ pimcore.plugin.datadefinitions.import.panel = Class.create(coreshop.resource.pan idProperty: 'cleaner' }); - pimcore.globalmanager.add('importdefinitions_s', cleanersStore); + pimcore.globalmanager.add('importdefinitions_cleaners', cleanersStore); pimcore.globalmanager.add('data_definitions_cleaners', cleanersStore); var interpretersStore = new Ext.data.ArrayStore({ From 29b3eaae9d089b295a5c96294889c67c8b881903 Mon Sep 17 00:00:00 2001 From: Tomasz Januszewicz Date: Wed, 18 Aug 2021 12:08:16 +0200 Subject: [PATCH 05/65] Adding missing newline at the end of file. --- src/DataDefinitionsBundle/Resources/config/services.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/DataDefinitionsBundle/Resources/config/services.yml b/src/DataDefinitionsBundle/Resources/config/services.yml index 873169b8..57944125 100644 --- a/src/DataDefinitionsBundle/Resources/config/services.yml +++ b/src/DataDefinitionsBundle/Resources/config/services.yml @@ -355,4 +355,4 @@ services: ### PERSISTER Wvision\Bundle\DataDefinitionsBundle\Persister\Persister: tags: - - { name: data_definitions.persister, type: persister } \ No newline at end of file + - { name: data_definitions.persister, type: persister } From 637e7aac821595ad1ca4424047d2dbc2db6aba28 Mon Sep 17 00:00:00 2001 From: Christof Opresnik Date: Thu, 23 Sep 2021 15:53:06 +0200 Subject: [PATCH 06/65] Checks if parameters are set because of strict_types directive --- src/DataDefinitionsBundle/Fetcher/ObjectsFetcher.php | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/DataDefinitionsBundle/Fetcher/ObjectsFetcher.php b/src/DataDefinitionsBundle/Fetcher/ObjectsFetcher.php index 14aa78c6..1fe716a0 100644 --- a/src/DataDefinitionsBundle/Fetcher/ObjectsFetcher.php +++ b/src/DataDefinitionsBundle/Fetcher/ObjectsFetcher.php @@ -61,21 +61,21 @@ private function getClassListing(ExportDefinitionInterface $definition, array $p } } - if ($params['query']) { + if (isset($params['query'])) { $query = $this->filterQueryParam($params['query']); if (!empty($query)) { $conditionFilters[] = 'oo_id IN (SELECT id FROM search_backend_data WHERE MATCH (`data`,`properties`) AGAINST (' . $list->quote($query) . ' IN BOOLEAN MODE))'; } } - if ($params['only_direct_children'] == 'true' && null !== $rootNode) { + if (isset($params['only_direct_children']) && $params['only_direct_children'] == 'true' && null !== $rootNode) { $conditionFilters[] = 'o_parentId = ' . $rootNode->getId(); } - if ($params['condition']) { + if (isset($params['condition'])) { $conditionFilters[] = '(' . $params['condition'] . ')'; } - if ($params['ids']) { + if (isset($params['ids'])) { $quotedIds = []; foreach ($params['ids'] as $id) { $quotedIds[] = $list->quote($id); From c6657c324efb5e7ca4440e6b7b92469195ed289a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Dalibor=20Karlovi=C4=87?= Date: Wed, 27 Oct 2021 17:07:32 +0200 Subject: [PATCH 07/65] fix: progress updates getting dispatched too often --- .../AbstractProcessManagerListener.php | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/src/DataDefinitionsBundle/ProcessManager/AbstractProcessManagerListener.php b/src/DataDefinitionsBundle/ProcessManager/AbstractProcessManagerListener.php index 2c165880..171f2c0d 100644 --- a/src/DataDefinitionsBundle/ProcessManager/AbstractProcessManagerListener.php +++ b/src/DataDefinitionsBundle/ProcessManager/AbstractProcessManagerListener.php @@ -33,6 +33,8 @@ abstract class AbstractProcessManagerListener public const PROCESS_NAME = 'Data Definitions'; + private const PROCESS_PROGRESS_THROTTLE_SECONDS = 5; + /** * @var ProcessInterface */ @@ -58,6 +60,11 @@ abstract class AbstractProcessManagerListener */ protected $eventDispatcher; + /** + * @var null|\DateTimeInterface + */ + protected $lastProgressAt; + /** * AbstractProcessManagerListener constructor. * @param FactoryInterface $processFactory @@ -125,6 +132,16 @@ public function onProgressEvent() : void $this->process = $this->repository->find($this->process->getId()); } + $now = new \DateTimeImmutable(); + if ($this->lastProgressAt instanceof \DateTimeInterface) { + $diff = $now->getTimestamp() - $this->lastProgressAt->getTimestamp(); + + if (self::PROCESS_PROGRESS_THROTTLE_SECONDS > $diff) { + return; + } + } + $this->lastProgressAt = $now; + if ($this->process->getStatus() === ProcessManagerBundle::STATUS_STOPPING) { $this->eventDispatcher->dispatch('data_definitions.stop'); $this->process->setStatus(ProcessManagerBundle::STATUS_STOPPED); From d91ed1550454aaaf30bc01684132d997ed825c80 Mon Sep 17 00:00:00 2001 From: Krzysztof Marczak Date: Fri, 19 Nov 2021 15:06:41 +0100 Subject: [PATCH 08/65] Update setter.md Bugfix for tremendous error in documentation. Poor junior developers was getting confiused. This is not acceptable at all. --- docs/import/setter.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/import/setter.md b/docs/import/setter.md index 4580af84..7a473c71 100644 --- a/docs/import/setter.md +++ b/docs/import/setter.md @@ -13,7 +13,7 @@ Of course, you can also implement your own Setters. Its basically the same as wi Todo that, you need to implement the interface ```Wvision\Bundle\DataDefinitionsBundle\Setter\SetterInterface``` and create a service ```yml -acme_bundle.data_definitions.my_interpter: +acme_bundle.data_definitions.my_setter: class: AcmeBundle\DataDefinitions\MySetter tags: - { name: data_definitions.setter, type: mysetter, form-type: Wvision\Bundle\DataDefinitionsBundle\Form\Type\NoConfigurationType } From ba62fa4b806ba2cfeddee57beb4f7e6f05b228f2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Dalibor=20Karlovi=C4=87?= Date: Wed, 22 Dec 2021 15:04:00 +0100 Subject: [PATCH 09/65] fix: properly account for progress steps when throttling status --- .../AbstractProcessManagerListener.php | 13 +++++++++++-- .../ProcessManager/ProcessManagerExportListener.php | 1 + 2 files changed, 12 insertions(+), 2 deletions(-) diff --git a/src/DataDefinitionsBundle/ProcessManager/AbstractProcessManagerListener.php b/src/DataDefinitionsBundle/ProcessManager/AbstractProcessManagerListener.php index 171f2c0d..73565279 100644 --- a/src/DataDefinitionsBundle/ProcessManager/AbstractProcessManagerListener.php +++ b/src/DataDefinitionsBundle/ProcessManager/AbstractProcessManagerListener.php @@ -65,6 +65,11 @@ abstract class AbstractProcessManagerListener */ protected $lastProgressAt; + /** + * @var int + */ + protected $lastStepsCount = 0; + /** * AbstractProcessManagerListener constructor. * @param FactoryInterface $processFactory @@ -125,7 +130,7 @@ public function onTotalEvent(DefinitionEventInterface $event) : void /** * @return void */ - public function onProgressEvent() : void + public function onProgressEvent(DefinitionEventInterface $event) : void { if ($this->process) { if ($this->process->getStoppable()) { @@ -133,6 +138,7 @@ public function onProgressEvent() : void } $now = new \DateTimeImmutable(); + $this->lastStepsCount++; if ($this->lastProgressAt instanceof \DateTimeInterface) { $diff = $now->getTimestamp() - $this->lastProgressAt->getTimestamp(); @@ -147,9 +153,11 @@ public function onProgressEvent() : void $this->process->setStatus(ProcessManagerBundle::STATUS_STOPPED); } - $this->process->progress(); + $this->process->progress($this->lastStepsCount); $this->process->save(); + $this->lastStepsCount = 0; + $this->processLogger->info($this->process, ImportDefinitionsReport::EVENT_PROGRESS); } } @@ -177,6 +185,7 @@ public function onFinishedEvent(DefinitionEventInterface $event) : void { if ($this->process) { if ($this->process->getStatus() === ProcessManagerBundle::STATUS_RUNNING) { + $this->process->setProgress($this->process->getTotal()); $this->process->setStatus(ProcessManagerBundle::STATUS_COMPLETED); $this->process->save(); } diff --git a/src/DataDefinitionsBundle/ProcessManager/ProcessManagerExportListener.php b/src/DataDefinitionsBundle/ProcessManager/ProcessManagerExportListener.php index e5dfd2cb..57a11f9e 100644 --- a/src/DataDefinitionsBundle/ProcessManager/ProcessManagerExportListener.php +++ b/src/DataDefinitionsBundle/ProcessManager/ProcessManagerExportListener.php @@ -42,6 +42,7 @@ public function onFinishedEvent(DefinitionEventInterface $event) : void { if (null !== $this->process) { if ($this->process->getStatus() == ProcessManagerBundle::STATUS_RUNNING) { + $this->process->setProgress($this->process->getTotal()); $this->process->setStatus(ProcessManagerBundle::STATUS_COMPLETED); $this->process->save(); } From 838042b9d4f03b571bbac87a5213e48a6e192902 Mon Sep 17 00:00:00 2001 From: Damijan Kozic Date: Wed, 26 Jan 2022 17:00:09 +0100 Subject: [PATCH 10/65] fixes for some uninitialized typed properties --- src/DataDefinitionsBundle/Model/DataSetAwareInterface.php | 4 ++-- src/DataDefinitionsBundle/Model/DataSetAwareTrait.php | 8 ++++---- .../ProcessManager/ArtifactProviderTrait.php | 2 +- src/DataDefinitionsBundle/Provider/ExcelProvider.php | 6 +++--- 4 files changed, 10 insertions(+), 10 deletions(-) diff --git a/src/DataDefinitionsBundle/Model/DataSetAwareInterface.php b/src/DataDefinitionsBundle/Model/DataSetAwareInterface.php index 84f93d13..bad56fe0 100644 --- a/src/DataDefinitionsBundle/Model/DataSetAwareInterface.php +++ b/src/DataDefinitionsBundle/Model/DataSetAwareInterface.php @@ -20,7 +20,7 @@ interface DataSetAwareInterface { - public function getDataSet(): ImportDataSetInterface; + public function getDataSet(): ?ImportDataSetInterface; - public function setDataSet(ImportDataSetInterface $dataSet): void; + public function setDataSet(?ImportDataSetInterface $dataSet): void; } diff --git a/src/DataDefinitionsBundle/Model/DataSetAwareTrait.php b/src/DataDefinitionsBundle/Model/DataSetAwareTrait.php index 139a5a5a..930f2e10 100644 --- a/src/DataDefinitionsBundle/Model/DataSetAwareTrait.php +++ b/src/DataDefinitionsBundle/Model/DataSetAwareTrait.php @@ -20,14 +20,14 @@ trait DataSetAwareTrait { - protected ImportDataSetInterface $dataSet; + protected ?ImportDataSetInterface $dataSet = null; - public function getDataSet(): ImportDataSetInterface + public function getDataSet(): ?ImportDataSetInterface { - return $this->dataSet; + return $this->dataSet ?? null; } - public function setDataSet(ImportDataSetInterface $dataSet): void + public function setDataSet(?ImportDataSetInterface $dataSet): void { $this->dataSet = $dataSet; } diff --git a/src/DataDefinitionsBundle/ProcessManager/ArtifactProviderTrait.php b/src/DataDefinitionsBundle/ProcessManager/ArtifactProviderTrait.php index f5c1d7a0..177e3536 100644 --- a/src/DataDefinitionsBundle/ProcessManager/ArtifactProviderTrait.php +++ b/src/DataDefinitionsBundle/ProcessManager/ArtifactProviderTrait.php @@ -23,7 +23,7 @@ trait ArtifactProviderTrait { public function generateArtifact($configuration, ExportDefinitionInterface $definition, $params): ?Asset { - if (!$params['artifact']) { + if (!isset($params['artifact'])) { return null; } diff --git a/src/DataDefinitionsBundle/Provider/ExcelProvider.php b/src/DataDefinitionsBundle/Provider/ExcelProvider.php index 19fd1bd1..276b1209 100644 --- a/src/DataDefinitionsBundle/Provider/ExcelProvider.php +++ b/src/DataDefinitionsBundle/Provider/ExcelProvider.php @@ -108,7 +108,7 @@ public function getData(array $configuration, ImportDefinitionInterface $definit public function addExportData(array $data, array $configuration, ExportDefinitionInterface $definition, array $params): void { $headers = null; - if (null === $this->writer) { + if (!isset($this->writer)) { $headers = array_keys($data); } $writer = $this->getWriter(); @@ -150,7 +150,7 @@ private function createReader($path): ReaderInterface private function getWriter(): WriterInterface { - if (null === $this->writer) { + if (!isset($this->writer)) { $this->writer = $this->getXlsxWriter(); $this->writer->openToFile($this->getExportPath()); } @@ -160,7 +160,7 @@ private function getWriter(): WriterInterface private function getExportPath(): string { - if (null === $this->exportPath) { + if (!isset($this->exportPath)) { $this->exportPath = tempnam(sys_get_temp_dir(), 'excel_export_provider'); } From 4fe75afc7cc89cbf3364cc078ab06670c5d25eb2 Mon Sep 17 00:00:00 2001 From: Dominik Pfaffenbauer Date: Wed, 26 Jan 2022 17:40:07 +0100 Subject: [PATCH 11/65] update tests --- .github/workflows/behat.yml | 48 ++++++++++++++++---- .github/workflows/static.yml | 87 +++++++++++++++++++----------------- 2 files changed, 86 insertions(+), 49 deletions(-) diff --git a/.github/workflows/behat.yml b/.github/workflows/behat.yml index 6f3b7aed..584188d6 100644 --- a/.github/workflows/behat.yml +++ b/.github/workflows/behat.yml @@ -10,10 +10,21 @@ jobs: runs-on: ubuntu-latest env: APP_ENV: "test" + IM_SKIP_DB_SETUP: "1" + PIMCORE_INSTALL_ADMIN_USERNAME: "admin" + PIMCORE_INSTALL_ADMIN_PASSWORD: "admin" + PIMCORE_INSTALL_MYSQL_HOST_SOCKET: "127.0.0.1" + PIMCORE_INSTALL_MYSQL_USERNAME: "root" + PIMCORE_INSTALL_MYSQL_PASSWORD: "root" + PIMCORE_INSTALL_MYSQL_DATABASE: "data_defs_test" + PIMCORE_INSTALL_MYSQL_PORT: "3306" + PIMCORE_KERNEL_CLASS: 'Kernel' + PIMCORE_CLASS_DIRECTORY: 'var/tmp/behat/var/classes' + PIMCORE_WRITE_TARGET_STATICROUTES: 'settings-store' PIMCORE_TEST_DB_DSN: "mysql://root:root@127.0.0.1:3306/data_defs_test" services: mysql: - image: mysql:5.7 + image: mysql:8.0 env: MYSQL_ROOT_PASSWORD: root MYSQL_DATABASE: data_defs_test @@ -23,8 +34,9 @@ jobs: name: "${{ matrix.pimcore }}, PHP ${{ matrix.php }}" strategy: matrix: - php: [8.0] - pimcore: [^10.0, ^10.1] + php: [ 8.0, 8.1 ] + pimcore: [ ^10.2, 10.x-dev ] + dependencies: [ highest, lowest ] steps: - uses: actions/checkout@v2 @@ -38,11 +50,9 @@ jobs: - name: Check PHP Version run: php -v - - name: Verify MySQL connection + - name: Setup DB run: | - mysql --version - sudo apt-get install -y mysql-client - mysql --host 127.0.0.1 --port ${{ job.services.mysql.ports['3306'] }} -uroot -proot -e "SHOW DATABASES" + mysql --host 127.0.0.1 --port ${{ job.services.database.ports['3306'] }} -uroot -proot -e "CREATE DATABASE coreshop_test CHARSET=utf8mb4;" - name: Get composer cache directory id: composer-cache @@ -55,10 +65,24 @@ jobs: key: ${{ runner.os }}-composer-${{ hashFiles('**/composer.json') }} restore-keys: ${{ runner.os }}-composer- - - name: Composer install + - name: Cache composer dependencies + uses: actions/cache@v1 + with: + path: ${{ steps.composer-cache.outputs.dir }} + key: ${{ runner.os }}-composer-${{ hashFiles('**/composer.json') }} + restore-keys: ${{ runner.os }}-composer- + + - if: matrix.dependencies == 'highest' + name: Install dependencies highest + run: | + composer req pimcore/pimcore:${{ matrix.pimcore }} --no-interaction --no-scripts --no-update + composer update --no-progress --prefer-dist --optimize-autoloader + + - if: matrix.dependencies == 'lowest' + name: Install dependencies lowest run: | composer req pimcore/pimcore:${{ matrix.pimcore }} --no-interaction --no-scripts --no-update - composer install --no-progress --no-suggest --prefer-dist --optimize-autoloader + composer update --no-progress --prefer-dist --optimize-autoloader --prefer-lowest - name: Cache clear run: bin/console cache:clear @@ -66,5 +90,11 @@ jobs: - name: Assets Install run: bin/console assets:install --symlink + - name: Install Pimcore + run: PIMCORE_KERNEL_CLASS=Kernel vendor/bin/pimcore-install --ignore-existing-config --env=test --skip-database-config + + - name: Install DataDefinitions + run: bin/console pimcore:bundle:install DataDefinitionsBundle + - name: Run Behat run: vendor/bin/behat --strict --no-interaction -vvv -f progress --config behat.yml.dist -p default diff --git a/.github/workflows/static.yml b/.github/workflows/static.yml index 9a41bbf9..20120fcd 100644 --- a/.github/workflows/static.yml +++ b/.github/workflows/static.yml @@ -11,60 +11,67 @@ jobs: env: APP_ENV: "test" PIMCORE_TEST_DB_DSN: "mysql://root:root@127.0.0.1:3306/data_defs_test" + + strategy: + matrix: + php: [ 8.0 ] + pimcore: [ ^10.2, 10.x-dev ] + database: [ 'mysql:8.0' ] + dependencies: [ highest, lowest ] + services: - mysql: - image: mysql:5.7 + database: + image: "${{ matrix.database }}" env: MYSQL_ROOT_PASSWORD: root MYSQL_DATABASE: data_defs_test ports: - 3306:3306 options: --health-cmd="mysqladmin ping" --health-interval=10s --health-timeout=5s --health-retries=3 - name: "${{ matrix.pimcore }}, PHP ${{ matrix.php }}" - strategy: - matrix: - php: [8.0] - pimcore: [^10.0, ^10.1] + + name: "${{ matrix.pimcore }}, PHP ${{ matrix.php }}, DB ${{ matrix.database }}, Deps ${{ matrix.dependencies }}" steps: - - uses: actions/checkout@v2 + - uses: actions/checkout@v2 - - name: Install PHP - uses: shivammathur/setup-php@v2 - with: - php-version: ${{ matrix.php }} - extensions: intl, gd, simpleXML, dom, exif, fileinfo, iconv, mbstring, mysqli, pdo_mysql, zip, zlib + - name: Install PHP + uses: shivammathur/setup-php@v2 + with: + php-version: ${{ matrix.php }} + ini-values: display_errors=On, display_startup_errors=On, error_reporting=32767 + extensions: intl, gd, simpleXML, dom, exif, fileinfo, iconv, mbstring, mysqli, pdo_mysql, zip, zlib - - name: Get composer cache directory - id: composer-cache - run: echo "::set-output name=dir::$(composer config cache-files-dir)" + - name: Validate composer.json and composer.lock + run: composer validate - - name: Cache dependencies - uses: actions/cache@v1 - with: - path: ${{ steps.composer-cache.outputs.dir }} - key: ${{ runner.os }}-composer-${{ hashFiles('**/composer.json') }} - restore-keys: ${{ runner.os }}-composer- + - name: Get composer cache directory + id: composer-cache + run: echo "::set-output name=dir::$(composer config cache-files-dir)" - - name: Verify MySQL connection - run: | - mysql --version - sudo apt-get install -y mysql-client - mysql --host 127.0.0.1 --port ${{ job.services.mysql.ports['3306'] }} -uroot -proot -e "SHOW DATABASES" + - name: Cache composer dependencies + uses: actions/cache@v1 + with: + path: ${{ steps.composer-cache.outputs.dir }} + key: ${{ runner.os }}-composer-${{ hashFiles('**/composer.json') }} + restore-keys: ${{ runner.os }}-composer- - - name: Validate composer.json and composer.lock - run: composer validate + - if: matrix.dependencies == 'highest' + name: Install dependencies highest + run: | + composer req pimcore/pimcore:${{ matrix.pimcore }} --no-interaction --no-scripts --no-update + composer update --no-progress --prefer-dist --optimize-autoloader - - name: Composer install - run: | - composer req pimcore/pimcore:${{ matrix.pimcore }} --no-interaction --no-scripts --no-update - composer install --no-progress --no-suggest --prefer-dist --optimize-autoloader + - if: matrix.dependencies == 'lowest' + name: Install dependencies lowest + run: | + composer req pimcore/pimcore:${{ matrix.pimcore }} --no-interaction --no-scripts --no-update + composer update --no-progress --prefer-dist --optimize-autoloader --prefer-lowest - - name: Validate YAML - run: bin/console lint:yaml src --parse-tags + - name: Validate YAML + run: bin/console lint:yaml src --parse-tags - - name: STAN - run: | - cp -f config/packages/stan/config.yaml config/packages/dev/config.yaml - bin/console cache:clear --env=dev - vendor/bin/phpstan analyse -c phpstan.neon src -l 3 + - name: STAN + run: | + cp -f config/packages/stan/config.yaml config/packages/dev/config.yaml + bin/console cache:clear --env=dev + vendor/bin/phpstan analyse -c phpstan.neon src -l 3 From ef7293c4f7de7b5d01af799b68b6f20574e9cb26 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Dalibor=20Karlovi=C4=87?= Date: Tue, 15 Mar 2022 12:23:51 +0100 Subject: [PATCH 12/65] Pimcore X compatibility & performance fixes (#341) * fix artifact stream: close stream only if resource is still valid * fix json provider: export to file only if parameter is set * fix xml provider: uninitialized properties, external process command as array * fix: XmlWriter::writeAttribute second arg = string on PHP 8.x * perf: don't find the process if we'll throttle it anyway * perf: throttle the status event same way as progress event * fix: set process completed time on complete and failure event * fix: remove web/ (Pimcore 6 public folder) from the path Pimcore X's workdir is in the public folder, when running via ProcessManager, the path needs to be relative to it, not root. Co-authored-by: Damijan Kozic --- .../AbstractProcessManagerListener.php | 36 ++++++++++++++----- .../ProcessManager/ArtifactProviderTrait.php | 4 ++- .../ProcessManagerExportListener.php | 2 ++ .../Provider/JsonProvider.php | 4 +++ .../Provider/XmlProvider.php | 20 +++++++---- .../js/process_manager/import_definitions.js | 3 +- 6 files changed, 50 insertions(+), 19 deletions(-) diff --git a/src/DataDefinitionsBundle/ProcessManager/AbstractProcessManagerListener.php b/src/DataDefinitionsBundle/ProcessManager/AbstractProcessManagerListener.php index 0b066887..37b6a586 100644 --- a/src/DataDefinitionsBundle/ProcessManager/AbstractProcessManagerListener.php +++ b/src/DataDefinitionsBundle/ProcessManager/AbstractProcessManagerListener.php @@ -31,7 +31,7 @@ abstract class AbstractProcessManagerListener public const PROCESS_TYPE = 'data_definitions'; public const PROCESS_NAME = 'Data Definitions'; - private const PROCESS_PROGRESS_THROTTLE_SECONDS = 5; + private const PROCESS_PROGRESS_THROTTLE_SECONDS = 1; protected $process; protected $processFactory; @@ -47,7 +47,12 @@ abstract class AbstractProcessManagerListener /** * @var int */ - protected $lastStepsCount = 0; + protected $lastProgressStepsCount = 0; + + /** + * @var null|\DateTimeInterface + */ + protected $lastStatusAt; public function __construct( FactoryInterface $processFactory, @@ -105,12 +110,8 @@ public function onTotalEvent(DefinitionEventInterface $event) : void public function onProgressEvent(DefinitionEventInterface $event) : void { if ($this->process) { - if ($this->process->getStoppable()) { - $this->process = $this->repository->find($this->process->getId()); - } - $now = new \DateTimeImmutable(); - $this->lastStepsCount++; + $this->lastProgressStepsCount++; if ($this->lastProgressAt instanceof \DateTimeInterface) { $diff = $now->getTimestamp() - $this->lastProgressAt->getTimestamp(); @@ -120,15 +121,19 @@ public function onProgressEvent(DefinitionEventInterface $event) : void } $this->lastProgressAt = $now; + if ($this->process->getStoppable()) { + $this->process = $this->repository->find($this->process->getId()); + } + if ($this->process->getStatus() === ProcessManagerBundle::STATUS_STOPPING) { $this->eventDispatcher->dispatch('data_definitions.stop'); $this->process->setStatus(ProcessManagerBundle::STATUS_STOPPED); } - $this->process->progress($this->lastStepsCount); + $this->process->progress($this->lastProgressStepsCount); $this->process->save(); - $this->lastStepsCount = 0; + $this->lastProgressStepsCount = 0; $this->processLogger->info($this->process, ImportDefinitionsReport::EVENT_PROGRESS); } @@ -140,6 +145,16 @@ public function onProgressEvent(DefinitionEventInterface $event) : void public function onStatusEvent(DefinitionEventInterface $event) : void { if ($this->process) { + $now = new \DateTimeImmutable(); + if ($this->lastStatusAt instanceof \DateTimeInterface) { + $diff = $now->getTimestamp() - $this->lastStatusAt->getTimestamp(); + + if (self::PROCESS_PROGRESS_THROTTLE_SECONDS > $diff) { + return; + } + } + $this->lastStatusAt = $now; + if ($this->process->getStoppable()) { $this->process = $this->repository->find($this->process->getId()); } @@ -158,7 +173,9 @@ public function onFinishedEvent(DefinitionEventInterface $event) : void if ($this->process) { if ($this->process->getStatus() === ProcessManagerBundle::STATUS_RUNNING) { $this->process->setProgress($this->process->getTotal()); + $this->process->setMessage($event->getSubject()); $this->process->setStatus(ProcessManagerBundle::STATUS_COMPLETED); + $this->process->setCompleted(time()); $this->process->save(); } $this->processLogger->info($this->process, ImportDefinitionsReport::EVENT_FINISHED.$event->getSubject()); @@ -176,6 +193,7 @@ public function onFailureEvent(DefinitionEventInterface $event) : void } else { $this->process->setStatus(ProcessManagerBundle::STATUS_COMPLETED_WITH_EXCEPTIONS); } + $this->process->setCompleted(time()); $this->process->save(); } } diff --git a/src/DataDefinitionsBundle/ProcessManager/ArtifactProviderTrait.php b/src/DataDefinitionsBundle/ProcessManager/ArtifactProviderTrait.php index 177e3536..38f30930 100644 --- a/src/DataDefinitionsBundle/ProcessManager/ArtifactProviderTrait.php +++ b/src/DataDefinitionsBundle/ProcessManager/ArtifactProviderTrait.php @@ -45,7 +45,9 @@ public function generateArtifact($configuration, ExportDefinitionInterface $defi $artifact->setFilename(Asset\Service::getUniqueKey($artifact)); $artifact->save(); - fclose($stream); + if (is_resource($stream)) { + fclose($stream); + } return $artifact; } diff --git a/src/DataDefinitionsBundle/ProcessManager/ProcessManagerExportListener.php b/src/DataDefinitionsBundle/ProcessManager/ProcessManagerExportListener.php index bda9ff7a..5af153fe 100644 --- a/src/DataDefinitionsBundle/ProcessManager/ProcessManagerExportListener.php +++ b/src/DataDefinitionsBundle/ProcessManager/ProcessManagerExportListener.php @@ -37,7 +37,9 @@ public function onFinishedEvent(DefinitionEventInterface $event) : void if (null !== $this->process) { if ($this->process->getStatus() == ProcessManagerBundle::STATUS_RUNNING) { $this->process->setProgress($this->process->getTotal()); + $this->process->setMessage($event->getSubject()); $this->process->setStatus(ProcessManagerBundle::STATUS_COMPLETED); + $this->process->setCompleted(time()); $this->process->save(); } $definition = $event->getDefinition(); diff --git a/src/DataDefinitionsBundle/Provider/JsonProvider.php b/src/DataDefinitionsBundle/Provider/JsonProvider.php index 645f1319..3e956975 100644 --- a/src/DataDefinitionsBundle/Provider/JsonProvider.php +++ b/src/DataDefinitionsBundle/Provider/JsonProvider.php @@ -96,6 +96,10 @@ public function getData(array $configuration, ImportDefinitionInterface $definit public function exportData(array $configuration, ExportDefinitionInterface $definition, array $params): void { + if (!array_key_exists('file', $params)) { + return; + } + $file = $this->getFile($params['file']); file_put_contents($file, json_encode($this->exportData)); diff --git a/src/DataDefinitionsBundle/Provider/XmlProvider.php b/src/DataDefinitionsBundle/Provider/XmlProvider.php index 6bb49571..0b6f92a0 100755 --- a/src/DataDefinitionsBundle/Provider/XmlProvider.php +++ b/src/DataDefinitionsBundle/Provider/XmlProvider.php @@ -132,7 +132,12 @@ public function exportData(array $configuration, ExportDefinitionInterface $defi file_put_contents($workingPath, $storage->read($path)); $this->exportPath = tempnam(sys_get_temp_dir(), 'xml_export_xslt_transformation'); - $cmd = sprintf('xsltproc -v %1$s %2$s > %3$s', $workingPath, $dataPath, $this->getExportPath()); + $cmd = [ + 'xsltproc', + '-v', '--noout', + '--output', $this->getExportPath(), + $workingPath, $dataPath, + ]; $process = new Process($cmd); $process->setTimeout(null); $process->run(); @@ -161,7 +166,7 @@ public function provideArtifactStream($configuration, ExportDefinitionInterface private function getXMLWriter(): XMLWriter { - if (null === $this->writer) { + if (!isset($this->writer)) { $this->writer = new XMLWriter(); $this->writer->openMemory(); $this->writer->setIndent(true); @@ -176,7 +181,7 @@ private function getXMLWriter(): XMLWriter private function getExportPath(): string { - if (null === $this->exportPath) { + if (!isset($this->exportPath)) { $this->exportPath = tempnam(sys_get_temp_dir(), 'xml_export_provider'); } @@ -196,12 +201,13 @@ private function serialize(XMLWriter $writer, ?string $name, $data, ?int $key = $writer->writeAttribute('name', $name); } if (null !== $key) { - $writer->writeAttribute('key', $key); + $writer->writeAttribute('key', (string) $key); } if (is_string($data)) { $writer->writeCdata($data); } else { - $writer->text($data); + // TODO: should be more elaborate/exact for "non-string" scalar values + $writer->text((string)$data); } $writer->endElement(); } else { @@ -211,7 +217,7 @@ private function serialize(XMLWriter $writer, ?string $name, $data, ?int $key = $writer->writeAttribute('name', $name); } if (null !== $key) { - $writer->writeAttribute('key', $key); + $writer->writeAttribute('key', (string) $key); } $this->serializeCollection($writer, $data); $writer->endElement(); @@ -222,7 +228,7 @@ private function serialize(XMLWriter $writer, ?string $name, $data, ?int $key = $writer->writeAttribute('name', $name); } if (null !== $key) { - $writer->writeAttribute('key', $key); + $writer->writeAttribute('key', (string) $key); } $writer->writeCdata((string)$data); $writer->endElement(); diff --git a/src/DataDefinitionsBundle/Resources/public/pimcore/js/process_manager/import_definitions.js b/src/DataDefinitionsBundle/Resources/public/pimcore/js/process_manager/import_definitions.js index 1e7d4eb9..33ab2cc8 100644 --- a/src/DataDefinitionsBundle/Resources/public/pimcore/js/process_manager/import_definitions.js +++ b/src/DataDefinitionsBundle/Resources/public/pimcore/js/process_manager/import_definitions.js @@ -85,11 +85,10 @@ document.addEventListener('processmanager.ready', function() { addDataFromSelector: function (data) { this.setValue(data.fullpath); - console.log(data); }, setValue: function (value) { - var params = '{"file":"web/var/assets' + value + '"}'; + var params = '{"file":"var/assets' + value + '"}'; Ext.getCmp('data_definitions_processmanager_params').setValue(params); } }); From 0038c09c1189cf2680d669d0d667c04426b50318 Mon Sep 17 00:00:00 2001 From: Dominik Pfaffenbauer Date: Wed, 16 Mar 2022 08:03:00 +0100 Subject: [PATCH 13/65] Introduce Start-Finish Runner for start and end of an import --- .../Importer/Importer.php | 35 +++++++++++++------ .../ImportStartFinishRunnerInterface.php | 28 +++++++++++++++ 2 files changed, 52 insertions(+), 11 deletions(-) create mode 100644 src/DataDefinitionsBundle/Runner/ImportStartFinishRunnerInterface.php diff --git a/src/DataDefinitionsBundle/Importer/Importer.php b/src/DataDefinitionsBundle/Importer/Importer.php index f119c317..5eda9a72 100644 --- a/src/DataDefinitionsBundle/Importer/Importer.php +++ b/src/DataDefinitionsBundle/Importer/Importer.php @@ -45,6 +45,7 @@ use Wvision\Bundle\DataDefinitionsBundle\Provider\ImportDataSetInterface; use Wvision\Bundle\DataDefinitionsBundle\Provider\ImportProviderInterface; use Wvision\Bundle\DataDefinitionsBundle\Persister\PersisterInterface; +use Wvision\Bundle\DataDefinitionsBundle\Runner\ImportStartFinishRunnerInterface; use Wvision\Bundle\DataDefinitionsBundle\Runner\RunnerInterface; use Wvision\Bundle\DataDefinitionsBundle\Runner\SaveRunnerInterface; use Wvision\Bundle\DataDefinitionsBundle\Runner\SetterRunnerInterface; @@ -112,6 +113,15 @@ public function doImport(ImportDefinitionInterface $definition, $params): array $filter = $this->filterRegistry->get($filterType); } + $runner = null; + + if ($definition->getRunner()) { + /** + * @var RunnerInterface $runner + */ + $runner = $this->runnerRegistry->get($definition->getRunner()); + } + /** @var ImportDataSetInterface|array $data */ $data = $this->getData($definition, $params); @@ -119,7 +129,15 @@ public function doImport(ImportDefinitionInterface $definition, $params): array $this->eventDispatcher->dispatch($definition, 'data_definitions.import.total', \count($data), $params); } - [$objectIds, $exceptions] = $this->runImport($definition, $params, $filter, $data); + if ($runner instanceof ImportStartFinishRunnerInterface) { + $runner->startImport($data, $definition, $params); + } + + [$objectIds, $exceptions] = $this->runImport($definition, $params, $filter, $runner, $data); + + if ($runner instanceof ImportStartFinishRunnerInterface) { + $runner->finishImport($data, $definition, $params); + } $cleanerType = $definition->getCleaner(); if ($cleanerType) { @@ -221,7 +239,8 @@ private function runImport( ImportDefinitionInterface $definition, array $params, FilterInterface $filter = null, - ImportDataSetInterface $dataSet = null + RunnerInterface $runner = null, + ImportDataSetInterface $dataSet = null, ): array { if (null === $dataSet) { @@ -239,7 +258,7 @@ private function runImport( } try { - $object = $this->importRow($definition, $row, $dataSet, array_merge($params, ['row' => $count]), $filter); + $object = $this->importRow($definition, $row, $dataSet, array_merge($params, ['row' => $count]), $filter, $runner); if ($object instanceof Concrete) { $objectIds[] = $object->getId(); @@ -283,11 +302,10 @@ private function importRow( array $data, ImportDataSetInterface $dataSet, array $params, - FilterInterface $filter = null + FilterInterface $filter = null, + RunnerInterface $runner = null, ): ?Concrete { - $runner = null; - $object = $this->getObject($definition, $data, $params); if (null !== $object && !$object->getId()) { @@ -333,11 +351,6 @@ private function importRow( $params ); - if ($definition->getRunner()) { - $runner = $this->runnerRegistry->get($definition->getRunner()); - } - - if ($runner instanceof RunnerInterface) { if ($runner instanceof DataSetAwareInterface) { $runner->setDataSet($dataSet); diff --git a/src/DataDefinitionsBundle/Runner/ImportStartFinishRunnerInterface.php b/src/DataDefinitionsBundle/Runner/ImportStartFinishRunnerInterface.php new file mode 100644 index 00000000..c2610f35 --- /dev/null +++ b/src/DataDefinitionsBundle/Runner/ImportStartFinishRunnerInterface.php @@ -0,0 +1,28 @@ + Date: Wed, 16 Mar 2022 10:33:15 +0100 Subject: [PATCH 14/65] add params to filter --- src/DataDefinitionsBundle/Filter/FilterInterface.php | 2 +- src/DataDefinitionsBundle/Importer/Importer.php | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/DataDefinitionsBundle/Filter/FilterInterface.php b/src/DataDefinitionsBundle/Filter/FilterInterface.php index 6ea05c37..0f3bb68b 100644 --- a/src/DataDefinitionsBundle/Filter/FilterInterface.php +++ b/src/DataDefinitionsBundle/Filter/FilterInterface.php @@ -21,5 +21,5 @@ interface FilterInterface { - public function filter(DataDefinitionInterface $definition, array $data, Concrete $object): bool; + public function filter(DataDefinitionInterface $definition, array $data, Concrete $object, array $params): bool; } diff --git a/src/DataDefinitionsBundle/Importer/Importer.php b/src/DataDefinitionsBundle/Importer/Importer.php index f119c317..4a8db4f5 100644 --- a/src/DataDefinitionsBundle/Importer/Importer.php +++ b/src/DataDefinitionsBundle/Importer/Importer.php @@ -313,7 +313,7 @@ private function importRow( $filter->setLogger($this->logger); } - if (!$filter->filter($definition, $data, $object)) { + if (!$filter->filter($definition, $data, $object, $params)) { $this->eventDispatcher->dispatch($definition, 'data_definitions.import.status', 'Filtered Object', $params); return null; From f8f4471db8dee5614aea64e7f1eb3af070987179 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Dalibor=20Karlovi=C4=87?= Date: Tue, 12 Apr 2022 11:37:10 +0200 Subject: [PATCH 15/65] feat: migrate AssetUrlInterpreter to PSR HTTP compatible implementation (#350) --- composer.json | 4 +++- .../Interpreter/AssetUrlInterpreter.php | 22 ++++++++++--------- .../Resources/config/services.yml | 6 +++-- 3 files changed, 19 insertions(+), 13 deletions(-) diff --git a/composer.json b/composer.json index e0b8174a..ea29a58e 100755 --- a/composer.json +++ b/composer.json @@ -36,7 +36,9 @@ "coreshop/resource-bundle": "^3.0", "coreshop/rule-bundle": "^3.0", "coreshop/pimcore-bundle": "^3.0", - "pimcore/pimcore": "^10.0" + "pimcore/pimcore": "^10.0", + "psr/http-client-implementation": "^1.0", + "psr/http-factory-implementation": "^1.0" }, "require-dev": { "roave/security-advisories": "dev-latest", diff --git a/src/DataDefinitionsBundle/Interpreter/AssetUrlInterpreter.php b/src/DataDefinitionsBundle/Interpreter/AssetUrlInterpreter.php index ad1913f5..41ceb11c 100644 --- a/src/DataDefinitionsBundle/Interpreter/AssetUrlInterpreter.php +++ b/src/DataDefinitionsBundle/Interpreter/AssetUrlInterpreter.php @@ -17,8 +17,6 @@ namespace Wvision\Bundle\DataDefinitionsBundle\Interpreter; use Doctrine\DBAL\Query\QueryBuilder; -use GuzzleHttp\Client; -use GuzzleHttp\Exception\TransferException; use Pimcore\File; use Pimcore\Http\Exception\ResponseException; use Pimcore\Model\Asset; @@ -34,11 +32,13 @@ class AssetUrlInterpreter implements InterpreterInterface, DataSetAwareInterface use DataSetAwareTrait; protected const METADATA_ORIGIN_URL = 'origin_url'; - protected Client $httpClient; + protected \Psr\Http\Client\ClientInterface $httpClient; + protected \Psr\Http\Message\RequestFactoryInterface $requestFactory; - public function __construct(Client $httpClient) + public function __construct(\Psr\Http\Client\ClientInterface $httpClient, \Psr\Http\Message\RequestFactoryInterface $requestFactory) { $this->httpClient = $httpClient; + $this->requestFactory = $requestFactory; } public function interpret( @@ -110,7 +110,8 @@ private function getFileName(string $url) : ?string { $filename = null; try { - $response = $this->httpClient->request("HEAD", $url); + $request = $this->requestFactory->createRequest('HEAD', $url); + $response = $this->httpClient->sendRequest($request); $headers = $response->getHeaders(); if ( @@ -123,7 +124,7 @@ private function getFileName(string $url) : ?string ) { $filename = trim($match['f'], ' ";'); } - } catch (ResponseException $exception) { + } catch (\Psr\Http\Client\ClientExceptionInterface $exception) { } if (!$filename) { @@ -136,12 +137,13 @@ private function getFileName(string $url) : ?string protected function getFileContents(string $value): ?string { try { - $response = $this->httpClient->request('GET', $value); - } catch (TransferException $ex) { - $response = null; + $request = $this->requestFactory->createRequest('GET', $value); + $response = $this->httpClient->sendRequest($request); + } catch (\Psr\Http\Client\ClientExceptionInterface $ex) { + return null; } - if ($response && $response->getStatusCode() === 200) { + if ($response->getStatusCode() === 200) { return (string) $response->getBody(); } diff --git a/src/DataDefinitionsBundle/Resources/config/services.yml b/src/DataDefinitionsBundle/Resources/config/services.yml index 57944125..ee74ed39 100644 --- a/src/DataDefinitionsBundle/Resources/config/services.yml +++ b/src/DataDefinitionsBundle/Resources/config/services.yml @@ -157,13 +157,15 @@ services: ### INTERPRETER Wvision\Bundle\DataDefinitionsBundle\Interpreter\AssetsUrlInterpreter: arguments: - - '@pimcore.http_client' + - '@Psr\Http\Client\ClientInterface' + - '@Psr\Http\Message\RequestFactoryInterface' tags: - { name: data_definitions.interpreter, type: assets_url, form-type: Wvision\Bundle\DataDefinitionsBundle\Form\Type\Interpreter\AssetsUrlInterpreterType } Wvision\Bundle\DataDefinitionsBundle\Interpreter\AssetUrlInterpreter: arguments: - - '@pimcore.http_client' + - '@Psr\Http\Client\ClientInterface' + - '@Psr\Http\Message\RequestFactoryInterface' tags: - { name: data_definitions.interpreter, type: asset_url, form-type: Wvision\Bundle\DataDefinitionsBundle\Form\Type\Interpreter\AssetUrlInterpreterType } From 1438ad248c2690354d3a1ecc2326b7aa50acfb69 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Dalibor=20Karlovi=C4=87?= Date: Tue, 12 Apr 2022 11:39:53 +0200 Subject: [PATCH 16/65] fix: asset deduplication join updated to Pimcore 10 API (#351) --- src/DataDefinitionsBundle/Interpreter/AssetUrlInterpreter.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/DataDefinitionsBundle/Interpreter/AssetUrlInterpreter.php b/src/DataDefinitionsBundle/Interpreter/AssetUrlInterpreter.php index 41ceb11c..4aad8236 100644 --- a/src/DataDefinitionsBundle/Interpreter/AssetUrlInterpreter.php +++ b/src/DataDefinitionsBundle/Interpreter/AssetUrlInterpreter.php @@ -155,7 +155,7 @@ private function getDuplicatedAsset(string $value) : ?Asset $listing = new Asset\Listing(); $listing->onCreateQueryBuilder( function (QueryBuilder $select) { - $select->join('assets_metadata AS am', 'id = am.cid', 'cid'); + $select->join('assets','assets_metadata', 'am', 'id = am.cid'); } ); $listing->addConditionParam('am.name = ?', static::METADATA_ORIGIN_URL); From bcf486f618ec256fb6f1c1eb72b0ab850df79edf Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Dalibor=20Karlovi=C4=87?= Date: Thu, 14 Apr 2022 10:10:49 +0200 Subject: [PATCH 17/65] feat: allow passing asset paths to import (#352) --- .../Provider/AbstractFileProvider.php | 16 ++++++++++++++-- .../Provider/CsvProvider.php | 4 ++-- .../Provider/ExcelProvider.php | 4 ++-- .../Provider/JsonProvider.php | 4 ++-- .../Provider/XmlProvider.php | 4 ++-- 5 files changed, 22 insertions(+), 10 deletions(-) diff --git a/src/DataDefinitionsBundle/Provider/AbstractFileProvider.php b/src/DataDefinitionsBundle/Provider/AbstractFileProvider.php index b7afb518..d8e198ce 100644 --- a/src/DataDefinitionsBundle/Provider/AbstractFileProvider.php +++ b/src/DataDefinitionsBundle/Provider/AbstractFileProvider.php @@ -16,14 +16,26 @@ namespace Wvision\Bundle\DataDefinitionsBundle\Provider; +use Pimcore\Model\Asset; + abstract class AbstractFileProvider { - protected function getFile(string $file): string + protected function getFile(array $params): string { // if (!str_starts_with($file, '/')) { // $file = sprintf('%s/%s', PIMCORE_PROJECT_ROOT, $file); // } - return $file; + if (isset($params['asset'])) { + $asset = Asset::getByPath($params['asset']); + + return $asset->getTemporaryFile(); + } + + if (isset($params['file'])) { + return $params['file']; + } + + throw new \RuntimeException('No file or asset given'); } } diff --git a/src/DataDefinitionsBundle/Provider/CsvProvider.php b/src/DataDefinitionsBundle/Provider/CsvProvider.php index edb4f5a6..51b4642c 100644 --- a/src/DataDefinitionsBundle/Provider/CsvProvider.php +++ b/src/DataDefinitionsBundle/Provider/CsvProvider.php @@ -82,7 +82,7 @@ public function getData(array $configuration, ImportDefinitionInterface $definit $offset = $params['offset'] ?? null; $limit = $params['limit'] ?? null; - $file = $this->getFile($params['file']); + $file = $this->getFile($params); $csv = Reader::createFromPath($file, 'r'); $csv->setDelimiter($delimiter); @@ -128,7 +128,7 @@ public function exportData(array $configuration, ExportDefinitionInterface $defi return; } - $file = $this->getFile($params['file']); + $file = $this->getFile($params); $headers = count($this->exportData) > 0 ? array_keys($this->exportData[0]) : []; diff --git a/src/DataDefinitionsBundle/Provider/ExcelProvider.php b/src/DataDefinitionsBundle/Provider/ExcelProvider.php index 276b1209..8f58a152 100644 --- a/src/DataDefinitionsBundle/Provider/ExcelProvider.php +++ b/src/DataDefinitionsBundle/Provider/ExcelProvider.php @@ -72,7 +72,7 @@ public function getColumns(array $configuration): array public function getData(array $configuration, ImportDefinitionInterface $definition, array $params, FilterInterface $filter = null): ImportDataSetInterface { - $file = $this->getFile($params['file']); + $file = $this->getFile($params); $reader = $this->createReader($file); $sheetIterator = $reader->getSheetIterator(); @@ -131,7 +131,7 @@ public function exportData(array $configuration, ExportDefinitionInterface $defi return; } - $file = $this->getFile($params['file']); + $file = $this->getFile($params); rename($this->getExportPath(), $file); } diff --git a/src/DataDefinitionsBundle/Provider/JsonProvider.php b/src/DataDefinitionsBundle/Provider/JsonProvider.php index 3e956975..32eb8bb2 100644 --- a/src/DataDefinitionsBundle/Provider/JsonProvider.php +++ b/src/DataDefinitionsBundle/Provider/JsonProvider.php @@ -83,7 +83,7 @@ public function getColumns(array $configuration): array public function getData(array $configuration, ImportDefinitionInterface $definition, array $params, FilterInterface $filter = null): ImportDataSetInterface { - $file = $this->getFile($params['file']); + $file = $this->getFile($params); if (file_exists($file)) { $json = file_get_contents($file); @@ -100,7 +100,7 @@ public function exportData(array $configuration, ExportDefinitionInterface $defi return; } - $file = $this->getFile($params['file']); + $file = $this->getFile($params); file_put_contents($file, json_encode($this->exportData)); } diff --git a/src/DataDefinitionsBundle/Provider/XmlProvider.php b/src/DataDefinitionsBundle/Provider/XmlProvider.php index 0b6f92a0..93af13b4 100755 --- a/src/DataDefinitionsBundle/Provider/XmlProvider.php +++ b/src/DataDefinitionsBundle/Provider/XmlProvider.php @@ -87,7 +87,7 @@ public function getColumns(array $configuration): array public function getData(array $configuration, ImportDefinitionInterface $definition, array $params, FilterInterface $filter = null): ImportDataSetInterface { - $file = $this->getFile($params['file']); + $file = $this->getFile($params); $xml = file_get_contents($file); return new ArrayImportDataSet($this->convertXmlToArray($xml, $configuration['xPath'])); @@ -155,7 +155,7 @@ public function exportData(array $configuration, ExportDefinitionInterface $defi return; } - $file = $this->getFile($params['file']); + $file = $this->getFile($params); rename($this->getExportPath(), $file); } From 1c8d687da7306909ff7cad569a2dfd982659ebd9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Dalibor=20Karlovi=C4=87?= Date: Thu, 28 Apr 2022 14:24:27 +0200 Subject: [PATCH 18/65] fix: XML Provider export rename() not friendly to streams (#357) Using copy() + unlink() instead --- src/DataDefinitionsBundle/Provider/XmlProvider.php | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/DataDefinitionsBundle/Provider/XmlProvider.php b/src/DataDefinitionsBundle/Provider/XmlProvider.php index 93af13b4..2b88bd10 100755 --- a/src/DataDefinitionsBundle/Provider/XmlProvider.php +++ b/src/DataDefinitionsBundle/Provider/XmlProvider.php @@ -156,7 +156,8 @@ public function exportData(array $configuration, ExportDefinitionInterface $defi } $file = $this->getFile($params); - rename($this->getExportPath(), $file); + copy($this->getExportPath(), $file); + unlink($this->getExportPath()); } public function provideArtifactStream($configuration, ExportDefinitionInterface $definition, $params) From 578cfdf683f73070d8384b7411e583a2752c149d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Dalibor=20Karlovi=C4=87?= Date: Tue, 3 May 2022 10:26:09 +0200 Subject: [PATCH 19/65] fix: auto-wire Guzzle PSR-7 if installed (which it is with Pimcore 10) (#358) --- .../DependencyInjection/DataDefinitionsExtension.php | 4 ++++ src/DataDefinitionsBundle/Resources/config/guzzle_psr7.yml | 3 +++ 2 files changed, 7 insertions(+) create mode 100644 src/DataDefinitionsBundle/Resources/config/guzzle_psr7.yml diff --git a/src/DataDefinitionsBundle/DependencyInjection/DataDefinitionsExtension.php b/src/DataDefinitionsBundle/DependencyInjection/DataDefinitionsExtension.php index 4f6c7468..cf2ca752 100644 --- a/src/DataDefinitionsBundle/DependencyInjection/DataDefinitionsExtension.php +++ b/src/DataDefinitionsBundle/DependencyInjection/DataDefinitionsExtension.php @@ -71,6 +71,10 @@ public function load(array $configs, ContainerBuilder $container) $loader->load('services.yml'); + if (class_exists(\GuzzleHttp\Psr7\HttpFactory::class)) { + $loader->load('guzzle_psr7.yml'); + } + if (array_key_exists('ProcessManagerBundle', $bundles)) { $config['pimcore_admin']['js']['process_manager_import'] = '/bundles/datadefinitions/pimcore/js/process_manager/import_definitions.js'; $config['pimcore_admin']['js']['process_manager_export'] = '/bundles/datadefinitions/pimcore/js/process_manager/export_definitions.js'; diff --git a/src/DataDefinitionsBundle/Resources/config/guzzle_psr7.yml b/src/DataDefinitionsBundle/Resources/config/guzzle_psr7.yml new file mode 100644 index 00000000..406f591b --- /dev/null +++ b/src/DataDefinitionsBundle/Resources/config/guzzle_psr7.yml @@ -0,0 +1,3 @@ +services: + GuzzleHttp\Psr7\HttpFactory: ~ + Psr\Http\Message\RequestFactoryInterface: '@GuzzleHttp\Psr7\HttpFactory' From 160af75a569e2d4fddad557056fa171a82f636ef Mon Sep 17 00:00:00 2001 From: Dominik Pfaffenbauer Date: Wed, 13 Jul 2022 11:17:12 +0200 Subject: [PATCH 20/65] fix simpleFilter --- .../DataDefinitionsBundle/Behat/Service/Filter/SimpleFilter.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/DataDefinitionsBundle/Behat/Service/Filter/SimpleFilter.php b/tests/DataDefinitionsBundle/Behat/Service/Filter/SimpleFilter.php index 76a38ea7..e4c3bbea 100644 --- a/tests/DataDefinitionsBundle/Behat/Service/Filter/SimpleFilter.php +++ b/tests/DataDefinitionsBundle/Behat/Service/Filter/SimpleFilter.php @@ -8,7 +8,7 @@ class SimpleFilter implements FilterInterface { - public function filter(DataDefinitionInterface $definition, array $data, Concrete $object): bool + public function filter(DataDefinitionInterface $definition, array $data, Concrete $object, array $params): bool { return $data['doFilter'] !== '1'; } From ddca324f2940e078781e48f0d40973518f5c79e6 Mon Sep 17 00:00:00 2001 From: Dominik Pfaffenbauer Date: Wed, 13 Jul 2022 11:21:39 +0200 Subject: [PATCH 21/65] add guzzlehttp/psr7 --- .github/workflows/behat.yml | 4 ++-- .github/workflows/static.yml | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/.github/workflows/behat.yml b/.github/workflows/behat.yml index 584188d6..e380c536 100644 --- a/.github/workflows/behat.yml +++ b/.github/workflows/behat.yml @@ -75,13 +75,13 @@ jobs: - if: matrix.dependencies == 'highest' name: Install dependencies highest run: | - composer req pimcore/pimcore:${{ matrix.pimcore }} --no-interaction --no-scripts --no-update + composer req guzzlehttp/psr7 pimcore/pimcore:${{ matrix.pimcore }} --no-interaction --no-scripts --no-update composer update --no-progress --prefer-dist --optimize-autoloader - if: matrix.dependencies == 'lowest' name: Install dependencies lowest run: | - composer req pimcore/pimcore:${{ matrix.pimcore }} --no-interaction --no-scripts --no-update + composer req guzzlehttp/psr7 pimcore/pimcore:${{ matrix.pimcore }} --no-interaction --no-scripts --no-update composer update --no-progress --prefer-dist --optimize-autoloader --prefer-lowest - name: Cache clear diff --git a/.github/workflows/static.yml b/.github/workflows/static.yml index 20120fcd..cb642ebd 100644 --- a/.github/workflows/static.yml +++ b/.github/workflows/static.yml @@ -58,13 +58,13 @@ jobs: - if: matrix.dependencies == 'highest' name: Install dependencies highest run: | - composer req pimcore/pimcore:${{ matrix.pimcore }} --no-interaction --no-scripts --no-update + composer req guzzlehttp/psr7 pimcore/pimcore:${{ matrix.pimcore }} --no-interaction --no-scripts --no-update composer update --no-progress --prefer-dist --optimize-autoloader - if: matrix.dependencies == 'lowest' name: Install dependencies lowest run: | - composer req pimcore/pimcore:${{ matrix.pimcore }} --no-interaction --no-scripts --no-update + composer req guzzlehttp/psr7 pimcore/pimcore:${{ matrix.pimcore }} --no-interaction --no-scripts --no-update composer update --no-progress --prefer-dist --optimize-autoloader --prefer-lowest - name: Validate YAML From 6f302856eea942dbafed58872f13a4f7082b462a Mon Sep 17 00:00:00 2001 From: Dominik Pfaffenbauer Date: Wed, 13 Jul 2022 12:49:58 +0200 Subject: [PATCH 22/65] stan tests --- .gitignore | 4 ++++ composer.json | 10 +++++----- phpstan.neon | 5 +---- .../Model/Log/Listing.php | 18 +++++++++--------- .../Provider/ArrayImportDataSet.php | 12 ++++++------ .../Provider/ImportDataSet.php | 12 ++++++------ .../Provider/TraversableImportDataSet.php | 10 +++++----- 7 files changed, 36 insertions(+), 35 deletions(-) diff --git a/.gitignore b/.gitignore index a399305d..62faa52b 100644 --- a/.gitignore +++ b/.gitignore @@ -66,3 +66,7 @@ var/classes var/config test.csv web +public +docker-compose.yaml +test-commands.txt +.docker \ No newline at end of file diff --git a/composer.json b/composer.json index ea29a58e..d95cc3d8 100755 --- a/composer.json +++ b/composer.json @@ -43,11 +43,11 @@ "require-dev": { "roave/security-advisories": "dev-latest", "behat/behat": "^3.8", - "friends-of-behat/symfony-extension": "^2.2.0", - "phpstan/phpstan": "^0.12", - "phpstan/phpstan-doctrine": "^0.12", - "phpstan/phpstan-symfony": "^0.12", - "phpstan/phpstan-webmozart-assert": "^0.12" + "friends-of-behat/symfony-extension": "^2.1", + "phpstan/phpstan": "^1.5.4", + "phpstan/phpstan-doctrine": "^1.3.2", + "phpstan/phpstan-symfony": "^1.1.8", + "phpstan/phpstan-webmozart-assert": "^1.1.2" }, "conflict": { diff --git a/phpstan.neon b/phpstan.neon index c40882e5..da21aefc 100644 --- a/phpstan.neon +++ b/phpstan.neon @@ -1,13 +1,10 @@ parameters: - autoload_files: - - %currentWorkingDirectory%/vendor/pimcore/pimcore/lib/helper-functions.php - reportUnmatchedIgnoredErrors: false symfony: container_xml_path: var/cache/dev/KernelDevDebugContainer.xml - excludes_analyse: + excludePaths: # Makes PHPStan crash - '**/DependencyInjection/Configuration.php' - '**/Migrations/Version*.php' diff --git a/src/DataDefinitionsBundle/Model/Log/Listing.php b/src/DataDefinitionsBundle/Model/Log/Listing.php index dad59131..825cf02c 100644 --- a/src/DataDefinitionsBundle/Model/Log/Listing.php +++ b/src/DataDefinitionsBundle/Model/Log/Listing.php @@ -79,10 +79,10 @@ public function setObjects($data) /** * Get total count * - * @return mixed + * @return int * @throws Exception */ - public function count() + public function count(): int { return $this->getTotalCount(); } @@ -142,7 +142,7 @@ public function getLocale() * * @throws Exception */ - public function rewind() + public function rewind(): void { $this->getData(); reset($this->data); @@ -154,7 +154,7 @@ public function rewind() * @return mixed * @throws Exception */ - public function current() + public function current(): mixed { $this->getData(); @@ -167,7 +167,7 @@ public function current() * @return mixed * @throws Exception */ - public function key() + public function key(): mixed { $this->getData(); @@ -177,14 +177,14 @@ public function key() /** * Next * - * @return mixed + * @return void * @throws Exception */ - public function next() + public function next(): void { $this->getData(); - return next($this->data); + next($this->data); } /** @@ -193,7 +193,7 @@ public function next() * @return bool * @throws Exception */ - public function valid() + public function valid(): bool { $this->getData(); diff --git a/src/DataDefinitionsBundle/Provider/ArrayImportDataSet.php b/src/DataDefinitionsBundle/Provider/ArrayImportDataSet.php index d1976821..2ed01cb5 100644 --- a/src/DataDefinitionsBundle/Provider/ArrayImportDataSet.php +++ b/src/DataDefinitionsBundle/Provider/ArrayImportDataSet.php @@ -35,7 +35,7 @@ public function __construct(array $data) * @return mixed Can return any type. * @since 5.0.0 */ - public function current() + public function current(): mixed { return ($this->iterator->current()); } @@ -46,7 +46,7 @@ public function current() * @return void Any returned value is ignored. * @since 5.0.0 */ - public function next() + public function next(): void { $this->iterator->next(); } @@ -57,7 +57,7 @@ public function next() * @return mixed scalar on success, or null on failure. * @since 5.0.0 */ - public function key() + public function key(): mixed { return $this->iterator->key(); } @@ -69,7 +69,7 @@ public function key() * Returns true on success or false on failure. * @since 5.0.0 */ - public function valid() + public function valid(): bool { return $this->iterator->valid(); } @@ -80,7 +80,7 @@ public function valid() * @return void Any returned value is ignored. * @since 5.0.0 */ - public function rewind() + public function rewind(): void { $this->iterator->rewind(); } @@ -94,7 +94,7 @@ public function rewind() * The return value is cast to an integer. * @since 5.1.0 */ - public function count() + public function count(): int { return count($this->data); } diff --git a/src/DataDefinitionsBundle/Provider/ImportDataSet.php b/src/DataDefinitionsBundle/Provider/ImportDataSet.php index ce8ebcac..5e987bbb 100644 --- a/src/DataDefinitionsBundle/Provider/ImportDataSet.php +++ b/src/DataDefinitionsBundle/Provider/ImportDataSet.php @@ -45,7 +45,7 @@ public function __construct(Iterator $iterator, Closure $processor = null) * @return mixed Can return any type. * @since 5.0.0 */ - public function current() + public function current(): mixed { return ($this->processor)($this->iterator->current()); } @@ -56,7 +56,7 @@ public function current() * @return void Any returned value is ignored. * @since 5.0.0 */ - public function next() + public function next(): void { $this->iterator->next(); } @@ -67,7 +67,7 @@ public function next() * @return mixed scalar on success, or null on failure. * @since 5.0.0 */ - public function key() + public function key(): mixed { return $this->iterator->key(); } @@ -79,7 +79,7 @@ public function key() * Returns true on success or false on failure. * @since 5.0.0 */ - public function valid() + public function valid(): bool { return $this->iterator->valid(); } @@ -90,7 +90,7 @@ public function valid() * @return void Any returned value is ignored. * @since 5.0.0 */ - public function rewind() + public function rewind(): void { $this->iterator->rewind(); } @@ -104,7 +104,7 @@ public function rewind() * The return value is cast to an integer. * @since 5.1.0 */ - public function count() + public function count(): int { if (false === $this->countAll) { $this->rewind(); diff --git a/src/DataDefinitionsBundle/Provider/TraversableImportDataSet.php b/src/DataDefinitionsBundle/Provider/TraversableImportDataSet.php index 52b6d36b..adbaf66b 100644 --- a/src/DataDefinitionsBundle/Provider/TraversableImportDataSet.php +++ b/src/DataDefinitionsBundle/Provider/TraversableImportDataSet.php @@ -33,7 +33,7 @@ public function __construct(\Traversable $iterator) * @return mixed Can return any type. * @since 5.0.0 */ - public function current() + public function current(): mixed { return ($this->iterator->current()); } @@ -44,7 +44,7 @@ public function current() * @return void Any returned value is ignored. * @since 5.0.0 */ - public function next() + public function next(): void { $this->iterator->next(); } @@ -55,7 +55,7 @@ public function next() * @return mixed scalar on success, or null on failure. * @since 5.0.0 */ - public function key() + public function key(): mixed { return $this->iterator->key(); } @@ -67,7 +67,7 @@ public function key() * Returns true on success or false on failure. * @since 5.0.0 */ - public function valid() + public function valid(): bool { return $this->iterator->valid(); } @@ -78,7 +78,7 @@ public function valid() * @return void Any returned value is ignored. * @since 5.0.0 */ - public function rewind() + public function rewind(): void { $this->iterator->rewind(); } From 3b837b3fc4561d385165a3e6f6d47e0d03cd4c74 Mon Sep 17 00:00:00 2001 From: Dominik Pfaffenbauer Date: Wed, 13 Jul 2022 13:11:41 +0200 Subject: [PATCH 23/65] behat tests --- .github/workflows/behat.yml | 22 +++++++++- .travis.yml | 81 ------------------------------------- etc/build/.gitkeep | 0 3 files changed, 20 insertions(+), 83 deletions(-) delete mode 100644 .travis.yml create mode 100644 etc/build/.gitkeep diff --git a/.github/workflows/behat.yml b/.github/workflows/behat.yml index e380c536..88ee8ff3 100644 --- a/.github/workflows/behat.yml +++ b/.github/workflows/behat.yml @@ -22,15 +22,17 @@ jobs: PIMCORE_CLASS_DIRECTORY: 'var/tmp/behat/var/classes' PIMCORE_WRITE_TARGET_STATICROUTES: 'settings-store' PIMCORE_TEST_DB_DSN: "mysql://root:root@127.0.0.1:3306/data_defs_test" + services: - mysql: - image: mysql:8.0 + database: + image: "mariadb:10.5" env: MYSQL_ROOT_PASSWORD: root MYSQL_DATABASE: data_defs_test ports: - 3306:3306 options: --health-cmd="mysqladmin ping" --health-interval=10s --health-timeout=5s --health-retries=3 + name: "${{ matrix.pimcore }}, PHP ${{ matrix.php }}" strategy: matrix: @@ -98,3 +100,19 @@ jobs: - name: Run Behat run: vendor/bin/behat --strict --no-interaction -vvv -f progress --config behat.yml.dist -p default + + - name: Upload Behat logs + uses: actions/upload-artifact@v2 + if: failure() + with: + name: "Behat logs (non-JS, PHP ${{ matrix.php }}, Symfony ${{ matrix.pimcore }})" + path: etc/build/ + if-no-files-found: ignore + + - name: Upload Pimcore logs + uses: actions/upload-artifact@v2 + if: failure() + with: + name: "Pimcore logs (non-JS, PHP ${{ matrix.php }}, Symfony ${{ matrix.pimcore }})" + path: var/log/ + if-no-files-found: ignore diff --git a/.travis.yml b/.travis.yml deleted file mode 100644 index 2e456eb7..00000000 --- a/.travis.yml +++ /dev/null @@ -1,81 +0,0 @@ -sudo: false -language: php - -addons: - mariadb: '10.2' - hosts: - - pimcore-test.dev -services: - - mysql - -env: - global: - - PIMCORE_ENVIRONMENT=test - - PIMCORE_TEST_DB_DSN="mysql://root@localhost/im_test" - - PIMCORE_VERSION="~6.5" - - IM_TEST=1 - - IM_SUITE=application - - SYMFONY_VERSION="^3.4" - -matrix: - include: - - sudo: required - php: 7.3 - env: - - IM_SUITE=codestyle - - - sudo: required - php: 7.3 - env: - - IM_SUITE=stan - - - sudo: required - php: 7.2 - - - sudo: required - php: 7.3 - - - sudo: required - php: 7.2 - env: - - SYMFONY_VERSION="^4.0" - - - sudo: required - php: 7.3 - env: - - SYMFONY_VERSION="^4.0" - - - sudo: required - php: 7.2 - env: - - PIMCORE_VERSION="dev-master" - - SYMFONY_VERSION="^4.0" - - - sudo: required - php: 7.3 - env: - - PIMCORE_VERSION="dev-master" - - SYMFONY_VERSION="^4.0" - allow_failures: - - env: - - IM_SUITE=codestyle - - env: - - PIMCORE_VERSION="dev-master" - - env: - - PIMCORE_VERSION="dev-master" - - SYMFONY_VERSION="^4.0" - fast_finish: true - -cache: - directories: - - $HOME/.cache/composer - -install: - - etc/travis/install - -script: - - etc/travis/script - -notifications: - email: - - travis-ci@coreshop.org diff --git a/etc/build/.gitkeep b/etc/build/.gitkeep new file mode 100644 index 00000000..e69de29b From 04c11f38e7e2f34082088036f23bb732eeb058d6 Mon Sep 17 00:00:00 2001 From: Dominik Pfaffenbauer Date: Wed, 13 Jul 2022 14:20:25 +0200 Subject: [PATCH 24/65] fix tests --- .github/workflows/behat.yml | 14 ++----- composer.json | 13 ++++--- public/app.php | 38 ------------------- .../Context/Transform/PimcoreClassContext.php | 3 -- 4 files changed, 11 insertions(+), 57 deletions(-) delete mode 100644 public/app.php diff --git a/.github/workflows/behat.yml b/.github/workflows/behat.yml index 88ee8ff3..3fd43be2 100644 --- a/.github/workflows/behat.yml +++ b/.github/workflows/behat.yml @@ -33,12 +33,11 @@ jobs: - 3306:3306 options: --health-cmd="mysqladmin ping" --health-interval=10s --health-timeout=5s --health-retries=3 - name: "${{ matrix.pimcore }}, PHP ${{ matrix.php }}" + name: "${{ matrix.pimcore }}, PHP ${{ matrix.php }}, Deps ${{ matrix.dependencies }}" strategy: matrix: - php: [ 8.0, 8.1 ] + php: [ 8.0 ] pimcore: [ ^10.2, 10.x-dev ] - dependencies: [ highest, lowest ] steps: - uses: actions/checkout@v2 @@ -74,18 +73,11 @@ jobs: key: ${{ runner.os }}-composer-${{ hashFiles('**/composer.json') }} restore-keys: ${{ runner.os }}-composer- - - if: matrix.dependencies == 'highest' - name: Install dependencies highest + - name: Install dependencies highest run: | composer req guzzlehttp/psr7 pimcore/pimcore:${{ matrix.pimcore }} --no-interaction --no-scripts --no-update composer update --no-progress --prefer-dist --optimize-autoloader - - if: matrix.dependencies == 'lowest' - name: Install dependencies lowest - run: | - composer req guzzlehttp/psr7 pimcore/pimcore:${{ matrix.pimcore }} --no-interaction --no-scripts --no-update - composer update --no-progress --prefer-dist --optimize-autoloader --prefer-lowest - - name: Cache clear run: bin/console cache:clear diff --git a/composer.json b/composer.json index d95cc3d8..90835d1a 100755 --- a/composer.json +++ b/composer.json @@ -32,11 +32,13 @@ "php": ">=8.0", "ext-json": "*", "box/spout": "^3.0", - "league/csv": "^9.7", + "coreshop/pimcore-bundle": "^3.0", "coreshop/resource-bundle": "^3.0", "coreshop/rule-bundle": "^3.0", - "coreshop/pimcore-bundle": "^3.0", - "pimcore/pimcore": "^10.0", + "jms/serializer": "^3.17.1", + "league/csv": "^9.7", + "nyholm/psr7": "^1.5", + "pimcore/pimcore": "^10.2", "psr/http-client-implementation": "^1.0", "psr/http-factory-implementation": "^1.0" }, @@ -50,10 +52,11 @@ "phpstan/phpstan-webmozart-assert": "^1.1.2" }, "conflict": { - + "guzzlehttp/psr7": "< 2.0" }, "suggest": { - "dpfaffenbauer/process-manager": "Allows to start Imports/Exports from within Pimcore UI and also tracks Status of current processes." + "dpfaffenbauer/process-manager": "Allows to start Imports/Exports from within Pimcore UI and also tracks Status of current processes.", + "guzzlehttp/psr7": "For downloading external data like Images" }, "autoload": { "psr-4": { diff --git a/public/app.php b/public/app.php deleted file mode 100644 index 2de934c4..00000000 --- a/public/app.php +++ /dev/null @@ -1,38 +0,0 @@ -handle($request); -$response->send(); - -$kernel->terminate($request, $response); diff --git a/tests/DataDefinitionsBundle/Behat/Context/Transform/PimcoreClassContext.php b/tests/DataDefinitionsBundle/Behat/Context/Transform/PimcoreClassContext.php index 42b58ffb..ce2ff728 100644 --- a/tests/DataDefinitionsBundle/Behat/Context/Transform/PimcoreClassContext.php +++ b/tests/DataDefinitionsBundle/Behat/Context/Transform/PimcoreClassContext.php @@ -15,7 +15,6 @@ namespace Wvision\Bundle\DataDefinitionsBundle\Behat\Context\Transform; use Behat\Behat\Context\Context; -use CoreShop\Component\Pimcore\DataObject\ClassLoader; use Wvision\Bundle\DataDefinitionsBundle\Behat\Service\ClassStorageInterface; use Wvision\Bundle\DataDefinitionsBundle\Behat\Service\SharedStorageInterface; use Pimcore\Cache\Runtime; @@ -47,8 +46,6 @@ public function class($name) $name = $this->classStorage->get($name); - ClassLoader::forceLoadDataObjectClass($name); - $classDefinition = ClassDefinition::getByName($name); Assert::notNull($classDefinition, sprintf('Class Definition for class with name %s not found', $name)); From a02a8aeed56ebeff3e4f6b4be049ca76916d5213 Mon Sep 17 00:00:00 2001 From: Dominik Pfaffenbauer Date: Wed, 13 Jul 2022 14:23:04 +0200 Subject: [PATCH 25/65] add tests for ^10.3 and ^10.4 --- .github/workflows/behat.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/behat.yml b/.github/workflows/behat.yml index 3fd43be2..b83b4eba 100644 --- a/.github/workflows/behat.yml +++ b/.github/workflows/behat.yml @@ -33,11 +33,11 @@ jobs: - 3306:3306 options: --health-cmd="mysqladmin ping" --health-interval=10s --health-timeout=5s --health-retries=3 - name: "${{ matrix.pimcore }}, PHP ${{ matrix.php }}, Deps ${{ matrix.dependencies }}" + name: "${{ matrix.pimcore }}, PHP ${{ matrix.php }}" strategy: matrix: php: [ 8.0 ] - pimcore: [ ^10.2, 10.x-dev ] + pimcore: [ ^10.2, ^10.3, ^10.4, 10.x-dev ] steps: - uses: actions/checkout@v2 From da6ecccd90493ce9a47fa5b5e5f8d18da9f3b182 Mon Sep 17 00:00:00 2001 From: Dominik Pfaffenbauer Date: Wed, 13 Jul 2022 15:56:00 +0200 Subject: [PATCH 26/65] [Contexts] introduce contexts to make params list for all kinds of extensions smaller and easier extendable --- .../Cleaner/AbstractCleaner.php | 1 - src/DataDefinitionsBundle/Cleaner/Deleter.php | 1 - .../AbstractImportDefinitionCommand.php | 2 - .../Command/ExportCommand.php | 13 +- .../Command/ImportCommand.php | 3 +- .../Command/ListExportDefinitionsCommand.php | 3 +- .../Command/ListImportDefinitionsCommand.php | 3 +- .../Context/ContextFactory.php | 99 +++ .../Context/ContextFactoryInterface.php | 85 +++ .../Context/FetcherContext.php | 38 + .../FetcherContextInterface.php} | 10 +- .../Context/FilterContext.php | 58 ++ .../Context/FilterContextInterface.php | 34 + .../Context/GetterContext.php | 52 ++ .../Context/GetterContextInterface.php | 32 + .../Context/InterpreterContext.php | 72 ++ .../Context/InterpreterContextInterface.php | 39 + .../Context/LoaderContext.php | 57 ++ .../Context/LoaderContextInterface.php | 33 + .../Context/RunnerContext.php | 58 ++ .../Context/RunnerContextInterface.php | 34 + .../Context/SetterContext.php | 71 ++ .../Context/SetterContextInterface.php | 39 + .../Controller/ExportDefinitionController.php | 61 +- .../Controller/ImportDefinitionController.php | 18 +- .../Controller/ImportRuleController.php | 81 +- .../DataDefinitionsBundle.php | 4 - .../DependencyInjection/Configuration.php | 131 ++-- .../DataDefinitionsExtension.php | 2 +- .../Event/EventDispatcherInterface.php | 7 +- .../Event/ImportDefinitionEvent.php | 2 +- .../Exception/InterpreterException.php | 44 +- .../Exporter/Exporter.php | 109 +-- .../Fetcher/FetcherInterface.php | 7 +- .../Fetcher/ObjectsFetcher.php | 23 +- .../Filter/FilterInterface.php | 5 +- .../Form/Type/ExportDefinitionType.php | 8 +- .../Form/Type/ExportMappingType.php | 8 +- .../Form/Type/ImportDefinitionType.php | 4 +- .../Form/Type/ImportMappingType.php | 8 +- .../Form/Type/ImportRulesImportType.php | 8 +- .../Interpreter/CarbonInterpreterType.php | 3 +- .../CoreShop/MoneyInterpreterType.php | 24 +- .../CoreShop/StoresInterpreterType.php | 42 +- .../Form/Type/Interpreter/InterpreterType.php | 4 +- .../ExportDefinitionObjectStartupForm.php | 13 +- .../Setter/CoreShop/StorePriceSetterType.php | 42 +- .../Setter/CoreShop/StoreValuesSetterType.php | 42 +- .../Getter/DynamicColumnGetterInterface.php | 5 +- .../Getter/GetterInterface.php | 5 +- .../Importer/Importer.php | 256 ++++--- src/DataDefinitionsBundle/Installer.php | 1 - .../Interpreter/AssetByPathInterpreter.php | 13 +- .../Interpreter/AssetUrlInterpreter.php | 52 +- .../Interpreter/AssetsUrlInterpreter.php | 15 +- .../Interpreter/CarbonInterpreter.php | 23 +- .../Interpreter/CheckboxInterpreter.php | 25 +- .../Interpreter/ConditionalInterpreter.php | 39 +- .../CoreShop/CurrencyInterpreter.php | 13 +- .../Interpreter/CoreShop/MoneyInterpreter.php | 13 +- .../Interpreter/CoreShop/PriceInterpreter.php | 12 +- .../CoreShop/StoresInterpreter.php | 11 +- .../Interpreter/DefaultValueInterpreter.php | 17 +- .../Interpreter/DefinitionInterpreter.php | 13 +- .../DoNotSetOnEmptyInterpreter.php | 23 +- .../Interpreter/ExpressionInterpreter.php | 38 +- .../Interpreter/ExternalImageInterpreter.php | 23 +- .../Interpreter/HrefInterpreter.php | 22 +- .../Interpreter/ImportRuleInterpreter.php | 44 +- .../Interpreter/InterpreterInterface.php | 12 +- .../Interpreter/IteratorInterpreter.php | 55 +- .../Interpreter/LinkInterpreter.php | 27 +- .../Interpreter/MappingInterpreter.php | 23 +- .../Interpreter/MetadataInterpreter.php | 21 +- .../Interpreter/MultiHrefInterpreter.php | 20 +- .../Interpreter/NestedInterpreter.php | 47 +- .../Interpreter/ObjectResolverInterpreter.php | 17 +- .../Interpreter/QuantityValueInterpreter.php | 19 +- .../Interpreter/SpecificObjectInterpreter.php | 11 +- .../Interpreter/TwigInterpreter.php | 24 +- .../Interpreter/TypeCastingInterpreter.php | 23 +- .../Loader/LoaderInterface.php | 4 +- .../Loader/PrimaryKeyLoader.php | 15 +- .../Model/ExportDefinition.php | 2 +- .../Model/ExportDefinition/Dao.php | 16 +- .../Model/ImportDefinition/Dao.php | 16 +- .../Model/Log/Listing.php | 2 +- .../Model/Log/Listing/Dao.php | 20 +- .../AbstractProcessManagerListener.php | 14 +- .../ArtifactGenerationProviderInterface.php | 2 +- .../ProcessManager/ArtifactProviderTrait.php | 6 +- .../ImportDefinitionsReport.php | 5 +- .../ProcessManagerExportListener.php | 4 +- .../Provider/AbstractSqlProvider.php | 8 +- .../Provider/CsvProvider.php | 18 +- .../Provider/ExcelProvider.php | 31 +- .../Provider/ExportProviderInterface.php | 7 +- .../Provider/ExternalSqlProvider.php | 1 - .../Provider/ImportDataSetInterface.php | 1 - .../Provider/ImportProviderInterface.php | 7 +- .../Provider/JsonProvider.php | 16 +- .../Provider/RawProvider.php | 8 +- .../Provider/SqlProvider.php | 1 - .../Provider/XmlProvider.php | 31 +- .../Resources/config/coreshop.yml | 58 +- .../Resources/config/guzzle_psr7.yml | 4 +- .../Resources/config/pimcore/config.yml | 148 ++-- .../Resources/config/pimcore/routing.yml | 120 +-- .../Resources/config/process_manager.yml | 82 +- .../config/serializer/Model.Definition.yml | 88 +-- .../serializer/Model.ExportDefinition.yml | 30 +- .../serializer/Model.ImportDefinition.yml | 102 +-- .../Resources/config/services.yml | 721 +++++++++--------- .../Resources/config/services/commands.yml | 80 +- .../Resources/config/services/forms.yml | 274 +++---- .../config/services/import_rules.yml | 224 +++--- .../Resources/config/services/installer.yml | 16 +- .../Resources/install/pimcore/sql/data.sql | 18 +- .../Resources/public/pimcore/img/rules.svg | 8 +- .../public/pimcore/js/import_rule/panel.js | 27 +- .../pimcore/js/interpreters/asseturl.js | 8 +- .../public/pimcore/js/interpreters/carbon.js | 6 +- .../pimcore/js/interpreters/import_rule.js | 2 +- .../js/process_manager/export_contextmenu.js | 8 +- .../js/process_manager/export_search.js | 4 +- .../js/process_manager/import_definitions.js | 2 +- .../Rules/Action/ExpressionProcessor.php | 9 +- .../Action/ImportRuleProcessorInterface.php | 8 +- .../Rules/Action/ObjectProcessor.php | 9 +- .../Condition/AbstractConditionChecker.php | 12 +- .../Condition/ExpressionConditionChecker.php | 8 +- .../ImportRuleConditionCheckerInterface.php | 7 +- .../Runner/ExportRunnerInterface.php | 7 +- .../ImportStartFinishRunnerInterface.php | 8 +- .../Runner/RunnerInterface.php | 7 +- .../Runner/SaveRunnerInterface.php | 5 +- .../Service/FieldSelection.php | 7 +- .../Setter/ClassificationStoreFieldGetter.php | 18 +- .../Setter/ClassificationStoreSetter.php | 23 +- .../Setter/CoreShop/StorePriceSetter.php | 25 +- .../Setter/CoreShop/StoreValuesSetter.php | 25 +- .../Setter/FieldCollectionSetter.php | 42 +- .../Setter/KeySetter.php | 11 +- .../Setter/LocalizedfieldSetter.php | 25 +- .../Setter/ObjectTypeSetter.php | 14 +- .../Setter/ObjectbrickSetter.php | 36 +- .../Setter/RelationSetter.php | 12 +- .../Setter/SetterInterface.php | 5 +- .../Behat/Service/Filter/SimpleFilter.php | 5 +- 149 files changed, 2956 insertions(+), 2136 deletions(-) create mode 100644 src/DataDefinitionsBundle/Context/ContextFactory.php create mode 100644 src/DataDefinitionsBundle/Context/ContextFactoryInterface.php create mode 100644 src/DataDefinitionsBundle/Context/FetcherContext.php rename src/DataDefinitionsBundle/{Model/DataSetAwareInterface.php => Context/FetcherContextInterface.php} (65%) create mode 100644 src/DataDefinitionsBundle/Context/FilterContext.php create mode 100644 src/DataDefinitionsBundle/Context/FilterContextInterface.php create mode 100644 src/DataDefinitionsBundle/Context/GetterContext.php create mode 100644 src/DataDefinitionsBundle/Context/GetterContextInterface.php create mode 100644 src/DataDefinitionsBundle/Context/InterpreterContext.php create mode 100644 src/DataDefinitionsBundle/Context/InterpreterContextInterface.php create mode 100644 src/DataDefinitionsBundle/Context/LoaderContext.php create mode 100644 src/DataDefinitionsBundle/Context/LoaderContextInterface.php create mode 100644 src/DataDefinitionsBundle/Context/RunnerContext.php create mode 100644 src/DataDefinitionsBundle/Context/RunnerContextInterface.php create mode 100644 src/DataDefinitionsBundle/Context/SetterContext.php create mode 100644 src/DataDefinitionsBundle/Context/SetterContextInterface.php diff --git a/src/DataDefinitionsBundle/Cleaner/AbstractCleaner.php b/src/DataDefinitionsBundle/Cleaner/AbstractCleaner.php index 5015b475..202a8528 100644 --- a/src/DataDefinitionsBundle/Cleaner/AbstractCleaner.php +++ b/src/DataDefinitionsBundle/Cleaner/AbstractCleaner.php @@ -16,7 +16,6 @@ namespace Wvision\Bundle\DataDefinitionsBundle\Cleaner; -use Exception; use Pimcore\Model\DataObject\Concrete; use Wvision\Bundle\DataDefinitionsBundle\Model\DataDefinitionInterface; use Wvision\Bundle\DataDefinitionsBundle\Model\Log; diff --git a/src/DataDefinitionsBundle/Cleaner/Deleter.php b/src/DataDefinitionsBundle/Cleaner/Deleter.php index adefd0c9..6ee8483b 100644 --- a/src/DataDefinitionsBundle/Cleaner/Deleter.php +++ b/src/DataDefinitionsBundle/Cleaner/Deleter.php @@ -16,7 +16,6 @@ namespace Wvision\Bundle\DataDefinitionsBundle\Cleaner; -use Exception; use Wvision\Bundle\DataDefinitionsBundle\Model\DataDefinitionInterface; class Deleter extends AbstractCleaner diff --git a/src/DataDefinitionsBundle/Command/AbstractImportDefinitionCommand.php b/src/DataDefinitionsBundle/Command/AbstractImportDefinitionCommand.php index 9fecc625..792d75be 100644 --- a/src/DataDefinitionsBundle/Command/AbstractImportDefinitionCommand.php +++ b/src/DataDefinitionsBundle/Command/AbstractImportDefinitionCommand.php @@ -19,8 +19,6 @@ use CoreShop\Bundle\ResourceBundle\Controller\ResourceFormFactoryInterface; use CoreShop\Bundle\ResourceBundle\Pimcore\ObjectManager; use CoreShop\Component\Resource\Metadata\MetadataInterface; -use CoreShop\Component\Resource\Repository\RepositoryInterface; -use Doctrine\ORM\EntityManagerInterface; use InvalidArgumentException; use Pimcore\Console\AbstractCommand; use Symfony\Component\Console\Input\InputArgument; diff --git a/src/DataDefinitionsBundle/Command/ExportCommand.php b/src/DataDefinitionsBundle/Command/ExportCommand.php index c3d95bb0..5cb1c0d3 100644 --- a/src/DataDefinitionsBundle/Command/ExportCommand.php +++ b/src/DataDefinitionsBundle/Command/ExportCommand.php @@ -52,17 +52,20 @@ protected function configure(): void $this ->setName('data-definitions:export') ->setDescription('Run a Data Definition Export.') - ->setHelp(<<setHelp( + <<%command.name% runs a Data Definition Export. EOT ) ->addOption( - 'definition', 'd', + 'definition', + 'd', InputOption::VALUE_REQUIRED, 'Import Definition ID or Name' ) ->addOption( - 'params', 'p', + 'params', + 'p', InputOption::VALUE_REQUIRED, 'JSON Encoded Params' ); @@ -100,7 +103,9 @@ protected function execute(InputInterface $input, OutputInterface $output) $total = $e->getSubject(); if ($total > 0) { $progress = new ProgressBar($output, $total); - $progress->setFormat(' %current%/%max% [%bar%] %percent:3s%% (%elapsed:6s%/%estimated:-6s%) %memory:6s%: %message%'); + $progress->setFormat( + ' %current%/%max% [%bar%] %percent:3s%% (%elapsed:6s%/%estimated:-6s%) %memory:6s%: %message%' + ); $progress->start(); } }; diff --git a/src/DataDefinitionsBundle/Command/ImportCommand.php b/src/DataDefinitionsBundle/Command/ImportCommand.php index e67cecf6..c5f1ee3c 100644 --- a/src/DataDefinitionsBundle/Command/ImportCommand.php +++ b/src/DataDefinitionsBundle/Command/ImportCommand.php @@ -101,8 +101,7 @@ protected function execute(InputInterface $input, OutputInterface $output) if ($progress instanceof ProgressBar) { $progress->setMessage($e->getSubject()); $progress->display(); - } - else { + } else { $output->writeln( sprintf( '%s (%s) (%s): %s', diff --git a/src/DataDefinitionsBundle/Command/ListExportDefinitionsCommand.php b/src/DataDefinitionsBundle/Command/ListExportDefinitionsCommand.php index f3dd4250..75dd7614 100644 --- a/src/DataDefinitionsBundle/Command/ListExportDefinitionsCommand.php +++ b/src/DataDefinitionsBundle/Command/ListExportDefinitionsCommand.php @@ -39,7 +39,8 @@ protected function configure(): void $this ->setName('data-definitions:list:exports') ->setDescription('List all Export Definitions.') - ->setHelp(<<setHelp( + <<%command.name% lists all Data Definitions for Exports. EOT ); diff --git a/src/DataDefinitionsBundle/Command/ListImportDefinitionsCommand.php b/src/DataDefinitionsBundle/Command/ListImportDefinitionsCommand.php index 77119fa9..db96ad39 100644 --- a/src/DataDefinitionsBundle/Command/ListImportDefinitionsCommand.php +++ b/src/DataDefinitionsBundle/Command/ListImportDefinitionsCommand.php @@ -39,7 +39,8 @@ protected function configure(): void $this ->setName('data-definitions:list:imports') ->setDescription('List all Import Definitions.') - ->setHelp(<<setHelp( + <<%command.name% lists all Data Definitions for Imports. EOT ); diff --git a/src/DataDefinitionsBundle/Context/ContextFactory.php b/src/DataDefinitionsBundle/Context/ContextFactory.php new file mode 100644 index 00000000..b3cafb67 --- /dev/null +++ b/src/DataDefinitionsBundle/Context/ContextFactory.php @@ -0,0 +1,99 @@ +definition; + } + + public function getParams(): array + { + return $this->params; + } +} diff --git a/src/DataDefinitionsBundle/Model/DataSetAwareInterface.php b/src/DataDefinitionsBundle/Context/FetcherContextInterface.php similarity index 65% rename from src/DataDefinitionsBundle/Model/DataSetAwareInterface.php rename to src/DataDefinitionsBundle/Context/FetcherContextInterface.php index bad56fe0..62120ff9 100644 --- a/src/DataDefinitionsBundle/Model/DataSetAwareInterface.php +++ b/src/DataDefinitionsBundle/Context/FetcherContextInterface.php @@ -14,13 +14,13 @@ declare(strict_types=1); -namespace Wvision\Bundle\DataDefinitionsBundle\Model; +namespace Wvision\Bundle\DataDefinitionsBundle\Context; -use Wvision\Bundle\DataDefinitionsBundle\Provider\ImportDataSetInterface; +use Wvision\Bundle\DataDefinitionsBundle\Model\ExportDefinitionInterface; -interface DataSetAwareInterface +interface FetcherContextInterface { - public function getDataSet(): ?ImportDataSetInterface; + public function getDefinition(): ExportDefinitionInterface; - public function setDataSet(?ImportDataSetInterface $dataSet): void; + public function getParams(): array; } diff --git a/src/DataDefinitionsBundle/Context/FilterContext.php b/src/DataDefinitionsBundle/Context/FilterContext.php new file mode 100644 index 00000000..9761fb2d --- /dev/null +++ b/src/DataDefinitionsBundle/Context/FilterContext.php @@ -0,0 +1,58 @@ +definition; + } + + public function getParams(): array + { + return $this->params; + } + + public function getDataRow(): array + { + return $this->dataRow; + } + + public function getDataSet(): ImportDataSetInterface + { + return $this->dataSet; + } + + public function getObject(): Concrete + { + return $this->object; + } +} diff --git a/src/DataDefinitionsBundle/Context/FilterContextInterface.php b/src/DataDefinitionsBundle/Context/FilterContextInterface.php new file mode 100644 index 00000000..b65a6eb2 --- /dev/null +++ b/src/DataDefinitionsBundle/Context/FilterContextInterface.php @@ -0,0 +1,34 @@ +definition; + } + + public function getParams(): array + { + return $this->params; + } + + public function getObject(): Concrete + { + return $this->object; + } + + public function getMapping(): ExportMapping + { + return $this->mapping; + } +} diff --git a/src/DataDefinitionsBundle/Context/GetterContextInterface.php b/src/DataDefinitionsBundle/Context/GetterContextInterface.php new file mode 100644 index 00000000..5735ada5 --- /dev/null +++ b/src/DataDefinitionsBundle/Context/GetterContextInterface.php @@ -0,0 +1,32 @@ +definition; + } + + public function getParams(): array + { + return $this->params; + } + + public function getDataRow(): array + { + return $this->dataRow; + } + + public function getDataSet(): ?ImportDataSetInterface + { + return $this->dataSet; + } + + public function getObject(): Concrete + { + return $this->object; + } + + + public function getValue(): mixed + { + return $this->value; + } + + public function getMapping(): MappingInterface + { + return $this->mapping; + } +} diff --git a/src/DataDefinitionsBundle/Context/InterpreterContextInterface.php b/src/DataDefinitionsBundle/Context/InterpreterContextInterface.php new file mode 100644 index 00000000..36ba6ce9 --- /dev/null +++ b/src/DataDefinitionsBundle/Context/InterpreterContextInterface.php @@ -0,0 +1,39 @@ +definition; + } + + public function getParams(): array + { + return $this->params; + } + + public function getDataRow(): array + { + return $this->dataRow; + } + + public function getDataSet(): ImportDataSetInterface + { + return $this->dataSet; + } + + public function getClass(): string + { + return $this->class; + } +} diff --git a/src/DataDefinitionsBundle/Context/LoaderContextInterface.php b/src/DataDefinitionsBundle/Context/LoaderContextInterface.php new file mode 100644 index 00000000..1c2b77f6 --- /dev/null +++ b/src/DataDefinitionsBundle/Context/LoaderContextInterface.php @@ -0,0 +1,33 @@ +definition; + } + + public function getParams(): array + { + return $this->params; + } + + public function getDataRow(): ?array + { + return $this->dataRow; + } + + public function getDataSet(): ?ImportDataSetInterface + { + return $this->dataSet; + } + + public function getObject(): ?Concrete + { + return $this->object; + } +} diff --git a/src/DataDefinitionsBundle/Context/RunnerContextInterface.php b/src/DataDefinitionsBundle/Context/RunnerContextInterface.php new file mode 100644 index 00000000..62d42e58 --- /dev/null +++ b/src/DataDefinitionsBundle/Context/RunnerContextInterface.php @@ -0,0 +1,34 @@ +definition; + } + + public function getParams(): array + { + return $this->params; + } + + public function getObject(): Concrete + { + return $this->object; + } + + public function getImportMapping(): ImportMapping + { + return $this->mapping; + } + + public function getDataRow(): array + { + return $this->dataRow; + } + + public function getDataSet(): ImportDataSetInterface + { + return $this->dataSet; + } + + public function getValue(): mixed + { + return $this->value; + } +} diff --git a/src/DataDefinitionsBundle/Context/SetterContextInterface.php b/src/DataDefinitionsBundle/Context/SetterContextInterface.php new file mode 100644 index 00000000..26b37f37 --- /dev/null +++ b/src/DataDefinitionsBundle/Context/SetterContextInterface.php @@ -0,0 +1,39 @@ + array_keys($fetchers), 'import_rules' => [ 'conditions' => array_keys($importRuleConditions), - 'actions' => array_keys($importRuleActions) - ] + 'actions' => array_keys($importRuleActions), + ], ] ); } @@ -173,8 +173,13 @@ public function getColumnsAction(Request $request): JsonResponse $localizedField->setGroup('localizedfield.'.strtolower($language)); $localizedField->setType('localizedfields'); - $localizedField->setIdentifier(sprintf('%s~%s', $localizedField->getIdentifier(), - $language)); + $localizedField->setIdentifier( + sprintf( + '%s~%s', + $localizedField->getIdentifier(), + $language + ) + ); $localizedField->setGetter('localizedfield'); $localizedField->setConfig(['language' => $language]); $localizedField->setGetterConfig(['language' => $language]); @@ -194,7 +199,8 @@ public function getColumnsAction(Request $request): JsonResponse $classDefs = $brickDefinition->getClassDefinitions(); foreach ($classDefs as $classDef) { - if ($classDef['classname'] === $classDefinition->getName() && $classDef['fieldname'] === $field->getName()) { + if ($classDef['classname'] === $classDefinition->getName( + ) && $classDef['fieldname'] === $field->getName()) { $fields = $brickDefinition->getFieldDefinitions(); foreach ($fields as $brickField) { @@ -202,8 +208,14 @@ public function getColumnsAction(Request $request): JsonResponse $resultField->setGroup('objectbrick.'.$key); $resultField->setType('objectbricks'); - $resultField->setIdentifier(sprintf('objectbrick~%s~%s~%s', $field->getName(), - $key, $resultField->getIdentifier())); + $resultField->setIdentifier( + sprintf( + 'objectbrick~%s~%s~%s', + $field->getName(), + $key, + $resultField->getIdentifier() + ) + ); $resultField->setGetter('objectbrick'); $resultField->setConfig(['class' => $key]); $resultField->setType('objectbrick'); @@ -228,8 +240,14 @@ public function getColumnsAction(Request $request): JsonResponse $resultField->setGroup('fieldcollection.'.$type); $resultField->setType('fieldcollections'); - $resultField->setIdentifier(sprintf('fieldcollection~%s~%s~%s', $field->getName(), $type, - $resultField->getIdentifier())); + $resultField->setIdentifier( + sprintf( + 'fieldcollection~%s~%s~%s', + $field->getName(), + $type, + $resultField->getIdentifier() + ) + ); $resultField->setGetter('fieldcollection'); $resultField->setConfig(['class' => $type]); $resultField->setType('fieldcollection'); @@ -250,8 +268,10 @@ public function getColumnsAction(Request $request): JsonResponse $allowedGroupIds = $field->getAllowedGroupIds(); if ($allowedGroupIds) { - $list->setCondition('ID in ('.implode(',', $allowedGroupIds).') AND storeId = ?', - [$field->getStoreId()]); + $list->setCondition( + 'ID in ('.implode(',', $allowedGroupIds).') AND storeId = ?', + [$field->getStoreId()] + ); } else { $list->setCondition('storeId = ?', [$field->getStoreId()]); } @@ -271,10 +291,21 @@ public function getColumnsAction(Request $request): JsonResponse $keyConfig = DataObject\Classificationstore\KeyConfig::getById($keyId); $toColumn = new FromColumn(); - $toColumn->setGroup(sprintf('classificationstore - %s (%s)', $config->getName(), - $config->getId())); - $toColumn->setIdentifier(sprintf('classificationstore~%s~%s~%s', $field->getName(), - $keyConfig->getId(), $config->getId())); + $toColumn->setGroup( + sprintf( + 'classificationstore - %s (%s)', + $config->getName(), + $config->getId() + ) + ); + $toColumn->setIdentifier( + sprintf( + 'classificationstore~%s~%s~%s', + $field->getName(), + $keyConfig->getId(), + $config->getId() + ) + ); $toColumn->setType('classificationstore'); $toColumn->setFieldtype($keyConfig->getType()); $toColumn->setGetter('classificationstore'); diff --git a/src/DataDefinitionsBundle/Controller/ImportDefinitionController.php b/src/DataDefinitionsBundle/Controller/ImportDefinitionController.php index 0e69864a..3cde1817 100644 --- a/src/DataDefinitionsBundle/Controller/ImportDefinitionController.php +++ b/src/DataDefinitionsBundle/Controller/ImportDefinitionController.php @@ -56,8 +56,8 @@ public function getConfigAction(): JsonResponse 'persister' => array_keys($persisters), 'import_rules' => [ 'conditions' => array_keys($importRuleConditions), - 'actions' => array_keys($importRuleActions) - ] + 'actions' => array_keys($importRuleActions), + ], ]); } @@ -68,7 +68,9 @@ public function testDataAction(Request $request): JsonResponse if ($definition instanceof ImportDefinitionInterface) { try { - if ($this->get('data_definitions.registry.provider')->get($definition->getProvider())->testData($definition->getConfiguration())) { + if ($this->get('data_definitions.registry.provider')->get($definition->getProvider())->testData( + $definition->getConfiguration() + )) { return $this->viewHandler->handle(['success' => true]); } } catch (Exception $ex) { @@ -90,7 +92,9 @@ public function getColumnsAction(Request $request): JsonResponse $customFromColumn->setLabel('Custom'); try { - $fromColumns = $this->get('data_definitions.registry.provider')->get($definition->getProvider())->getColumns($definition->getConfiguration()); + $fromColumns = $this->get('data_definitions.registry.provider')->get( + $definition->getProvider() + )->getColumns($definition->getConfiguration()); $fromColumns[] = $customFromColumn; } catch (Exception $e) { $fromColumns = []; @@ -193,8 +197,10 @@ public function exportAction(Request $request): Response $response = new Response(); $response->headers->set('Content-Type', 'application/json'); - $response->headers->set('Content-Disposition', - sprintf('attachment; filename="import-definition-%s.json"', $name)); + $response->headers->set( + 'Content-Disposition', + sprintf('attachment; filename="import-definition-%s.json"', $name) + ); $response->headers->set('Pragma', 'no-cache'); $response->headers->set('Expires', '0'); $response->headers->set('Content-Transfer-Encoding', 'binary'); diff --git a/src/DataDefinitionsBundle/Controller/ImportRuleController.php b/src/DataDefinitionsBundle/Controller/ImportRuleController.php index 535f3467..4eb20db7 100644 --- a/src/DataDefinitionsBundle/Controller/ImportRuleController.php +++ b/src/DataDefinitionsBundle/Controller/ImportRuleController.php @@ -22,7 +22,6 @@ use Symfony\Component\HttpFoundation\File\UploadedFile; use Symfony\Component\HttpFoundation\JsonResponse; use Symfony\Component\HttpFoundation\Request; -use Wvision\Bundle\DataDefinitionsBundle\Exception\SpoutException; use Wvision\Bundle\DataDefinitionsBundle\Form\Type\ImportRulesImportType; class ImportRuleController extends AdminController @@ -114,18 +113,19 @@ public function importAction(Request $request, FormFactoryInterface $formFactory $lastConfigIndex = $configIndex; $condition = [ 'type' => $configType, - 'configuration' => [] + 'configuration' => [], ]; - } - else if ($lastConfigType !== $configType || $lastConfigKey === $configKey || $lastConfigIndex !== $configIndex) { - if (null !== $condition && count($condition['configuration']) > 0) { - $conditions[] = $condition; + } else { + if ($lastConfigType !== $configType || $lastConfigKey === $configKey || $lastConfigIndex !== $configIndex) { + if (null !== $condition && count($condition['configuration']) > 0) { + $conditions[] = $condition; + } + + $condition = [ + 'type' => $configType, + 'configuration' => [], + ]; } - - $condition = [ - 'type' => $configType, - 'configuration' => [] - ]; } $condition['configuration'][$configKey] = $value; @@ -148,18 +148,19 @@ public function importAction(Request $request, FormFactoryInterface $formFactory $lastConfigIndex = $configIndex; $action = [ 'type' => $configType, - 'configuration' => [] + 'configuration' => [], ]; - } - else if ($lastConfigType !== $configType || $lastConfigKey === $configKey || $lastConfigIndex !== $configIndex) { - if (null !== $action && count($action['configuration']) > 0) { - $actions[] = $action; + } else { + if ($lastConfigType !== $configType || $lastConfigKey === $configKey || $lastConfigIndex !== $configIndex) { + if (null !== $action && count($action['configuration']) > 0) { + $actions[] = $action; + } + + $action = [ + 'type' => $configType, + 'configuration' => [], + ]; } - - $action = [ - 'type' => $configType, - 'configuration' => [] - ]; } $action['configuration'][$configKey] = $value; @@ -176,7 +177,17 @@ public function importAction(Request $request, FormFactoryInterface $formFactory $rule['actions'] = $actions; $rule['conditions'] = $conditions; - $rule['id'] = sprintf('%04X%04X-%04X-%04X-%04X-%04X%04X%04X', mt_rand(0, 65535), mt_rand(0, 65535), mt_rand(0, 65535), mt_rand(16384, 20479), mt_rand(32768, 49151), mt_rand(0, 65535), mt_rand(0, 65535), mt_rand(0, 65535)); + $rule['id'] = sprintf( + '%04X%04X-%04X-%04X-%04X-%04X%04X%04X', + mt_rand(0, 65535), + mt_rand(0, 65535), + mt_rand(0, 65535), + mt_rand(16384, 20479), + mt_rand(32768, 49151), + mt_rand(0, 65535), + mt_rand(0, 65535), + mt_rand(0, 65535) + ); $rules[] = $rule; } @@ -197,7 +208,7 @@ public function exportAction(Request $request): BinaryFileResponse $headers = [ 'name', - 'active' + 'active', ]; $headersCondition = []; $headersAction = []; @@ -210,7 +221,7 @@ public function exportAction(Request $request): BinaryFileResponse $type = $condition['type']; foreach ($condition['configuration'] as $key => $value) { - $conditionHeader = 'condition_' . $type . '___1___' . $key; + $conditionHeader = 'condition_'.$type.'___1___'.$key; if (!array_key_exists($conditionHeader, $countPerType)) { $countPerType[$conditionHeader] = 0; @@ -219,7 +230,7 @@ public function exportAction(Request $request): BinaryFileResponse $countPerType[$conditionHeader]++; if ($countPerType[$conditionHeader] > 1) { - $conditionHeader = 'condition_' . $type . '___'.$countPerType[$conditionHeader].'___' . $key; + $conditionHeader = 'condition_'.$type.'___'.$countPerType[$conditionHeader].'___'.$key; } if (!in_array($conditionHeader, $headersCondition)) { @@ -232,7 +243,7 @@ public function exportAction(Request $request): BinaryFileResponse $type = $action['type']; foreach ($action['configuration'] as $key => $value) { - $actionHeader = 'action_' . $type . '___1___' . $key; + $actionHeader = 'action_'.$type.'___1___'.$key; if (!array_key_exists($actionHeader, $countPerType)) { $countPerType[$actionHeader] = 0; @@ -241,7 +252,7 @@ public function exportAction(Request $request): BinaryFileResponse $countPerType[$actionHeader]++; if ($countPerType[$actionHeader] > 1) { - $actionHeader = 'action_' . $type . '___'.$countPerType[$actionHeader].'___' . $key; + $actionHeader = 'action_'.$type.'___'.$countPerType[$actionHeader].'___'.$key; } if (!in_array($actionHeader, $headersAction)) { @@ -266,7 +277,7 @@ public function exportAction(Request $request): BinaryFileResponse $type = $condition['type']; foreach ($condition['configuration'] as $key => $value) { - $conditionHeader = 'condition_' . $type . '___1___' . $key; + $conditionHeader = 'condition_'.$type.'___1___'.$key; if (!array_key_exists($conditionHeader, $countPerType)) { $countPerType[$conditionHeader] = 0; @@ -275,7 +286,7 @@ public function exportAction(Request $request): BinaryFileResponse $countPerType[$conditionHeader]++; if ($countPerType[$conditionHeader] > 1) { - $conditionHeader = 'condition_' . $type . '___'.$countPerType[$conditionHeader].'___' . $key; + $conditionHeader = 'condition_'.$type.'___'.$countPerType[$conditionHeader].'___'.$key; } if (is_array($value)) { @@ -290,7 +301,7 @@ public function exportAction(Request $request): BinaryFileResponse $type = $action['type']; foreach ($action['configuration'] as $key => $value) { - $actionHeader = 'action_' . $type . '___1___' . $key; + $actionHeader = 'action_'.$type.'___1___'.$key; if (!array_key_exists($actionHeader, $countPerType)) { $countPerType[$actionHeader] = 0; @@ -299,7 +310,7 @@ public function exportAction(Request $request): BinaryFileResponse $countPerType[$actionHeader]++; if ($countPerType[$actionHeader] > 1) { - $actionHeader = 'action_' . $type . '___'.$countPerType[$actionHeader].'___' . $key; + $actionHeader = 'action_'.$type.'___'.$countPerType[$actionHeader].'___'.$key; } if (is_array($value)) { @@ -327,12 +338,16 @@ public function exportAction(Request $request): BinaryFileResponse $entry[$key] = $value; } - $result[] = $this->useSpoutLegacy ? $entry : \Box\Spout\Writer\Common\Creator\WriterEntityFactory::createRowFromArray($entry); + $result[] = $this->useSpoutLegacy ? $entry : \Box\Spout\Writer\Common\Creator\WriterEntityFactory::createRowFromArray( + $entry + ); } //merge all headers $headerValues = array_values(array_merge($headers, $headersCondition, $headersAction)); - $headers = $this->useSpoutLegacy ? $headerValues : \Box\Spout\Writer\Common\Creator\WriterEntityFactory::createRowFromArray($headerValues); + $headers = $this->useSpoutLegacy ? $headerValues : \Box\Spout\Writer\Common\Creator\WriterEntityFactory::createRowFromArray( + $headerValues + ); //write data $writer->addRow($headers); diff --git a/src/DataDefinitionsBundle/DataDefinitionsBundle.php b/src/DataDefinitionsBundle/DataDefinitionsBundle.php index 8b217f41..d2f84309 100644 --- a/src/DataDefinitionsBundle/DataDefinitionsBundle.php +++ b/src/DataDefinitionsBundle/DataDefinitionsBundle.php @@ -18,15 +18,11 @@ use Composer\InstalledVersions; use CoreShop\Bundle\ResourceBundle\AbstractResourceBundle; -use CoreShop\Bundle\ResourceBundle\ComposerPackageBundleInterface; use CoreShop\Bundle\ResourceBundle\CoreShopResourceBundle; use CoreShop\Bundle\RuleBundle\CoreShopRuleBundle; -use LogicException; use Pimcore\Extension\Bundle\PimcoreBundleInterface; -use Pimcore\Extension\Bundle\Traits\PackageVersionTrait; use Pimcore\HttpKernel\BundleCollection\BundleCollection; use Symfony\Component\DependencyInjection\ContainerBuilder; -use Symfony\Component\DependencyInjection\Extension\ExtensionInterface; use Wvision\Bundle\DataDefinitionsBundle\DependencyInjection\Compiler\CleanerRegistryCompilerPass; use Wvision\Bundle\DataDefinitionsBundle\DependencyInjection\Compiler\ExportProviderRegistryCompilerPass; use Wvision\Bundle\DataDefinitionsBundle\DependencyInjection\Compiler\ExportRunnerRegistryCompilerPass; diff --git a/src/DataDefinitionsBundle/DependencyInjection/Configuration.php b/src/DataDefinitionsBundle/DependencyInjection/Configuration.php index f8b9e270..321143b2 100644 --- a/src/DataDefinitionsBundle/DependencyInjection/Configuration.php +++ b/src/DataDefinitionsBundle/DependencyInjection/Configuration.php @@ -40,7 +40,7 @@ public function getConfigTreeBuilder(): TreeBuilder $rootNode ->children() - ->scalarNode('driver')->defaultValue(CoreShopResourceBundle::DRIVER_PIMCORE)->end() + ->scalarNode('driver')->defaultValue(CoreShopResourceBundle::DRIVER_PIMCORE)->end() ->end(); $this->addPimcoreResourcesSection($rootNode); @@ -53,76 +53,75 @@ private function addModelsSection(ArrayNodeDefinition $node) { $node ->children() - ->arrayNode('resources') - ->addDefaultsIfNotSet() - ->children() - ->arrayNode('import_definition') - ->addDefaultsIfNotSet() - ->children() - ->variableNode('options')->end() - ->scalarNode('permission')->defaultValue('data_definitions_import')->cannotBeOverwritten() - ->end() - ->arrayNode('classes') - ->addDefaultsIfNotSet() - ->children() - ->scalarNode('model')->defaultValue(ImportDefinition::class)->cannotBeEmpty()->end() - ->scalarNode('interface')->defaultValue(ImportDefinitionInterface::class)->cannotBeEmpty()->end() - ->scalarNode('admin_controller')->defaultValue(ImportDefinitionController::class)->cannotBeEmpty()->end() - ->scalarNode('factory')->defaultValue(Factory::class)->cannotBeEmpty()->end() - ->scalarNode('repository')->defaultValue(Repository\DefinitionRepository::class)->cannotBeEmpty()->end() - ->scalarNode('form')->defaultValue(ImportDefinitionType::class)->cannotBeEmpty()->end() - ->end() - ->end() - ->end() - ->end() - ->arrayNode('export_definition') - ->addDefaultsIfNotSet() - ->children() - ->variableNode('options')->end() - ->scalarNode('permission')->defaultValue('data_definitions_export')->cannotBeOverwritten() - ->end() - ->arrayNode('classes') - ->addDefaultsIfNotSet() - ->children() - ->scalarNode('model')->defaultValue(ExportDefinition::class)->cannotBeEmpty()->end() - ->scalarNode('interface')->defaultValue(ExportDefinitionInterface::class)->cannotBeEmpty()->end() - ->scalarNode('admin_controller')->defaultValue(ExportDefinitionController::class)->cannotBeEmpty()->end() - ->scalarNode('factory')->defaultValue(Factory::class)->cannotBeEmpty()->end() - ->scalarNode('repository')->defaultValue(Repository\DefinitionRepository::class)->cannotBeEmpty()->end() - ->scalarNode('form')->defaultValue(ExportDefinitionType::class)->cannotBeEmpty()->end() - ->end() - ->end() - ->end() - ->end() - ->end() - ->end() - ->end() - ; + ->arrayNode('resources') + ->addDefaultsIfNotSet() + ->children() + ->arrayNode('import_definition') + ->addDefaultsIfNotSet() + ->children() + ->variableNode('options')->end() + ->scalarNode('permission')->defaultValue('data_definitions_import')->cannotBeOverwritten() + ->end() + ->arrayNode('classes') + ->addDefaultsIfNotSet() + ->children() + ->scalarNode('model')->defaultValue(ImportDefinition::class)->cannotBeEmpty()->end() + ->scalarNode('interface')->defaultValue(ImportDefinitionInterface::class)->cannotBeEmpty()->end() + ->scalarNode('admin_controller')->defaultValue(ImportDefinitionController::class)->cannotBeEmpty()->end() + ->scalarNode('factory')->defaultValue(Factory::class)->cannotBeEmpty()->end() + ->scalarNode('repository')->defaultValue(Repository\DefinitionRepository::class)->cannotBeEmpty()->end() + ->scalarNode('form')->defaultValue(ImportDefinitionType::class)->cannotBeEmpty()->end() + ->end() + ->end() + ->end() + ->end() + ->arrayNode('export_definition') + ->addDefaultsIfNotSet() + ->children() + ->variableNode('options')->end() + ->scalarNode('permission')->defaultValue('data_definitions_export')->cannotBeOverwritten() + ->end() + ->arrayNode('classes') + ->addDefaultsIfNotSet() + ->children() + ->scalarNode('model')->defaultValue(ExportDefinition::class)->cannotBeEmpty()->end() + ->scalarNode('interface')->defaultValue(ExportDefinitionInterface::class)->cannotBeEmpty()->end() + ->scalarNode('admin_controller')->defaultValue(ExportDefinitionController::class)->cannotBeEmpty()->end() + ->scalarNode('factory')->defaultValue(Factory::class)->cannotBeEmpty()->end() + ->scalarNode('repository')->defaultValue(Repository\DefinitionRepository::class)->cannotBeEmpty()->end() + ->scalarNode('form')->defaultValue(ExportDefinitionType::class)->cannotBeEmpty()->end() + ->end() + ->end() + ->end() + ->end() + ->end() + ->end() + ->end(); } private function addPimcoreResourcesSection(ArrayNodeDefinition $node) { $node->children() ->arrayNode('pimcore_admin') - ->addDefaultsIfNotSet() - ->children() - ->arrayNode('js') - ->useAttributeAsKey('name') - ->prototype('scalar')->end() - ->end() - ->arrayNode('css') - ->useAttributeAsKey('name') - ->prototype('scalar')->end() - ->end() - ->arrayNode('install') - ->addDefaultsIfNotSet() - ->ignoreExtraKeys(false) - ->children() - ->scalarNode('sql')->defaultValue(['@DataDefinitionsBundle/Resources/install/pimcore/sql/data.sql'])->end() - ->end() - ->end() - ->end() - ->end() - ->end(); + ->addDefaultsIfNotSet() + ->children() + ->arrayNode('js') + ->useAttributeAsKey('name') + ->prototype('scalar')->end() + ->end() + ->arrayNode('css') + ->useAttributeAsKey('name') + ->prototype('scalar')->end() + ->end() + ->arrayNode('install') + ->addDefaultsIfNotSet() + ->ignoreExtraKeys(false) + ->children() + ->scalarNode('sql')->defaultValue(['@DataDefinitionsBundle/Resources/install/pimcore/sql/data.sql'])->end() + ->end() + ->end() + ->end() + ->end() + ->end(); } } diff --git a/src/DataDefinitionsBundle/DependencyInjection/DataDefinitionsExtension.php b/src/DataDefinitionsBundle/DependencyInjection/DataDefinitionsExtension.php index cf2ca752..23f5498b 100644 --- a/src/DataDefinitionsBundle/DependencyInjection/DataDefinitionsExtension.php +++ b/src/DataDefinitionsBundle/DependencyInjection/DataDefinitionsExtension.php @@ -49,7 +49,7 @@ class DataDefinitionsExtension extends AbstractModelExtension { public function load(array $configs, ContainerBuilder $container) { - $loader = new Loader\YamlFileLoader($container, new FileLocator(__DIR__ . '/../Resources/config')); + $loader = new Loader\YamlFileLoader($container, new FileLocator(__DIR__.'/../Resources/config')); $configuration = new Configuration(); $config = $this->processConfiguration($configuration, $configs); diff --git a/src/DataDefinitionsBundle/Event/EventDispatcherInterface.php b/src/DataDefinitionsBundle/Event/EventDispatcherInterface.php index d2a6336c..d30642be 100644 --- a/src/DataDefinitionsBundle/Event/EventDispatcherInterface.php +++ b/src/DataDefinitionsBundle/Event/EventDispatcherInterface.php @@ -18,5 +18,10 @@ interface EventDispatcherInterface { - public function dispatch(DataDefinitionInterface $definition, string $eventName, $subject = null, array $params = []); + public function dispatch( + DataDefinitionInterface $definition, + string $eventName, + $subject = null, + array $params = [] + ); } diff --git a/src/DataDefinitionsBundle/Event/ImportDefinitionEvent.php b/src/DataDefinitionsBundle/Event/ImportDefinitionEvent.php index 77ba7c16..a715e296 100644 --- a/src/DataDefinitionsBundle/Event/ImportDefinitionEvent.php +++ b/src/DataDefinitionsBundle/Event/ImportDefinitionEvent.php @@ -32,7 +32,7 @@ public function __construct(ImportDefinitionInterface $definition, $subject = nu $this->options = $options; } - public function getDefinition() : ImportDefinitionInterface + public function getDefinition(): ImportDefinitionInterface { return $this->definition; } diff --git a/src/DataDefinitionsBundle/Exception/InterpreterException.php b/src/DataDefinitionsBundle/Exception/InterpreterException.php index 816ba6d0..905268c1 100644 --- a/src/DataDefinitionsBundle/Exception/InterpreterException.php +++ b/src/DataDefinitionsBundle/Exception/InterpreterException.php @@ -23,24 +23,44 @@ class InterpreterException extends RuntimeException { - private function __construct(DataDefinitionInterface $definition, MappingInterface $mapping, array $params, $value, ?Throwable $previous = null) - { + private function __construct( + DataDefinitionInterface $definition, + MappingInterface $mapping, + array $params, + $value, + ?Throwable $previous = null + ) { parent::__construct($this->formatMessage($definition, $mapping, $params, $value, $previous), 0, $previous); } - public static function fromInterpreter(DataDefinitionInterface $definition, MappingInterface $mapping, array $params, $value, ?Throwable $previous = null): InterpreterException - { + public static function fromInterpreter( + DataDefinitionInterface $definition, + MappingInterface $mapping, + array $params, + $value, + ?Throwable $previous = null + ): InterpreterException { return new self($definition, $mapping, $params, $value, $previous); } - private function formatMessage(DataDefinitionInterface $definition, MappingInterface $mapping, array $params, $value, ?Throwable $previous = null): string - { + private function formatMessage( + DataDefinitionInterface $definition, + MappingInterface $mapping, + array $params, + $value, + ?Throwable $previous = null + ): string { $format = '%1$s, %2$s'; if ($previous !== null) { $format = '%1$s, %2$s: %3$s'; } - return sprintf($format, $this->formatDefinition($definition), $this->formatSource($mapping, $value, $params['row'] ?? null), $previous ? $previous->getMessage() : null); + return sprintf( + $format, + $this->formatDefinition($definition), + $this->formatSource($mapping, $value, $params['row'] ?? null), + $previous ? $previous->getMessage() : null + ); } private function formatDefinition(DataDefinitionInterface $definition): string @@ -55,7 +75,15 @@ private function formatSource(MappingInterface $mapping, $value, ?int $row = nul $format = 'from "%1$s" (row %5$d) to "%2$s" (interpreter "%3$s", config %4$s), got value %6$s'; } - return sprintf($format, $mapping->getFromColumn(), $mapping->getToColumn(), $mapping->getInterpreter(), var_export_pretty($mapping->getInterpreterConfig()), $row, $this->formatValue($value)); + return sprintf( + $format, + $mapping->getFromColumn(), + $mapping->getToColumn(), + $mapping->getInterpreter(), + var_export_pretty($mapping->getInterpreterConfig()), + $row, + $this->formatValue($value) + ); } private function formatValue($value): string diff --git a/src/DataDefinitionsBundle/Exporter/Exporter.php b/src/DataDefinitionsBundle/Exporter/Exporter.php index b75435e3..4d31b39e 100644 --- a/src/DataDefinitionsBundle/Exporter/Exporter.php +++ b/src/DataDefinitionsBundle/Exporter/Exporter.php @@ -24,8 +24,9 @@ use Pimcore\Model\DataObject\Concrete; use Psr\Log\LoggerInterface; use Symfony\Component\EventDispatcher\EventDispatcherInterface; +use Wvision\Bundle\DataDefinitionsBundle\Context\ContextFactoryInterface; +use Wvision\Bundle\DataDefinitionsBundle\Context\FetcherContextInterface; use Wvision\Bundle\DataDefinitionsBundle\Event\ExportDefinitionEvent; -use Wvision\Bundle\DataDefinitionsBundle\Exception\DoNotSetException; use Wvision\Bundle\DataDefinitionsBundle\Exception\UnexpectedValueException; use Wvision\Bundle\DataDefinitionsBundle\Fetcher\FetcherInterface; use Wvision\Bundle\DataDefinitionsBundle\Getter\DynamicColumnGetterInterface; @@ -39,47 +40,39 @@ final class Exporter implements ExporterInterface { - private ServiceRegistryInterface$fetcherRegistry; - private ServiceRegistryInterface$runnerRegistry; - private ServiceRegistryInterface$interpreterRegistry; - private ServiceRegistryInterface$getterRegistry; - private ServiceRegistryInterface$exportProviderRegistry; - private EventDispatcherInterface$eventDispatcher; - private LoggerInterface$logger; - private array $exceptions = []; private bool $shouldStop = false; + private array $exceptions = []; public function __construct( - ServiceRegistryInterface $fetcherRegistry, - ServiceRegistryInterface $runnerRegistry, - ServiceRegistryInterface $interpreterRegistry, - ServiceRegistryInterface $getterRegistry, - ServiceRegistryInterface $exportProviderRegistry, - EventDispatcherInterface $eventDispatcher, - LoggerInterface $logger + private ServiceRegistryInterface $fetcherRegistry, + private ServiceRegistryInterface $runnerRegistry, + private ServiceRegistryInterface $interpreterRegistry, + private ServiceRegistryInterface $getterRegistry, + private ServiceRegistryInterface $exportProviderRegistry, + private ContextFactoryInterface $contextFactory, + private EventDispatcherInterface $eventDispatcher, + private LoggerInterface $logger ) { - $this->fetcherRegistry = $fetcherRegistry; - $this->runnerRegistry = $runnerRegistry; - $this->interpreterRegistry = $interpreterRegistry; - $this->getterRegistry = $getterRegistry; - $this->exportProviderRegistry = $exportProviderRegistry; - $this->eventDispatcher = $eventDispatcher; - $this->logger = $logger; + } public function doExport(ExportDefinitionInterface $definition, array $params) { + $fetcherContext = $this->contextFactory->createFetcherContext($definition, $params); + $fetcher = $this->getFetcher($definition); $provider = $this->getProvider($definition); - $total = $fetcher->count($definition, $params, - is_array($definition->getFetcherConfig()) ? $definition->getFetcherConfig() : []); + $total = $fetcher->count( + $fetcherContext, + is_array($definition->getFetcherConfig()) ? $definition->getFetcherConfig() : [] + ); $this->eventDispatcher->dispatch( new ExportDefinitionEvent($definition, $total, $params), 'data_definitions.export.total' ); - $this->runExport($definition, $params, $total, $fetcher, $provider); + $this->runExport($definition, $params, $total, $fetcherContext, $fetcher, $provider); $this->eventDispatcher->dispatch( new ExportDefinitionEvent($definition, null, $params), @@ -90,8 +83,12 @@ public function doExport(ExportDefinitionInterface $definition, array $params) private function getFetcher(ExportDefinitionInterface $definition): FetcherInterface { if (!$this->fetcherRegistry->has($definition->getFetcher())) { - throw new InvalidArgumentException(sprintf('Export Definition %s has no valid fetcher configured', - $definition->getName())); + throw new InvalidArgumentException( + sprintf( + 'Export Definition %s has no valid fetcher configured', + $definition->getName() + ) + ); } /** @var FetcherInterface $fetcher */ @@ -103,8 +100,12 @@ private function getFetcher(ExportDefinitionInterface $definition): FetcherInter private function getProvider(ExportDefinitionInterface $definition): ExportProviderInterface { if (!$this->exportProviderRegistry->has($definition->getProvider())) { - throw new InvalidArgumentException(sprintf('Definition %s has no valid export provider configured', - $definition->getName())); + throw new InvalidArgumentException( + sprintf( + 'Definition %s has no valid export provider configured', + $definition->getName() + ) + ); } return $this->exportProviderRegistry->get($definition->getProvider()); @@ -114,11 +115,12 @@ private function runExport( ExportDefinitionInterface $definition, $params, int $total, + FetcherContextInterface $fetcherContext, FetcherInterface $fetcher, ExportProviderInterface $provider ) { UnpublishedHelper::hideUnpublished( - function () use ($definition, $params, $total, $fetcher, $provider) { + function () use ($definition, $params, $total, $fetcher, $provider, $fetcherContext) { $count = 0; $countToClean = 1000; $perLoop = 50; @@ -126,8 +128,7 @@ function () use ($definition, $params, $total, $fetcher, $provider) { for ($i = 0; $i < $perRun; $i++) { $objects = $fetcher->fetch( - $definition, - $params, + $fetcherContext, $perLoop, $i * $perLoop, is_array($definition->getFetcherConfig()) ? $definition->getFetcherConfig() : [] @@ -153,7 +154,9 @@ function () use ($definition, $params, $total, $fetcher, $provider) { $this->exceptions[] = $ex; $this->eventDispatcher->dispatch( - new ExportDefinitionEvent($definition, sprintf('Error: %s', $ex->getMessage()), $params), + new ExportDefinitionEvent( + $definition, sprintf('Error: %s', $ex->getMessage()), $params + ), 'data_definitions.export.status' ); @@ -173,6 +176,7 @@ function () use ($definition, $params, $total, $fetcher, $provider) { new ExportDefinitionEvent($definition, 'Process has been stopped.', $params), 'data_definitions.export.status' ); + return; } @@ -192,6 +196,7 @@ private function exportRow( $data = []; $runner = null; + $runnerContext = $this->contextFactory->createRunnerContext($definition, $params, null, null, $object); $this->eventDispatcher->dispatch( new ExportDefinitionEvent($definition, sprintf('Export Object %s', $object->getId()), $params), @@ -207,7 +212,7 @@ private function exportRow( } if ($runner instanceof ExportRunnerInterface) { - $data = $runner->exportPreRun($object, $data, $definition, $params); + $data = $runner->exportPreRun($runnerContext); } $this->logger->info(sprintf('Export Object: %s', $object->getRealFullPath())); @@ -247,7 +252,7 @@ private function exportRow( ); if ($runner instanceof ExportRunnerInterface) { - $data = $runner->exportPostRun($object, $data, $definition, $params); + $data = $runner->exportPostRun($runnerContext); } return $data; @@ -264,9 +269,10 @@ private function getObjectValue( $value = null; if (null !== $getter) { - $value = $getter->get($object, $map, $data); + $getterContext = $this->contextFactory->createGetterContext($definition, $params, $object, $map); + $value = $getter->get($getterContext); } else { - $getter = 'get' . ucfirst($map->getFromColumn()); + $getter = 'get'.ucfirst($map->getFromColumn()); if (method_exists($object, $getter)) { $value = $object->$getter(); @@ -278,18 +284,27 @@ private function getObjectValue( if ($interpreter instanceof InterpreterInterface) { try { - $value = $interpreter->interpret( - $object, - $value, - $map, - $data, + $context = $this->contextFactory->createInterpreterContext( $definition, $params, + $data, + null, + $object, + $value, + $map + ); + $value = $interpreter->interpret( + $context, $map->getInterpreterConfig() ); - } - catch (UnexpectedValueException $ex) { - $this->logger->info(sprintf('Unexpected Value from Interpreter "%s" with message "%s"', $map->getInterpreter(), $ex->getMessage())); + } catch (UnexpectedValueException $ex) { + $this->logger->info( + sprintf( + 'Unexpected Value from Interpreter "%s" with message "%s"', + $map->getInterpreter(), + $ex->getMessage() + ) + ); } } @@ -311,7 +326,7 @@ private function fetchGetter(ExportMapping $map): ?GetterInterface return null; } - public function stop() : void + public function stop(): void { $this->shouldStop = true; } diff --git a/src/DataDefinitionsBundle/Fetcher/FetcherInterface.php b/src/DataDefinitionsBundle/Fetcher/FetcherInterface.php index 8a552a3f..6a33f3b2 100644 --- a/src/DataDefinitionsBundle/Fetcher/FetcherInterface.php +++ b/src/DataDefinitionsBundle/Fetcher/FetcherInterface.php @@ -16,18 +16,17 @@ namespace Wvision\Bundle\DataDefinitionsBundle\Fetcher; -use Wvision\Bundle\DataDefinitionsBundle\Model\ExportDefinitionInterface; +use Wvision\Bundle\DataDefinitionsBundle\Context\FetcherContextInterface; interface FetcherInterface { public function fetch( - ExportDefinitionInterface $definition, - array $params, + FetcherContextInterface $context, int $limit, int $offset, array $configuration ); - public function count(ExportDefinitionInterface $definition, array $params, array $configuration): int; + public function count(FetcherContextInterface $context, array $configuration): int; } diff --git a/src/DataDefinitionsBundle/Fetcher/ObjectsFetcher.php b/src/DataDefinitionsBundle/Fetcher/ObjectsFetcher.php index 1fe716a0..116bec1e 100644 --- a/src/DataDefinitionsBundle/Fetcher/ObjectsFetcher.php +++ b/src/DataDefinitionsBundle/Fetcher/ObjectsFetcher.php @@ -19,22 +19,23 @@ use InvalidArgumentException; use Pimcore\Model\DataObject\ClassDefinition; use Pimcore\Model\DataObject\Concrete; +use Wvision\Bundle\DataDefinitionsBundle\Context\FetcherContextInterface; use Wvision\Bundle\DataDefinitionsBundle\Model\ExportDefinitionInterface; class ObjectsFetcher implements FetcherInterface { - public function fetch(ExportDefinitionInterface $definition, array $params, int $limit, int $offset, array $configuration) + public function fetch(FetcherContextInterface $context, int $limit, int $offset, array $configuration) { - $list = $this->getClassListing($definition, $params); + $list = $this->getClassListing($context->getDefinition(), $context->getParams()); $list->setLimit($limit); $list->setOffset($offset); return $list->load(); } - public function count(ExportDefinitionInterface $definition, array $params, array $configuration): int + public function count(FetcherContextInterface $context, array $configuration): int { - return $this->getClassListing($definition, $params)->getTotalCount(); + return $this->getClassListing($context->getDefinition(), $context->getParams())->getTotalCount(); } private function getClassListing(ExportDefinitionInterface $definition, array $params) @@ -56,24 +57,26 @@ private function getClassListing(ExportDefinitionInterface $definition, array $p if (null !== $rootNode) { $quotedPath = $list->quote($rootNode->getRealFullPath()); - $quotedWildcardPath = $list->quote(str_replace('//', '/', $rootNode->getRealFullPath() . '/') . '%'); - $conditionFilters[] = '(o_path = ' . $quotedPath . ' OR o_path LIKE ' . $quotedWildcardPath . ')'; + $quotedWildcardPath = $list->quote(str_replace('//', '/', $rootNode->getRealFullPath().'/').'%'); + $conditionFilters[] = '(o_path = '.$quotedPath.' OR o_path LIKE '.$quotedWildcardPath.')'; } } if (isset($params['query'])) { $query = $this->filterQueryParam($params['query']); if (!empty($query)) { - $conditionFilters[] = 'oo_id IN (SELECT id FROM search_backend_data WHERE MATCH (`data`,`properties`) AGAINST (' . $list->quote($query) . ' IN BOOLEAN MODE))'; + $conditionFilters[] = 'oo_id IN (SELECT id FROM search_backend_data WHERE MATCH (`data`,`properties`) AGAINST ('.$list->quote( + $query + ).' IN BOOLEAN MODE))'; } } if (isset($params['only_direct_children']) && $params['only_direct_children'] == 'true' && null !== $rootNode) { - $conditionFilters[] = 'o_parentId = ' . $rootNode->getId(); + $conditionFilters[] = 'o_parentId = '.$rootNode->getId(); } if (isset($params['condition'])) { - $conditionFilters[] = '(' . $params['condition'] . ')'; + $conditionFilters[] = '('.$params['condition'].')'; } if (isset($params['ids'])) { $quotedIds = []; @@ -81,7 +84,7 @@ private function getClassListing(ExportDefinitionInterface $definition, array $p $quotedIds[] = $list->quote($id); } if (!empty($quotedIds)) { - $conditionFilters[] = 'oo_id IN (' . implode(',', $quotedIds) . ')'; + $conditionFilters[] = 'oo_id IN ('.implode(',', $quotedIds).')'; } } diff --git a/src/DataDefinitionsBundle/Filter/FilterInterface.php b/src/DataDefinitionsBundle/Filter/FilterInterface.php index 0f3bb68b..1162d9c0 100644 --- a/src/DataDefinitionsBundle/Filter/FilterInterface.php +++ b/src/DataDefinitionsBundle/Filter/FilterInterface.php @@ -16,10 +16,9 @@ namespace Wvision\Bundle\DataDefinitionsBundle\Filter; -use Pimcore\Model\DataObject\Concrete; -use Wvision\Bundle\DataDefinitionsBundle\Model\DataDefinitionInterface; +use Wvision\Bundle\DataDefinitionsBundle\Context\FilterContextInterface; interface FilterInterface { - public function filter(DataDefinitionInterface $definition, array $data, Concrete $object, array $params): bool; + public function filter(FilterContextInterface $context): bool; } diff --git a/src/DataDefinitionsBundle/Form/Type/ExportDefinitionType.php b/src/DataDefinitionsBundle/Form/Type/ExportDefinitionType.php index 7f571797..7ffa436f 100644 --- a/src/DataDefinitionsBundle/Form/Type/ExportDefinitionType.php +++ b/src/DataDefinitionsBundle/Form/Type/ExportDefinitionType.php @@ -134,7 +134,7 @@ public function buildForm(FormBuilderInterface $builder, array $options): void /** * @param FormInterface $form - * @param string $configurationType + * @param string $configurationType */ protected function addConfigurationFields(FormInterface $form, string $configurationType): void { @@ -143,7 +143,7 @@ protected function addConfigurationFields(FormInterface $form, string $configura /** * @param FormInterface $form - * @param mixed $data + * @param mixed $data * @return string|null */ protected function getRegistryIdentifier(FormInterface $form, $data = null): ?string @@ -161,7 +161,7 @@ protected function getRegistryIdentifier(FormInterface $form, $data = null): ?st /** * @param FormInterface $form - * @param string $configurationType + * @param string $configurationType */ protected function addFetcherConfigurationFields(FormInterface $form, string $configurationType): void { @@ -170,7 +170,7 @@ protected function addFetcherConfigurationFields(FormInterface $form, string $co /** * @param FormInterface $form - * @param mixed $data + * @param mixed $data * @return string|null */ protected function getFetcherRegistryIdentifier(FormInterface $form, $data = null): ?string diff --git a/src/DataDefinitionsBundle/Form/Type/ExportMappingType.php b/src/DataDefinitionsBundle/Form/Type/ExportMappingType.php index 79c7fdd7..61b42e9b 100644 --- a/src/DataDefinitionsBundle/Form/Type/ExportMappingType.php +++ b/src/DataDefinitionsBundle/Form/Type/ExportMappingType.php @@ -110,7 +110,7 @@ public function buildForm(FormBuilderInterface $builder, array $options): void /** * @param FormInterface $form - * @param string $configurationType + * @param string $configurationType */ protected function addGetterConfigurationFields(FormInterface $form, string $configurationType): void { @@ -119,7 +119,7 @@ protected function addGetterConfigurationFields(FormInterface $form, string $con /** * @param FormInterface $form - * @param string $configurationType + * @param string $configurationType */ protected function addInterpreterConfigurationFields(FormInterface $form, string $configurationType): void { @@ -129,7 +129,7 @@ protected function addInterpreterConfigurationFields(FormInterface $form, string /** * @param FormInterface $form - * @param mixed $data + * @param mixed $data * @return string|null */ protected function getGetterRegistryIdentifier(FormInterface $form, $data = null): ?string @@ -143,7 +143,7 @@ protected function getGetterRegistryIdentifier(FormInterface $form, $data = null /** * @param FormInterface $form - * @param mixed $data + * @param mixed $data * @return string|null */ protected function getInterpreterRegistryIdentifier(FormInterface $form, $data = null): ?string diff --git a/src/DataDefinitionsBundle/Form/Type/ImportDefinitionType.php b/src/DataDefinitionsBundle/Form/Type/ImportDefinitionType.php index 9f452136..d0f738ed 100644 --- a/src/DataDefinitionsBundle/Form/Type/ImportDefinitionType.php +++ b/src/DataDefinitionsBundle/Form/Type/ImportDefinitionType.php @@ -105,7 +105,7 @@ public function buildForm(FormBuilderInterface $builder, array $options): void /** * @param FormInterface $form - * @param string $configurationType + * @param string $configurationType */ protected function addConfigurationFields(FormInterface $form, string $configurationType): void { @@ -114,7 +114,7 @@ protected function addConfigurationFields(FormInterface $form, string $configura /** * @param FormInterface $form - * @param mixed $data + * @param mixed $data * @return string|null */ protected function getRegistryIdentifier(FormInterface $form, $data = null): ?string diff --git a/src/DataDefinitionsBundle/Form/Type/ImportMappingType.php b/src/DataDefinitionsBundle/Form/Type/ImportMappingType.php index aecf6c52..7d84e355 100644 --- a/src/DataDefinitionsBundle/Form/Type/ImportMappingType.php +++ b/src/DataDefinitionsBundle/Form/Type/ImportMappingType.php @@ -114,7 +114,7 @@ public function buildForm(FormBuilderInterface $builder, array $options): void /** * @param FormInterface $form - * @param string $configurationType + * @param string $configurationType */ protected function addSetterConfigurationFields(FormInterface $form, string $configurationType): void { @@ -123,7 +123,7 @@ protected function addSetterConfigurationFields(FormInterface $form, string $con /** * @param FormInterface $form - * @param string $configurationType + * @param string $configurationType */ protected function addInterpreterConfigurationFields(FormInterface $form, string $configurationType): void { @@ -132,7 +132,7 @@ protected function addInterpreterConfigurationFields(FormInterface $form, string /** * @param FormInterface $form - * @param mixed $data + * @param mixed $data * @return string|null */ protected function getSetterRegistryIdentifier(FormInterface $form, $data = null): ?string @@ -146,7 +146,7 @@ protected function getSetterRegistryIdentifier(FormInterface $form, $data = null /** * @param FormInterface $form - * @param mixed $data + * @param mixed $data * @return string|null */ protected function getInterpreterRegistryIdentifier(FormInterface $form, $data = null): ?string diff --git a/src/DataDefinitionsBundle/Form/Type/ImportRulesImportType.php b/src/DataDefinitionsBundle/Form/Type/ImportRulesImportType.php index fefaf60e..05409c8c 100644 --- a/src/DataDefinitionsBundle/Form/Type/ImportRulesImportType.php +++ b/src/DataDefinitionsBundle/Form/Type/ImportRulesImportType.php @@ -31,10 +31,10 @@ public function buildForm(FormBuilderInterface $builder, array $options): void 'constraints' => [ new File([ 'mimeTypes' => [ - 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet' - ] - ]) - ] + 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet', + ], + ]), + ], ]); } diff --git a/src/DataDefinitionsBundle/Form/Type/Interpreter/CarbonInterpreterType.php b/src/DataDefinitionsBundle/Form/Type/Interpreter/CarbonInterpreterType.php index 08b7df33..aff2ee11 100644 --- a/src/DataDefinitionsBundle/Form/Type/Interpreter/CarbonInterpreterType.php +++ b/src/DataDefinitionsBundle/Form/Type/Interpreter/CarbonInterpreterType.php @@ -25,7 +25,6 @@ final class CarbonInterpreterType extends AbstractType public function buildForm(FormBuilderInterface $builder, array $options): void { $builder - ->add('date_format', TextType::class) - ; + ->add('date_format', TextType::class); } } diff --git a/src/DataDefinitionsBundle/Form/Type/Interpreter/CoreShop/MoneyInterpreterType.php b/src/DataDefinitionsBundle/Form/Type/Interpreter/CoreShop/MoneyInterpreterType.php index 6c711399..1ff387fe 100644 --- a/src/DataDefinitionsBundle/Form/Type/Interpreter/CoreShop/MoneyInterpreterType.php +++ b/src/DataDefinitionsBundle/Form/Type/Interpreter/CoreShop/MoneyInterpreterType.php @@ -18,18 +18,20 @@ public function buildForm(FormBuilderInterface $builder, array $options) $builder ->add('isFloat', CheckboxType::class) ->add('currency', CurrencyChoiceType::class) - ->addModelTransformer(new CallbackTransformer( - function ($value) { - return $value; - }, - function ($value) { + ->addModelTransformer( + new CallbackTransformer( + function ($value) { + return $value; + }, + function ($value) { - if (isset($value['currency']) && $value['currency'] instanceof CurrencyInterface) { - $value['currency'] = $value['currency']->getId(); - } + if (isset($value['currency']) && $value['currency'] instanceof CurrencyInterface) { + $value['currency'] = $value['currency']->getId(); + } - return $value; - } - )); + return $value; + } + ) + ); } } diff --git a/src/DataDefinitionsBundle/Form/Type/Interpreter/CoreShop/StoresInterpreterType.php b/src/DataDefinitionsBundle/Form/Type/Interpreter/CoreShop/StoresInterpreterType.php index 8c2fa978..1a24d4e8 100644 --- a/src/DataDefinitionsBundle/Form/Type/Interpreter/CoreShop/StoresInterpreterType.php +++ b/src/DataDefinitionsBundle/Form/Type/Interpreter/CoreShop/StoresInterpreterType.php @@ -32,29 +32,31 @@ public function buildForm(FormBuilderInterface $builder, array $options) ->add('stores', StoreChoiceType::class, [ 'multiple' => true, ]) - ->addModelTransformer(new CallbackTransformer( - function ($value) { - return $value; - }, - function ($value) { - $resolvedValues = []; - - if (!is_array($value) || - !array_key_exists('stores', $value) || - !$value['stores'] instanceof ArrayCollection) { - return []; - } + ->addModelTransformer( + new CallbackTransformer( + function ($value) { + return $value; + }, + function ($value) { + $resolvedValues = []; + + if (!is_array($value) || + !array_key_exists('stores', $value) || + !$value['stores'] instanceof ArrayCollection) { + return []; + } - foreach ($value['stores'] as $val) { - if ($val instanceof StoreInterface) { - $resolvedValues[] = $val->getId(); + foreach ($value['stores'] as $val) { + if ($val instanceof StoreInterface) { + $resolvedValues[] = $val->getId(); + } } - } - $value['stores'] = $resolvedValues; + $value['stores'] = $resolvedValues; - return $value; - } - )); + return $value; + } + ) + ); } } diff --git a/src/DataDefinitionsBundle/Form/Type/Interpreter/InterpreterType.php b/src/DataDefinitionsBundle/Form/Type/Interpreter/InterpreterType.php index 53de6c54..b5a3301c 100644 --- a/src/DataDefinitionsBundle/Form/Type/Interpreter/InterpreterType.php +++ b/src/DataDefinitionsBundle/Form/Type/Interpreter/InterpreterType.php @@ -89,7 +89,7 @@ public function configureOptions(OptionsResolver $resolver): void /** * @param FormInterface $form - * @param string $configurationType + * @param string $configurationType */ protected function addConfigurationFields(FormInterface $form, string $configurationType): void { @@ -98,7 +98,7 @@ protected function addConfigurationFields(FormInterface $form, string $configura /** * @param FormInterface $form - * @param mixed $data + * @param mixed $data * * @return string|null */ diff --git a/src/DataDefinitionsBundle/Form/Type/ProcessManager/ExportDefinitionObjectStartupForm.php b/src/DataDefinitionsBundle/Form/Type/ProcessManager/ExportDefinitionObjectStartupForm.php index 2b019a37..2782e22c 100644 --- a/src/DataDefinitionsBundle/Form/Type/ProcessManager/ExportDefinitionObjectStartupForm.php +++ b/src/DataDefinitionsBundle/Form/Type/ProcessManager/ExportDefinitionObjectStartupForm.php @@ -28,22 +28,21 @@ public function buildForm(FormBuilderInterface $builder, array $options): void { $builder ->add('root', TextType::class, [ - 'required' => false + 'required' => false, ]) ->add('query', TextType::class, [ - 'required' => false + 'required' => false, ]) ->add('only_direct_children', CheckboxType::class, [ - 'required' => false + 'required' => false, ]) ->add('condition', TextType::class, [ - 'required' => false + 'required' => false, ]) ->add('ids', CollectionType::class, [ 'allow_add' => true, 'entry_type' => TextType::class, - 'required' => false - ]) - ; + 'required' => false, + ]); } } diff --git a/src/DataDefinitionsBundle/Form/Type/Setter/CoreShop/StorePriceSetterType.php b/src/DataDefinitionsBundle/Form/Type/Setter/CoreShop/StorePriceSetterType.php index 8fedb4b9..ae3db1e0 100644 --- a/src/DataDefinitionsBundle/Form/Type/Setter/CoreShop/StorePriceSetterType.php +++ b/src/DataDefinitionsBundle/Form/Type/Setter/CoreShop/StorePriceSetterType.php @@ -32,29 +32,31 @@ public function buildForm(FormBuilderInterface $builder, array $options): void ->add('stores', StoreChoiceType::class, [ 'multiple' => true, ]) - ->addModelTransformer(new CallbackTransformer( - function ($value) { - return $value; - }, - function ($value) { - $resolvedValues = []; - - if (!is_array($value) || - !array_key_exists('stores', $value) || - !$value['stores'] instanceof ArrayCollection) { - return []; - } + ->addModelTransformer( + new CallbackTransformer( + function ($value) { + return $value; + }, + function ($value) { + $resolvedValues = []; + + if (!is_array($value) || + !array_key_exists('stores', $value) || + !$value['stores'] instanceof ArrayCollection) { + return []; + } - foreach ($value['stores'] as $val) { - if ($val instanceof StoreInterface) { - $resolvedValues[] = $val->getId(); + foreach ($value['stores'] as $val) { + if ($val instanceof StoreInterface) { + $resolvedValues[] = $val->getId(); + } } - } - $value['stores'] = $resolvedValues; + $value['stores'] = $resolvedValues; - return $value; - } - )); + return $value; + } + ) + ); } } diff --git a/src/DataDefinitionsBundle/Form/Type/Setter/CoreShop/StoreValuesSetterType.php b/src/DataDefinitionsBundle/Form/Type/Setter/CoreShop/StoreValuesSetterType.php index 7d5d8938..d2cc097e 100644 --- a/src/DataDefinitionsBundle/Form/Type/Setter/CoreShop/StoreValuesSetterType.php +++ b/src/DataDefinitionsBundle/Form/Type/Setter/CoreShop/StoreValuesSetterType.php @@ -34,29 +34,31 @@ public function buildForm(FormBuilderInterface $builder, array $options): void 'multiple' => true, ]) ->add('type', TextType::class) - ->addModelTransformer(new CallbackTransformer( - function ($value) { - return $value; - }, - function ($value) { - $resolvedValues = []; - - if (!is_array($value) || - !array_key_exists('stores', $value) || - !$value['stores'] instanceof ArrayCollection) { - return []; - } + ->addModelTransformer( + new CallbackTransformer( + function ($value) { + return $value; + }, + function ($value) { + $resolvedValues = []; - foreach ($value['stores'] as $val) { - if ($val instanceof StoreInterface) { - $resolvedValues[] = $val->getId(); + if (!is_array($value) || + !array_key_exists('stores', $value) || + !$value['stores'] instanceof ArrayCollection) { + return []; } - } - $value['stores'] = $resolvedValues; + foreach ($value['stores'] as $val) { + if ($val instanceof StoreInterface) { + $resolvedValues[] = $val->getId(); + } + } - return $value; - } - )); + $value['stores'] = $resolvedValues; + + return $value; + } + ) + ); } } diff --git a/src/DataDefinitionsBundle/Getter/DynamicColumnGetterInterface.php b/src/DataDefinitionsBundle/Getter/DynamicColumnGetterInterface.php index c4e53b9b..5f095e24 100644 --- a/src/DataDefinitionsBundle/Getter/DynamicColumnGetterInterface.php +++ b/src/DataDefinitionsBundle/Getter/DynamicColumnGetterInterface.php @@ -16,8 +16,7 @@ namespace Wvision\Bundle\DataDefinitionsBundle\Getter; -use Pimcore\Model\DataObject\Concrete; -use Wvision\Bundle\DataDefinitionsBundle\Model\ExportMapping; +use Wvision\Bundle\DataDefinitionsBundle\Context\GetterContextInterface; interface DynamicColumnGetterInterface extends GetterInterface { @@ -31,5 +30,5 @@ interface DynamicColumnGetterInterface extends GetterInterface * with other columns from the definition and to always return * exactly the same keys in exactly the same order for each object. */ - public function get(Concrete $object, ExportMapping $map, ?array $data): array; + public function get(GetterContextInterface $context): array; } diff --git a/src/DataDefinitionsBundle/Getter/GetterInterface.php b/src/DataDefinitionsBundle/Getter/GetterInterface.php index becfa52c..f086d11d 100644 --- a/src/DataDefinitionsBundle/Getter/GetterInterface.php +++ b/src/DataDefinitionsBundle/Getter/GetterInterface.php @@ -16,10 +16,9 @@ namespace Wvision\Bundle\DataDefinitionsBundle\Getter; -use Pimcore\Model\DataObject\Concrete; -use Wvision\Bundle\DataDefinitionsBundle\Model\ExportMapping; +use Wvision\Bundle\DataDefinitionsBundle\Context\GetterContextInterface; interface GetterInterface { - public function get(Concrete $object, ExportMapping $map, ?array $data); + public function get(GetterContextInterface $context); } diff --git a/src/DataDefinitionsBundle/Importer/Importer.php b/src/DataDefinitionsBundle/Importer/Importer.php index 79a3cc15..e4ece5a7 100644 --- a/src/DataDefinitionsBundle/Importer/Importer.php +++ b/src/DataDefinitionsBundle/Importer/Importer.php @@ -32,19 +32,20 @@ use Psr\Log\LoggerInterface; use Symfony\Component\ExpressionLanguage\ExpressionLanguage; use Throwable; +use Wvision\Bundle\DataDefinitionsBundle\Context\ContextFactoryInterface; use Wvision\Bundle\DataDefinitionsBundle\Event\EventDispatcherInterface; use Wvision\Bundle\DataDefinitionsBundle\Exception\DoNotSetException; use Wvision\Bundle\DataDefinitionsBundle\Exception\UnexpectedValueException; use Wvision\Bundle\DataDefinitionsBundle\Filter\FilterInterface; +use Wvision\Bundle\DataDefinitionsBundle\Interpreter\InterpreterInterface; use Wvision\Bundle\DataDefinitionsBundle\Loader\LoaderInterface; -use Wvision\Bundle\DataDefinitionsBundle\Model\DataSetAwareInterface; use Wvision\Bundle\DataDefinitionsBundle\Model\ImportDefinitionInterface; use Wvision\Bundle\DataDefinitionsBundle\Model\ImportMapping; use Wvision\Bundle\DataDefinitionsBundle\Model\ParamsAwareInterface; +use Wvision\Bundle\DataDefinitionsBundle\Persister\PersisterInterface; use Wvision\Bundle\DataDefinitionsBundle\Provider\ImportDataSet; use Wvision\Bundle\DataDefinitionsBundle\Provider\ImportDataSetInterface; use Wvision\Bundle\DataDefinitionsBundle\Provider\ImportProviderInterface; -use Wvision\Bundle\DataDefinitionsBundle\Persister\PersisterInterface; use Wvision\Bundle\DataDefinitionsBundle\Runner\ImportStartFinishRunnerInterface; use Wvision\Bundle\DataDefinitionsBundle\Runner\RunnerInterface; use Wvision\Bundle\DataDefinitionsBundle\Runner\SaveRunnerInterface; @@ -53,46 +54,24 @@ final class Importer implements ImporterInterface { - private ServiceRegistryInterface $providerRegistry; - private ServiceRegistryInterface $filterRegistry; - private ServiceRegistryInterface $runnerRegistry; - private ServiceRegistryInterface $interpreterRegistry; - private ServiceRegistryInterface $setterRegistry; - private ServiceRegistryInterface $cleanerRegistry; - private ServiceRegistryInterface $loaderRegistry; - private ServiceRegistryInterface $persisterRegistry; - private EventDispatcherInterface $eventDispatcher; - private LoggerInterface $logger; - private Factory $modelFactory; - private ExpressionLanguage $expressionLanguage; private bool $shouldStop = false; public function __construct( - ServiceRegistryInterface $providerRegistry, - ServiceRegistryInterface $filterRegistry, - ServiceRegistryInterface $runnerRegistry, - ServiceRegistryInterface $interpreterRegistry, - ServiceRegistryInterface $setterRegistry, - ServiceRegistryInterface $cleanerRegistry, - ServiceRegistryInterface $loaderRegistry, - ServiceRegistryInterface $persisterRegistry, - EventDispatcherInterface $eventDispatcher, - LoggerInterface $logger, - Factory $modelFactory, - ExpressionLanguage $expressionLanguage + private ServiceRegistryInterface $providerRegistry, + private ServiceRegistryInterface $filterRegistry, + private ServiceRegistryInterface $runnerRegistry, + private ServiceRegistryInterface $interpreterRegistry, + private ServiceRegistryInterface $setterRegistry, + private ServiceRegistryInterface $cleanerRegistry, + private ServiceRegistryInterface $loaderRegistry, + private ServiceRegistryInterface $persisterRegistry, + private EventDispatcherInterface $eventDispatcher, + private ContextFactoryInterface $contextFactory, + private LoggerInterface $logger, + private Factory $modelFactory, + private ExpressionLanguage $expressionLanguage ) { - $this->providerRegistry = $providerRegistry; - $this->filterRegistry = $filterRegistry; - $this->runnerRegistry = $runnerRegistry; - $this->interpreterRegistry = $interpreterRegistry; - $this->setterRegistry = $setterRegistry; - $this->cleanerRegistry = $cleanerRegistry; - $this->loaderRegistry = $loaderRegistry; - $this->persisterRegistry = $persisterRegistry; - $this->eventDispatcher = $eventDispatcher; - $this->logger = $logger; - $this->modelFactory = $modelFactory; - $this->expressionLanguage = $expressionLanguage; + } public function doImport(ImportDefinitionInterface $definition, $params): array @@ -113,7 +92,12 @@ public function doImport(ImportDefinitionInterface $definition, $params): array $filter = $this->filterRegistry->get($filterType); } + + /** @var ImportDataSetInterface|array $data */ + $data = $this->getData($definition, $params); + $runner = null; + $runnerContext = $this->contextFactory->createRunnerContext($definition, $params, null, $data, null); if ($definition->getRunner()) { /** @@ -122,21 +106,19 @@ public function doImport(ImportDefinitionInterface $definition, $params): array $runner = $this->runnerRegistry->get($definition->getRunner()); } - /** @var ImportDataSetInterface|array $data */ - $data = $this->getData($definition, $params); if ((\is_countable($data) || $data instanceof Countable) && \count($data) > 0) { $this->eventDispatcher->dispatch($definition, 'data_definitions.import.total', \count($data), $params); } if ($runner instanceof ImportStartFinishRunnerInterface) { - $runner->startImport($data, $definition, $params); + $runner->startImport($runnerContext); } [$objectIds, $exceptions] = $this->runImport($definition, $params, $filter, $runner, $data); if ($runner instanceof ImportStartFinishRunnerInterface) { - $runner->finishImport($data, $definition, $params); + $runner->finishImport($runnerContext); } $cleanerType = $definition->getCleaner(); @@ -144,12 +126,11 @@ public function doImport(ImportDefinitionInterface $definition, $params): array $cleaner = $this->cleanerRegistry->get($cleanerType); $this->logger->info(sprintf('Running Cleaner "%s"', $cleanerType)); - $this->eventDispatcher->dispatch($definition, 'data_definitions.import.status', - sprintf('Running Cleaner "%s"', $cleanerType)); - - if ($cleaner instanceof DataSetAwareInterface) { - $cleaner->setDataSet($data); - } + $this->eventDispatcher->dispatch( + $definition, + 'data_definitions.import.status', + sprintf('Running Cleaner "%s"', $cleanerType) + ); if ($cleaner instanceof ParamsAwareInterface) { $cleaner->setParams($params); @@ -162,8 +143,11 @@ public function doImport(ImportDefinitionInterface $definition, $params): array $cleaner->cleanup($definition, $objectIds); $this->logger->info(sprintf('Finished Cleaner "%s"', $cleanerType)); - $this->eventDispatcher->dispatch($definition, 'data_definitions.import.status', - sprintf('Finished Cleaner "%s"', $cleanerType)); + $this->eventDispatcher->dispatch( + $definition, + 'data_definitions.import.status', + sprintf('Finished Cleaner "%s"', $cleanerType) + ); } if (count($exceptions) > 0) { @@ -179,7 +163,12 @@ public function doImport(ImportDefinitionInterface $definition, $params): array public function processSuccessfullImport(ImportDefinitionInterface $definition, $params, $objectIds, $exceptions) { - $this->sendDocument($definition, Document::getById($definition->getSuccessNotificationDocument()), $objectIds, $exceptions); + $this->sendDocument( + $definition, + Document::getById($definition->getSuccessNotificationDocument()), + $objectIds, + $exceptions + ); $this->eventDispatcher->dispatch($definition, 'data_definitions.import.success', $params); } @@ -194,7 +183,7 @@ public function processFailedImport(ImportDefinitionInterface $definition, $para $this->eventDispatcher->dispatch($definition, 'data_definitions.import.failure', $params); } - public function stop() : void + public function stop(): void { $this->shouldStop = true; } @@ -204,8 +193,7 @@ private function sendDocument( ?Document $document, array $objectIds, array $exceptions - ) - { + ) { if ($document instanceof Document) { $params = [ 'exceptions' => $exceptions, @@ -241,8 +229,7 @@ private function runImport( FilterInterface $filter = null, RunnerInterface $runner = null, ImportDataSetInterface $dataSet = null, - ): array - { + ): array { if (null === $dataSet) { $dataSet = new ImportDataSet(new \EmptyIterator()); } @@ -258,7 +245,14 @@ private function runImport( } try { - $object = $this->importRow($definition, $row, $dataSet, array_merge($params, ['row' => $count]), $filter, $runner); + $object = $this->importRow( + $definition, + $row, + $dataSet, + array_merge($params, ['row' => $count]), + $filter, + $runner + ); if ($object instanceof Concrete) { $objectIds[] = $object->getId(); @@ -267,8 +261,12 @@ private function runImport( if (($count + 1) % $countToClean === 0) { Pimcore::collectGarbage(); $this->logger->info('Clean Garbage'); - $this->eventDispatcher->dispatch($definition, 'data_definitions.import.status', 'Collect Garbage', - $params); + $this->eventDispatcher->dispatch( + $definition, + 'data_definitions.import.status', + 'Collect Garbage', + $params + ); } $count++; @@ -277,8 +275,12 @@ private function runImport( $exceptions[] = $ex; - $this->eventDispatcher->dispatch($definition, 'data_definitions.import.status', - sprintf('Error: %s', $ex->getMessage()), $params); + $this->eventDispatcher->dispatch( + $definition, + 'data_definitions.import.status', + sprintf('Error: %s', $ex->getMessage()), + $params + ); if ($definition->getStopOnException()) { throw $ex; @@ -288,8 +290,12 @@ private function runImport( $this->eventDispatcher->dispatch($definition, 'data_definitions.import.progress', '', $params); if ($this->shouldStop) { - $this->eventDispatcher->dispatch($definition, 'data_definitions.import.status', - 'Process has been stopped.'); + $this->eventDispatcher->dispatch( + $definition, + 'data_definitions.import.status', + 'Process has been stopped.' + ); + return [$objectIds, $exceptions]; } } @@ -304,35 +310,47 @@ private function importRow( array $params, FilterInterface $filter = null, RunnerInterface $runner = null, - ): ?Concrete - { - $object = $this->getObject($definition, $data, $params); + ): ?Concrete { + $object = $this->getObject($definition, $data, $dataSet, $params); if (null !== $object && !$object->getId()) { if ($definition->getSkipNewObjects()) { - $this->eventDispatcher->dispatch($definition, 'data_definitions.import.status', 'Ignoring new Object', - $params); + $this->eventDispatcher->dispatch( + $definition, + 'data_definitions.import.status', + 'Ignoring new Object', + $params + ); return null; } - } else if ($definition->getSkipExistingObjects()) { - $this->eventDispatcher->dispatch($definition, 'data_definitions.import.status', 'Ignoring existing Object', - $params); + } else { + if ($definition->getSkipExistingObjects()) { + $this->eventDispatcher->dispatch( + $definition, + 'data_definitions.import.status', + 'Ignoring existing Object', + $params + ); - return null; + return null; + } } if ($filter instanceof FilterInterface) { - if ($filter instanceof DataSetAwareInterface) { - $filter->setDataSet($dataSet); - } - if ($filter instanceof LoggerAwareInterface) { $filter->setLogger($this->logger); } - if (!$filter->filter($definition, $data, $object, $params)) { - $this->eventDispatcher->dispatch($definition, 'data_definitions.import.status', 'Filtered Object', $params); + $context = $this->contextFactory->createFilterContext($definition, $params, $data, $dataSet, $object); + + if (!$filter->filter($context)) { + $this->eventDispatcher->dispatch( + $definition, + 'data_definitions.import.status', + 'Filtered Object', + $params + ); return null; } @@ -351,16 +369,14 @@ private function importRow( $params ); - if ($runner instanceof RunnerInterface) { - if ($runner instanceof DataSetAwareInterface) { - $runner->setDataSet($dataSet); - } + $runnerContext = $this->contextFactory->createRunnerContext($definition, $params, $data, $dataSet, $object); + if ($runner instanceof RunnerInterface) { if ($runner instanceof LoggerAwareInterface) { $runner->setLogger($this->logger); } - $runner->preRun($object, $data, $definition, $params); + $runner->preRun($runnerContext); } $this->logger->info(sprintf('Imported Object: %s', $object->getRealFullPath())); @@ -377,15 +393,11 @@ private function importRow( $shouldSave = true; if ($runner instanceof SaveRunnerInterface) { - if ($runner instanceof DataSetAwareInterface) { - $runner->setDataSet($dataSet); - } - if ($runner instanceof LoggerAwareInterface) { $runner->setLogger($this->logger); } - $shouldSave = $runner->shouldSaveObject($object, $data, $definition, $params); + $shouldSave = $runner->shouldSaveObject($runnerContext); } if ($shouldSave) { @@ -425,15 +437,11 @@ private function importRow( ); if ($runner instanceof RunnerInterface) { - if ($runner instanceof DataSetAwareInterface) { - $runner->setDataSet($dataSet); - } - if ($runner instanceof LoggerAwareInterface) { $runner->setLogger($this->logger); } - $runner->postRun($object, $data, $definition, $params); + $runner->postRun($runnerContext); } return $object; @@ -453,8 +461,8 @@ private function setObjectValue( try { $interpreter = $this->interpreterRegistry->get($map->getInterpreter()); - if ($interpreter instanceof DataSetAwareInterface) { - $interpreter->setDataSet($dataSet); + if (!$interpreter instanceof InterpreterInterface) { + return; } if ($interpreter instanceof LoggerAwareInterface) { @@ -462,18 +470,27 @@ private function setObjectValue( } try { - $value = $interpreter->interpret( - $object, - $value, - $map, - $data, + $context = $this->contextFactory->createInterpreterContext( $definition, $params, + $data, + $dataSet, + $object, + $value, + $map + ); + $value = $interpreter->interpret( + $context, $map->getInterpreterConfig() ?? [] ); - } - catch (UnexpectedValueException $ex) { - $this->logger->info(sprintf('Unexpected Value from Interpreter "%s" with message "%s"', $map->getInterpreter(), $ex->getMessage())); + } catch (UnexpectedValueException $ex) { + $this->logger->info( + sprintf( + 'Unexpected Value from Interpreter "%s" with message "%s"', + $map->getInterpreter(), + $ex->getMessage() + ) + ); } } catch (DoNotSetException $ex) { @@ -489,10 +506,6 @@ private function setObjectValue( $shouldSetField = true; if ($runner instanceof SetterRunnerInterface) { - if ($runner instanceof DataSetAwareInterface) { - $runner->setDataSet($dataSet); - } - if ($runner instanceof LoggerAwareInterface) { $runner->setLogger($this->logger); } @@ -506,25 +519,34 @@ private function setObjectValue( if ($map->getSetter()) { $setter = $this->setterRegistry->get($map->getSetter()); + $setterContext = $this->contextFactory->createSetterContext( + $definition, + $params, + $object, + $map, + $data, + $dataSet, + $value + ); if ($setter instanceof SetterInterface) { - if ($setter instanceof DataSetAwareInterface) { - $setter->setDataSet($dataSet); - } - if ($setter instanceof LoggerAwareInterface) { $setter->setLogger($this->logger); } - $setter->set($object, $value, $map, $data); + $setter->set($setterContext); } } else { $object->setValue($map->getToColumn(), $value); } } - private function getObject(ImportDefinitionInterface $definition, $data, $params): Concrete - { + private function getObject( + ImportDefinitionInterface $definition, + $data, + ImportDataSetInterface $dataSet, + $params + ): Concrete { $class = $definition->getClass(); $classObject = '\Pimcore\Model\DataObject\\'.ucfirst($class); $classDefinition = ClassDefinition::getByName($class); @@ -541,8 +563,8 @@ private function getObject(ImportDefinitionInterface $definition, $data, $params } else { $loader = $this->loaderRegistry->get('primary_key'); } - - $obj = $loader->load($class, $data, $definition, $params); + $loaderContext = $this->contextFactory->createLoaderContext($definition, $params, $data, $dataSet, $class); + $obj = $loader->load($loaderContext); if (null === $obj) { $classImplementation = $this->modelFactory->getClassNameFor($classObject) ?? $classObject; @@ -572,7 +594,7 @@ private function getObject(ImportDefinitionInterface $definition, $data, $params return $obj; } -private function createPath(ImportDefinitionInterface $definition, array $data): string + private function createPath(ImportDefinitionInterface $definition, array $data): string { if (!$definition->getObjectPath()) { return ''; diff --git a/src/DataDefinitionsBundle/Installer.php b/src/DataDefinitionsBundle/Installer.php index 0f316a60..6585c3c2 100644 --- a/src/DataDefinitionsBundle/Installer.php +++ b/src/DataDefinitionsBundle/Installer.php @@ -18,7 +18,6 @@ use Pimcore; use Pimcore\Extension\Bundle\Installer\SettingsStoreAwareInstaller; -use Symfony\Bundle\FrameworkBundle\Console\Application; use Symfony\Component\Console\Input\ArrayInput; class Installer extends SettingsStoreAwareInstaller diff --git a/src/DataDefinitionsBundle/Interpreter/AssetByPathInterpreter.php b/src/DataDefinitionsBundle/Interpreter/AssetByPathInterpreter.php index c2863646..093a68c3 100644 --- a/src/DataDefinitionsBundle/Interpreter/AssetByPathInterpreter.php +++ b/src/DataDefinitionsBundle/Interpreter/AssetByPathInterpreter.php @@ -17,22 +17,15 @@ namespace Wvision\Bundle\DataDefinitionsBundle\Interpreter; use Pimcore\Model\Asset; -use Pimcore\Model\DataObject\Concrete; -use Wvision\Bundle\DataDefinitionsBundle\Model\DataDefinitionInterface; -use Wvision\Bundle\DataDefinitionsBundle\Model\MappingInterface; +use Wvision\Bundle\DataDefinitionsBundle\Context\InterpreterContextInterface; class AssetByPathInterpreter implements InterpreterInterface { public function interpret( - Concrete $object, - $value, - MappingInterface $map, - array $data, - DataDefinitionInterface $definition, - array $params, + InterpreterContextInterface $context, array $configuration ) { - $assetFullPath = $configuration['path'] . '/' . $value; + $assetFullPath = $configuration['path'].'/'.$context->getValue(); return Asset::getByPath($assetFullPath); } diff --git a/src/DataDefinitionsBundle/Interpreter/AssetUrlInterpreter.php b/src/DataDefinitionsBundle/Interpreter/AssetUrlInterpreter.php index 4aad8236..d2588a24 100644 --- a/src/DataDefinitionsBundle/Interpreter/AssetUrlInterpreter.php +++ b/src/DataDefinitionsBundle/Interpreter/AssetUrlInterpreter.php @@ -18,53 +18,41 @@ use Doctrine\DBAL\Query\QueryBuilder; use Pimcore\File; -use Pimcore\Http\Exception\ResponseException; use Pimcore\Model\Asset; -use Pimcore\Model\DataObject\Concrete; -use Pimcore\Tool as PimcoreTool; -use Wvision\Bundle\DataDefinitionsBundle\Model\DataSetAwareInterface; -use Wvision\Bundle\DataDefinitionsBundle\Model\DataSetAwareTrait; -use Wvision\Bundle\DataDefinitionsBundle\Model\DataDefinitionInterface; -use Wvision\Bundle\DataDefinitionsBundle\Model\MappingInterface; - -class AssetUrlInterpreter implements InterpreterInterface, DataSetAwareInterface -{ - use DataSetAwareTrait; +use Wvision\Bundle\DataDefinitionsBundle\Context\InterpreterContextInterface; +class AssetUrlInterpreter implements InterpreterInterface +{ protected const METADATA_ORIGIN_URL = 'origin_url'; protected \Psr\Http\Client\ClientInterface $httpClient; protected \Psr\Http\Message\RequestFactoryInterface $requestFactory; - public function __construct(\Psr\Http\Client\ClientInterface $httpClient, \Psr\Http\Message\RequestFactoryInterface $requestFactory) - { + public function __construct( + \Psr\Http\Client\ClientInterface $httpClient, + \Psr\Http\Message\RequestFactoryInterface $requestFactory + ) { $this->httpClient = $httpClient; $this->requestFactory = $requestFactory; } public function interpret( - Concrete $object, - $value, - MappingInterface $map, - array $data, - DataDefinitionInterface $definition, - array $params, + InterpreterContextInterface $context, array $configuration ) { $path = $configuration['path']; - if (filter_var($value, FILTER_VALIDATE_URL)) { + if (filter_var($context->getValue(), FILTER_VALIDATE_URL)) { $asset = null; - $filename = $this->getFileName($value); + $filename = $this->getFileName($context->getValue()); if ($configuration['deduplicate_by_url']) { - if ($asset = $this->getDuplicatedAsset($value)) { + if ($asset = $this->getDuplicatedAsset($context->getValue())) { $filename = $asset->getFilename(); $assetPath = $asset->getPath(); } else { $assetPath = $path; } - } - else { + } else { $assetPath = $path; } @@ -72,14 +60,14 @@ public function interpret( if (!$asset instanceof Asset) { // Download - $fileData = $this->getFileContents($value); + $fileData = $this->getFileContents($context->getValue()); if ($fileData) { $asset = Asset::create($parent->getId(), [ 'filename' => $filename, - 'data' => $fileData + 'data' => $fileData, ], false); - $asset->addMetadata(self::METADATA_ORIGIN_URL, 'input', $value); + $asset->addMetadata(self::METADATA_ORIGIN_URL, 'input', $context->getValue()); $asset->save(); } } else { @@ -106,7 +94,7 @@ public function interpret( return null; } - private function getFileName(string $url) : ?string + private function getFileName(string $url): ?string { $filename = null; try { @@ -122,7 +110,7 @@ private function getFileName(string $url) : ?string $match ) ) { - $filename = trim($match['f'], ' ";'); + $filename = trim($match['f'], ' ";'); } } catch (\Psr\Http\Client\ClientExceptionInterface $exception) { } @@ -144,18 +132,18 @@ protected function getFileContents(string $value): ?string } if ($response->getStatusCode() === 200) { - return (string) $response->getBody(); + return (string)$response->getBody(); } return null; } - private function getDuplicatedAsset(string $value) : ?Asset + private function getDuplicatedAsset(string $value): ?Asset { $listing = new Asset\Listing(); $listing->onCreateQueryBuilder( function (QueryBuilder $select) { - $select->join('assets','assets_metadata', 'am', 'id = am.cid'); + $select->join('assets', 'assets_metadata', 'am', 'id = am.cid'); } ); $listing->addConditionParam('am.name = ?', static::METADATA_ORIGIN_URL); diff --git a/src/DataDefinitionsBundle/Interpreter/AssetsUrlInterpreter.php b/src/DataDefinitionsBundle/Interpreter/AssetsUrlInterpreter.php index 763cb826..5ee9b3ee 100644 --- a/src/DataDefinitionsBundle/Interpreter/AssetsUrlInterpreter.php +++ b/src/DataDefinitionsBundle/Interpreter/AssetsUrlInterpreter.php @@ -16,24 +16,17 @@ namespace Wvision\Bundle\DataDefinitionsBundle\Interpreter; -use Pimcore\Model\DataObject\Concrete; -use Wvision\Bundle\DataDefinitionsBundle\Model\DataDefinitionInterface; -use Wvision\Bundle\DataDefinitionsBundle\Model\MappingInterface; +use Wvision\Bundle\DataDefinitionsBundle\Context\InterpreterContextInterface; class AssetsUrlInterpreter extends AssetUrlInterpreter { public function interpret( - Concrete $object, - $value, - MappingInterface $map, - array $data, - DataDefinitionInterface $definition, - array $params, + InterpreterContextInterface $context, array $configuration ) { $assets = []; - foreach ((array)$value as $item) { - $asset = parent::interpret($object, $item, $map, $data, $definition, $params, $configuration); + foreach ((array)$context->getValue() as $item) { + $asset = parent::interpret($context, $configuration); if ($asset) { $assets[] = $asset; diff --git a/src/DataDefinitionsBundle/Interpreter/CarbonInterpreter.php b/src/DataDefinitionsBundle/Interpreter/CarbonInterpreter.php index f185f9f2..841a96e0 100644 --- a/src/DataDefinitionsBundle/Interpreter/CarbonInterpreter.php +++ b/src/DataDefinitionsBundle/Interpreter/CarbonInterpreter.php @@ -17,32 +17,21 @@ namespace Wvision\Bundle\DataDefinitionsBundle\Interpreter; use Carbon\Carbon; -use Pimcore\Model\DataObject\Concrete; -use Wvision\Bundle\DataDefinitionsBundle\Model\DataSetAwareInterface; -use Wvision\Bundle\DataDefinitionsBundle\Model\DataSetAwareTrait; -use Wvision\Bundle\DataDefinitionsBundle\Model\DataDefinitionInterface; -use Wvision\Bundle\DataDefinitionsBundle\Model\MappingInterface; +use Wvision\Bundle\DataDefinitionsBundle\Context\InterpreterContextInterface; -class CarbonInterpreter implements InterpreterInterface, DataSetAwareInterface +class CarbonInterpreter implements InterpreterInterface { - use DataSetAwareTrait; - public function interpret( - Concrete $object, - $value, - MappingInterface $map, - array $data, - DataDefinitionInterface $definition, - array $params, + InterpreterContextInterface $context, array $configuration ) { - if ($value) { + if ($context->getValue()) { $format = $configuration['date_format']; if (!empty($format)) { - return Carbon::createFromFormat($format, $value); + return Carbon::createFromFormat($format, $context->getValue()); } - return new Carbon($value); + return new Carbon($context->getValue()); } return null; diff --git a/src/DataDefinitionsBundle/Interpreter/CheckboxInterpreter.php b/src/DataDefinitionsBundle/Interpreter/CheckboxInterpreter.php index accce3fc..312b2f71 100644 --- a/src/DataDefinitionsBundle/Interpreter/CheckboxInterpreter.php +++ b/src/DataDefinitionsBundle/Interpreter/CheckboxInterpreter.php @@ -16,33 +16,22 @@ namespace Wvision\Bundle\DataDefinitionsBundle\Interpreter; -use Pimcore\Model\DataObject\Concrete; -use Wvision\Bundle\DataDefinitionsBundle\Model\DataSetAwareInterface; -use Wvision\Bundle\DataDefinitionsBundle\Model\DataSetAwareTrait; -use Wvision\Bundle\DataDefinitionsBundle\Model\DataDefinitionInterface; -use Wvision\Bundle\DataDefinitionsBundle\Model\MappingInterface; +use Wvision\Bundle\DataDefinitionsBundle\Context\InterpreterContextInterface; -class CheckboxInterpreter implements InterpreterInterface, DataSetAwareInterface +class CheckboxInterpreter implements InterpreterInterface { - use DataSetAwareTrait; - public function interpret( - Concrete $object, - $value, - MappingInterface $map, - array $data, - DataDefinitionInterface $definition, - array $params, + InterpreterContextInterface $context, array $configuration ) { - if (is_string($value)) { - if ($value === "") { + if (is_string($context->getValue())) { + if ($context->getValue() === "") { return null; } - return filter_var(strtolower($value), FILTER_VALIDATE_BOOLEAN, FILTER_NULL_ON_FAILURE); + return filter_var(strtolower($context->getValue()), FILTER_VALIDATE_BOOLEAN, FILTER_NULL_ON_FAILURE); } - return ((bool)$value); + return ((bool)$context->getValue()); } } diff --git a/src/DataDefinitionsBundle/Interpreter/ConditionalInterpreter.php b/src/DataDefinitionsBundle/Interpreter/ConditionalInterpreter.php index 9c39499f..167168d2 100644 --- a/src/DataDefinitionsBundle/Interpreter/ConditionalInterpreter.php +++ b/src/DataDefinitionsBundle/Interpreter/ConditionalInterpreter.php @@ -17,18 +17,12 @@ namespace Wvision\Bundle\DataDefinitionsBundle\Interpreter; use CoreShop\Component\Registry\ServiceRegistryInterface; -use Pimcore\Model\DataObject\Concrete; use Symfony\Component\DependencyInjection\ContainerInterface; use Symfony\Component\ExpressionLanguage\ExpressionLanguage; -use Wvision\Bundle\DataDefinitionsBundle\Model\DataSetAwareInterface; -use Wvision\Bundle\DataDefinitionsBundle\Model\DataSetAwareTrait; -use Wvision\Bundle\DataDefinitionsBundle\Model\DataDefinitionInterface; -use Wvision\Bundle\DataDefinitionsBundle\Model\MappingInterface; +use Wvision\Bundle\DataDefinitionsBundle\Context\InterpreterContextInterface; -class ConditionalInterpreter implements InterpreterInterface, DataSetAwareInterface +class ConditionalInterpreter implements InterpreterInterface { - use DataSetAwareTrait; - private ServiceRegistryInterface $interpreterRegistry; protected ExpressionLanguage $expressionLanguage; protected ContainerInterface $container; @@ -44,21 +38,17 @@ public function __construct( } public function interpret( - Concrete $object, - $value, - MappingInterface $map, - array $data, - DataDefinitionInterface $definition, - array $params, + InterpreterContextInterface $context, array $configuration ) { $params = [ - 'value' => $value, - 'object' => $object, - 'map' => $map, - 'data' => $data, - 'definition' => $definition, - 'params' => $params, + 'value' => $context->getValue(), + 'object' => $context->getObject(), + 'map' => $context->getMapping(), + 'data' => $context->getDataRow(), + 'data_set' => $context->getDataSet(), + 'definition' => $context->getDefinition(), + 'params' => $context->getParams(), 'configuration' => $configuration, 'container' => $this->container, ]; @@ -74,14 +64,9 @@ public function interpret( $interpreterObject = $this->interpreterRegistry->get($interpreter['type']); if (!$interpreterObject instanceof InterpreterInterface) { - return $value; - } - - if ($interpreterObject instanceof DataSetAwareInterface) { - $interpreterObject->setDataSet($this->getDataSet()); + return $context->getValue(); } - return $interpreterObject->interpret($object, $value, $map, $data, $definition, $params, - $interpreter['interpreterConfig']); + return $interpreterObject->interpret($context, $interpreter['interpreterConfig']); } } diff --git a/src/DataDefinitionsBundle/Interpreter/CoreShop/CurrencyInterpreter.php b/src/DataDefinitionsBundle/Interpreter/CoreShop/CurrencyInterpreter.php index 194336a8..d633b7dd 100644 --- a/src/DataDefinitionsBundle/Interpreter/CoreShop/CurrencyInterpreter.php +++ b/src/DataDefinitionsBundle/Interpreter/CoreShop/CurrencyInterpreter.php @@ -15,10 +15,8 @@ namespace Wvision\Bundle\DataDefinitionsBundle\Interpreter\CoreShop; use CoreShop\Component\Currency\Repository\CurrencyRepositoryInterface; -use Pimcore\Model\DataObject\Concrete; +use Wvision\Bundle\DataDefinitionsBundle\Context\InterpreterContextInterface; use Wvision\Bundle\DataDefinitionsBundle\Interpreter\InterpreterInterface; -use Wvision\Bundle\DataDefinitionsBundle\Model\DataDefinitionInterface; -use Wvision\Bundle\DataDefinitionsBundle\Model\MappingInterface; final class CurrencyInterpreter implements InterpreterInterface { @@ -30,15 +28,10 @@ public function __construct(CurrencyRepositoryInterface $currencyRepository) } public function interpret( - Concrete $object, - $value, - MappingInterface $map, - array $data, - DataDefinitionInterface $definition, - array $params, + InterpreterContextInterface $context, array $configuration ) { - return $this->currencyRepository->getByCode($value); + return $this->currencyRepository->getByCode($context->getValue()); } } diff --git a/src/DataDefinitionsBundle/Interpreter/CoreShop/MoneyInterpreter.php b/src/DataDefinitionsBundle/Interpreter/CoreShop/MoneyInterpreter.php index 0a544726..98f6a5ad 100644 --- a/src/DataDefinitionsBundle/Interpreter/CoreShop/MoneyInterpreter.php +++ b/src/DataDefinitionsBundle/Interpreter/CoreShop/MoneyInterpreter.php @@ -7,10 +7,8 @@ use CoreShop\Component\Core\Repository\CurrencyRepositoryInterface; use CoreShop\Component\Currency\Model\CurrencyInterface; use CoreShop\Component\Currency\Model\Money; -use Pimcore\Model\DataObject\Concrete; +use Wvision\Bundle\DataDefinitionsBundle\Context\InterpreterContextInterface; use Wvision\Bundle\DataDefinitionsBundle\Interpreter\InterpreterInterface; -use Wvision\Bundle\DataDefinitionsBundle\Model\DataDefinitionInterface; -use Wvision\Bundle\DataDefinitionsBundle\Model\MappingInterface; use function is_string; final class MoneyInterpreter implements InterpreterInterface @@ -23,15 +21,10 @@ public function __construct(CurrencyRepositoryInterface $currencyRepository) } public function interpret( - Concrete $object, - $value, - MappingInterface $map, - array $data, - DataDefinitionInterface $definition, - array $params, + InterpreterContextInterface $context, array $configuration ) { - $value = $this->getValue($value, $configuration); + $value = $this->getValue($context->getValue(), $configuration); $currency = $this->resolveCurrency($value, $configuration); if (null === $currency) { diff --git a/src/DataDefinitionsBundle/Interpreter/CoreShop/PriceInterpreter.php b/src/DataDefinitionsBundle/Interpreter/CoreShop/PriceInterpreter.php index e01d422e..53d8da7a 100644 --- a/src/DataDefinitionsBundle/Interpreter/CoreShop/PriceInterpreter.php +++ b/src/DataDefinitionsBundle/Interpreter/CoreShop/PriceInterpreter.php @@ -14,24 +14,18 @@ namespace Wvision\Bundle\DataDefinitionsBundle\Interpreter\CoreShop; -use Pimcore\Model\DataObject\Concrete; +use Wvision\Bundle\DataDefinitionsBundle\Context\InterpreterContextInterface; use Wvision\Bundle\DataDefinitionsBundle\Interpreter\InterpreterInterface; -use Wvision\Bundle\DataDefinitionsBundle\Model\DataDefinitionInterface; -use Wvision\Bundle\DataDefinitionsBundle\Model\MappingInterface; use function is_string; final class PriceInterpreter implements InterpreterInterface { public function interpret( - Concrete $object, - $value, - MappingInterface $map, - array $data, - DataDefinitionInterface $definition, - array $params, + InterpreterContextInterface $context, array $configuration ) { $inputIsFloat = $configuration['isFloat']; + $value = $context->getValue(); if (is_string($value)) { $value = str_replace(',', '.', $value); diff --git a/src/DataDefinitionsBundle/Interpreter/CoreShop/StoresInterpreter.php b/src/DataDefinitionsBundle/Interpreter/CoreShop/StoresInterpreter.php index 0317b760..3cce2968 100644 --- a/src/DataDefinitionsBundle/Interpreter/CoreShop/StoresInterpreter.php +++ b/src/DataDefinitionsBundle/Interpreter/CoreShop/StoresInterpreter.php @@ -14,20 +14,13 @@ namespace Wvision\Bundle\DataDefinitionsBundle\Interpreter\CoreShop; -use Pimcore\Model\DataObject\Concrete; +use Wvision\Bundle\DataDefinitionsBundle\Context\InterpreterContextInterface; use Wvision\Bundle\DataDefinitionsBundle\Interpreter\InterpreterInterface; -use Wvision\Bundle\DataDefinitionsBundle\Model\DataDefinitionInterface; -use Wvision\Bundle\DataDefinitionsBundle\Model\MappingInterface; final class StoresInterpreter implements InterpreterInterface { public function interpret( - Concrete $object, - $value, - MappingInterface $map, - array $data, - DataDefinitionInterface $definition, - array $params, + InterpreterContextInterface $context, array $configuration ) { return $configuration['stores']; diff --git a/src/DataDefinitionsBundle/Interpreter/DefaultValueInterpreter.php b/src/DataDefinitionsBundle/Interpreter/DefaultValueInterpreter.php index 4bda73e2..4f142cf1 100644 --- a/src/DataDefinitionsBundle/Interpreter/DefaultValueInterpreter.php +++ b/src/DataDefinitionsBundle/Interpreter/DefaultValueInterpreter.php @@ -16,23 +16,12 @@ namespace Wvision\Bundle\DataDefinitionsBundle\Interpreter; -use Pimcore\Model\DataObject\Concrete; -use Wvision\Bundle\DataDefinitionsBundle\Model\DataSetAwareInterface; -use Wvision\Bundle\DataDefinitionsBundle\Model\DataSetAwareTrait; -use Wvision\Bundle\DataDefinitionsBundle\Model\DataDefinitionInterface; -use Wvision\Bundle\DataDefinitionsBundle\Model\MappingInterface; +use Wvision\Bundle\DataDefinitionsBundle\Context\InterpreterContextInterface; -class DefaultValueInterpreter implements InterpreterInterface, DataSetAwareInterface +class DefaultValueInterpreter implements InterpreterInterface { - use DataSetAwareTrait; - public function interpret( - Concrete $object, - $value, - MappingInterface $map, - array $data, - DataDefinitionInterface $definition, - array $params, + InterpreterContextInterface $context, array $configuration ) { return $configuration['value']; diff --git a/src/DataDefinitionsBundle/Interpreter/DefinitionInterpreter.php b/src/DataDefinitionsBundle/Interpreter/DefinitionInterpreter.php index 374ec9b2..7a3cd0d1 100644 --- a/src/DataDefinitionsBundle/Interpreter/DefinitionInterpreter.php +++ b/src/DataDefinitionsBundle/Interpreter/DefinitionInterpreter.php @@ -18,11 +18,9 @@ use CoreShop\Component\Resource\Repository\RepositoryInterface; use Pimcore\Model\DataObject; -use Pimcore\Model\DataObject\Concrete; +use Wvision\Bundle\DataDefinitionsBundle\Context\InterpreterContextInterface; use Wvision\Bundle\DataDefinitionsBundle\Importer\ImporterInterface; -use Wvision\Bundle\DataDefinitionsBundle\Model\DataDefinitionInterface; use Wvision\Bundle\DataDefinitionsBundle\Model\ImportDefinitionInterface; -use Wvision\Bundle\DataDefinitionsBundle\Model\MappingInterface; class DefinitionInterpreter implements InterpreterInterface { @@ -36,12 +34,7 @@ public function __construct(RepositoryInterface $definitionRepository, ImporterI } public function interpret( - Concrete $object, - $value, - MappingInterface $map, - array $data, - DataDefinitionInterface $definition, - array $params, + InterpreterContextInterface $context, array $configuration ) { $subDefinition = $this->definitionRepository->find($configuration['definition']); @@ -50,7 +43,7 @@ public function interpret( return null; } - $imported = $this->importer->doImport($subDefinition, ['data' => [$data], 'child' => true]); + $imported = $this->importer->doImport($subDefinition, ['data' => [$context->getDataRow()], 'child' => true]); if (count($imported) === 1) { return DataObject::getById($imported[0]); diff --git a/src/DataDefinitionsBundle/Interpreter/DoNotSetOnEmptyInterpreter.php b/src/DataDefinitionsBundle/Interpreter/DoNotSetOnEmptyInterpreter.php index 5f744ab6..21346ad8 100644 --- a/src/DataDefinitionsBundle/Interpreter/DoNotSetOnEmptyInterpreter.php +++ b/src/DataDefinitionsBundle/Interpreter/DoNotSetOnEmptyInterpreter.php @@ -16,34 +16,23 @@ namespace Wvision\Bundle\DataDefinitionsBundle\Interpreter; -use Pimcore\Model\DataObject\Concrete; +use Wvision\Bundle\DataDefinitionsBundle\Context\InterpreterContextInterface; use Wvision\Bundle\DataDefinitionsBundle\Exception\DoNotSetException; -use Wvision\Bundle\DataDefinitionsBundle\Model\DataSetAwareInterface; -use Wvision\Bundle\DataDefinitionsBundle\Model\DataSetAwareTrait; -use Wvision\Bundle\DataDefinitionsBundle\Model\DataDefinitionInterface; -use Wvision\Bundle\DataDefinitionsBundle\Model\MappingInterface; -class DoNotSetOnEmptyInterpreter implements InterpreterInterface, DataSetAwareInterface +class DoNotSetOnEmptyInterpreter implements InterpreterInterface { - use DataSetAwareTrait; - public function interpret( - Concrete $object, - $value, - MappingInterface $map, - array $data, - DataDefinitionInterface $definition, - array $params, + InterpreterContextInterface $context, array $configuration ) { - if ($value === "" || $value === null) { + if ($context->getValue() === "" || $context->getValue() === null) { throw new DoNotSetException(); } - if (is_array($value) && count($value) === 0) { + if (is_array($context->getValue()) && count($context->getValue()) === 0) { throw new DoNotSetException(); } - return $value; + return $context->getValue(); } } diff --git a/src/DataDefinitionsBundle/Interpreter/ExpressionInterpreter.php b/src/DataDefinitionsBundle/Interpreter/ExpressionInterpreter.php index a2dc158d..0745ccb8 100644 --- a/src/DataDefinitionsBundle/Interpreter/ExpressionInterpreter.php +++ b/src/DataDefinitionsBundle/Interpreter/ExpressionInterpreter.php @@ -16,20 +16,14 @@ namespace Wvision\Bundle\DataDefinitionsBundle\Interpreter; -use Pimcore\Model\DataObject\Concrete; use Symfony\Component\DependencyInjection\ContainerInterface; use Symfony\Component\ExpressionLanguage\ExpressionLanguage; use Throwable; +use Wvision\Bundle\DataDefinitionsBundle\Context\InterpreterContextInterface; use Wvision\Bundle\DataDefinitionsBundle\Exception\InterpreterException; -use Wvision\Bundle\DataDefinitionsBundle\Model\DataSetAwareInterface; -use Wvision\Bundle\DataDefinitionsBundle\Model\DataSetAwareTrait; -use Wvision\Bundle\DataDefinitionsBundle\Model\DataDefinitionInterface; -use Wvision\Bundle\DataDefinitionsBundle\Model\MappingInterface; -class ExpressionInterpreter implements InterpreterInterface, DataSetAwareInterface +class ExpressionInterpreter implements InterpreterInterface { - use DataSetAwareTrait; - protected ExpressionLanguage $expressionLanguage; protected ContainerInterface $container; @@ -40,29 +34,31 @@ public function __construct(ExpressionLanguage $expressionLanguage, ContainerInt } public function interpret( - Concrete $object, - $value, - MappingInterface $map, - array $data, - DataDefinitionInterface $definition, - array $params, + InterpreterContextInterface $context, array $configuration ) { $expression = $configuration['expression']; try { return $this->expressionLanguage->evaluate($expression, [ - 'value' => $value, - 'object' => $object, - 'map' => $map, - 'data' => $data, - 'definition' => $definition, - 'params' => $params, + 'value' => $context->getValue(), + 'object' => $context->getObject(), + 'map' => $context->getMapping(), + 'data' => $context->getDataRow(), + 'data_set' => $context->getDataSet(), + 'definition' => $context->getDefinition(), + 'params' => $context->getParams(), 'configuration' => $configuration, 'container' => $this->container, ]); } catch (Throwable $exception) { - throw InterpreterException::fromInterpreter($definition, $map, $params, $value, $exception); + throw InterpreterException::fromInterpreter( + $context->getDefinition(), + $context->getMapping(), + $context->getParams(), + $context->getValue(), + $exception + ); } } } diff --git a/src/DataDefinitionsBundle/Interpreter/ExternalImageInterpreter.php b/src/DataDefinitionsBundle/Interpreter/ExternalImageInterpreter.php index 0a3fe42e..f418a066 100644 --- a/src/DataDefinitionsBundle/Interpreter/ExternalImageInterpreter.php +++ b/src/DataDefinitionsBundle/Interpreter/ExternalImageInterpreter.php @@ -16,30 +16,27 @@ namespace Wvision\Bundle\DataDefinitionsBundle\Interpreter; -use Pimcore\Model\DataObject\Concrete; use Pimcore\Model\DataObject\Data\ExternalImage; -use Wvision\Bundle\DataDefinitionsBundle\Model\DataDefinitionInterface; +use Wvision\Bundle\DataDefinitionsBundle\Context\InterpreterContextInterface; use Wvision\Bundle\DataDefinitionsBundle\Model\ExportDefinitionInterface; use Wvision\Bundle\DataDefinitionsBundle\Model\ImportDefinitionInterface; -use Wvision\Bundle\DataDefinitionsBundle\Model\MappingInterface; class ExternalImageInterpreter implements InterpreterInterface { public function interpret( - Concrete $object, - $value, - MappingInterface $map, - array $data, - DataDefinitionInterface $definition, - array $params, + InterpreterContextInterface $context, array $configuration ) { - if (($definition instanceof ExportDefinitionInterface) && $value instanceof ExternalImage) { - return $value->getUrl(); + if (($context->getDefinition() instanceof ExportDefinitionInterface) && $context->getValue( + ) instanceof ExternalImage) { + return $context->getValue()->getUrl(); } - if (($definition instanceof ImportDefinitionInterface) && filter_var($value, FILTER_VALIDATE_URL)) { - return new ExternalImage($value); + if (($context->getDefinition() instanceof ImportDefinitionInterface) && filter_var( + $context->getValue(), + FILTER_VALIDATE_URL + )) { + return new ExternalImage($context->getValue()); } return null; diff --git a/src/DataDefinitionsBundle/Interpreter/HrefInterpreter.php b/src/DataDefinitionsBundle/Interpreter/HrefInterpreter.php index 3ee42ab1..b1acb2a0 100644 --- a/src/DataDefinitionsBundle/Interpreter/HrefInterpreter.php +++ b/src/DataDefinitionsBundle/Interpreter/HrefInterpreter.php @@ -19,28 +19,18 @@ use Pimcore\Model\DataObject\Concrete; use Pimcore\Model\Element\Service; use Pimcore\Tool; -use Wvision\Bundle\DataDefinitionsBundle\Model\DataSetAwareInterface; -use Wvision\Bundle\DataDefinitionsBundle\Model\DataSetAwareTrait; -use Wvision\Bundle\DataDefinitionsBundle\Model\DataDefinitionInterface; -use Wvision\Bundle\DataDefinitionsBundle\Model\MappingInterface; +use Wvision\Bundle\DataDefinitionsBundle\Context\InterpreterContextInterface; -class HrefInterpreter implements InterpreterInterface, DataSetAwareInterface +class HrefInterpreter implements InterpreterInterface { - use DataSetAwareTrait; - public function interpret( - Concrete $object, - $value, - MappingInterface $map, - array $data, - DataDefinitionInterface $definition, - array $params, + InterpreterContextInterface $context, array $configuration ) { $type = $configuration['type'] ?: 'object'; $objectClass = $configuration['class']; - if (!$value) { + if (!$context->getValue()) { return null; } @@ -55,7 +45,7 @@ public function interpret( $class = new $class(); if ($class instanceof Concrete) { - $ret = $class::getById($value); + $ret = $class::getById($context->getValue()); if ($ret instanceof Concrete) { return $ret; @@ -63,7 +53,7 @@ public function interpret( } } } else { - return Service::getElementById($type, $value); + return Service::getElementById($type, $context->getValue()); } return null; diff --git a/src/DataDefinitionsBundle/Interpreter/ImportRuleInterpreter.php b/src/DataDefinitionsBundle/Interpreter/ImportRuleInterpreter.php index 49732f55..e30a7371 100644 --- a/src/DataDefinitionsBundle/Interpreter/ImportRuleInterpreter.php +++ b/src/DataDefinitionsBundle/Interpreter/ImportRuleInterpreter.php @@ -16,41 +16,28 @@ namespace Wvision\Bundle\DataDefinitionsBundle\Interpreter; -use CoreShop\Component\Rule\Condition\RuleValidationProcessorInterface; use CoreShop\Component\Rule\Model\Action; use CoreShop\Component\Rule\Model\Condition; -use Pimcore\Model\DataObject\Concrete; -use Wvision\Bundle\DataDefinitionsBundle\Model\DataSetAwareInterface; -use Wvision\Bundle\DataDefinitionsBundle\Model\DataSetAwareTrait; -use Wvision\Bundle\DataDefinitionsBundle\Model\DataDefinitionInterface; -use Wvision\Bundle\DataDefinitionsBundle\Model\MappingInterface; +use Wvision\Bundle\DataDefinitionsBundle\Context\InterpreterContextInterface; use Wvision\Bundle\DataDefinitionsBundle\Rules\Model\ImportRule; use Wvision\Bundle\DataDefinitionsBundle\Rules\Processor\ImportRuleValidationProcessorInterface; use Wvision\Bundle\DataDefinitionsBundle\Rules\Processor\RuleApplierInterface; -class ImportRuleInterpreter implements InterpreterInterface, DataSetAwareInterface +class ImportRuleInterpreter implements InterpreterInterface { - use DataSetAwareTrait; - protected RuleApplierInterface $ruleProcessor; protected ImportRuleValidationProcessorInterface $ruleValidationProcessor; public function __construct( ImportRuleValidationProcessorInterface $ruleValidationProcessor, RuleApplierInterface $ruleProcessor - ) - { + ) { $this->ruleValidationProcessor = $ruleValidationProcessor; $this->ruleProcessor = $ruleProcessor; } public function interpret( - Concrete $object, - $value, - MappingInterface $map, - array $data, - DataDefinitionInterface $definition, - array $params, + InterpreterContextInterface $context, array $configuration ) { $rules = $configuration['rules']; @@ -81,19 +68,26 @@ public function interpret( } $params = [ - 'value' => $value, - 'object' => $object, - 'map' => $map, - 'data' => $data, - 'params' => $params, - 'dataSet' => $this->getDataSet() + 'value' => $context->getValue(), + 'object' => $context->getObject(), + 'map' => $context->getMapping(), + 'data' => $context->getDataRow(), + 'params' => $context->getParams(), + 'data_set' => $context->getDataSet(), ]; + $value = $context->getValue(); + foreach ($ruleObjects as $rule) { - if ($this->ruleValidationProcessor->isImportRuleValid($definition, $object, $rule, $params)) { + if ($this->ruleValidationProcessor->isImportRuleValid( + $context->getDefinition(), + $context->getObject(), + $rule, + $params + )) { $value = $this->ruleProcessor->applyRule( $rule, - $object, + $context->getObject(), $value, $params ); diff --git a/src/DataDefinitionsBundle/Interpreter/InterpreterInterface.php b/src/DataDefinitionsBundle/Interpreter/InterpreterInterface.php index 75a7310c..8960d6c4 100644 --- a/src/DataDefinitionsBundle/Interpreter/InterpreterInterface.php +++ b/src/DataDefinitionsBundle/Interpreter/InterpreterInterface.php @@ -16,20 +16,12 @@ namespace Wvision\Bundle\DataDefinitionsBundle\Interpreter; -use Pimcore\Model\DataObject\Concrete; -use Wvision\Bundle\DataDefinitionsBundle\Exception\DoNotSetException; -use Wvision\Bundle\DataDefinitionsBundle\Model\DataDefinitionInterface; -use Wvision\Bundle\DataDefinitionsBundle\Model\MappingInterface; +use Wvision\Bundle\DataDefinitionsBundle\Context\InterpreterContextInterface; interface InterpreterInterface { public function interpret( - Concrete $object, - $value, - MappingInterface $map, - array $data, - DataDefinitionInterface $definition, - array $params, + InterpreterContextInterface $context, array $configuration ); } diff --git a/src/DataDefinitionsBundle/Interpreter/IteratorInterpreter.php b/src/DataDefinitionsBundle/Interpreter/IteratorInterpreter.php index 2a8d795a..465f10a5 100644 --- a/src/DataDefinitionsBundle/Interpreter/IteratorInterpreter.php +++ b/src/DataDefinitionsBundle/Interpreter/IteratorInterpreter.php @@ -17,50 +17,47 @@ namespace Wvision\Bundle\DataDefinitionsBundle\Interpreter; use CoreShop\Component\Registry\ServiceRegistryInterface; -use Pimcore\Model\DataObject\Concrete; use Webmozart\Assert\Assert; -use Wvision\Bundle\DataDefinitionsBundle\Model\DataSetAwareInterface; -use Wvision\Bundle\DataDefinitionsBundle\Model\DataSetAwareTrait; -use Wvision\Bundle\DataDefinitionsBundle\Model\DataDefinitionInterface; -use Wvision\Bundle\DataDefinitionsBundle\Model\MappingInterface; +use Wvision\Bundle\DataDefinitionsBundle\Context\ContextFactoryInterface; +use Wvision\Bundle\DataDefinitionsBundle\Context\InterpreterContextInterface; -final class IteratorInterpreter implements InterpreterInterface, DataSetAwareInterface +final class IteratorInterpreter implements InterpreterInterface { - use DataSetAwareTrait; - - private ServiceRegistryInterface $interpreterRegistry; - - public function __construct(ServiceRegistryInterface $interpreterRegistry) - { - $this->interpreterRegistry = $interpreterRegistry; + public function __construct( + private ServiceRegistryInterface $interpreterRegistry, + private ContextFactoryInterface $contextFactory + ) { } public function interpret( - Concrete $object, - $value, - MappingInterface $map, - array $data, - DataDefinitionInterface $definition, - array $params, + InterpreterContextInterface $context, array $configuration ) { - if (null === $value) { + if (null === $context->getValue()) { return []; } - Assert::isArray($value, 'IteratorInterpreter can only be used with array values'); + Assert::isArray($context->getValue(), 'IteratorInterpreter can only be used with array values'); $interpreter = $configuration['interpreter']; $interpreterObject = $this->interpreterRegistry->get($interpreter['type']); - if ($interpreterObject instanceof DataSetAwareInterface) { - $interpreterObject->setDataSet($this->getDataSet()); - } - - foreach ($value as &$val) { - $val = $interpreterObject->interpret($object, $val, $map, $data, $definition, $params, - $interpreter['interpreterConfig']); + $value = $context->getValue(); + $result = []; + + foreach ($value as $val) { + $context = $this->contextFactory->createInterpreterContext( + $context->getDefinition(), + $context->getParams(), + $context->getDataRow(), + $context->getDataSet(), + $context->getObject(), + $val, + $context->getMapping() + ); + + $result[] = $interpreterObject->interpret($context, $interpreter['interpreterConfig']); } - return $value; + return $result; } } diff --git a/src/DataDefinitionsBundle/Interpreter/LinkInterpreter.php b/src/DataDefinitionsBundle/Interpreter/LinkInterpreter.php index 31fd6068..6808cd5a 100644 --- a/src/DataDefinitionsBundle/Interpreter/LinkInterpreter.php +++ b/src/DataDefinitionsBundle/Interpreter/LinkInterpreter.php @@ -16,40 +16,33 @@ namespace Wvision\Bundle\DataDefinitionsBundle\Interpreter; -use Pimcore\Model\DataObject\Concrete; use Pimcore\Model\DataObject\Data\Link; use Pimcore\Model\Element\ElementInterface; -use Wvision\Bundle\DataDefinitionsBundle\Model\DataDefinitionInterface; +use Wvision\Bundle\DataDefinitionsBundle\Context\InterpreterContextInterface; use Wvision\Bundle\DataDefinitionsBundle\Model\ExportDefinitionInterface; use Wvision\Bundle\DataDefinitionsBundle\Model\ImportDefinitionInterface; -use Wvision\Bundle\DataDefinitionsBundle\Model\MappingInterface; class LinkInterpreter implements InterpreterInterface { public function interpret( - Concrete $object, - $value, - MappingInterface $map, - array $data, - DataDefinitionInterface $definition, - array $params, + InterpreterContextInterface $context, array $configuration ) { - if (($definition instanceof ExportDefinitionInterface) && $value instanceof Link) { - return $value->getHref(); + if (($context->getDefinition() instanceof ExportDefinitionInterface) && $context->getValue() instanceof Link) { + return $context->getValue()->getHref(); } - if (($definition instanceof ImportDefinitionInterface)) { + if (($context->getDefinition() instanceof ImportDefinitionInterface)) { $link = new Link(); - if (filter_var($value, FILTER_VALIDATE_URL)) { - $link->setDirect($value); + if (filter_var($context->getValue(), FILTER_VALIDATE_URL)) { + $link->setDirect($context->getValue()); } - $link->setText($value); + $link->setText($context->getValue()); - if ($value instanceof ElementInterface) { - $link->setElement($value); + if ($context->getValue() instanceof ElementInterface) { + $link->setElement($context->getValue()); } return $link; diff --git a/src/DataDefinitionsBundle/Interpreter/MappingInterpreter.php b/src/DataDefinitionsBundle/Interpreter/MappingInterpreter.php index fd9b7e29..4d802828 100644 --- a/src/DataDefinitionsBundle/Interpreter/MappingInterpreter.php +++ b/src/DataDefinitionsBundle/Interpreter/MappingInterpreter.php @@ -16,23 +16,12 @@ namespace Wvision\Bundle\DataDefinitionsBundle\Interpreter; -use Pimcore\Model\DataObject\Concrete; -use Wvision\Bundle\DataDefinitionsBundle\Model\DataSetAwareInterface; -use Wvision\Bundle\DataDefinitionsBundle\Model\DataSetAwareTrait; -use Wvision\Bundle\DataDefinitionsBundle\Model\DataDefinitionInterface; -use Wvision\Bundle\DataDefinitionsBundle\Model\MappingInterface; +use Wvision\Bundle\DataDefinitionsBundle\Context\InterpreterContextInterface; -class MappingInterpreter implements InterpreterInterface, DataSetAwareInterface +class MappingInterpreter implements InterpreterInterface { - use DataSetAwareTrait; - public function interpret( - Concrete $object, - $value, - MappingInterface $map, - array $data, - DataDefinitionInterface $definition, - array $params, + InterpreterContextInterface $context, array $configuration ) { $interpreterMap = $configuration['mapping']; @@ -46,14 +35,14 @@ public function interpret( $resolvedMap[$itemMap['from']] = $itemMap['to']; } - if (array_key_exists($value, $resolvedMap)) { - return $resolvedMap[$value]; + if (array_key_exists($context->getValue(), $resolvedMap)) { + return $resolvedMap[$context->getValue()]; } if ($configuration['return_null_when_not_found']) { return null; } - return $value; + return $context->getValue(); } } diff --git a/src/DataDefinitionsBundle/Interpreter/MetadataInterpreter.php b/src/DataDefinitionsBundle/Interpreter/MetadataInterpreter.php index da7ed6c3..4d797426 100644 --- a/src/DataDefinitionsBundle/Interpreter/MetadataInterpreter.php +++ b/src/DataDefinitionsBundle/Interpreter/MetadataInterpreter.php @@ -16,36 +16,29 @@ namespace Wvision\Bundle\DataDefinitionsBundle\Interpreter; -use Pimcore\Model\DataObject\Concrete; -use Wvision\Bundle\DataDefinitionsBundle\Model\DataDefinitionInterface; -use Wvision\Bundle\DataDefinitionsBundle\Model\MappingInterface; use Pimcore\Model\DataObject\Data\ElementMetadata; use Pimcore\Model\DataObject\Data\ObjectMetadata; +use Wvision\Bundle\DataDefinitionsBundle\Context\InterpreterContextInterface; class MetadataInterpreter implements InterpreterInterface { public function interpret( - Concrete $object, - $value, - MappingInterface $map, - array $data, - DataDefinitionInterface $definition, - array $params, + InterpreterContextInterface $context, array $configuration ) { - $class = "\\Pimcore\\Model\\DataObject\\Data\\" . $configuration['class']; - $fieldname = $map->getToColumn(); + $class = "\\Pimcore\\Model\\DataObject\\Data\\".$configuration['class']; + $fieldname = $context->getMapping()->getToColumn(); $metadata = $configuration['metadata']; - $metadata = json_decode($metadata, true); + $metadata = json_decode($metadata, true, 512, JSON_THROW_ON_ERROR); if (!is_array($metadata)) { $metadata = []; } /** @var ElementMetadata|ObjectMetadata $elementMetadata */ - $elementMetadata = new $class($fieldname, array_keys($metadata), $value); + $elementMetadata = new $class($fieldname, array_keys($metadata), $context->getValue()); foreach ($metadata as $metadataKey => $metadataValue) { - $setter = 'set' . ucfirst($metadataKey); + $setter = 'set'.ucfirst($metadataKey); $elementMetadata->$setter($metadataValue); } diff --git a/src/DataDefinitionsBundle/Interpreter/MultiHrefInterpreter.php b/src/DataDefinitionsBundle/Interpreter/MultiHrefInterpreter.php index e7dc5353..3e97241e 100644 --- a/src/DataDefinitionsBundle/Interpreter/MultiHrefInterpreter.php +++ b/src/DataDefinitionsBundle/Interpreter/MultiHrefInterpreter.php @@ -18,22 +18,12 @@ use Pimcore\Model\DataObject\Concrete; use Pimcore\Tool; -use Wvision\Bundle\DataDefinitionsBundle\Model\DataSetAwareInterface; -use Wvision\Bundle\DataDefinitionsBundle\Model\DataSetAwareTrait; -use Wvision\Bundle\DataDefinitionsBundle\Model\DataDefinitionInterface; -use Wvision\Bundle\DataDefinitionsBundle\Model\MappingInterface; +use Wvision\Bundle\DataDefinitionsBundle\Context\InterpreterContextInterface; -class MultiHrefInterpreter implements InterpreterInterface, DataSetAwareInterface +class MultiHrefInterpreter implements InterpreterInterface { - use DataSetAwareTrait; - public function interpret( - Concrete $object, - $value, - MappingInterface $map, - array $data, - DataDefinitionInterface $definition, - array $params, + InterpreterContextInterface $context, array $configuration ) { $objectClass = $configuration['class']; @@ -44,7 +34,7 @@ public function interpret( $class = new $class(); if ($class instanceof Concrete) { - $ret = $class::getById($value); + $ret = $class::getById($context->getValue()); if ($ret instanceof Concrete) { return [$ret]; @@ -52,6 +42,6 @@ public function interpret( } } - return $value; + return $context->getValue(); } } diff --git a/src/DataDefinitionsBundle/Interpreter/NestedInterpreter.php b/src/DataDefinitionsBundle/Interpreter/NestedInterpreter.php index 769c38d8..7c92ea1b 100644 --- a/src/DataDefinitionsBundle/Interpreter/NestedInterpreter.php +++ b/src/DataDefinitionsBundle/Interpreter/NestedInterpreter.php @@ -17,45 +17,40 @@ namespace Wvision\Bundle\DataDefinitionsBundle\Interpreter; use CoreShop\Component\Registry\ServiceRegistryInterface; -use Pimcore\Model\DataObject\Concrete; use Webmozart\Assert\Assert; -use Wvision\Bundle\DataDefinitionsBundle\Model\DataSetAwareInterface; -use Wvision\Bundle\DataDefinitionsBundle\Model\DataSetAwareTrait; -use Wvision\Bundle\DataDefinitionsBundle\Model\DataDefinitionInterface; -use Wvision\Bundle\DataDefinitionsBundle\Model\MappingInterface; +use Wvision\Bundle\DataDefinitionsBundle\Context\ContextFactoryInterface; +use Wvision\Bundle\DataDefinitionsBundle\Context\InterpreterContextInterface; -final class NestedInterpreter implements InterpreterInterface, DataSetAwareInterface +final class NestedInterpreter implements InterpreterInterface { - use DataSetAwareTrait; - - private ServiceRegistryInterface $interpreterRegistry; - - public function __construct(ServiceRegistryInterface $interpreterRegistry) - { - $this->interpreterRegistry = $interpreterRegistry; + public function __construct( + private ServiceRegistryInterface $interpreterRegistry, + private ContextFactoryInterface $contextFactory + ) { } public function interpret( - Concrete $object, - $value, - MappingInterface $map, - array $data, - DataDefinitionInterface $definition, - array $params, + InterpreterContextInterface $context, array $configuration ) { Assert::keyExists($configuration, 'interpreters'); Assert::isArray($configuration['interpreters'], 'Interpreter Config needs to be array'); + $value = $context->getValue(); + foreach ($configuration['interpreters'] as $interpreter) { $interpreterObject = $this->interpreterRegistry->get($interpreter['type']); - - if ($interpreterObject instanceof DataSetAwareInterface) { - $interpreterObject->setDataSet($this->getDataSet()); - } - - $value = $interpreterObject->interpret($object, $value, $map, $data, $definition, $params, - $interpreter['interpreterConfig']); + $newContext = $this->contextFactory->createInterpreterContext( + $context->getDefinition(), + $context->getParams(), + $context->getDataRow(), + $context->getDataSet(), + $context->getObject(), + $value, + $context->getMapping() + ); + + $value = $interpreterObject->interpret($newContext, $interpreter['interpreterConfig']); } return $value; diff --git a/src/DataDefinitionsBundle/Interpreter/ObjectResolverInterpreter.php b/src/DataDefinitionsBundle/Interpreter/ObjectResolverInterpreter.php index bf56ec7d..059cb18e 100644 --- a/src/DataDefinitionsBundle/Interpreter/ObjectResolverInterpreter.php +++ b/src/DataDefinitionsBundle/Interpreter/ObjectResolverInterpreter.php @@ -16,23 +16,16 @@ namespace Wvision\Bundle\DataDefinitionsBundle\Interpreter; -use Pimcore\Model\DataObject\Concrete; use Pimcore\Model\DataObject\Listing; -use Wvision\Bundle\DataDefinitionsBundle\Model\DataDefinitionInterface; -use Wvision\Bundle\DataDefinitionsBundle\Model\MappingInterface; +use Wvision\Bundle\DataDefinitionsBundle\Context\InterpreterContextInterface; class ObjectResolverInterpreter implements InterpreterInterface { public function interpret( - Concrete $object, - $value, - MappingInterface $map, - $data, - DataDefinitionInterface $definition, - $params, - $configuration + InterpreterContextInterface $context, + array $configuration ) { - if (!$value) { + if (!$context->getValue()) { return null; } @@ -42,7 +35,7 @@ public function interpret( /** * @var Listing $listing */ - $listing = $class::$lookup($value); + $listing = $class::$lookup($context->getValue()); $listing->setUnpublished($configuration['match_unpublished']); if ($listing->count() === 1) { diff --git a/src/DataDefinitionsBundle/Interpreter/QuantityValueInterpreter.php b/src/DataDefinitionsBundle/Interpreter/QuantityValueInterpreter.php index 1d4a73de..7ba856e0 100644 --- a/src/DataDefinitionsBundle/Interpreter/QuantityValueInterpreter.php +++ b/src/DataDefinitionsBundle/Interpreter/QuantityValueInterpreter.php @@ -16,27 +16,16 @@ namespace Wvision\Bundle\DataDefinitionsBundle\Interpreter; -use Pimcore\Model\DataObject\Concrete; use Pimcore\Model\DataObject\Data\QuantityValue; -use Wvision\Bundle\DataDefinitionsBundle\Model\DataSetAwareInterface; -use Wvision\Bundle\DataDefinitionsBundle\Model\DataSetAwareTrait; -use Wvision\Bundle\DataDefinitionsBundle\Model\DataDefinitionInterface; -use Wvision\Bundle\DataDefinitionsBundle\Model\MappingInterface; +use Wvision\Bundle\DataDefinitionsBundle\Context\InterpreterContextInterface; -class QuantityValueInterpreter implements InterpreterInterface, DataSetAwareInterface +class QuantityValueInterpreter implements InterpreterInterface { - use DataSetAwareTrait; - public function interpret( - Concrete $object, - $value, - MappingInterface $map, - array $data, - DataDefinitionInterface $definition, - array $params, + InterpreterContextInterface $context, array $configuration ) { - $value = $value !== '' ? $value : null; + $value = $context->getValue() !== '' ? $context->getValue() : null; $unit = $configuration['unit']; return new QuantityValue($value, $unit); diff --git a/src/DataDefinitionsBundle/Interpreter/SpecificObjectInterpreter.php b/src/DataDefinitionsBundle/Interpreter/SpecificObjectInterpreter.php index 355f5b9e..3c852332 100644 --- a/src/DataDefinitionsBundle/Interpreter/SpecificObjectInterpreter.php +++ b/src/DataDefinitionsBundle/Interpreter/SpecificObjectInterpreter.php @@ -17,19 +17,12 @@ namespace Wvision\Bundle\DataDefinitionsBundle\Interpreter; use Pimcore\Model\DataObject; -use Pimcore\Model\DataObject\Concrete; -use Wvision\Bundle\DataDefinitionsBundle\Model\DataDefinitionInterface; -use Wvision\Bundle\DataDefinitionsBundle\Model\MappingInterface; +use Wvision\Bundle\DataDefinitionsBundle\Context\InterpreterContextInterface; class SpecificObjectInterpreter implements InterpreterInterface { public function interpret( - Concrete $object, - $value, - MappingInterface $map, - array $data, - DataDefinitionInterface $definition, - array $params, + InterpreterContextInterface $context, array $configuration ) { $objectId = $configuration['objectId']; diff --git a/src/DataDefinitionsBundle/Interpreter/TwigInterpreter.php b/src/DataDefinitionsBundle/Interpreter/TwigInterpreter.php index 00b87eed..d55082be 100644 --- a/src/DataDefinitionsBundle/Interpreter/TwigInterpreter.php +++ b/src/DataDefinitionsBundle/Interpreter/TwigInterpreter.php @@ -16,10 +16,8 @@ namespace Wvision\Bundle\DataDefinitionsBundle\Interpreter; -use Pimcore\Model\DataObject\Concrete; use Twig\Environment; -use Wvision\Bundle\DataDefinitionsBundle\Model\DataDefinitionInterface; -use Wvision\Bundle\DataDefinitionsBundle\Model\MappingInterface; +use Wvision\Bundle\DataDefinitionsBundle\Context\InterpreterContextInterface; class TwigInterpreter implements InterpreterInterface { @@ -31,21 +29,17 @@ public function __construct(Environment $twig) } public function interpret( - Concrete $object, - $value, - MappingInterface $map, - array $data, - DataDefinitionInterface $definition, - array $params, + InterpreterContextInterface $context, array $configuration ) { return $this->twig->createTemplate($configuration['template'])->render([ - 'value' => $value, - 'object' => $object, - 'map' => $map, - 'data' => $data, - 'definition' => $definition, - 'params' => $params, + 'value' => $context->getValue(), + 'object' => $context->getObject(), + 'map' => $context->getMapping(), + 'data' => $context->getDataRow(), + 'data_set' => $context->getDataSet(), + 'definition' => $context->getDefinition(), + 'params' => $context->getParams(), 'configuration' => $configuration, ]); } diff --git a/src/DataDefinitionsBundle/Interpreter/TypeCastingInterpreter.php b/src/DataDefinitionsBundle/Interpreter/TypeCastingInterpreter.php index 628a7ee7..f3bd19a0 100644 --- a/src/DataDefinitionsBundle/Interpreter/TypeCastingInterpreter.php +++ b/src/DataDefinitionsBundle/Interpreter/TypeCastingInterpreter.php @@ -17,38 +17,27 @@ namespace Wvision\Bundle\DataDefinitionsBundle\Interpreter; use InvalidArgumentException; -use Pimcore\Model\DataObject\Concrete; -use Wvision\Bundle\DataDefinitionsBundle\Model\DataSetAwareInterface; -use Wvision\Bundle\DataDefinitionsBundle\Model\DataSetAwareTrait; -use Wvision\Bundle\DataDefinitionsBundle\Model\DataDefinitionInterface; -use Wvision\Bundle\DataDefinitionsBundle\Model\MappingInterface; +use Wvision\Bundle\DataDefinitionsBundle\Context\InterpreterContextInterface; -class TypeCastingInterpreter implements InterpreterInterface, DataSetAwareInterface +class TypeCastingInterpreter implements InterpreterInterface { - use DataSetAwareTrait; - protected const TYPE_INT = 'int'; protected const TYPE_STRING = 'string'; protected const TYPE_BOOLEAN = 'boolean'; public function interpret( - Concrete $object, - $value, - MappingInterface $map, - array $data, - DataDefinitionInterface $definition, - array $params, + InterpreterContextInterface $context, array $configuration ) { $type = $configuration['toType']; switch ($type) { case static::TYPE_INT: - return (int)$value; + return (int)$context->getValue(); case static::TYPE_STRING: - return (string)$value; + return (string)$context->getValue(); case static::TYPE_BOOLEAN: - return (boolean)$value; + return (boolean)$context->getValue(); } throw new InvalidArgumentException(sprintf('Not valid type cast given, given %s', $type)); diff --git a/src/DataDefinitionsBundle/Loader/LoaderInterface.php b/src/DataDefinitionsBundle/Loader/LoaderInterface.php index 962a9a4a..be0d92f6 100644 --- a/src/DataDefinitionsBundle/Loader/LoaderInterface.php +++ b/src/DataDefinitionsBundle/Loader/LoaderInterface.php @@ -17,9 +17,9 @@ namespace Wvision\Bundle\DataDefinitionsBundle\Loader; use Pimcore\Model\DataObject\Concrete; -use Wvision\Bundle\DataDefinitionsBundle\Model\ImportDefinitionInterface; +use Wvision\Bundle\DataDefinitionsBundle\Context\LoaderContextInterface; interface LoaderInterface { - public function load(string $class, array $data, ImportDefinitionInterface $definition, array $params): ?Concrete; + public function load(LoaderContextInterface $context): ?Concrete; } diff --git a/src/DataDefinitionsBundle/Loader/PrimaryKeyLoader.php b/src/DataDefinitionsBundle/Loader/PrimaryKeyLoader.php index 8c76689d..5f1aec88 100644 --- a/src/DataDefinitionsBundle/Loader/PrimaryKeyLoader.php +++ b/src/DataDefinitionsBundle/Loader/PrimaryKeyLoader.php @@ -20,17 +20,16 @@ use Pimcore\Model\DataObject; use Pimcore\Model\DataObject\Concrete; use Pimcore\Model\DataObject\Listing; -use Wvision\Bundle\DataDefinitionsBundle\Model\DataDefinitionInterface; -use Wvision\Bundle\DataDefinitionsBundle\Model\ImportDefinitionInterface; +use Wvision\Bundle\DataDefinitionsBundle\Context\LoaderContextInterface; use Wvision\Bundle\DataDefinitionsBundle\Model\ImportMapping; use function count; class PrimaryKeyLoader implements LoaderInterface { - public function load(string $class, array $data, ImportDefinitionInterface $definition, array $params): ?Concrete + public function load(LoaderContextInterface $context): ?Concrete { - $classObject = '\Pimcore\Model\DataObject\\'.ucfirst($class); - $classList = '\Pimcore\Model\DataObject\\'.ucfirst($class).'\Listing'; + $classObject = '\Pimcore\Model\DataObject\\'.ucfirst($context->getClass()); + $classList = '\Pimcore\Model\DataObject\\'.ucfirst($context->getClass()).'\Listing'; $list = new $classList(); @@ -38,13 +37,13 @@ public function load(string $class, array $data, ImportDefinitionInterface $defi /** * @var ImportMapping[] $mapping */ - $mapping = $definition->getMapping(); + $mapping = $context->getDefinition()->getMapping(); $condition = []; $conditionValues = []; foreach ($mapping as $map) { if ($map->getPrimaryIdentifier()) { $condition[] = '`'.$map->getToColumn().'` = ?'; - $conditionValues[] = $data[$map->getFromColumn()]; + $conditionValues[] = $context->getDataRow()[$map->getFromColumn()]; } } @@ -69,7 +68,7 @@ public function load(string $class, array $data, ImportDefinitionInterface $defi if (count($objectData) === 1) { $obj = $objectData[0]; - if ($definition->getForceLoadObject()) { + if ($context->getDefinition()->getForceLoadObject()) { $obj = DataObject::getById($obj->getId(), true); if (!$obj instanceof $classObject) { diff --git a/src/DataDefinitionsBundle/Model/ExportDefinition.php b/src/DataDefinitionsBundle/Model/ExportDefinition.php index 7b1b6c5f..052f0199 100644 --- a/src/DataDefinitionsBundle/Model/ExportDefinition.php +++ b/src/DataDefinitionsBundle/Model/ExportDefinition.php @@ -33,7 +33,7 @@ class ExportDefinition extends AbstractDataDefinition implements ExportDefinitio */ public $fetchUnpublished = false; - public static function getById($id) + public static function getById($id) { $definitionEntry = new ExportDefinition(); $definitionEntry->setId((int)$id); diff --git a/src/DataDefinitionsBundle/Model/ExportDefinition/Dao.php b/src/DataDefinitionsBundle/Model/ExportDefinition/Dao.php index 865d01c0..898ae3d5 100644 --- a/src/DataDefinitionsBundle/Model/ExportDefinition/Dao.php +++ b/src/DataDefinitionsBundle/Model/ExportDefinition/Dao.php @@ -52,8 +52,12 @@ public function getById($id = null) if (isset($data['id'])) { $this->assignVariablesToModel($data); } else { - throw new InvalidArgumentException(sprintf('Export Definition with id: %s does not exist', - $this->model->getId())); + throw new InvalidArgumentException( + sprintf( + 'Export Definition with id: %s does not exist', + $this->model->getId() + ) + ); } } @@ -105,8 +109,12 @@ public function getByName($name = null) if ($data[0]['id'] && count($data)) { $this->assignVariablesToModel($data[0]); } else { - throw new InvalidArgumentException(sprintf('Definition with name: %s does not exist', - $this->model->getName())); + throw new InvalidArgumentException( + sprintf( + 'Definition with name: %s does not exist', + $this->model->getName() + ) + ); } } diff --git a/src/DataDefinitionsBundle/Model/ImportDefinition/Dao.php b/src/DataDefinitionsBundle/Model/ImportDefinition/Dao.php index 6755c430..23e965dd 100644 --- a/src/DataDefinitionsBundle/Model/ImportDefinition/Dao.php +++ b/src/DataDefinitionsBundle/Model/ImportDefinition/Dao.php @@ -52,8 +52,12 @@ public function getById($id = null) if (isset($data['id'])) { $this->assignVariablesToModel($data); } else { - throw new InvalidArgumentException(sprintf('Definition with id: %s does not exist', - $this->model->getId())); + throw new InvalidArgumentException( + sprintf( + 'Definition with id: %s does not exist', + $this->model->getId() + ) + ); } } @@ -105,8 +109,12 @@ public function getByName($name = null) if (isset($data[0]['id']) && count($data)) { $this->assignVariablesToModel($data[0]); } else { - throw new InvalidArgumentException(sprintf('Definition with name: %s does not exist', - $this->model->getName())); + throw new InvalidArgumentException( + sprintf( + 'Definition with name: %s does not exist', + $this->model->getName() + ) + ); } } diff --git a/src/DataDefinitionsBundle/Model/Log/Listing.php b/src/DataDefinitionsBundle/Model/Log/Listing.php index 825cf02c..52f06ee9 100644 --- a/src/DataDefinitionsBundle/Model/Log/Listing.php +++ b/src/DataDefinitionsBundle/Model/Log/Listing.php @@ -18,8 +18,8 @@ use Exception; use Pimcore\Model; -use Wvision\Bundle\DataDefinitionsBundle\Model\Log; use Pimcore\Model\Paginator\PaginateListingInterface; +use Wvision\Bundle\DataDefinitionsBundle\Model\Log; use function in_array; class Listing extends Model\Listing\AbstractListing implements PaginateListingInterface diff --git a/src/DataDefinitionsBundle/Model/Log/Listing/Dao.php b/src/DataDefinitionsBundle/Model/Log/Listing/Dao.php index 7a195c51..ff77c639 100644 --- a/src/DataDefinitionsBundle/Model/Log/Listing/Dao.php +++ b/src/DataDefinitionsBundle/Model/Log/Listing/Dao.php @@ -16,7 +16,6 @@ namespace Wvision\Bundle\DataDefinitionsBundle\Model\Log\Listing; -use Doctrine\DBAL\Query\QueryBuilder; use Doctrine\DBAL\Query\QueryBuilder as DoctrineQueryBuilder; use Exception; use Pimcore\Model\Listing; @@ -86,13 +85,16 @@ public function getQueryBuilder(...$columns): DoctrineQueryBuilder public function loadIdList() { $queryBuilder = $this->getQueryBuilder(['id']); - $assetIds = $this->db->fetchCol((string) $queryBuilder, $this->model->getConditionVariables(), $this->model->getConditionVariableTypes()); + $assetIds = $this->db->fetchCol( + (string)$queryBuilder, + $this->model->getConditionVariables(), + $this->model->getConditionVariableTypes() + ); return array_map('intval', $assetIds); } - /** * Get Count * @@ -101,8 +103,10 @@ public function loadIdList() */ public function getCount(): int { - return (int)$this->db->fetchOne('SELECT COUNT(*) as amount FROM '.$this->getTableName().$this->getCondition().$this->getOffsetLimit(), - $this->model->getConditionVariables()); + return (int)$this->db->fetchOne( + 'SELECT COUNT(*) as amount FROM '.$this->getTableName().$this->getCondition().$this->getOffsetLimit(), + $this->model->getConditionVariables() + ); } /** @@ -113,7 +117,9 @@ public function getCount(): int */ public function getTotalCount(): int { - return (int)$this->db->fetchOne('SELECT COUNT(*) as amount FROM '.$this->getTableName().$this->getCondition(), - $this->model->getConditionVariables()); + return (int)$this->db->fetchOne( + 'SELECT COUNT(*) as amount FROM '.$this->getTableName().$this->getCondition(), + $this->model->getConditionVariables() + ); } } diff --git a/src/DataDefinitionsBundle/ProcessManager/AbstractProcessManagerListener.php b/src/DataDefinitionsBundle/ProcessManager/AbstractProcessManagerListener.php index 37b6a586..d5375591 100644 --- a/src/DataDefinitionsBundle/ProcessManager/AbstractProcessManagerListener.php +++ b/src/DataDefinitionsBundle/ProcessManager/AbstractProcessManagerListener.php @@ -69,7 +69,7 @@ public function __construct( /** * @return ProcessInterface|null */ - public function getProcess() : ProcessInterface + public function getProcess(): ProcessInterface { return $this->process; } @@ -77,14 +77,14 @@ public function getProcess() : ProcessInterface /** * @param DefinitionEventInterface $event */ - public function onTotalEvent(DefinitionEventInterface $event) : void + public function onTotalEvent(DefinitionEventInterface $event): void { if (null === $this->process) { $date = Carbon::now(); $this->process = $this->processFactory->createProcess( sprintf( - static::PROCESS_NAME . ' (%s): %s', + static::PROCESS_NAME.' (%s): %s', $date->formatLocalized('%A %d %B %Y'), $event->getDefinition()->getName() ), @@ -107,7 +107,7 @@ public function onTotalEvent(DefinitionEventInterface $event) : void /** * @return void */ - public function onProgressEvent(DefinitionEventInterface $event) : void + public function onProgressEvent(DefinitionEventInterface $event): void { if ($this->process) { $now = new \DateTimeImmutable(); @@ -142,7 +142,7 @@ public function onProgressEvent(DefinitionEventInterface $event) : void /** * @param DefinitionEventInterface $event */ - public function onStatusEvent(DefinitionEventInterface $event) : void + public function onStatusEvent(DefinitionEventInterface $event): void { if ($this->process) { $now = new \DateTimeImmutable(); @@ -168,7 +168,7 @@ public function onStatusEvent(DefinitionEventInterface $event) : void /** * @param DefinitionEventInterface $event */ - public function onFinishedEvent(DefinitionEventInterface $event) : void + public function onFinishedEvent(DefinitionEventInterface $event): void { if ($this->process) { if ($this->process->getStatus() === ProcessManagerBundle::STATUS_RUNNING) { @@ -185,7 +185,7 @@ public function onFinishedEvent(DefinitionEventInterface $event) : void /** * @param DefinitionEventInterface $event */ - public function onFailureEvent(DefinitionEventInterface $event) : void + public function onFailureEvent(DefinitionEventInterface $event): void { if ($this->process) { if ($event->getDefinition()->getStopOnException()) { diff --git a/src/DataDefinitionsBundle/ProcessManager/ArtifactGenerationProviderInterface.php b/src/DataDefinitionsBundle/ProcessManager/ArtifactGenerationProviderInterface.php index 2f16a63c..5cc46d93 100644 --- a/src/DataDefinitionsBundle/ProcessManager/ArtifactGenerationProviderInterface.php +++ b/src/DataDefinitionsBundle/ProcessManager/ArtifactGenerationProviderInterface.php @@ -22,7 +22,7 @@ interface ArtifactGenerationProviderInterface { /** - * @param array $configuration + * @param array $configuration * @param ExportDefinitionInterface $definition * @param $params * @return Asset diff --git a/src/DataDefinitionsBundle/ProcessManager/ArtifactProviderTrait.php b/src/DataDefinitionsBundle/ProcessManager/ArtifactProviderTrait.php index 38f30930..1a945d78 100644 --- a/src/DataDefinitionsBundle/ProcessManager/ArtifactProviderTrait.php +++ b/src/DataDefinitionsBundle/ProcessManager/ArtifactProviderTrait.php @@ -57,5 +57,9 @@ public function generateArtifact($configuration, ExportDefinitionInterface $defi * @param ExportDefinitionInterface $definition * @param array $params */ - abstract public function provideArtifactStream(array $configuration, ExportDefinitionInterface $definition, array $params); + abstract public function provideArtifactStream( + array $configuration, + ExportDefinitionInterface $definition, + array $params + ); } diff --git a/src/DataDefinitionsBundle/ProcessManager/ImportDefinitionsReport.php b/src/DataDefinitionsBundle/ProcessManager/ImportDefinitionsReport.php index 4f3d06a9..e3d4ae31 100644 --- a/src/DataDefinitionsBundle/ProcessManager/ImportDefinitionsReport.php +++ b/src/DataDefinitionsBundle/ProcessManager/ImportDefinitionsReport.php @@ -200,7 +200,10 @@ protected function checkForError($line, &$result): bool { $pos = strpos($line, self::EVENT_STATUS_ERROR); if (false !== $pos) { - $result['productStatus'][$result['currentObject']]['error'] = substr($line, $pos + strlen(self::EVENT_STATUS_ERROR)); + $result['productStatus'][$result['currentObject']]['error'] = substr( + $line, + $pos + strlen(self::EVENT_STATUS_ERROR) + ); return true; } diff --git a/src/DataDefinitionsBundle/ProcessManager/ProcessManagerExportListener.php b/src/DataDefinitionsBundle/ProcessManager/ProcessManagerExportListener.php index 5af153fe..a496cab4 100644 --- a/src/DataDefinitionsBundle/ProcessManager/ProcessManagerExportListener.php +++ b/src/DataDefinitionsBundle/ProcessManager/ProcessManagerExportListener.php @@ -27,12 +27,12 @@ final class ProcessManagerExportListener extends AbstractProcessManagerListener private $providerRegistry; - public function setProviderRegistry(ServiceRegistryInterface $providerRegistry) : void + public function setProviderRegistry(ServiceRegistryInterface $providerRegistry): void { $this->providerRegistry = $providerRegistry; } - public function onFinishedEvent(DefinitionEventInterface $event) : void + public function onFinishedEvent(DefinitionEventInterface $event): void { if (null !== $this->process) { if ($this->process->getStatus() == ProcessManagerBundle::STATUS_RUNNING) { diff --git a/src/DataDefinitionsBundle/Provider/AbstractSqlProvider.php b/src/DataDefinitionsBundle/Provider/AbstractSqlProvider.php index 3b4531c7..5d83a1b3 100644 --- a/src/DataDefinitionsBundle/Provider/AbstractSqlProvider.php +++ b/src/DataDefinitionsBundle/Provider/AbstractSqlProvider.php @@ -55,8 +55,12 @@ public function getColumns(array $configuration): array return $returnColumns; } - public function getData(array $configuration, ImportDefinitionInterface $definition, array $params, FilterInterface $filter = null): ImportDataSetInterface - { + public function getData( + array $configuration, + ImportDefinitionInterface $definition, + array $params, + FilterInterface $filter = null + ): ImportDataSetInterface { $db = $this->getDb($configuration); return new ArrayImportDataSet($db->fetchAllAssociative($configuration['query'])); diff --git a/src/DataDefinitionsBundle/Provider/CsvProvider.php b/src/DataDefinitionsBundle/Provider/CsvProvider.php index 51b4642c..49a20805 100644 --- a/src/DataDefinitionsBundle/Provider/CsvProvider.php +++ b/src/DataDefinitionsBundle/Provider/CsvProvider.php @@ -41,7 +41,7 @@ public function testData(array $configuration): bool public function getColumns(array $configuration): array { - $csvHeaders = (string) $configuration['csvHeaders']; + $csvHeaders = (string)$configuration['csvHeaders']; $csvExample = $configuration['csvExample']; $delimiter = $configuration['delimiter']; $enclosure = $configuration['enclosure']; @@ -73,8 +73,12 @@ public function getColumns(array $configuration): array return $returnHeaders; } - public function getData(array $configuration, ImportDefinitionInterface $definition, array $params, FilterInterface $filter = null): ImportDataSetInterface - { + public function getData( + array $configuration, + ImportDefinitionInterface $definition, + array $params, + FilterInterface $filter = null + ): ImportDataSetInterface { $csvHeaders = $configuration['csvHeaders']; $delimiter = $configuration['delimiter']; $enclosure = $configuration['enclosure']; @@ -139,8 +143,12 @@ public function exportData(array $configuration, ExportDefinitionInterface $defi $writer->insertAll($this->exportData); } - public function addExportData(array $data, array $configuration, ExportDefinitionInterface $definition, array $params): void - { + public function addExportData( + array $data, + array $configuration, + ExportDefinitionInterface $definition, + array $params + ): void { $this->exportData[] = $data; } diff --git a/src/DataDefinitionsBundle/Provider/ExcelProvider.php b/src/DataDefinitionsBundle/Provider/ExcelProvider.php index 8f58a152..da70542e 100644 --- a/src/DataDefinitionsBundle/Provider/ExcelProvider.php +++ b/src/DataDefinitionsBundle/Provider/ExcelProvider.php @@ -17,13 +17,10 @@ namespace Wvision\Bundle\DataDefinitionsBundle\Provider; use Box\Spout\Common\Entity\Row; -use Box\Spout\Common\Exception\IOException; use Box\Spout\Reader\ReaderInterface; -use Box\Spout\Writer\Exception\WriterNotOpenedException; use Box\Spout\Writer\WriterInterface; use Pimcore\Model\Asset; use Pimcore\Tool\Storage; -use Wvision\Bundle\DataDefinitionsBundle\Exception\SpoutException; use Wvision\Bundle\DataDefinitionsBundle\Filter\FilterInterface; use Wvision\Bundle\DataDefinitionsBundle\Model\ExportDefinitionInterface; use Wvision\Bundle\DataDefinitionsBundle\Model\ImportDefinitionInterface; @@ -70,8 +67,12 @@ public function getColumns(array $configuration): array return []; } - public function getData(array $configuration, ImportDefinitionInterface $definition, array $params, FilterInterface $filter = null): ImportDataSetInterface - { + public function getData( + array $configuration, + ImportDefinitionInterface $definition, + array $params, + FilterInterface $filter = null + ): ImportDataSetInterface { $file = $this->getFile($params); $reader = $this->createReader($file); @@ -105,8 +106,12 @@ public function getData(array $configuration, ImportDefinitionInterface $definit }); } - public function addExportData(array $data, array $configuration, ExportDefinitionInterface $definition, array $params): void - { + public function addExportData( + array $data, + array $configuration, + ExportDefinitionInterface $definition, + array $params + ): void { $headers = null; if (!isset($this->writer)) { $headers = array_keys($data); @@ -119,7 +124,11 @@ public function addExportData(array $data, array $configuration, ExportDefinitio $data[$key] = (string)$item; } } - $writer->addRow($this->useSpoutLegacy ? array_values($data) : \Box\Spout\Writer\Common\Creator\WriterEntityFactory::createRowFromArray(array_values($data))); + $writer->addRow( + $this->useSpoutLegacy ? array_values( + $data + ) : \Box\Spout\Writer\Common\Creator\WriterEntityFactory::createRowFromArray(array_values($data)) + ); } public function exportData(array $configuration, ExportDefinitionInterface $definition, array $params): void @@ -190,7 +199,11 @@ private function buildColumns($row): array private function addHeaders(?array $headers, WriterInterface $writer): void { if (null !== $headers) { - $writer->addRow($this->useSpoutLegacy ? $headers : \Box\Spout\Writer\Common\Creator\WriterEntityFactory::createRowFromArray($headers)); + $writer->addRow( + $this->useSpoutLegacy ? $headers : \Box\Spout\Writer\Common\Creator\WriterEntityFactory::createRowFromArray( + $headers + ) + ); } } diff --git a/src/DataDefinitionsBundle/Provider/ExportProviderInterface.php b/src/DataDefinitionsBundle/Provider/ExportProviderInterface.php index c3f87be7..65efcf52 100644 --- a/src/DataDefinitionsBundle/Provider/ExportProviderInterface.php +++ b/src/DataDefinitionsBundle/Provider/ExportProviderInterface.php @@ -20,7 +20,12 @@ interface ExportProviderInterface { - public function addExportData(array $data, array $configuration, ExportDefinitionInterface $definition, array $params): void; + public function addExportData( + array $data, + array $configuration, + ExportDefinitionInterface $definition, + array $params + ): void; public function exportData(array $configuration, ExportDefinitionInterface $definition, array $params): void; } diff --git a/src/DataDefinitionsBundle/Provider/ExternalSqlProvider.php b/src/DataDefinitionsBundle/Provider/ExternalSqlProvider.php index 7dab6f8f..60922972 100644 --- a/src/DataDefinitionsBundle/Provider/ExternalSqlProvider.php +++ b/src/DataDefinitionsBundle/Provider/ExternalSqlProvider.php @@ -19,7 +19,6 @@ use Doctrine\DBAL\Configuration; use Doctrine\DBAL\Connection; use Doctrine\DBAL\DriverManager; -use Doctrine\DBAL\Exception; class ExternalSqlProvider extends AbstractSqlProvider { diff --git a/src/DataDefinitionsBundle/Provider/ImportDataSetInterface.php b/src/DataDefinitionsBundle/Provider/ImportDataSetInterface.php index f8ca2180..44905556 100644 --- a/src/DataDefinitionsBundle/Provider/ImportDataSetInterface.php +++ b/src/DataDefinitionsBundle/Provider/ImportDataSetInterface.php @@ -16,7 +16,6 @@ namespace Wvision\Bundle\DataDefinitionsBundle\Provider; -use Countable; use Iterator; interface ImportDataSetInterface extends Iterator diff --git a/src/DataDefinitionsBundle/Provider/ImportProviderInterface.php b/src/DataDefinitionsBundle/Provider/ImportProviderInterface.php index 94da6ca9..f328865c 100644 --- a/src/DataDefinitionsBundle/Provider/ImportProviderInterface.php +++ b/src/DataDefinitionsBundle/Provider/ImportProviderInterface.php @@ -25,5 +25,10 @@ public function testData(array $configuration): bool; public function getColumns(array $configuration): array; - public function getData(array $configuration, ImportDefinitionInterface $definition, array $params, FilterInterface $filter = null): ImportDataSetInterface; + public function getData( + array $configuration, + ImportDefinitionInterface $definition, + array $params, + FilterInterface $filter = null + ): ImportDataSetInterface; } diff --git a/src/DataDefinitionsBundle/Provider/JsonProvider.php b/src/DataDefinitionsBundle/Provider/JsonProvider.php index 32eb8bb2..7c08f6f9 100644 --- a/src/DataDefinitionsBundle/Provider/JsonProvider.php +++ b/src/DataDefinitionsBundle/Provider/JsonProvider.php @@ -81,8 +81,12 @@ public function getColumns(array $configuration): array return $returnHeaders; } - public function getData(array $configuration, ImportDefinitionInterface $definition, array $params, FilterInterface $filter = null): ImportDataSetInterface - { + public function getData( + array $configuration, + ImportDefinitionInterface $definition, + array $params, + FilterInterface $filter = null + ): ImportDataSetInterface { $file = $this->getFile($params); if (file_exists($file)) { @@ -105,8 +109,12 @@ public function exportData(array $configuration, ExportDefinitionInterface $defi file_put_contents($file, json_encode($this->exportData)); } - public function addExportData(array $data, array $configuration, ExportDefinitionInterface $definition, array $params): void - { + public function addExportData( + array $data, + array $configuration, + ExportDefinitionInterface $definition, + array $params + ): void { $this->exportData[] = $data; } diff --git a/src/DataDefinitionsBundle/Provider/RawProvider.php b/src/DataDefinitionsBundle/Provider/RawProvider.php index 46c2351b..6bd88618 100644 --- a/src/DataDefinitionsBundle/Provider/RawProvider.php +++ b/src/DataDefinitionsBundle/Provider/RawProvider.php @@ -51,8 +51,12 @@ public function getColumns(array $configuration): array return $returnHeaders; } - public function getData(array $configuration, ImportDefinitionInterface $definition, array $params, FilterInterface $filter = null): ImportDataSetInterface - { + public function getData( + array $configuration, + ImportDefinitionInterface $definition, + array $params, + FilterInterface $filter = null + ): ImportDataSetInterface { return new ArrayImportDataSet($params['data']); } } diff --git a/src/DataDefinitionsBundle/Provider/SqlProvider.php b/src/DataDefinitionsBundle/Provider/SqlProvider.php index b6803472..79353b17 100644 --- a/src/DataDefinitionsBundle/Provider/SqlProvider.php +++ b/src/DataDefinitionsBundle/Provider/SqlProvider.php @@ -17,7 +17,6 @@ namespace Wvision\Bundle\DataDefinitionsBundle\Provider; use Doctrine\DBAL\Connection; -use Pimcore\Db; class SqlProvider extends AbstractSqlProvider { diff --git a/src/DataDefinitionsBundle/Provider/XmlProvider.php b/src/DataDefinitionsBundle/Provider/XmlProvider.php index 2b88bd10..360903d8 100755 --- a/src/DataDefinitionsBundle/Provider/XmlProvider.php +++ b/src/DataDefinitionsBundle/Provider/XmlProvider.php @@ -85,16 +85,24 @@ public function getColumns(array $configuration): array return $returnHeaders; } - public function getData(array $configuration, ImportDefinitionInterface $definition, array $params, FilterInterface $filter = null): ImportDataSetInterface - { + public function getData( + array $configuration, + ImportDefinitionInterface $definition, + array $params, + FilterInterface $filter = null + ): ImportDataSetInterface { $file = $this->getFile($params); $xml = file_get_contents($file); return new ArrayImportDataSet($this->convertXmlToArray($xml, $configuration['xPath'])); } - public function addExportData(array $data, array $configuration, ExportDefinitionInterface $definition, array $params): void - { + public function addExportData( + array $data, + array $configuration, + ExportDefinitionInterface $definition, + array $params + ): void { $writer = $this->getXMLWriter(); $writer->startElement('object'); @@ -134,9 +142,12 @@ public function exportData(array $configuration, ExportDefinitionInterface $defi $this->exportPath = tempnam(sys_get_temp_dir(), 'xml_export_xslt_transformation'); $cmd = [ 'xsltproc', - '-v', '--noout', - '--output', $this->getExportPath(), - $workingPath, $dataPath, + '-v', + '--noout', + '--output', + $this->getExportPath(), + $workingPath, + $dataPath, ]; $process = new Process($cmd); $process->setTimeout(null); @@ -202,7 +213,7 @@ private function serialize(XMLWriter $writer, ?string $name, $data, ?int $key = $writer->writeAttribute('name', $name); } if (null !== $key) { - $writer->writeAttribute('key', (string) $key); + $writer->writeAttribute('key', (string)$key); } if (is_string($data)) { $writer->writeCdata($data); @@ -218,7 +229,7 @@ private function serialize(XMLWriter $writer, ?string $name, $data, ?int $key = $writer->writeAttribute('name', $name); } if (null !== $key) { - $writer->writeAttribute('key', (string) $key); + $writer->writeAttribute('key', (string)$key); } $this->serializeCollection($writer, $data); $writer->endElement(); @@ -229,7 +240,7 @@ private function serialize(XMLWriter $writer, ?string $name, $data, ?int $key = $writer->writeAttribute('name', $name); } if (null !== $key) { - $writer->writeAttribute('key', (string) $key); + $writer->writeAttribute('key', (string)$key); } $writer->writeCdata((string)$data); $writer->endElement(); diff --git a/src/DataDefinitionsBundle/Resources/config/coreshop.yml b/src/DataDefinitionsBundle/Resources/config/coreshop.yml index 9e23de49..c469353e 100644 --- a/src/DataDefinitionsBundle/Resources/config/coreshop.yml +++ b/src/DataDefinitionsBundle/Resources/config/coreshop.yml @@ -1,36 +1,36 @@ services: - Wvision\Bundle\DataDefinitionsBundle\Interpreter\CoreShop\PriceInterpreter: - tags: - - { name: data_definitions.interpreter, type: coreshop_price, form-type: Wvision\Bundle\DataDefinitionsBundle\Form\Type\Interpreter\CoreShop\PriceInterpreterType } + Wvision\Bundle\DataDefinitionsBundle\Interpreter\CoreShop\PriceInterpreter: + tags: + - { name: data_definitions.interpreter, type: coreshop_price, form-type: Wvision\Bundle\DataDefinitionsBundle\Form\Type\Interpreter\CoreShop\PriceInterpreterType } - Wvision\Bundle\DataDefinitionsBundle\Setter\CoreShop\StorePriceSetter: - arguments: - - '@coreshop.repository.store' - tags: - - { name: data_definitions.setter, type: coreshop_store_price, form-type: Wvision\Bundle\DataDefinitionsBundle\Form\Type\Setter\CoreShop\StorePriceSetterType } - - { name: data_definitions.getter, type: coreshop_store_price, form-type: Wvision\Bundle\DataDefinitionsBundle\Form\Type\Setter\CoreShop\StorePriceSetterType } + Wvision\Bundle\DataDefinitionsBundle\Setter\CoreShop\StorePriceSetter: + arguments: + - '@coreshop.repository.store' + tags: + - { name: data_definitions.setter, type: coreshop_store_price, form-type: Wvision\Bundle\DataDefinitionsBundle\Form\Type\Setter\CoreShop\StorePriceSetterType } + - { name: data_definitions.getter, type: coreshop_store_price, form-type: Wvision\Bundle\DataDefinitionsBundle\Form\Type\Setter\CoreShop\StorePriceSetterType } - importdefinitions.coreshop.setter.store_values: '@Wvision\Bundle\DataDefinitionsBundle\Setter\CoreShop\StoreValuesSetter' - Wvision\Bundle\DataDefinitionsBundle\Setter\CoreShop\StoreValuesSetter: - arguments: - - '@coreshop.repository.store' - tags: - - { name: data_definitions.setter, type: coreshop_store_values, form-type: Wvision\Bundle\DataDefinitionsBundle\Form\Type\Setter\CoreShop\StoreValuesSetterType } - - { name: data_definitions.getter, type: coreshop_store_values, form-type: Wvision\Bundle\DataDefinitionsBundle\Form\Type\Setter\CoreShop\StoreValuesSetterType } + importdefinitions.coreshop.setter.store_values: '@Wvision\Bundle\DataDefinitionsBundle\Setter\CoreShop\StoreValuesSetter' + Wvision\Bundle\DataDefinitionsBundle\Setter\CoreShop\StoreValuesSetter: + arguments: + - '@coreshop.repository.store' + tags: + - { name: data_definitions.setter, type: coreshop_store_values, form-type: Wvision\Bundle\DataDefinitionsBundle\Form\Type\Setter\CoreShop\StoreValuesSetterType } + - { name: data_definitions.getter, type: coreshop_store_values, form-type: Wvision\Bundle\DataDefinitionsBundle\Form\Type\Setter\CoreShop\StoreValuesSetterType } - Wvision\Bundle\DataDefinitionsBundle\Interpreter\CoreShop\StoresInterpreter: - tags: - - { name: data_definitions.interpreter, type: coreshop_stores, form-type: Wvision\Bundle\DataDefinitionsBundle\Form\Type\Interpreter\CoreShop\StoresInterpreterType } + Wvision\Bundle\DataDefinitionsBundle\Interpreter\CoreShop\StoresInterpreter: + tags: + - { name: data_definitions.interpreter, type: coreshop_stores, form-type: Wvision\Bundle\DataDefinitionsBundle\Form\Type\Interpreter\CoreShop\StoresInterpreterType } - Wvision\Bundle\DataDefinitionsBundle\Interpreter\CoreShop\CurrencyInterpreter: - arguments: - - '@coreshop.repository.currency' - tags: - - { name: data_definitions.interpreter, type: coreshop_currency, form-type: Wvision\Bundle\DataDefinitionsBundle\Form\Type\NoConfigurationType } + Wvision\Bundle\DataDefinitionsBundle\Interpreter\CoreShop\CurrencyInterpreter: + arguments: + - '@coreshop.repository.currency' + tags: + - { name: data_definitions.interpreter, type: coreshop_currency, form-type: Wvision\Bundle\DataDefinitionsBundle\Form\Type\NoConfigurationType } - Wvision\Bundle\DataDefinitionsBundle\Interpreter\CoreShop\MoneyInterpreter: - arguments: - - '@coreshop.repository.currency' - tags: - - { name: data_definitions.interpreter, type: coreshop_money, form-type: Wvision\Bundle\DataDefinitionsBundle\Form\Type\Interpreter\CoreShop\MoneyInterpreterType } + Wvision\Bundle\DataDefinitionsBundle\Interpreter\CoreShop\MoneyInterpreter: + arguments: + - '@coreshop.repository.currency' + tags: + - { name: data_definitions.interpreter, type: coreshop_money, form-type: Wvision\Bundle\DataDefinitionsBundle\Form\Type\Interpreter\CoreShop\MoneyInterpreterType } diff --git a/src/DataDefinitionsBundle/Resources/config/guzzle_psr7.yml b/src/DataDefinitionsBundle/Resources/config/guzzle_psr7.yml index 406f591b..ad117d12 100644 --- a/src/DataDefinitionsBundle/Resources/config/guzzle_psr7.yml +++ b/src/DataDefinitionsBundle/Resources/config/guzzle_psr7.yml @@ -1,3 +1,3 @@ services: - GuzzleHttp\Psr7\HttpFactory: ~ - Psr\Http\Message\RequestFactoryInterface: '@GuzzleHttp\Psr7\HttpFactory' + GuzzleHttp\Psr7\HttpFactory: ~ + Psr\Http\Message\RequestFactoryInterface: '@GuzzleHttp\Psr7\HttpFactory' diff --git a/src/DataDefinitionsBundle/Resources/config/pimcore/config.yml b/src/DataDefinitionsBundle/Resources/config/pimcore/config.yml index ada2b364..16f5c299 100644 --- a/src/DataDefinitionsBundle/Resources/config/pimcore/config.yml +++ b/src/DataDefinitionsBundle/Resources/config/pimcore/config.yml @@ -1,77 +1,77 @@ jms_serializer: - metadata: - directories: - data-definitions: - namespace_prefix: "DataDefinitionsBundle" - path: "@DataDefinitionsBundle/Resources/config/serializer" + metadata: + directories: + data-definitions: + namespace_prefix: "DataDefinitionsBundle" + path: "@DataDefinitionsBundle/Resources/config/serializer" data_definitions: - pimcore_admin: - js: - startup: '/bundles/datadefinitions/pimcore/js/startup.js' - definition_abstract_item: '/bundles/datadefinitions/pimcore/js/definition/abstractItem.js' - import_definition_panel: '/bundles/datadefinitions/pimcore/js/import/panel.js' - import_definition_item: '/bundles/datadefinitions/pimcore/js/import/item.js' - import_definition_config: '/bundles/datadefinitions/pimcore/js/import/configDialog.js' - export_definition_panel: '/bundles/datadefinitions/pimcore/js/export/panel.js' - export_definition_item: '/bundles/datadefinitions/pimcore/js/export/item.js' - export_definition_config: '/bundles/datadefinitions/pimcore/js/export/configDialog.js' - export_definition_fields: '/bundles/datadefinitions/pimcore/js/export/fields.js' - import_provider_abstract: '/bundles/datadefinitions/pimcore/js/provider/abstractprovider.js' - import_provider_csv: '/bundles/datadefinitions/pimcore/js/provider/csv.js' - import_provider_excel: '/bundles/datadefinitions/pimcore/js/provider/excel.js' - import_provider_sql: '/bundles/datadefinitions/pimcore/js/provider/sql.js' - import_provider_external_sql: '/bundles/datadefinitions/pimcore/js/provider/externalSql.js' - import_provider_json: '/bundles/datadefinitions/pimcore/js/provider/json.js' - import_provider_xml: '/bundles/datadefinitions/pimcore/js/provider/xml.js' - import_provider_raw: '/bundles/datadefinitions/pimcore/js/provider/raw.js' - export_provider_abstract: '/bundles/datadefinitions/pimcore/js/export_provider/abstractprovider.js' - export_provider_csv: '/bundles/datadefinitions/pimcore/js/export_provider/csv.js' - export_provider_xml: '/bundles/datadefinitions/pimcore/js/export_provider/xml.js' - resource_definition: '/bundles/datadefinitions/pimcore/js/resource/definition.js' - definition_panel: '/bundles/datadefinitions/pimcore/js/import/panel.js' - definition_item: '/bundles/datadefinitions/pimcore/js/import/item.js' - definition_config: '/bundles/datadefinitions/pimcore/js/import/configDialog.js' - interpreter_abstract: '/bundles/datadefinitions/pimcore/js/interpreters/abstract.js' - interpreter_href: '/bundles/datadefinitions/pimcore/js/interpreters/href.js' - interpreter_multihref: '/bundles/datadefinitions/pimcore/js/interpreters/multihref.js' - interpreter_defaultvalue: '/bundles/datadefinitions/pimcore/js/interpreters/defaultvalue.js' - interpreter_specificobject: '/bundles/datadefinitions/pimcore/js/interpreters/specificobject.js' - interpreter_assetbypath: '/bundles/datadefinitions/pimcore/js/interpreters/assetbypath.js' - interpreter_asseturl: '/bundles/datadefinitions/pimcore/js/interpreters/asseturl.js' - interpreter_assetsurl: '/bundles/datadefinitions/pimcore/js/interpreters/assetsurl.js' - interpreter_quantityvalue: '/bundles/datadefinitions/pimcore/js/interpreters/quantityvalue.js' - interpreter_nested: '/bundles/datadefinitions/pimcore/js/interpreters/nested.js' - interpreter_nested_container: '/bundles/datadefinitions/pimcore/js/interpreters/nestedcontainer.js' - interpreter_empty: '/bundles/datadefinitions/pimcore/js/interpreters/empty.js' - interpreter_expression: '/bundles/datadefinitions/pimcore/js/interpreters/expression.js' - interpreter_object_resolver: '/bundles/datadefinitions/pimcore/js/interpreters/objectresolver.js' - interpreter_mapping: '/bundles/datadefinitions/pimcore/js/interpreters/mapping.js' - interpreter_iterator: '/bundles/datadefinitions/pimcore/js/interpreters/iterator.js' - interpreter_definition: '/bundles/datadefinitions/pimcore/js/interpreters/definition.js' - interpreter_conditional: '/bundles/datadefinitions/pimcore/js/interpreters/conditional.js' - interpreter_twig: '/bundles/datadefinitions/pimcore/js/interpreters/twig.js' - interpreter_carbon: '/bundles/datadefinitions/pimcore/js/interpreters/carbon.js' - interpreter_metadata: '/bundles/datadefinitions/pimcore/js/interpreters/metadata.js' - setter_abstract: '/bundles/datadefinitions/pimcore/js/setters/abstract.js' - setter_fieldcollection: '/bundles/datadefinitions/pimcore/js/setters/fieldcollection.js' - setter_objectbrick: '/bundles/datadefinitions/pimcore/js/setters/objectbrick.js' - setter_classificationstore: '/bundles/datadefinitions/pimcore/js/setters/classificationstore.js' - setter_localizedfield: '/bundles/datadefinitions/pimcore/js/setters/localizedfield.js' - getter_fieldcollection: '/bundles/datadefinitions/pimcore/js/getters/fieldcollection.js' - getter_objectbrick: '/bundles/datadefinitions/pimcore/js/getters/objectbrick.js' - getter_classificationstore: '/bundles/datadefinitions/pimcore/js/getters/classificationstore.js' - getter_localizedfield: '/bundles/datadefinitions/pimcore/js/getters/localizedfield.js' - fetcher_abstract: '/bundles/datadefinitions/pimcore/js/fetchers/abstract.js' - fetcher_objects: '/bundles/datadefinitions/pimcore/js/fetchers/objects.js' - fuse: '/bundles/datadefinitions/pimcore/js/automap/fuse.min.js' - import_rule_action: '/bundles/datadefinitions/pimcore/js/import_rule/action.js' - import_rule_condition: '/bundles/datadefinitions/pimcore/js/import_rule/condition.js' - import_rule_item: '/bundles/datadefinitions/pimcore/js/import_rule/item.js' - import_rule_panel: '/bundles/datadefinitions/pimcore/js/import_rule/panel.js' - import_rules_interpreter: '/bundles/datadefinitions/pimcore/js/interpreters/import_rule.js' - import_rules_condition_expression: '/bundles/datadefinitions/pimcore/js/import_rule/conditions/expression.js' - import_rules_action_expression: '/bundles/datadefinitions/pimcore/js/import_rule/actions/expression.js' - import_rules_action_object: '/bundles/datadefinitions/pimcore/js/import_rule/actions/object.js' - css: - data_definition: '/bundles/datadefinitions/pimcore/css/datadefinition.css' + pimcore_admin: + js: + startup: '/bundles/datadefinitions/pimcore/js/startup.js' + definition_abstract_item: '/bundles/datadefinitions/pimcore/js/definition/abstractItem.js' + import_definition_panel: '/bundles/datadefinitions/pimcore/js/import/panel.js' + import_definition_item: '/bundles/datadefinitions/pimcore/js/import/item.js' + import_definition_config: '/bundles/datadefinitions/pimcore/js/import/configDialog.js' + export_definition_panel: '/bundles/datadefinitions/pimcore/js/export/panel.js' + export_definition_item: '/bundles/datadefinitions/pimcore/js/export/item.js' + export_definition_config: '/bundles/datadefinitions/pimcore/js/export/configDialog.js' + export_definition_fields: '/bundles/datadefinitions/pimcore/js/export/fields.js' + import_provider_abstract: '/bundles/datadefinitions/pimcore/js/provider/abstractprovider.js' + import_provider_csv: '/bundles/datadefinitions/pimcore/js/provider/csv.js' + import_provider_excel: '/bundles/datadefinitions/pimcore/js/provider/excel.js' + import_provider_sql: '/bundles/datadefinitions/pimcore/js/provider/sql.js' + import_provider_external_sql: '/bundles/datadefinitions/pimcore/js/provider/externalSql.js' + import_provider_json: '/bundles/datadefinitions/pimcore/js/provider/json.js' + import_provider_xml: '/bundles/datadefinitions/pimcore/js/provider/xml.js' + import_provider_raw: '/bundles/datadefinitions/pimcore/js/provider/raw.js' + export_provider_abstract: '/bundles/datadefinitions/pimcore/js/export_provider/abstractprovider.js' + export_provider_csv: '/bundles/datadefinitions/pimcore/js/export_provider/csv.js' + export_provider_xml: '/bundles/datadefinitions/pimcore/js/export_provider/xml.js' + resource_definition: '/bundles/datadefinitions/pimcore/js/resource/definition.js' + definition_panel: '/bundles/datadefinitions/pimcore/js/import/panel.js' + definition_item: '/bundles/datadefinitions/pimcore/js/import/item.js' + definition_config: '/bundles/datadefinitions/pimcore/js/import/configDialog.js' + interpreter_abstract: '/bundles/datadefinitions/pimcore/js/interpreters/abstract.js' + interpreter_href: '/bundles/datadefinitions/pimcore/js/interpreters/href.js' + interpreter_multihref: '/bundles/datadefinitions/pimcore/js/interpreters/multihref.js' + interpreter_defaultvalue: '/bundles/datadefinitions/pimcore/js/interpreters/defaultvalue.js' + interpreter_specificobject: '/bundles/datadefinitions/pimcore/js/interpreters/specificobject.js' + interpreter_assetbypath: '/bundles/datadefinitions/pimcore/js/interpreters/assetbypath.js' + interpreter_asseturl: '/bundles/datadefinitions/pimcore/js/interpreters/asseturl.js' + interpreter_assetsurl: '/bundles/datadefinitions/pimcore/js/interpreters/assetsurl.js' + interpreter_quantityvalue: '/bundles/datadefinitions/pimcore/js/interpreters/quantityvalue.js' + interpreter_nested: '/bundles/datadefinitions/pimcore/js/interpreters/nested.js' + interpreter_nested_container: '/bundles/datadefinitions/pimcore/js/interpreters/nestedcontainer.js' + interpreter_empty: '/bundles/datadefinitions/pimcore/js/interpreters/empty.js' + interpreter_expression: '/bundles/datadefinitions/pimcore/js/interpreters/expression.js' + interpreter_object_resolver: '/bundles/datadefinitions/pimcore/js/interpreters/objectresolver.js' + interpreter_mapping: '/bundles/datadefinitions/pimcore/js/interpreters/mapping.js' + interpreter_iterator: '/bundles/datadefinitions/pimcore/js/interpreters/iterator.js' + interpreter_definition: '/bundles/datadefinitions/pimcore/js/interpreters/definition.js' + interpreter_conditional: '/bundles/datadefinitions/pimcore/js/interpreters/conditional.js' + interpreter_twig: '/bundles/datadefinitions/pimcore/js/interpreters/twig.js' + interpreter_carbon: '/bundles/datadefinitions/pimcore/js/interpreters/carbon.js' + interpreter_metadata: '/bundles/datadefinitions/pimcore/js/interpreters/metadata.js' + setter_abstract: '/bundles/datadefinitions/pimcore/js/setters/abstract.js' + setter_fieldcollection: '/bundles/datadefinitions/pimcore/js/setters/fieldcollection.js' + setter_objectbrick: '/bundles/datadefinitions/pimcore/js/setters/objectbrick.js' + setter_classificationstore: '/bundles/datadefinitions/pimcore/js/setters/classificationstore.js' + setter_localizedfield: '/bundles/datadefinitions/pimcore/js/setters/localizedfield.js' + getter_fieldcollection: '/bundles/datadefinitions/pimcore/js/getters/fieldcollection.js' + getter_objectbrick: '/bundles/datadefinitions/pimcore/js/getters/objectbrick.js' + getter_classificationstore: '/bundles/datadefinitions/pimcore/js/getters/classificationstore.js' + getter_localizedfield: '/bundles/datadefinitions/pimcore/js/getters/localizedfield.js' + fetcher_abstract: '/bundles/datadefinitions/pimcore/js/fetchers/abstract.js' + fetcher_objects: '/bundles/datadefinitions/pimcore/js/fetchers/objects.js' + fuse: '/bundles/datadefinitions/pimcore/js/automap/fuse.min.js' + import_rule_action: '/bundles/datadefinitions/pimcore/js/import_rule/action.js' + import_rule_condition: '/bundles/datadefinitions/pimcore/js/import_rule/condition.js' + import_rule_item: '/bundles/datadefinitions/pimcore/js/import_rule/item.js' + import_rule_panel: '/bundles/datadefinitions/pimcore/js/import_rule/panel.js' + import_rules_interpreter: '/bundles/datadefinitions/pimcore/js/interpreters/import_rule.js' + import_rules_condition_expression: '/bundles/datadefinitions/pimcore/js/import_rule/conditions/expression.js' + import_rules_action_expression: '/bundles/datadefinitions/pimcore/js/import_rule/actions/expression.js' + import_rules_action_object: '/bundles/datadefinitions/pimcore/js/import_rule/actions/object.js' + css: + data_definition: '/bundles/datadefinitions/pimcore/css/datadefinition.css' diff --git a/src/DataDefinitionsBundle/Resources/config/pimcore/routing.yml b/src/DataDefinitionsBundle/Resources/config/pimcore/routing.yml index 7d59a7bc..d70c3bda 100755 --- a/src/DataDefinitionsBundle/Resources/config/pimcore/routing.yml +++ b/src/DataDefinitionsBundle/Resources/config/pimcore/routing.yml @@ -1,67 +1,67 @@ data_definitions_admin_import_definitions: - type: coreshop.resources - resource: | - alias: data_definitions.import_definition - additional_routes: - config: - path: get-config - action: getConfig - methods: [GET] - columns: - path: get-columns - action: getColumns - methods: [GET] - testData: - path: test-data - action: testData - methods: [GET] - import: - path: import - action: import - methods: [GET,POST] - export: - path: export - action: export - methods: [GET] - duplicate: - path: duplicate - action: duplicate - methods: [POST] + type: coreshop.resources + resource: | + alias: data_definitions.import_definition + additional_routes: + config: + path: get-config + action: getConfig + methods: [GET] + columns: + path: get-columns + action: getColumns + methods: [GET] + testData: + path: test-data + action: testData + methods: [GET] + import: + path: import + action: import + methods: [GET,POST] + export: + path: export + action: export + methods: [GET] + duplicate: + path: duplicate + action: duplicate + methods: [POST] data_definitions_admin_export_definitions: - type: coreshop.resources - resource: | - alias: data_definitions.export_definition - additional_routes: - config: - path: get-config - action: getConfig - methods: [GET] - columns: - path: get-columns - action: getColumns - methods: [GET] - testData: - path: test-data - action: testData - methods: [GET] - import: - path: import - action: import - methods: [GET,POST] - export: - path: export - action: export - methods: [GET] - duplicate: - path: duplicate - action: duplicate - methods: [POST] + type: coreshop.resources + resource: | + alias: data_definitions.export_definition + additional_routes: + config: + path: get-config + action: getConfig + methods: [GET] + columns: + path: get-columns + action: getColumns + methods: [GET] + testData: + path: test-data + action: testData + methods: [GET] + import: + path: import + action: import + methods: [GET,POST] + export: + path: export + action: export + methods: [GET] + duplicate: + path: duplicate + action: duplicate + methods: [POST] data_definitions_admin_export_import_rules: - path: /admin/data_definitions/import_rules/export - defaults: { _controller: Wvision\Bundle\DataDefinitionsBundle\Controller\ImportRuleController::exportAction} + path: /admin/data_definitions/import_rules/export + defaults: { _controller: Wvision\Bundle\DataDefinitionsBundle\Controller\ImportRuleController::exportAction } data_definitions_admin_import_import_rules: - path: /admin/data_definitions/import_rules/import - defaults: { _controller: Wvision\Bundle\DataDefinitionsBundle\Controller\ImportRuleController::importAction} + path: /admin/data_definitions/import_rules/import + defaults: { _controller: Wvision\Bundle\DataDefinitionsBundle\Controller\ImportRuleController::importAction } diff --git a/src/DataDefinitionsBundle/Resources/config/process_manager.yml b/src/DataDefinitionsBundle/Resources/config/process_manager.yml index 7f509f8a..c02bb4ab 100644 --- a/src/DataDefinitionsBundle/Resources/config/process_manager.yml +++ b/src/DataDefinitionsBundle/Resources/config/process_manager.yml @@ -1,48 +1,48 @@ services: - Wvision\Bundle\DataDefinitionsBundle\ProcessManager\ProcessManagerImportListener: - arguments: - - '@process_manager.factory.process' - - '@ProcessManagerBundle\Logger\ProcessLogger' - - '@process_manager.repository.process' - - '@event_dispatcher' - tags: - - { name: 'kernel.event_listener', event: 'data_definitions.import.total', method: 'onTotalEvent' } - - { name: 'kernel.event_listener', event: 'data_definitions.import.progress', method: 'onProgressEvent' } - - { name: 'kernel.event_listener', event: 'data_definitions.import.status', method: 'onStatusEvent' } - - { name: 'kernel.event_listener', event: 'data_definitions.import.finished', method: 'onFinishedEvent' } - - { name: 'kernel.event_listener', event: 'data_definitions.import.failure', method: 'onFailureEvent' } + Wvision\Bundle\DataDefinitionsBundle\ProcessManager\ProcessManagerImportListener: + arguments: + - '@process_manager.factory.process' + - '@ProcessManagerBundle\Logger\ProcessLogger' + - '@process_manager.repository.process' + - '@event_dispatcher' + tags: + - { name: 'kernel.event_listener', event: 'data_definitions.import.total', method: 'onTotalEvent' } + - { name: 'kernel.event_listener', event: 'data_definitions.import.progress', method: 'onProgressEvent' } + - { name: 'kernel.event_listener', event: 'data_definitions.import.status', method: 'onStatusEvent' } + - { name: 'kernel.event_listener', event: 'data_definitions.import.finished', method: 'onFinishedEvent' } + - { name: 'kernel.event_listener', event: 'data_definitions.import.failure', method: 'onFailureEvent' } - Wvision\Bundle\DataDefinitionsBundle\ProcessManager\ProcessManagerExportListener: + Wvision\Bundle\DataDefinitionsBundle\ProcessManager\ProcessManagerExportListener: + arguments: + - '@process_manager.factory.process' + - '@ProcessManagerBundle\Logger\ProcessLogger' + - '@process_manager.repository.process' + - '@event_dispatcher' + calls: + - method: setProviderRegistry arguments: - - '@process_manager.factory.process' - - '@ProcessManagerBundle\Logger\ProcessLogger' - - '@process_manager.repository.process' - - '@event_dispatcher' - calls: - - method: setProviderRegistry - arguments: - - '@data_definitions.registry.export_provider' - tags: - - { name: 'kernel.event_listener', event: 'data_definitions.export.total', method: 'onTotalEvent' } - - { name: 'kernel.event_listener', event: 'data_definitions.export.progress', method: 'onProgressEvent' } - - { name: 'kernel.event_listener', event: 'data_definitions.export.status', method: 'onStatusEvent' } - - { name: 'kernel.event_listener', event: 'data_definitions.export.finished', method: 'onFinishedEvent' } - - { name: 'kernel.event_listener', event: 'data_definitions.export.failure', method: 'onFailureEvent' } + - '@data_definitions.registry.export_provider' + tags: + - { name: 'kernel.event_listener', event: 'data_definitions.export.total', method: 'onTotalEvent' } + - { name: 'kernel.event_listener', event: 'data_definitions.export.progress', method: 'onProgressEvent' } + - { name: 'kernel.event_listener', event: 'data_definitions.export.status', method: 'onStatusEvent' } + - { name: 'kernel.event_listener', event: 'data_definitions.export.finished', method: 'onFinishedEvent' } + - { name: 'kernel.event_listener', event: 'data_definitions.export.failure', method: 'onFailureEvent' } - Wvision\Bundle\DataDefinitionsBundle\ProcessManager\ImportDefinitionProcess: - tags: - - { name: 'process_manager.process', type: 'importdefinition', form-type: Wvision\Bundle\DataDefinitionsBundle\Form\Type\ProcessManager\ImportDefinitionsType } + Wvision\Bundle\DataDefinitionsBundle\ProcessManager\ImportDefinitionProcess: + tags: + - { name: 'process_manager.process', type: 'importdefinition', form-type: Wvision\Bundle\DataDefinitionsBundle\Form\Type\ProcessManager\ImportDefinitionsType } - Wvision\Bundle\DataDefinitionsBundle\ProcessManager\ExportDefinitionProcess: - tags: - - { name: 'process_manager.process', type: 'exportdefinition', form-type: Wvision\Bundle\DataDefinitionsBundle\Form\Type\ProcessManager\ImportDefinitionsType } + Wvision\Bundle\DataDefinitionsBundle\ProcessManager\ExportDefinitionProcess: + tags: + - { name: 'process_manager.process', type: 'exportdefinition', form-type: Wvision\Bundle\DataDefinitionsBundle\Form\Type\ProcessManager\ImportDefinitionsType } - Wvision\Bundle\DataDefinitionsBundle\ProcessManager\ExportDefinitionStartupFormResolver: - arguments: - - '@data_definitions.repository.export_definition' - tags: - - { name: 'process_manager.startup_form_resolver', type: 'exportdefinition' } + Wvision\Bundle\DataDefinitionsBundle\ProcessManager\ExportDefinitionStartupFormResolver: + arguments: + - '@data_definitions.repository.export_definition' + tags: + - { name: 'process_manager.startup_form_resolver', type: 'exportdefinition' } - Wvision\Bundle\DataDefinitionsBundle\ProcessManager\ImportDefinitionsReport: - tags: - - { name: process_manager.process_report, type: import_definitions } + Wvision\Bundle\DataDefinitionsBundle\ProcessManager\ImportDefinitionsReport: + tags: + - { name: process_manager.process_report, type: import_definitions } diff --git a/src/DataDefinitionsBundle/Resources/config/serializer/Model.Definition.yml b/src/DataDefinitionsBundle/Resources/config/serializer/Model.Definition.yml index 8e823170..c7391ba6 100755 --- a/src/DataDefinitionsBundle/Resources/config/serializer/Model.Definition.yml +++ b/src/DataDefinitionsBundle/Resources/config/serializer/Model.Definition.yml @@ -1,45 +1,45 @@ Wvision\Bundle\DataDefinitionsBundle\Model\Definition: - exclusion_policy: ALL - xml_root_name: definition - properties: - id: - expose: true - type: integer - xml_attribute: true - groups: [List, Detailed] - name: - expose: true - type: string - groups: [List, Detailed] - provider: - expose: true - type: string - groups: [Detailed] - class: - expose: true - type: string - groups: [Detailed] - configuration: - expose: true - type: array - groups: [Detailed] - mapping: - expose: true - type: array - groups: [Detailed] - runner: - expose: true - type: string - groups: [Detailed] - stopOnException: - expose: true - type: boolean - groups: [Detailed] - failureNotificationDocument: - expose: true - type: integer - groups: [Detailed] - successNotificationDocument: - expose: true - type: integer - groups: [Detailed] + exclusion_policy: ALL + xml_root_name: definition + properties: + id: + expose: true + type: integer + xml_attribute: true + groups: [ List, Detailed ] + name: + expose: true + type: string + groups: [ List, Detailed ] + provider: + expose: true + type: string + groups: [ Detailed ] + class: + expose: true + type: string + groups: [ Detailed ] + configuration: + expose: true + type: array + groups: [ Detailed ] + mapping: + expose: true + type: array + groups: [ Detailed ] + runner: + expose: true + type: string + groups: [ Detailed ] + stopOnException: + expose: true + type: boolean + groups: [ Detailed ] + failureNotificationDocument: + expose: true + type: integer + groups: [ Detailed ] + successNotificationDocument: + expose: true + type: integer + groups: [ Detailed ] diff --git a/src/DataDefinitionsBundle/Resources/config/serializer/Model.ExportDefinition.yml b/src/DataDefinitionsBundle/Resources/config/serializer/Model.ExportDefinition.yml index f0e203c7..fb48406b 100755 --- a/src/DataDefinitionsBundle/Resources/config/serializer/Model.ExportDefinition.yml +++ b/src/DataDefinitionsBundle/Resources/config/serializer/Model.ExportDefinition.yml @@ -1,16 +1,16 @@ Wvision\Bundle\DataDefinitionsBundle\Model\ExportDefinition: - exclusion_policy: ALL - xml_root_name: export_definition - properties: - fetcher: - expose: true - type: string - groups: [Detailed] - fetcherConfig: - expose: true - type: array - groups: [Detailed] - fetchUnpublished: - expose: true - type: boolean - groups: [Detailed] + exclusion_policy: ALL + xml_root_name: export_definition + properties: + fetcher: + expose: true + type: string + groups: [ Detailed ] + fetcherConfig: + expose: true + type: array + groups: [ Detailed ] + fetchUnpublished: + expose: true + type: boolean + groups: [ Detailed ] diff --git a/src/DataDefinitionsBundle/Resources/config/serializer/Model.ImportDefinition.yml b/src/DataDefinitionsBundle/Resources/config/serializer/Model.ImportDefinition.yml index be7b7b33..1ec31c51 100755 --- a/src/DataDefinitionsBundle/Resources/config/serializer/Model.ImportDefinition.yml +++ b/src/DataDefinitionsBundle/Resources/config/serializer/Model.ImportDefinition.yml @@ -1,52 +1,52 @@ Wvision\Bundle\DataDefinitionsBundle\Model\ImportDefinition: - exclusion_policy: ALL - xml_root_name: import_definition - properties: - loader: - expose: true - type: string - groups: [Detailed] - objectPath: - expose: true - type: string - groups: [Detailed] - cleaner: - expose: true - type: string - groups: [Detailed] - key: - expose: true - type: string - groups: [Detailed] - filter: - expose: true - type: string - groups: [Detailed] - renameExistingObjects: - expose: true - type: boolean - groups: [Detailed] - relocateExistingObjects: - expose: true - type: boolean - groups: [Detailed] - omitMandatoryCheck: - expose: true - type: boolean - groups: [Detailed] - skipNewObjects: - expose: true - type: boolean - groups: [Detailed] - skipExistingObjects: - expose: true - type: boolean - groups: [Detailed] - forceLoadObject: - expose: true - type: boolean - groups: [Detailed] - createVersion: - expose: true - type: boolean - groups: [Detailed] + exclusion_policy: ALL + xml_root_name: import_definition + properties: + loader: + expose: true + type: string + groups: [ Detailed ] + objectPath: + expose: true + type: string + groups: [ Detailed ] + cleaner: + expose: true + type: string + groups: [ Detailed ] + key: + expose: true + type: string + groups: [ Detailed ] + filter: + expose: true + type: string + groups: [ Detailed ] + renameExistingObjects: + expose: true + type: boolean + groups: [ Detailed ] + relocateExistingObjects: + expose: true + type: boolean + groups: [ Detailed ] + omitMandatoryCheck: + expose: true + type: boolean + groups: [ Detailed ] + skipNewObjects: + expose: true + type: boolean + groups: [ Detailed ] + skipExistingObjects: + expose: true + type: boolean + groups: [ Detailed ] + forceLoadObject: + expose: true + type: boolean + groups: [ Detailed ] + createVersion: + expose: true + type: boolean + groups: [ Detailed ] diff --git a/src/DataDefinitionsBundle/Resources/config/services.yml b/src/DataDefinitionsBundle/Resources/config/services.yml index ee74ed39..4aebeda8 100644 --- a/src/DataDefinitionsBundle/Resources/config/services.yml +++ b/src/DataDefinitionsBundle/Resources/config/services.yml @@ -1,360 +1,367 @@ imports: - - { resource: "services/forms.yml" } - - { resource: "services/installer.yml" } - - { resource: "services/commands.yml" } - - { resource: "services/import_rules.yml" } + - { resource: "services/forms.yml" } + - { resource: "services/installer.yml" } + - { resource: "services/commands.yml" } + - { resource: "services/import_rules.yml" } services: - Wvision\Bundle\DataDefinitionsBundle\Event\EventDispatcher: - arguments: - - '@event_dispatcher' - - Wvision\Bundle\DataDefinitionsBundle\Service\FieldSelection: - public: true - - Wvision\Bundle\DataDefinitionsBundle\Importer\ImporterInterface: '@Wvision\Bundle\DataDefinitionsBundle\Importer\Importer' - Wvision\Bundle\DataDefinitionsBundle\Importer\Importer: - arguments: - - '@data_definitions.registry.provider' - - '@data_definitions.registry.filter' - - '@data_definitions.registry.runner' - - '@data_definitions.registry.interpreter' - - '@data_definitions.registry.setter' - - '@data_definitions.registry.cleaner' - - '@data_definitions.registry.loader' - - '@data_definitions.registry.persister' - - '@Wvision\Bundle\DataDefinitionsBundle\Event\EventDispatcher' - - '@logger' - - '@pimcore.model.factory' - - '@coreshop.expression_language' - tags: - - { name: monolog.logger, channel: import_definition } - - { name: 'kernel.event_listener', event: 'data_definitions.stop', method: 'stop' } - - Wvision\Bundle\DataDefinitionsBundle\Exporter\ExporterInterface: '@Wvision\Bundle\DataDefinitionsBundle\Exporter\Exporter' - Wvision\Bundle\DataDefinitionsBundle\Exporter\Exporter: - arguments: - - '@data_definitions.registry.fetcher' - - '@data_definitions.registry.export_runner' - - '@data_definitions.registry.interpreter' - - '@data_definitions.registry.getter' - - '@data_definitions.registry.export_provider' - - '@event_dispatcher' - - '@logger' - tags: - - { name: monolog.logger, channel: export_definition } - - { name: 'kernel.event_listener', event: 'data_definitions.stop', method: 'stop' } - - ### Registries - data_definitions.registry.provider: - class: CoreShop\Component\Registry\ServiceRegistry - public: true - arguments: - - Wvision\Bundle\DataDefinitionsBundle\Provider\ImportProviderInterface - - 'Import Definition Providers' - - data_definitions.form.registry.provider: - class: CoreShop\Bundle\ResourceBundle\Form\Registry\FormTypeRegistry - - data_definitions.registry.export_provider: - class: CoreShop\Component\Registry\ServiceRegistry - arguments: - - Wvision\Bundle\DataDefinitionsBundle\Provider\ExportProviderInterface - - 'Import Definition Export Providers' - - data_definitions.form.registry.export_provider: - class: CoreShop\Bundle\ResourceBundle\Form\Registry\FormTypeRegistry - - data_definitions.registry.loader: - class: CoreShop\Component\Registry\ServiceRegistry - arguments: - - Wvision\Bundle\DataDefinitionsBundle\Loader\LoaderInterface - - 'Import Definition Loaders' - - data_definitions.registry.cleaner: - class: CoreShop\Component\Registry\ServiceRegistry - arguments: - - Wvision\Bundle\DataDefinitionsBundle\Cleaner\CleanerInterface - - 'Import Definition Cleaners' - - data_definitions.registry.filter: - class: CoreShop\Component\Registry\ServiceRegistry - arguments: - - Wvision\Bundle\DataDefinitionsBundle\Filter\FilterInterface - - 'Import Definition Filters' - - data_definitions.registry.interpreter: - class: CoreShop\Component\Registry\ServiceRegistry - arguments: - - Wvision\Bundle\DataDefinitionsBundle\Interpreter\InterpreterInterface - - 'Import Definition Interpreters' - - data_definitions.form.registry.interpreter: - class: CoreShop\Bundle\ResourceBundle\Form\Registry\FormTypeRegistry - - data_definitions.registry.setter: - class: CoreShop\Component\Registry\ServiceRegistry - arguments: - - Wvision\Bundle\DataDefinitionsBundle\Setter\SetterInterface - - 'Import Definition Setters' - - data_definitions.form.registry.setter: - class: CoreShop\Bundle\ResourceBundle\Form\Registry\FormTypeRegistry - - data_definitions.registry.getter: - class: CoreShop\Component\Registry\ServiceRegistry - arguments: - - Wvision\Bundle\DataDefinitionsBundle\Getter\GetterInterface - - 'Import Definition Getters' - - data_definitions.form.registry.getter: - class: CoreShop\Bundle\ResourceBundle\Form\Registry\FormTypeRegistry - - data_definitions.registry.fetcher: - class: CoreShop\Component\Registry\ServiceRegistry - arguments: - - Wvision\Bundle\DataDefinitionsBundle\Fetcher\FetcherInterface - - 'Import Definition Fetchers' - - data_definitions.form.registry.fetcher: - class: CoreShop\Bundle\ResourceBundle\Form\Registry\FormTypeRegistry - - data_definitions.registry.runner: - class: CoreShop\Component\Registry\ServiceRegistry - arguments: - - Wvision\Bundle\DataDefinitionsBundle\Runner\RunnerInterface - - 'Import Definition Runners' - - data_definitions.registry.export_runner: - class: CoreShop\Component\Registry\ServiceRegistry - arguments: - - Wvision\Bundle\DataDefinitionsBundle\Runner\ExportRunnerInterface - - 'Export Definition Runners' - - data_definitions.registry.persister: - class: CoreShop\Component\Registry\ServiceRegistry - arguments: - - Wvision\Bundle\DataDefinitionsBundle\Persister\PersisterInterface - - 'Import Definition Persisters' - - ### CLEANER - Wvision\Bundle\DataDefinitionsBundle\Cleaner\Deleter: - tags: - - { name: data_definitions.cleaner, type: deleter } - - Wvision\Bundle\DataDefinitionsBundle\Cleaner\None: - tags: - - { name: data_definitions.cleaner, type: none } - - Wvision\Bundle\DataDefinitionsBundle\Cleaner\ReferenceCleaner: - tags: - - { name: data_definitions.cleaner, type: reference_cleaner } - - Wvision\Bundle\DataDefinitionsBundle\Cleaner\Unpublisher: - tags: - - { name: data_definitions.cleaner, type: unpublisher } - - ### INTERPRETER - Wvision\Bundle\DataDefinitionsBundle\Interpreter\AssetsUrlInterpreter: - arguments: - - '@Psr\Http\Client\ClientInterface' - - '@Psr\Http\Message\RequestFactoryInterface' - tags: - - { name: data_definitions.interpreter, type: assets_url, form-type: Wvision\Bundle\DataDefinitionsBundle\Form\Type\Interpreter\AssetsUrlInterpreterType } - - Wvision\Bundle\DataDefinitionsBundle\Interpreter\AssetUrlInterpreter: - arguments: - - '@Psr\Http\Client\ClientInterface' - - '@Psr\Http\Message\RequestFactoryInterface' - tags: - - { name: data_definitions.interpreter, type: asset_url, form-type: Wvision\Bundle\DataDefinitionsBundle\Form\Type\Interpreter\AssetUrlInterpreterType } - - Wvision\Bundle\DataDefinitionsBundle\Interpreter\MetadataInterpreter: - tags: - - { name: data_definitions.interpreter, type: metadata, form-type: Wvision\Bundle\DataDefinitionsBundle\Form\Type\Interpreter\MetadataInterpreterType } - - Wvision\Bundle\DataDefinitionsBundle\Interpreter\AssetByPathInterpreter: - tags: - - { name: data_definitions.interpreter, type: asset_by_path, form-type: Wvision\Bundle\DataDefinitionsBundle\Form\Type\Interpreter\AssetByPathInterpreterType } - - Wvision\Bundle\DataDefinitionsBundle\Interpreter\CarbonInterpreter: - tags: - - { name: data_definitions.interpreter, type: carbon, form-type: Wvision\Bundle\DataDefinitionsBundle\Form\Type\Interpreter\CarbonInterpreterType } - - Wvision\Bundle\DataDefinitionsBundle\Interpreter\CheckboxInterpreter: - tags: - - { name: data_definitions.interpreter, type: checkbox, form-type: Wvision\Bundle\DataDefinitionsBundle\Form\Type\NoConfigurationType } - - Wvision\Bundle\DataDefinitionsBundle\Interpreter\DefaultValueInterpreter: - tags: - - { name: data_definitions.interpreter, type: default_value, form-type: Wvision\Bundle\DataDefinitionsBundle\Form\Type\Interpreter\DefaultValueInterpreterType } - - Wvision\Bundle\DataDefinitionsBundle\Interpreter\SpecificObjectInterpreter: - tags: - - { name: data_definitions.interpreter, type: specific_object, form-type: Wvision\Bundle\DataDefinitionsBundle\Form\Type\Interpreter\SpecificObjectInterpreterType } - - Wvision\Bundle\DataDefinitionsBundle\Interpreter\HrefInterpreter: - tags: - - { name: data_definitions.interpreter, type: href, form-type: Wvision\Bundle\DataDefinitionsBundle\Form\Type\Interpreter\HrefInterpreterType } - - Wvision\Bundle\DataDefinitionsBundle\Interpreter\MultiHrefInterpreter: - tags: - - { name: data_definitions.interpreter, type: multi_href, form-type: Wvision\Bundle\DataDefinitionsBundle\Form\Type\Interpreter\MultiHrefInterpreterType } - - Wvision\Bundle\DataDefinitionsBundle\Interpreter\QuantityValueInterpreter: - tags: - - { name: data_definitions.interpreter, type: quantity_value, form-type: Wvision\Bundle\DataDefinitionsBundle\Form\Type\Interpreter\QuantityValueInterpreterType } - - Wvision\Bundle\DataDefinitionsBundle\Interpreter\NestedInterpreter: - arguments: - - '@data_definitions.registry.interpreter' - tags: - - { name: data_definitions.interpreter, type: nested, form-type: Wvision\Bundle\DataDefinitionsBundle\Form\Type\Interpreter\NestedInterpreterType } - - Wvision\Bundle\DataDefinitionsBundle\Interpreter\ExpressionInterpreter: - arguments: - - '@coreshop.expression_language' - - '@service_container' - tags: - - { name: data_definitions.interpreter, type: expression, form-type: Wvision\Bundle\DataDefinitionsBundle\Form\Type\Interpreter\ExpressionInterpreterType } - - Wvision\Bundle\DataDefinitionsBundle\Interpreter\ObjectResolverInterpreter: - arguments: - - '@service_container' - tags: - - { name: data_definitions.interpreter, type: object_resolver, form-type: Wvision\Bundle\DataDefinitionsBundle\Form\Type\Interpreter\ObjectResolverType } - - Wvision\Bundle\DataDefinitionsBundle\Interpreter\DefinitionInterpreter: - arguments: - - '@data_definitions.repository.import_definition' - - '@Wvision\Bundle\DataDefinitionsBundle\Importer\ImporterInterface' - tags: - - { name: data_definitions.interpreter, type: definition, form-type: Wvision\Bundle\DataDefinitionsBundle\Form\Type\Interpreter\DefinitionType } - - Wvision\Bundle\DataDefinitionsBundle\Interpreter\ConditionalInterpreter: - arguments: - - '@data_definitions.registry.interpreter' - - '@coreshop.expression_language' - - '@service_container' - tags: - - { name: data_definitions.interpreter, type: conditional, form-type: Wvision\Bundle\DataDefinitionsBundle\Form\Type\Interpreter\ConditionalInterpreterType } - - Wvision\Bundle\DataDefinitionsBundle\Interpreter\MappingInterpreter: - arguments: - - '@service_container' - tags: - - { name: data_definitions.interpreter, type: mapping, form-type: Wvision\Bundle\DataDefinitionsBundle\Form\Type\Interpreter\MappingInterpreterType } - - Wvision\Bundle\DataDefinitionsBundle\Interpreter\IteratorInterpreter: - arguments: - - '@data_definitions.registry.interpreter' - tags: - - { name: data_definitions.interpreter, type: iterator, form-type: Wvision\Bundle\DataDefinitionsBundle\Form\Type\Interpreter\IteratorInterpreterType } - - Wvision\Bundle\DataDefinitionsBundle\Interpreter\TwigInterpreter: - arguments: - - '@twig' - tags: - - { name: data_definitions.interpreter, type: twig, form-type: Wvision\Bundle\DataDefinitionsBundle\Form\Type\Interpreter\TwigInterpreterType } - - Wvision\Bundle\DataDefinitionsBundle\Interpreter\DoNotSetOnEmptyInterpreter: - tags: - - { name: data_definitions.interpreter, type: donotsetonempty, form-type: Wvision\Bundle\DataDefinitionsBundle\Form\Type\NoConfigurationType } - - Wvision\Bundle\DataDefinitionsBundle\Interpreter\LinkInterpreter: - tags: - - { name: data_definitions.interpreter, type: link, form-type: Wvision\Bundle\DataDefinitionsBundle\Form\Type\NoConfigurationType } - - Wvision\Bundle\DataDefinitionsBundle\Interpreter\ExternalImageInterpreter: - tags: - - { name: data_definitions.interpreter, type: external_image, form-type: Wvision\Bundle\DataDefinitionsBundle\Form\Type\NoConfigurationType } - - ### PROVIDER - Wvision\Bundle\DataDefinitionsBundle\Provider\CsvProvider: - tags: - - { name: data_definitions.import_provider, type: csv, form-type: Wvision\Bundle\DataDefinitionsBundle\Form\Type\ImportProvider\CsvProviderType } - - { name: data_definitions.export_provider, type: csv, form-type: Wvision\Bundle\DataDefinitionsBundle\Form\Type\ExportProvider\CsvProviderType } - - Wvision\Bundle\DataDefinitionsBundle\Provider\ExcelProvider: - tags: - - { name: data_definitions.import_provider, type: excel, form-type: Wvision\Bundle\DataDefinitionsBundle\Form\Type\ImportProvider\ExcelProviderType } - - { name: data_definitions.export_provider, type: excel, form-type: Wvision\Bundle\DataDefinitionsBundle\Form\Type\NoConfigurationType } - - Wvision\Bundle\DataDefinitionsBundle\Provider\JsonProvider: - tags: - - { name: data_definitions.import_provider, type: json, form-type: Wvision\Bundle\DataDefinitionsBundle\Form\Type\ImportProvider\JsonProviderType } - - { name: data_definitions.export_provider, type: json, form-type: Wvision\Bundle\DataDefinitionsBundle\Form\Type\NoConfigurationType } - - Wvision\Bundle\DataDefinitionsBundle\Provider\ExternalSqlProvider: - tags: - - { name: data_definitions.import_provider, type: external_sql, form-type: Wvision\Bundle\DataDefinitionsBundle\Form\Type\ImportProvider\ExternalSqlProviderType } - - Wvision\Bundle\DataDefinitionsBundle\Provider\SqlProvider: - arguments: - - '@doctrine.dbal.default_connection' - tags: - - { name: data_definitions.import_provider, type: sql, form-type: Wvision\Bundle\DataDefinitionsBundle\Form\Type\ImportProvider\SqlProviderType } - - Wvision\Bundle\DataDefinitionsBundle\Provider\XmlProvider: - tags: - - { name: data_definitions.import_provider, type: xml, form-type: Wvision\Bundle\DataDefinitionsBundle\Form\Type\ImportProvider\XmlProviderType } - - { name: data_definitions.export_provider, type: xml, form-type: Wvision\Bundle\DataDefinitionsBundle\Form\Type\ExportProvider\XmlProviderType } - - Wvision\Bundle\DataDefinitionsBundle\Provider\RawProvider: - tags: - - { name: data_definitions.import_provider, type: raw, form-type: Wvision\Bundle\DataDefinitionsBundle\Form\Type\ImportProvider\RawProviderType } - - ### SETTER AND GETTER - Wvision\Bundle\DataDefinitionsBundle\Setter\ClassificationStoreSetter: - tags: - - { name: data_definitions.setter, type: classificationstore, form-type: Wvision\Bundle\DataDefinitionsBundle\Form\Type\Setter\ClassificationStoreSetterType } - - { name: data_definitions.getter, type: classificationstore, form-type: Wvision\Bundle\DataDefinitionsBundle\Form\Type\Setter\ClassificationStoreSetterType } - - Wvision\Bundle\DataDefinitionsBundle\Setter\ClassificationStoreFieldGetter: - tags: - - { name: data_definitions.getter, type: classificationstore_field, form-type: Wvision\Bundle\DataDefinitionsBundle\Form\Type\NoConfigurationType } - - Wvision\Bundle\DataDefinitionsBundle\Setter\FieldCollectionSetter: - tags: - - { name: data_definitions.setter, type: fieldcollection, form-type: Wvision\Bundle\DataDefinitionsBundle\Form\Type\Setter\FieldCollectionSetterType } - - { name: data_definitions.getter, type: fieldcollection, form-type: Wvision\Bundle\DataDefinitionsBundle\Form\Type\Setter\FieldCollectionSetterType } - - Wvision\Bundle\DataDefinitionsBundle\Setter\KeySetter: - tags: - - { name: data_definitions.setter, type: key, form-type: Wvision\Bundle\DataDefinitionsBundle\Form\Type\NoConfigurationType } - - Wvision\Bundle\DataDefinitionsBundle\Setter\LocalizedfieldSetter: - tags: - - { name: data_definitions.setter, type: localizedfield, form-type: Wvision\Bundle\DataDefinitionsBundle\Form\Type\Setter\LocalizedFieldSetterType } - - { name: data_definitions.getter, type: localizedfield, form-type: Wvision\Bundle\DataDefinitionsBundle\Form\Type\Setter\LocalizedFieldSetterType } - - Wvision\Bundle\DataDefinitionsBundle\Setter\ObjectbrickSetter: - tags: - - { name: data_definitions.setter, type: objectbrick, form-type: Wvision\Bundle\DataDefinitionsBundle\Form\Type\Setter\ObjectBrickSetterType } - - { name: data_definitions.getter, type: objectbrick, form-type: Wvision\Bundle\DataDefinitionsBundle\Form\Type\Setter\ObjectBrickSetterType } - - Wvision\Bundle\DataDefinitionsBundle\Setter\ObjectTypeSetter: - tags: - - { name: data_definitions.setter, type: object_type, form-type: Wvision\Bundle\DataDefinitionsBundle\Form\Type\NoConfigurationType } - - Wvision\Bundle\DataDefinitionsBundle\Setter\RelationSetter: - tags: - - { name: data_definitions.setter, type: relation, form-type: Wvision\Bundle\DataDefinitionsBundle\Form\Type\NoConfigurationType } - - Wvision\Bundle\DataDefinitionsBundle\EventListener\ObjectDeleteListener: - tags: - - { name: kernel.event_listener, event: pimcore.dataobject.postDelete, method: onDataObjectDelete } - - Wvision\Bundle\DataDefinitionsBundle\Fetcher\ObjectsFetcher: - tags: - - { name: data_definitions.fetcher, type: objects, form-type: Wvision\Bundle\DataDefinitionsBundle\Form\Type\Fetcher\ObjectsFetcherType } - - ### LOADER - Wvision\Bundle\DataDefinitionsBundle\Loader\PrimaryKeyLoader: - tags: - - { name: data_definitions.loader, type: primary_key } - - ### PERSISTER - Wvision\Bundle\DataDefinitionsBundle\Persister\Persister: - tags: - - { name: data_definitions.persister, type: persister } + Wvision\Bundle\DataDefinitionsBundle\Event\EventDispatcher: + arguments: + - '@event_dispatcher' + + Wvision\Bundle\DataDefinitionsBundle\Service\FieldSelection: + public: true + + Wvision\Bundle\DataDefinitionsBundle\Context\ContextFactoryInterface: '@Wvision\Bundle\DataDefinitionsBundle\Context\ContextFactory' + Wvision\Bundle\DataDefinitionsBundle\Context\ContextFactory: ~ + + Wvision\Bundle\DataDefinitionsBundle\Importer\ImporterInterface: '@Wvision\Bundle\DataDefinitionsBundle\Importer\Importer' + Wvision\Bundle\DataDefinitionsBundle\Importer\Importer: + arguments: + - '@data_definitions.registry.provider' + - '@data_definitions.registry.filter' + - '@data_definitions.registry.runner' + - '@data_definitions.registry.interpreter' + - '@data_definitions.registry.setter' + - '@data_definitions.registry.cleaner' + - '@data_definitions.registry.loader' + - '@data_definitions.registry.persister' + - '@Wvision\Bundle\DataDefinitionsBundle\Event\EventDispatcher' + - '@Wvision\Bundle\DataDefinitionsBundle\Context\ContextFactoryInterface' + - '@logger' + - '@pimcore.model.factory' + - '@coreshop.expression_language' + tags: + - { name: monolog.logger, channel: import_definition } + - { name: 'kernel.event_listener', event: 'data_definitions.stop', method: 'stop' } + + Wvision\Bundle\DataDefinitionsBundle\Exporter\ExporterInterface: '@Wvision\Bundle\DataDefinitionsBundle\Exporter\Exporter' + Wvision\Bundle\DataDefinitionsBundle\Exporter\Exporter: + arguments: + - '@data_definitions.registry.fetcher' + - '@data_definitions.registry.export_runner' + - '@data_definitions.registry.interpreter' + - '@data_definitions.registry.getter' + - '@data_definitions.registry.export_provider' + - '@Wvision\Bundle\DataDefinitionsBundle\Context\ContextFactoryInterface' + - '@event_dispatcher' + - '@logger' + tags: + - { name: monolog.logger, channel: export_definition } + - { name: 'kernel.event_listener', event: 'data_definitions.stop', method: 'stop' } + + ### Registries + data_definitions.registry.provider: + class: CoreShop\Component\Registry\ServiceRegistry + public: true + arguments: + - Wvision\Bundle\DataDefinitionsBundle\Provider\ImportProviderInterface + - 'Import Definition Providers' + + data_definitions.form.registry.provider: + class: CoreShop\Bundle\ResourceBundle\Form\Registry\FormTypeRegistry + + data_definitions.registry.export_provider: + class: CoreShop\Component\Registry\ServiceRegistry + arguments: + - Wvision\Bundle\DataDefinitionsBundle\Provider\ExportProviderInterface + - 'Import Definition Export Providers' + + data_definitions.form.registry.export_provider: + class: CoreShop\Bundle\ResourceBundle\Form\Registry\FormTypeRegistry + + data_definitions.registry.loader: + class: CoreShop\Component\Registry\ServiceRegistry + arguments: + - Wvision\Bundle\DataDefinitionsBundle\Loader\LoaderInterface + - 'Import Definition Loaders' + + data_definitions.registry.cleaner: + class: CoreShop\Component\Registry\ServiceRegistry + arguments: + - Wvision\Bundle\DataDefinitionsBundle\Cleaner\CleanerInterface + - 'Import Definition Cleaners' + + data_definitions.registry.filter: + class: CoreShop\Component\Registry\ServiceRegistry + arguments: + - Wvision\Bundle\DataDefinitionsBundle\Filter\FilterInterface + - 'Import Definition Filters' + + data_definitions.registry.interpreter: + class: CoreShop\Component\Registry\ServiceRegistry + arguments: + - Wvision\Bundle\DataDefinitionsBundle\Interpreter\InterpreterInterface + - 'Import Definition Interpreters' + + data_definitions.form.registry.interpreter: + class: CoreShop\Bundle\ResourceBundle\Form\Registry\FormTypeRegistry + + data_definitions.registry.setter: + class: CoreShop\Component\Registry\ServiceRegistry + arguments: + - Wvision\Bundle\DataDefinitionsBundle\Setter\SetterInterface + - 'Import Definition Setters' + + data_definitions.form.registry.setter: + class: CoreShop\Bundle\ResourceBundle\Form\Registry\FormTypeRegistry + + data_definitions.registry.getter: + class: CoreShop\Component\Registry\ServiceRegistry + arguments: + - Wvision\Bundle\DataDefinitionsBundle\Getter\GetterInterface + - 'Import Definition Getters' + + data_definitions.form.registry.getter: + class: CoreShop\Bundle\ResourceBundle\Form\Registry\FormTypeRegistry + + data_definitions.registry.fetcher: + class: CoreShop\Component\Registry\ServiceRegistry + arguments: + - Wvision\Bundle\DataDefinitionsBundle\Fetcher\FetcherInterface + - 'Import Definition Fetchers' + + data_definitions.form.registry.fetcher: + class: CoreShop\Bundle\ResourceBundle\Form\Registry\FormTypeRegistry + + data_definitions.registry.runner: + class: CoreShop\Component\Registry\ServiceRegistry + arguments: + - Wvision\Bundle\DataDefinitionsBundle\Runner\RunnerInterface + - 'Import Definition Runners' + + data_definitions.registry.export_runner: + class: CoreShop\Component\Registry\ServiceRegistry + arguments: + - Wvision\Bundle\DataDefinitionsBundle\Runner\ExportRunnerInterface + - 'Export Definition Runners' + + data_definitions.registry.persister: + class: CoreShop\Component\Registry\ServiceRegistry + arguments: + - Wvision\Bundle\DataDefinitionsBundle\Persister\PersisterInterface + - 'Import Definition Persisters' + + ### CLEANER + Wvision\Bundle\DataDefinitionsBundle\Cleaner\Deleter: + tags: + - { name: data_definitions.cleaner, type: deleter } + + Wvision\Bundle\DataDefinitionsBundle\Cleaner\None: + tags: + - { name: data_definitions.cleaner, type: none } + + Wvision\Bundle\DataDefinitionsBundle\Cleaner\ReferenceCleaner: + tags: + - { name: data_definitions.cleaner, type: reference_cleaner } + + Wvision\Bundle\DataDefinitionsBundle\Cleaner\Unpublisher: + tags: + - { name: data_definitions.cleaner, type: unpublisher } + + ### INTERPRETER + Wvision\Bundle\DataDefinitionsBundle\Interpreter\AssetsUrlInterpreter: + arguments: + - '@Psr\Http\Client\ClientInterface' + - '@Psr\Http\Message\RequestFactoryInterface' + tags: + - { name: data_definitions.interpreter, type: assets_url, form-type: Wvision\Bundle\DataDefinitionsBundle\Form\Type\Interpreter\AssetsUrlInterpreterType } + + Wvision\Bundle\DataDefinitionsBundle\Interpreter\AssetUrlInterpreter: + arguments: + - '@Psr\Http\Client\ClientInterface' + - '@Psr\Http\Message\RequestFactoryInterface' + tags: + - { name: data_definitions.interpreter, type: asset_url, form-type: Wvision\Bundle\DataDefinitionsBundle\Form\Type\Interpreter\AssetUrlInterpreterType } + + Wvision\Bundle\DataDefinitionsBundle\Interpreter\MetadataInterpreter: + tags: + - { name: data_definitions.interpreter, type: metadata, form-type: Wvision\Bundle\DataDefinitionsBundle\Form\Type\Interpreter\MetadataInterpreterType } + + Wvision\Bundle\DataDefinitionsBundle\Interpreter\AssetByPathInterpreter: + tags: + - { name: data_definitions.interpreter, type: asset_by_path, form-type: Wvision\Bundle\DataDefinitionsBundle\Form\Type\Interpreter\AssetByPathInterpreterType } + + Wvision\Bundle\DataDefinitionsBundle\Interpreter\CarbonInterpreter: + tags: + - { name: data_definitions.interpreter, type: carbon, form-type: Wvision\Bundle\DataDefinitionsBundle\Form\Type\Interpreter\CarbonInterpreterType } + + Wvision\Bundle\DataDefinitionsBundle\Interpreter\CheckboxInterpreter: + tags: + - { name: data_definitions.interpreter, type: checkbox, form-type: Wvision\Bundle\DataDefinitionsBundle\Form\Type\NoConfigurationType } + + Wvision\Bundle\DataDefinitionsBundle\Interpreter\DefaultValueInterpreter: + tags: + - { name: data_definitions.interpreter, type: default_value, form-type: Wvision\Bundle\DataDefinitionsBundle\Form\Type\Interpreter\DefaultValueInterpreterType } + + Wvision\Bundle\DataDefinitionsBundle\Interpreter\SpecificObjectInterpreter: + tags: + - { name: data_definitions.interpreter, type: specific_object, form-type: Wvision\Bundle\DataDefinitionsBundle\Form\Type\Interpreter\SpecificObjectInterpreterType } + + Wvision\Bundle\DataDefinitionsBundle\Interpreter\HrefInterpreter: + tags: + - { name: data_definitions.interpreter, type: href, form-type: Wvision\Bundle\DataDefinitionsBundle\Form\Type\Interpreter\HrefInterpreterType } + + Wvision\Bundle\DataDefinitionsBundle\Interpreter\MultiHrefInterpreter: + tags: + - { name: data_definitions.interpreter, type: multi_href, form-type: Wvision\Bundle\DataDefinitionsBundle\Form\Type\Interpreter\MultiHrefInterpreterType } + + Wvision\Bundle\DataDefinitionsBundle\Interpreter\QuantityValueInterpreter: + tags: + - { name: data_definitions.interpreter, type: quantity_value, form-type: Wvision\Bundle\DataDefinitionsBundle\Form\Type\Interpreter\QuantityValueInterpreterType } + + Wvision\Bundle\DataDefinitionsBundle\Interpreter\NestedInterpreter: + arguments: + - '@data_definitions.registry.interpreter' + - '@Wvision\Bundle\DataDefinitionsBundle\Context\ContextFactoryInterface' + tags: + - { name: data_definitions.interpreter, type: nested, form-type: Wvision\Bundle\DataDefinitionsBundle\Form\Type\Interpreter\NestedInterpreterType } + + Wvision\Bundle\DataDefinitionsBundle\Interpreter\ExpressionInterpreter: + arguments: + - '@coreshop.expression_language' + - '@service_container' + tags: + - { name: data_definitions.interpreter, type: expression, form-type: Wvision\Bundle\DataDefinitionsBundle\Form\Type\Interpreter\ExpressionInterpreterType } + + Wvision\Bundle\DataDefinitionsBundle\Interpreter\ObjectResolverInterpreter: + arguments: + - '@service_container' + tags: + - { name: data_definitions.interpreter, type: object_resolver, form-type: Wvision\Bundle\DataDefinitionsBundle\Form\Type\Interpreter\ObjectResolverType } + + Wvision\Bundle\DataDefinitionsBundle\Interpreter\DefinitionInterpreter: + arguments: + - '@data_definitions.repository.import_definition' + - '@Wvision\Bundle\DataDefinitionsBundle\Importer\ImporterInterface' + tags: + - { name: data_definitions.interpreter, type: definition, form-type: Wvision\Bundle\DataDefinitionsBundle\Form\Type\Interpreter\DefinitionType } + + Wvision\Bundle\DataDefinitionsBundle\Interpreter\ConditionalInterpreter: + arguments: + - '@data_definitions.registry.interpreter' + - '@coreshop.expression_language' + - '@service_container' + tags: + - { name: data_definitions.interpreter, type: conditional, form-type: Wvision\Bundle\DataDefinitionsBundle\Form\Type\Interpreter\ConditionalInterpreterType } + + Wvision\Bundle\DataDefinitionsBundle\Interpreter\MappingInterpreter: + arguments: + - '@service_container' + tags: + - { name: data_definitions.interpreter, type: mapping, form-type: Wvision\Bundle\DataDefinitionsBundle\Form\Type\Interpreter\MappingInterpreterType } + + Wvision\Bundle\DataDefinitionsBundle\Interpreter\IteratorInterpreter: + arguments: + - '@data_definitions.registry.interpreter' + - '@Wvision\Bundle\DataDefinitionsBundle\Context\ContextFactoryInterface' + tags: + - { name: data_definitions.interpreter, type: iterator, form-type: Wvision\Bundle\DataDefinitionsBundle\Form\Type\Interpreter\IteratorInterpreterType } + + Wvision\Bundle\DataDefinitionsBundle\Interpreter\TwigInterpreter: + arguments: + - '@twig' + tags: + - { name: data_definitions.interpreter, type: twig, form-type: Wvision\Bundle\DataDefinitionsBundle\Form\Type\Interpreter\TwigInterpreterType } + + Wvision\Bundle\DataDefinitionsBundle\Interpreter\DoNotSetOnEmptyInterpreter: + tags: + - { name: data_definitions.interpreter, type: donotsetonempty, form-type: Wvision\Bundle\DataDefinitionsBundle\Form\Type\NoConfigurationType } + + Wvision\Bundle\DataDefinitionsBundle\Interpreter\LinkInterpreter: + tags: + - { name: data_definitions.interpreter, type: link, form-type: Wvision\Bundle\DataDefinitionsBundle\Form\Type\NoConfigurationType } + + Wvision\Bundle\DataDefinitionsBundle\Interpreter\ExternalImageInterpreter: + tags: + - { name: data_definitions.interpreter, type: external_image, form-type: Wvision\Bundle\DataDefinitionsBundle\Form\Type\NoConfigurationType } + + ### PROVIDER + Wvision\Bundle\DataDefinitionsBundle\Provider\CsvProvider: + tags: + - { name: data_definitions.import_provider, type: csv, form-type: Wvision\Bundle\DataDefinitionsBundle\Form\Type\ImportProvider\CsvProviderType } + - { name: data_definitions.export_provider, type: csv, form-type: Wvision\Bundle\DataDefinitionsBundle\Form\Type\ExportProvider\CsvProviderType } + + Wvision\Bundle\DataDefinitionsBundle\Provider\ExcelProvider: + tags: + - { name: data_definitions.import_provider, type: excel, form-type: Wvision\Bundle\DataDefinitionsBundle\Form\Type\ImportProvider\ExcelProviderType } + - { name: data_definitions.export_provider, type: excel, form-type: Wvision\Bundle\DataDefinitionsBundle\Form\Type\NoConfigurationType } + + Wvision\Bundle\DataDefinitionsBundle\Provider\JsonProvider: + tags: + - { name: data_definitions.import_provider, type: json, form-type: Wvision\Bundle\DataDefinitionsBundle\Form\Type\ImportProvider\JsonProviderType } + - { name: data_definitions.export_provider, type: json, form-type: Wvision\Bundle\DataDefinitionsBundle\Form\Type\NoConfigurationType } + + Wvision\Bundle\DataDefinitionsBundle\Provider\ExternalSqlProvider: + tags: + - { name: data_definitions.import_provider, type: external_sql, form-type: Wvision\Bundle\DataDefinitionsBundle\Form\Type\ImportProvider\ExternalSqlProviderType } + + Wvision\Bundle\DataDefinitionsBundle\Provider\SqlProvider: + arguments: + - '@doctrine.dbal.default_connection' + tags: + - { name: data_definitions.import_provider, type: sql, form-type: Wvision\Bundle\DataDefinitionsBundle\Form\Type\ImportProvider\SqlProviderType } + + Wvision\Bundle\DataDefinitionsBundle\Provider\XmlProvider: + tags: + - { name: data_definitions.import_provider, type: xml, form-type: Wvision\Bundle\DataDefinitionsBundle\Form\Type\ImportProvider\XmlProviderType } + - { name: data_definitions.export_provider, type: xml, form-type: Wvision\Bundle\DataDefinitionsBundle\Form\Type\ExportProvider\XmlProviderType } + + Wvision\Bundle\DataDefinitionsBundle\Provider\RawProvider: + tags: + - { name: data_definitions.import_provider, type: raw, form-type: Wvision\Bundle\DataDefinitionsBundle\Form\Type\ImportProvider\RawProviderType } + + ### SETTER AND GETTER + Wvision\Bundle\DataDefinitionsBundle\Setter\ClassificationStoreSetter: + tags: + - { name: data_definitions.setter, type: classificationstore, form-type: Wvision\Bundle\DataDefinitionsBundle\Form\Type\Setter\ClassificationStoreSetterType } + - { name: data_definitions.getter, type: classificationstore, form-type: Wvision\Bundle\DataDefinitionsBundle\Form\Type\Setter\ClassificationStoreSetterType } + + Wvision\Bundle\DataDefinitionsBundle\Setter\ClassificationStoreFieldGetter: + tags: + - { name: data_definitions.getter, type: classificationstore_field, form-type: Wvision\Bundle\DataDefinitionsBundle\Form\Type\NoConfigurationType } + + Wvision\Bundle\DataDefinitionsBundle\Setter\FieldCollectionSetter: + tags: + - { name: data_definitions.setter, type: fieldcollection, form-type: Wvision\Bundle\DataDefinitionsBundle\Form\Type\Setter\FieldCollectionSetterType } + - { name: data_definitions.getter, type: fieldcollection, form-type: Wvision\Bundle\DataDefinitionsBundle\Form\Type\Setter\FieldCollectionSetterType } + + Wvision\Bundle\DataDefinitionsBundle\Setter\KeySetter: + tags: + - { name: data_definitions.setter, type: key, form-type: Wvision\Bundle\DataDefinitionsBundle\Form\Type\NoConfigurationType } + + Wvision\Bundle\DataDefinitionsBundle\Setter\LocalizedfieldSetter: + tags: + - { name: data_definitions.setter, type: localizedfield, form-type: Wvision\Bundle\DataDefinitionsBundle\Form\Type\Setter\LocalizedFieldSetterType } + - { name: data_definitions.getter, type: localizedfield, form-type: Wvision\Bundle\DataDefinitionsBundle\Form\Type\Setter\LocalizedFieldSetterType } + + Wvision\Bundle\DataDefinitionsBundle\Setter\ObjectbrickSetter: + tags: + - { name: data_definitions.setter, type: objectbrick, form-type: Wvision\Bundle\DataDefinitionsBundle\Form\Type\Setter\ObjectBrickSetterType } + - { name: data_definitions.getter, type: objectbrick, form-type: Wvision\Bundle\DataDefinitionsBundle\Form\Type\Setter\ObjectBrickSetterType } + + Wvision\Bundle\DataDefinitionsBundle\Setter\ObjectTypeSetter: + tags: + - { name: data_definitions.setter, type: object_type, form-type: Wvision\Bundle\DataDefinitionsBundle\Form\Type\NoConfigurationType } + + Wvision\Bundle\DataDefinitionsBundle\Setter\RelationSetter: + tags: + - { name: data_definitions.setter, type: relation, form-type: Wvision\Bundle\DataDefinitionsBundle\Form\Type\NoConfigurationType } + + Wvision\Bundle\DataDefinitionsBundle\EventListener\ObjectDeleteListener: + tags: + - { name: kernel.event_listener, event: pimcore.dataobject.postDelete, method: onDataObjectDelete } + + Wvision\Bundle\DataDefinitionsBundle\Fetcher\ObjectsFetcher: + tags: + - { name: data_definitions.fetcher, type: objects, form-type: Wvision\Bundle\DataDefinitionsBundle\Form\Type\Fetcher\ObjectsFetcherType } + + ### LOADER + Wvision\Bundle\DataDefinitionsBundle\Loader\PrimaryKeyLoader: + tags: + - { name: data_definitions.loader, type: primary_key } + + ### PERSISTER + Wvision\Bundle\DataDefinitionsBundle\Persister\Persister: + tags: + - { name: data_definitions.persister, type: persister } diff --git a/src/DataDefinitionsBundle/Resources/config/services/commands.yml b/src/DataDefinitionsBundle/Resources/config/services/commands.yml index 6ade77a0..d8a32392 100644 --- a/src/DataDefinitionsBundle/Resources/config/services/commands.yml +++ b/src/DataDefinitionsBundle/Resources/config/services/commands.yml @@ -1,46 +1,46 @@ services: - Wvision\Bundle\DataDefinitionsBundle\Command\ListImportDefinitionsCommand: - arguments: - - '@data_definitions.repository.import_definition' - tags: - - { name: 'console.command', command: 'data-definitions:list:imports' } + Wvision\Bundle\DataDefinitionsBundle\Command\ListImportDefinitionsCommand: + arguments: + - '@data_definitions.repository.import_definition' + tags: + - { name: 'console.command', command: 'data-definitions:list:imports' } - Wvision\Bundle\DataDefinitionsBundle\Command\ListExportDefinitionsCommand: - arguments: - - '@data_definitions.repository.export_definition' - tags: - - { name: 'console.command', command: 'data-definitions:list:exports' } + Wvision\Bundle\DataDefinitionsBundle\Command\ListExportDefinitionsCommand: + arguments: + - '@data_definitions.repository.export_definition' + tags: + - { name: 'console.command', command: 'data-definitions:list:exports' } - Wvision\Bundle\DataDefinitionsBundle\Command\ImportCommand: - arguments: - - '@event_dispatcher' - - '@data_definitions.repository.import_definition' - - '@Wvision\Bundle\DataDefinitionsBundle\Importer\ImporterInterface' - tags: - - { name: 'console.command', command: 'data-definitions:import' } + Wvision\Bundle\DataDefinitionsBundle\Command\ImportCommand: + arguments: + - '@event_dispatcher' + - '@data_definitions.repository.import_definition' + - '@Wvision\Bundle\DataDefinitionsBundle\Importer\ImporterInterface' + tags: + - { name: 'console.command', command: 'data-definitions:import' } - Wvision\Bundle\DataDefinitionsBundle\Command\ExportCommand: - arguments: - - '@event_dispatcher' - - '@data_definitions.repository.export_definition' - - '@Wvision\Bundle\DataDefinitionsBundle\Exporter\ExporterInterface' - tags: - - { name: 'console.command', command: 'data-definitions:export' } + Wvision\Bundle\DataDefinitionsBundle\Command\ExportCommand: + arguments: + - '@event_dispatcher' + - '@data_definitions.repository.export_definition' + - '@Wvision\Bundle\DataDefinitionsBundle\Exporter\ExporterInterface' + tags: + - { name: 'console.command', command: 'data-definitions:export' } - Wvision\Bundle\DataDefinitionsBundle\Command\ImportImportDefinitionCommand: - arguments: - - '@=service("CoreShop\\Component\\Resource\\Metadata\\RegistryInterface").get("data_definitions.import_definition")' - - '@data_definitions.repository.import_definition' - - '@CoreShop\Bundle\ResourceBundle\Pimcore\ObjectManager' - - '@CoreShop\Bundle\ResourceBundle\Controller\ResourceFormFactoryInterface' - tags: - - { name: 'console.command', command: 'data-definitions:definition:import:import' } + Wvision\Bundle\DataDefinitionsBundle\Command\ImportImportDefinitionCommand: + arguments: + - '@=service("CoreShop\\Component\\Resource\\Metadata\\RegistryInterface").get("data_definitions.import_definition")' + - '@data_definitions.repository.import_definition' + - '@CoreShop\Bundle\ResourceBundle\Pimcore\ObjectManager' + - '@CoreShop\Bundle\ResourceBundle\Controller\ResourceFormFactoryInterface' + tags: + - { name: 'console.command', command: 'data-definitions:definition:import:import' } - Wvision\Bundle\DataDefinitionsBundle\Command\ImportExportDefinitionCommand: - arguments: - - '@=service("CoreShop\\Component\\Resource\\Metadata\\RegistryInterface").get("data_definitions.export_definition")' - - '@data_definitions.repository.export_definition' - - '@CoreShop\Bundle\ResourceBundle\Pimcore\ObjectManager' - - '@CoreShop\Bundle\ResourceBundle\Controller\ResourceFormFactoryInterface' - tags: - - { name: 'console.command', command: 'data-definitions:definition:import:export' } + Wvision\Bundle\DataDefinitionsBundle\Command\ImportExportDefinitionCommand: + arguments: + - '@=service("CoreShop\\Component\\Resource\\Metadata\\RegistryInterface").get("data_definitions.export_definition")' + - '@data_definitions.repository.export_definition' + - '@CoreShop\Bundle\ResourceBundle\Pimcore\ObjectManager' + - '@CoreShop\Bundle\ResourceBundle\Controller\ResourceFormFactoryInterface' + tags: + - { name: 'console.command', command: 'data-definitions:definition:import:export' } diff --git a/src/DataDefinitionsBundle/Resources/config/services/forms.yml b/src/DataDefinitionsBundle/Resources/config/services/forms.yml index d747fada..fb9935eb 100644 --- a/src/DataDefinitionsBundle/Resources/config/services/forms.yml +++ b/src/DataDefinitionsBundle/Resources/config/services/forms.yml @@ -1,142 +1,142 @@ parameters: - data_definitions.form.type.definition.validation_groups: [data_definitions] - data_definitions.form.type.mapping.validation_groups: [data_definitions] - data_definitions.form.type.export_definition.validation_groups: [data_definitions] - data_definitions.form.type.export_mapping.validation_groups: [data_definitions] + data_definitions.form.type.definition.validation_groups: [ data_definitions ] + data_definitions.form.type.mapping.validation_groups: [ data_definitions ] + data_definitions.form.type.export_definition.validation_groups: [ data_definitions ] + data_definitions.form.type.export_mapping.validation_groups: [ data_definitions ] services: - Wvision\Bundle\DataDefinitionsBundle\Form\DataMapper\DefinitionMappingDataMapper: + Wvision\Bundle\DataDefinitionsBundle\Form\DataMapper\DefinitionMappingDataMapper: + arguments: + - !service + class: Symfony\Component\Form\Extension\Core\DataMapper\PropertyPathMapper arguments: - - !service - class: Symfony\Component\Form\Extension\Core\DataMapper\PropertyPathMapper - arguments: - - '@property_accessor' - - Wvision\Bundle\DataDefinitionsBundle\Form\Type\ClassChoiceType: - tags: - - { name: form.type } - - Wvision\Bundle\DataDefinitionsBundle\Form\Type\CleanerChoiceType: - arguments: ['%data_definitions.cleaners%'] - tags: - - { name: form.type } - - Wvision\Bundle\DataDefinitionsBundle\Form\Type\FilterChoiceType: - arguments: ['%data_definitions.filters%'] - tags: - - { name: form.type } - - Wvision\Bundle\DataDefinitionsBundle\Form\Type\InterpreterChoiceType: - arguments: ['%data_definitions.interpreters%'] - tags: - - { name: form.type } - - Wvision\Bundle\DataDefinitionsBundle\Form\Type\ImportProviderChoiceType: - arguments: ['%data_definitions.import_providers%'] - tags: - - { name: form.type } - - Wvision\Bundle\DataDefinitionsBundle\Form\Type\ExportProviderChoiceType: - arguments: ['%data_definitions.export_providers%'] - tags: - - { name: form.type } - - Wvision\Bundle\DataDefinitionsBundle\Form\Type\LoaderChoiceType: - arguments: ['%data_definitions.loaders%'] - tags: - - { name: form.type } - - Wvision\Bundle\DataDefinitionsBundle\Form\Type\RunnerChoiceType: - arguments: ['%data_definitions.runners%'] - tags: - - { name: form.type } - - Wvision\Bundle\DataDefinitionsBundle\Form\Type\SetterChoiceType: - arguments: ['%data_definitions.setters%'] - tags: - - { name: form.type } - - Wvision\Bundle\DataDefinitionsBundle\Form\Type\PersisterChoiceType: - arguments: ['%data_definitions.persisters%'] - tags: - - { name: form.type } - - Wvision\Bundle\DataDefinitionsBundle\Form\Type\ImportDefinitionType: - arguments: - - '%data_definitions.model.import_definition.class%' - - '%data_definitions.form.type.definition.validation_groups%' - - '@data_definitions.form.registry.provider' - tags: - - { name: form.type } - - Wvision\Bundle\DataDefinitionsBundle\Form\Type\ImportMappingCollectionType: - arguments: - - '@Wvision\Bundle\DataDefinitionsBundle\Form\DataMapper\DefinitionMappingDataMapper' - tags: - - { name: form.type } - - Wvision\Bundle\DataDefinitionsBundle\Form\Type\ImportMappingType: - arguments: - - '%data_definitions.form.type.mapping.validation_groups%' - - '@data_definitions.form.registry.setter' - - '@data_definitions.form.registry.interpreter' - - '@data_definitions.form.registry.getter' - tags: - - { name: form.type } - - Wvision\Bundle\DataDefinitionsBundle\Form\Type\ExportDefinitionType: - arguments: - - '%data_definitions.model.export_definition.class%' - - '%data_definitions.form.type.export_definition.validation_groups%' - - '@data_definitions.form.registry.export_provider' - - '@data_definitions.form.registry.fetcher' - tags: - - { name: form.type } - - Wvision\Bundle\DataDefinitionsBundle\Form\Type\ExportMappingCollectionType: - arguments: - - '@Wvision\Bundle\DataDefinitionsBundle\Form\DataMapper\DefinitionMappingDataMapper' - tags: - - { name: form.type } - - Wvision\Bundle\DataDefinitionsBundle\Form\Type\ExportMappingType: - arguments: - - '%data_definitions.form.type.export_mapping.validation_groups%' - - '@data_definitions.form.registry.getter' - - '@data_definitions.form.registry.interpreter' - tags: - - { name: form.type } - - Wvision\Bundle\DataDefinitionsBundle\Form\Type\Interpreter\InterpreterType: - arguments: ['@data_definitions.form.registry.interpreter'] - tags: - - { name: form.type } - - Wvision\Bundle\DataDefinitionsBundle\Form\Type\Interpreter\InterpreterCollectionType: - arguments: ['@data_definitions.registry.interpreter'] - tags: - - { name: form.type } - - Wvision\Bundle\DataDefinitionsBundle\Form\Type\Interpreter\NestedInterpreterType: - tags: - - { name: form.type } - - Wvision\Bundle\DataDefinitionsBundle\Form\Type\Interpreter\ObjectResolverType: - tags: - - { name: form.type } - - Wvision\Bundle\DataDefinitionsBundle\Form\Type\FetcherChoiceType: - arguments: ['%data_definitions.fetchers%'] - tags: - - { name: form.type } - - Wvision\Bundle\DataDefinitionsBundle\Form\Type\DefinitionChoiceType: - arguments: ['@data_definitions.repository.import_definition'] - tags: - - { name: form.type } - - Wvision\Bundle\DataDefinitionsBundle\Form\Type\ExportRunnerChoiceType: - arguments: ['%data_definitions.export_runners%'] - tags: - - { name: form.type } + - '@property_accessor' + + Wvision\Bundle\DataDefinitionsBundle\Form\Type\ClassChoiceType: + tags: + - { name: form.type } + + Wvision\Bundle\DataDefinitionsBundle\Form\Type\CleanerChoiceType: + arguments: [ '%data_definitions.cleaners%' ] + tags: + - { name: form.type } + + Wvision\Bundle\DataDefinitionsBundle\Form\Type\FilterChoiceType: + arguments: [ '%data_definitions.filters%' ] + tags: + - { name: form.type } + + Wvision\Bundle\DataDefinitionsBundle\Form\Type\InterpreterChoiceType: + arguments: [ '%data_definitions.interpreters%' ] + tags: + - { name: form.type } + + Wvision\Bundle\DataDefinitionsBundle\Form\Type\ImportProviderChoiceType: + arguments: [ '%data_definitions.import_providers%' ] + tags: + - { name: form.type } + + Wvision\Bundle\DataDefinitionsBundle\Form\Type\ExportProviderChoiceType: + arguments: [ '%data_definitions.export_providers%' ] + tags: + - { name: form.type } + + Wvision\Bundle\DataDefinitionsBundle\Form\Type\LoaderChoiceType: + arguments: [ '%data_definitions.loaders%' ] + tags: + - { name: form.type } + + Wvision\Bundle\DataDefinitionsBundle\Form\Type\RunnerChoiceType: + arguments: [ '%data_definitions.runners%' ] + tags: + - { name: form.type } + + Wvision\Bundle\DataDefinitionsBundle\Form\Type\SetterChoiceType: + arguments: [ '%data_definitions.setters%' ] + tags: + - { name: form.type } + + Wvision\Bundle\DataDefinitionsBundle\Form\Type\PersisterChoiceType: + arguments: [ '%data_definitions.persisters%' ] + tags: + - { name: form.type } + + Wvision\Bundle\DataDefinitionsBundle\Form\Type\ImportDefinitionType: + arguments: + - '%data_definitions.model.import_definition.class%' + - '%data_definitions.form.type.definition.validation_groups%' + - '@data_definitions.form.registry.provider' + tags: + - { name: form.type } + + Wvision\Bundle\DataDefinitionsBundle\Form\Type\ImportMappingCollectionType: + arguments: + - '@Wvision\Bundle\DataDefinitionsBundle\Form\DataMapper\DefinitionMappingDataMapper' + tags: + - { name: form.type } + + Wvision\Bundle\DataDefinitionsBundle\Form\Type\ImportMappingType: + arguments: + - '%data_definitions.form.type.mapping.validation_groups%' + - '@data_definitions.form.registry.setter' + - '@data_definitions.form.registry.interpreter' + - '@data_definitions.form.registry.getter' + tags: + - { name: form.type } + + Wvision\Bundle\DataDefinitionsBundle\Form\Type\ExportDefinitionType: + arguments: + - '%data_definitions.model.export_definition.class%' + - '%data_definitions.form.type.export_definition.validation_groups%' + - '@data_definitions.form.registry.export_provider' + - '@data_definitions.form.registry.fetcher' + tags: + - { name: form.type } + + Wvision\Bundle\DataDefinitionsBundle\Form\Type\ExportMappingCollectionType: + arguments: + - '@Wvision\Bundle\DataDefinitionsBundle\Form\DataMapper\DefinitionMappingDataMapper' + tags: + - { name: form.type } + + Wvision\Bundle\DataDefinitionsBundle\Form\Type\ExportMappingType: + arguments: + - '%data_definitions.form.type.export_mapping.validation_groups%' + - '@data_definitions.form.registry.getter' + - '@data_definitions.form.registry.interpreter' + tags: + - { name: form.type } + + Wvision\Bundle\DataDefinitionsBundle\Form\Type\Interpreter\InterpreterType: + arguments: [ '@data_definitions.form.registry.interpreter' ] + tags: + - { name: form.type } + + Wvision\Bundle\DataDefinitionsBundle\Form\Type\Interpreter\InterpreterCollectionType: + arguments: [ '@data_definitions.registry.interpreter' ] + tags: + - { name: form.type } + + Wvision\Bundle\DataDefinitionsBundle\Form\Type\Interpreter\NestedInterpreterType: + tags: + - { name: form.type } + + Wvision\Bundle\DataDefinitionsBundle\Form\Type\Interpreter\ObjectResolverType: + tags: + - { name: form.type } + + Wvision\Bundle\DataDefinitionsBundle\Form\Type\FetcherChoiceType: + arguments: [ '%data_definitions.fetchers%' ] + tags: + - { name: form.type } + + Wvision\Bundle\DataDefinitionsBundle\Form\Type\DefinitionChoiceType: + arguments: [ '@data_definitions.repository.import_definition' ] + tags: + - { name: form.type } + + Wvision\Bundle\DataDefinitionsBundle\Form\Type\ExportRunnerChoiceType: + arguments: [ '%data_definitions.export_runners%' ] + tags: + - { name: form.type } diff --git a/src/DataDefinitionsBundle/Resources/config/services/import_rules.yml b/src/DataDefinitionsBundle/Resources/config/services/import_rules.yml index 6b28b7bc..5efb6877 100644 --- a/src/DataDefinitionsBundle/Resources/config/services/import_rules.yml +++ b/src/DataDefinitionsBundle/Resources/config/services/import_rules.yml @@ -1,115 +1,115 @@ parameters: - data_definitions.form.type.import_rule.action.validation_groups: [data_definitions] - data_definitions.form.type.import_rule.condition.validation_groups: [data_definitions] - data_definitions.form.type.import_rule.validation_groups: [data_definitions] + data_definitions.form.type.import_rule.action.validation_groups: [ data_definitions ] + data_definitions.form.type.import_rule.condition.validation_groups: [ data_definitions ] + data_definitions.form.type.import_rule.validation_groups: [ data_definitions ] services: - data_definitions.import_rule.action: - class: CoreShop\Component\Registry\ServiceRegistry - public: true - arguments: - - Wvision\Bundle\DataDefinitionsBundle\Rules\Action\ImportRuleProcessorInterface - - 'Import Rule Action Processors' - - data_definitions.form.import_rule.action: - class: CoreShop\Bundle\ResourceBundle\Form\Registry\FormTypeRegistry - - data_definitions.import_rule.condition: - class: CoreShop\Component\Registry\ServiceRegistry - public: true - arguments: - - Wvision\Bundle\DataDefinitionsBundle\Rules\Condition\ImportRuleConditionCheckerInterface - - 'Import Rule Condition Checkers' - - data_definitions.form.import_rule.condition: - class: CoreShop\Bundle\ResourceBundle\Form\Registry\FormTypeRegistry - - Wvision\Bundle\DataDefinitionsBundle\Rules\Form\Type\ImportRuleActionChoiceType: - arguments: - - '%data_definitions.import_rule.actions%' - tags: - - { name: form.type } - - Wvision\Bundle\DataDefinitionsBundle\Rules\Form\Type\ImportRuleConditionChoiceType: - arguments: - - '%data_definitions.import_rule.conditions%' - tags: - - { name: form.type } - - Wvision\Bundle\DataDefinitionsBundle\Rules\Form\Type\ImportRuleActionCollectionType: - arguments: - - '@data_definitions.import_rule.action' - tags: - - { name: form.type } - - Wvision\Bundle\DataDefinitionsBundle\Rules\Form\Type\ImportRuleConditionCollectionType: - arguments: - - '@data_definitions.import_rule.condition' - tags: - - { name: form.type } - - Wvision\Bundle\DataDefinitionsBundle\Rules\Form\Type\ImportRuleActionType: - arguments: - - '%data_definitions.form.type.import_rule.action.validation_groups%' - - '@data_definitions.form.import_rule.action' - tags: - - { name: form.type } - - Wvision\Bundle\DataDefinitionsBundle\Rules\Form\Type\ImportRuleConditionType: - arguments: - - '%data_definitions.form.type.definition.validation_groups%' - - '@data_definitions.form.import_rule.condition' - tags: - - { name: form.type } - - Wvision\Bundle\DataDefinitionsBundle\Rules\Form\Type\ImportRuleType: - arguments: - - '%data_definitions.form.type.definition.validation_groups%' - tags: - - { name: form.type } - - Wvision\Bundle\DataDefinitionsBundle\Rules\Condition\ExpressionConditionChecker: - arguments: - - '@coreshop.expression_language' - - '@service_container' - tags: - - { name: data_definitions.import_rule.condition, type: expression, form-type: Wvision\Bundle\DataDefinitionsBundle\Rules\Form\Type\Condition\ExpressionConditionType } - - Wvision\Bundle\DataDefinitionsBundle\Rules\Action\ExpressionProcessor: - arguments: - - '@coreshop.expression_language' - - '@service_container' - tags: - - { name: data_definitions.import_rule.action, type: expression, form-type: Wvision\Bundle\DataDefinitionsBundle\Rules\Form\Type\Action\ExpressionType } - - Wvision\Bundle\DataDefinitionsBundle\Rules\Action\ObjectProcessor: - tags: - - { name: data_definitions.import_rule.action, type: object, form-type: Wvision\Bundle\DataDefinitionsBundle\Rules\Form\Type\Action\ObjectType } - - Wvision\Bundle\DataDefinitionsBundle\Rules\Processor\RuleApplierInterface: '@Wvision\Bundle\DataDefinitionsBundle\Rules\Processor\RuleApplier' - Wvision\Bundle\DataDefinitionsBundle\Rules\Processor\RuleApplier: - arguments: - - '@data_definitions.import_rule.action' - - data_definitions.import_rules.conditions.validation.processor: - class: CoreShop\Component\Rule\Condition\RuleConditionsValidationProcessor - shared: false - arguments: - - '@data_definitions.import_rule.condition' - - 'Import Rules Interface' - - Wvision\Bundle\DataDefinitionsBundle\Rules\Processor\ImportRuleValidationProcessorInterface: '@Wvision\Bundle\DataDefinitionsBundle\Rules\Processor\ImportRuleValidationProcessor' - Wvision\Bundle\DataDefinitionsBundle\Rules\Processor\ImportRuleValidationProcessor: - arguments: - - '@data_definitions.import_rules.conditions.validation.processor' - - Wvision\Bundle\DataDefinitionsBundle\Interpreter\ImportRuleInterpreter: - arguments: - - '@Wvision\Bundle\DataDefinitionsBundle\Rules\Processor\ImportRuleValidationProcessorInterface' - - '@Wvision\Bundle\DataDefinitionsBundle\Rules\Processor\RuleApplierInterface' - tags: - - { name: data_definitions.interpreter, type: import_rule, form-type: Wvision\Bundle\DataDefinitionsBundle\Rules\Form\Type\ImportRulesInterpreterType } - - Wvision\Bundle\DataDefinitionsBundle\Controller\ImportRuleController: - tags: - - { name: controller.service_arguments } + data_definitions.import_rule.action: + class: CoreShop\Component\Registry\ServiceRegistry + public: true + arguments: + - Wvision\Bundle\DataDefinitionsBundle\Rules\Action\ImportRuleProcessorInterface + - 'Import Rule Action Processors' + + data_definitions.form.import_rule.action: + class: CoreShop\Bundle\ResourceBundle\Form\Registry\FormTypeRegistry + + data_definitions.import_rule.condition: + class: CoreShop\Component\Registry\ServiceRegistry + public: true + arguments: + - Wvision\Bundle\DataDefinitionsBundle\Rules\Condition\ImportRuleConditionCheckerInterface + - 'Import Rule Condition Checkers' + + data_definitions.form.import_rule.condition: + class: CoreShop\Bundle\ResourceBundle\Form\Registry\FormTypeRegistry + + Wvision\Bundle\DataDefinitionsBundle\Rules\Form\Type\ImportRuleActionChoiceType: + arguments: + - '%data_definitions.import_rule.actions%' + tags: + - { name: form.type } + + Wvision\Bundle\DataDefinitionsBundle\Rules\Form\Type\ImportRuleConditionChoiceType: + arguments: + - '%data_definitions.import_rule.conditions%' + tags: + - { name: form.type } + + Wvision\Bundle\DataDefinitionsBundle\Rules\Form\Type\ImportRuleActionCollectionType: + arguments: + - '@data_definitions.import_rule.action' + tags: + - { name: form.type } + + Wvision\Bundle\DataDefinitionsBundle\Rules\Form\Type\ImportRuleConditionCollectionType: + arguments: + - '@data_definitions.import_rule.condition' + tags: + - { name: form.type } + + Wvision\Bundle\DataDefinitionsBundle\Rules\Form\Type\ImportRuleActionType: + arguments: + - '%data_definitions.form.type.import_rule.action.validation_groups%' + - '@data_definitions.form.import_rule.action' + tags: + - { name: form.type } + + Wvision\Bundle\DataDefinitionsBundle\Rules\Form\Type\ImportRuleConditionType: + arguments: + - '%data_definitions.form.type.definition.validation_groups%' + - '@data_definitions.form.import_rule.condition' + tags: + - { name: form.type } + + Wvision\Bundle\DataDefinitionsBundle\Rules\Form\Type\ImportRuleType: + arguments: + - '%data_definitions.form.type.definition.validation_groups%' + tags: + - { name: form.type } + + Wvision\Bundle\DataDefinitionsBundle\Rules\Condition\ExpressionConditionChecker: + arguments: + - '@coreshop.expression_language' + - '@service_container' + tags: + - { name: data_definitions.import_rule.condition, type: expression, form-type: Wvision\Bundle\DataDefinitionsBundle\Rules\Form\Type\Condition\ExpressionConditionType } + + Wvision\Bundle\DataDefinitionsBundle\Rules\Action\ExpressionProcessor: + arguments: + - '@coreshop.expression_language' + - '@service_container' + tags: + - { name: data_definitions.import_rule.action, type: expression, form-type: Wvision\Bundle\DataDefinitionsBundle\Rules\Form\Type\Action\ExpressionType } + + Wvision\Bundle\DataDefinitionsBundle\Rules\Action\ObjectProcessor: + tags: + - { name: data_definitions.import_rule.action, type: object, form-type: Wvision\Bundle\DataDefinitionsBundle\Rules\Form\Type\Action\ObjectType } + + Wvision\Bundle\DataDefinitionsBundle\Rules\Processor\RuleApplierInterface: '@Wvision\Bundle\DataDefinitionsBundle\Rules\Processor\RuleApplier' + Wvision\Bundle\DataDefinitionsBundle\Rules\Processor\RuleApplier: + arguments: + - '@data_definitions.import_rule.action' + + data_definitions.import_rules.conditions.validation.processor: + class: CoreShop\Component\Rule\Condition\RuleConditionsValidationProcessor + shared: false + arguments: + - '@data_definitions.import_rule.condition' + - 'Import Rules Interface' + + Wvision\Bundle\DataDefinitionsBundle\Rules\Processor\ImportRuleValidationProcessorInterface: '@Wvision\Bundle\DataDefinitionsBundle\Rules\Processor\ImportRuleValidationProcessor' + Wvision\Bundle\DataDefinitionsBundle\Rules\Processor\ImportRuleValidationProcessor: + arguments: + - '@data_definitions.import_rules.conditions.validation.processor' + + Wvision\Bundle\DataDefinitionsBundle\Interpreter\ImportRuleInterpreter: + arguments: + - '@Wvision\Bundle\DataDefinitionsBundle\Rules\Processor\ImportRuleValidationProcessorInterface' + - '@Wvision\Bundle\DataDefinitionsBundle\Rules\Processor\RuleApplierInterface' + tags: + - { name: data_definitions.interpreter, type: import_rule, form-type: Wvision\Bundle\DataDefinitionsBundle\Rules\Form\Type\ImportRulesInterpreterType } + + Wvision\Bundle\DataDefinitionsBundle\Controller\ImportRuleController: + tags: + - { name: controller.service_arguments } diff --git a/src/DataDefinitionsBundle/Resources/config/services/installer.yml b/src/DataDefinitionsBundle/Resources/config/services/installer.yml index 4983c58a..6a43e238 100644 --- a/src/DataDefinitionsBundle/Resources/config/services/installer.yml +++ b/src/DataDefinitionsBundle/Resources/config/services/installer.yml @@ -1,10 +1,10 @@ services: - _defaults: - autowire: true - autoconfigure: true - public: false + _defaults: + autowire: true + autoconfigure: true + public: false - Wvision\Bundle\DataDefinitionsBundle\Installer: - public: true - arguments: - $bundle: "@=service('kernel').getBundle('DataDefinitionsBundle')" + Wvision\Bundle\DataDefinitionsBundle\Installer: + public: true + arguments: + $bundle: "@=service('kernel').getBundle('DataDefinitionsBundle')" diff --git a/src/DataDefinitionsBundle/Resources/install/pimcore/sql/data.sql b/src/DataDefinitionsBundle/Resources/install/pimcore/sql/data.sql index abcff742..5633b2b1 100644 --- a/src/DataDefinitionsBundle/Resources/install/pimcore/sql/data.sql +++ b/src/DataDefinitionsBundle/Resources/install/pimcore/sql/data.sql @@ -1,6 +1,18 @@ CREATE TABLE IF NOT EXISTS `data_definitions_import_log` ( - `id` INT NOT NULL AUTO_INCREMENT PRIMARY KEY, - `definition` INT NOT NULL, - `o_id` INT NOT NULL + `id` + INT + NOT + NULL + AUTO_INCREMENT + PRIMARY + KEY, + `definition` + INT + NOT + NULL, + `o_id` + INT + NOT + NULL ); diff --git a/src/DataDefinitionsBundle/Resources/public/pimcore/img/rules.svg b/src/DataDefinitionsBundle/Resources/public/pimcore/img/rules.svg index 552d1a6a..2505ba40 100644 --- a/src/DataDefinitionsBundle/Resources/public/pimcore/img/rules.svg +++ b/src/DataDefinitionsBundle/Resources/public/pimcore/img/rules.svg @@ -1 +1,7 @@ - \ No newline at end of file + + + + + + + \ No newline at end of file diff --git a/src/DataDefinitionsBundle/Resources/public/pimcore/js/import_rule/panel.js b/src/DataDefinitionsBundle/Resources/public/pimcore/js/import_rule/panel.js index d307e1d1..38c4109d 100644 --- a/src/DataDefinitionsBundle/Resources/public/pimcore/js/import_rule/panel.js +++ b/src/DataDefinitionsBundle/Resources/public/pimcore/js/import_rule/panel.js @@ -55,14 +55,14 @@ pimcore.plugin.datadefinitions.import_rule.panel = Class.create(coreshop.rules.p layout: 'border', items: this.getItems(), buttons: [{ - text: t('import'), - iconCls: 'pimcore_icon_import', - handler: this.importRules.bind(this) + text: t('import'), + iconCls: 'pimcore_icon_import', + handler: this.importRules.bind(this) }, { text: t('export'), iconCls: 'pimcore_icon_export', handler: this.exportRules.bind(this) - },{ + }, { text: t('save'), iconCls: 'pimcore_icon_apply', handler: this.save.bind(this) @@ -73,7 +73,7 @@ pimcore.plugin.datadefinitions.import_rule.panel = Class.create(coreshop.rules.p return this.layout; }, - exportRules: function() { + exportRules: function () { pimcore.settings.showCloseConfirmation = false; window.setTimeout(function () { pimcore.settings.showCloseConfirmation = true; @@ -93,14 +93,14 @@ pimcore.plugin.datadefinitions.import_rule.panel = Class.create(coreshop.rules.p }); }, - importRules: function() { + importRules: function () { pimcore.helpers.uploadDialog('/admin/data_definitions/import_rules/import', 'file', function (res) { var res = Ext.decode(res.response.responseText); if (res.success) { pimcore.helpers.showNotification(t('success'), t('success'), 'success'); - Ext.Object.each(this.panels, function(key, panel) { + Ext.Object.each(this.panels, function (key, panel) { panel.destroy(); }); @@ -115,25 +115,25 @@ pimcore.plugin.datadefinitions.import_rule.panel = Class.create(coreshop.rules.p }); }, - getData: function() { + getData: function () { var panelData = {}; - this.store.getRange().forEach(function(value, index) { + this.store.getRange().forEach(function (value, index) { panelData[value.id] = value.data; panelData[value.id].id = value.id; }); - var result = Ext.Object.each(this.panels, function(key, panel) { + var result = Ext.Object.each(this.panels, function (key, panel) { panelData[key] = panel.getSaveData(); }); return Object.values(panelData); }, - save: function() { + save: function () { var stopped = false; - var result = Ext.Object.each(this.panels, function(key, panel) { + var result = Ext.Object.each(this.panels, function (key, panel) { if (!panel.isValid()) { stopped = true; return false; @@ -224,8 +224,7 @@ pimcore.plugin.datadefinitions.import_rule.panel = Class.create(coreshop.rules.p if (this.panels[panelKey]) { this.panels[panelKey].activate(); - } - else { + } else { var itemClass = this.getItemClass(); this.panels[panelKey] = new itemClass(this, record.data, panelKey, this.type, record); diff --git a/src/DataDefinitionsBundle/Resources/public/pimcore/js/interpreters/asseturl.js b/src/DataDefinitionsBundle/Resources/public/pimcore/js/interpreters/asseturl.js index 7bdc4649..63370074 100644 --- a/src/DataDefinitionsBundle/Resources/public/pimcore/js/interpreters/asseturl.js +++ b/src/DataDefinitionsBundle/Resources/public/pimcore/js/interpreters/asseturl.js @@ -87,12 +87,12 @@ pimcore.plugin.datadefinitions.interpreters.asset_url = Class.create(pimcore.plu var isDeduplicateByUrlDisabled = (enabled === false); relocateExistingCheckbox - .setValue(false) - .setDisabled(isDeduplicateByUrlDisabled); + .setValue(false) + .setDisabled(isDeduplicateByUrlDisabled); renameExistingCheckbox - .setValue(false) - .setDisabled(isDeduplicateByUrlDisabled); + .setValue(false) + .setDisabled(isDeduplicateByUrlDisabled); } } }, diff --git a/src/DataDefinitionsBundle/Resources/public/pimcore/js/interpreters/carbon.js b/src/DataDefinitionsBundle/Resources/public/pimcore/js/interpreters/carbon.js index 02c1e0d6..b1759cc5 100644 --- a/src/DataDefinitionsBundle/Resources/public/pimcore/js/interpreters/carbon.js +++ b/src/DataDefinitionsBundle/Resources/public/pimcore/js/interpreters/carbon.js @@ -14,13 +14,13 @@ pimcore.registerNS('pimcore.plugin.datadefinitions.interpreters.carbon'); pimcore.plugin.datadefinitions.interpreters.carbon = Class.create(pimcore.plugin.datadefinitions.interpreters.abstract, { - getLayout : function (fromColumn, toColumn, record, config) { + getLayout: function (fromColumn, toColumn, record, config) { return [{ - xtype : 'textfield', + xtype: 'textfield', fieldLabel: t('date_format'), name: 'date_format', width: 500, - value : config.date_format ? config.date_format : null + value: config.date_format ? config.date_format : null }]; } }); diff --git a/src/DataDefinitionsBundle/Resources/public/pimcore/js/interpreters/import_rule.js b/src/DataDefinitionsBundle/Resources/public/pimcore/js/interpreters/import_rule.js index e434744c..11d7fffc 100644 --- a/src/DataDefinitionsBundle/Resources/public/pimcore/js/interpreters/import_rule.js +++ b/src/DataDefinitionsBundle/Resources/public/pimcore/js/interpreters/import_rule.js @@ -49,7 +49,7 @@ pimcore.plugin.datadefinitions.interpreters.import_rule = Class.create(pimcore.p }); }, - close: function(rules) { + close: function (rules) { this.rules = rules; this.window.destroy(); }, diff --git a/src/DataDefinitionsBundle/Resources/public/pimcore/js/process_manager/export_contextmenu.js b/src/DataDefinitionsBundle/Resources/public/pimcore/js/process_manager/export_contextmenu.js index 28383438..8f62748f 100644 --- a/src/DataDefinitionsBundle/Resources/public/pimcore/js/process_manager/export_contextmenu.js +++ b/src/DataDefinitionsBundle/Resources/public/pimcore/js/process_manager/export_contextmenu.js @@ -1,11 +1,11 @@ pimcore.registerNS("pimcore.plugin.datadefinitions.export.context_menu"); pimcore.plugin.datadefinitions.export.context_menu = Class.create(pimcore.plugin.admin, { - getClassName: function() { + getClassName: function () { return "pimcore.plugin.datadefinitions.export.context_menu"; }, - initialize: function() { + initialize: function () { pimcore.plugin.broker.registerPlugin(this); }, @@ -40,7 +40,7 @@ pimcore.plugin.datadefinitions.export.context_menu = Class.create(pimcore.plugin sortRoot: 'data', autoLoad: true, listeners: { - refresh: function(store) { + refresh: function (store) { var exportMenu = []; store.each(function (executable) { exportMenu.push({ @@ -52,7 +52,7 @@ pimcore.plugin.datadefinitions.export.context_menu = Class.create(pimcore.plugin if (exportMenu) { tree.add([ - { xtype: 'menuseparator' }, + {xtype: 'menuseparator'}, { text: t("data_definitions_processmanager_export_from_here"), iconCls: "pimcore_icon_object pimcore_icon_overlay_download", diff --git a/src/DataDefinitionsBundle/Resources/public/pimcore/js/process_manager/export_search.js b/src/DataDefinitionsBundle/Resources/public/pimcore/js/process_manager/export_search.js index 93d3c975..235a0b4f 100644 --- a/src/DataDefinitionsBundle/Resources/public/pimcore/js/process_manager/export_search.js +++ b/src/DataDefinitionsBundle/Resources/public/pimcore/js/process_manager/export_search.js @@ -21,7 +21,7 @@ pimcore.object.search = Class.create(pimcore.object.search, { ] }); } - + this.exportFromHere = new Ext.SplitButton({ text: t('data_definitions_processmanager_export_from_here'), iconCls: "pimcore_icon_object pimcore_icon_overlay_add", @@ -49,7 +49,7 @@ pimcore.object.search = Class.create(pimcore.object.search, { sortRoot: 'data', autoLoad: true, listeners: { - refresh: function(store) { + refresh: function (store) { var exportMenu = []; store.each(function (executable) { exportMenu.push({ diff --git a/src/DataDefinitionsBundle/Resources/public/pimcore/js/process_manager/import_definitions.js b/src/DataDefinitionsBundle/Resources/public/pimcore/js/process_manager/import_definitions.js index 33ab2cc8..89fbbb89 100644 --- a/src/DataDefinitionsBundle/Resources/public/pimcore/js/process_manager/import_definitions.js +++ b/src/DataDefinitionsBundle/Resources/public/pimcore/js/process_manager/import_definitions.js @@ -11,7 +11,7 @@ * @license https://github.com/w-vision/DataDefinitions/blob/master/gpl-3.0.txt GNU General Public License version 3 (GPLv3) */ -document.addEventListener('processmanager.ready', function() { +document.addEventListener('processmanager.ready', function () { processmanager.executable.types.importdefinition = Class.create(pimcore.plugin.processmanager.executable.abstractType, { getItems: function () { pimcore.globalmanager.get('data_definitions_definitions').load(); diff --git a/src/DataDefinitionsBundle/Rules/Action/ExpressionProcessor.php b/src/DataDefinitionsBundle/Rules/Action/ExpressionProcessor.php index cb3589e2..694cbf6f 100644 --- a/src/DataDefinitionsBundle/Rules/Action/ExpressionProcessor.php +++ b/src/DataDefinitionsBundle/Rules/Action/ExpressionProcessor.php @@ -32,8 +32,13 @@ public function __construct(ExpressionLanguage $expressionLanguage, ContainerInt $this->container = $container; } - public function apply(ImportRuleInterface $rule, Concrete $concrete, $value, array $configuration, array $params = []) - { + public function apply( + ImportRuleInterface $rule, + Concrete $concrete, + $value, + array $configuration, + array $params = [] + ) { $expression = $configuration['expression']; return $this->expressionLanguage->evaluate( diff --git a/src/DataDefinitionsBundle/Rules/Action/ImportRuleProcessorInterface.php b/src/DataDefinitionsBundle/Rules/Action/ImportRuleProcessorInterface.php index c9fb2ec2..74acfe28 100644 --- a/src/DataDefinitionsBundle/Rules/Action/ImportRuleProcessorInterface.php +++ b/src/DataDefinitionsBundle/Rules/Action/ImportRuleProcessorInterface.php @@ -21,5 +21,11 @@ interface ImportRuleProcessorInterface { - public function apply(ImportRuleInterface $rule, Concrete $concrete, $value, array $configuration, array $params = []); + public function apply( + ImportRuleInterface $rule, + Concrete $concrete, + $value, + array $configuration, + array $params = [] + ); } diff --git a/src/DataDefinitionsBundle/Rules/Action/ObjectProcessor.php b/src/DataDefinitionsBundle/Rules/Action/ObjectProcessor.php index 70d9230d..c823f45a 100644 --- a/src/DataDefinitionsBundle/Rules/Action/ObjectProcessor.php +++ b/src/DataDefinitionsBundle/Rules/Action/ObjectProcessor.php @@ -21,8 +21,13 @@ class ObjectProcessor implements ImportRuleProcessorInterface { - public function apply(ImportRuleInterface $rule, Concrete $concrete, $value, array $configuration, array $params = []) - { + public function apply( + ImportRuleInterface $rule, + Concrete $concrete, + $value, + array $configuration, + array $params = [] + ) { $object = Concrete::getById($configuration['object']); if ($object) { diff --git a/src/DataDefinitionsBundle/Rules/Condition/AbstractConditionChecker.php b/src/DataDefinitionsBundle/Rules/Condition/AbstractConditionChecker.php index 7c9055fb..753f306b 100644 --- a/src/DataDefinitionsBundle/Rules/Condition/AbstractConditionChecker.php +++ b/src/DataDefinitionsBundle/Rules/Condition/AbstractConditionChecker.php @@ -25,10 +25,16 @@ abstract class AbstractConditionChecker implements ImportRuleConditionCheckerInterface { - public function isValid(ResourceInterface $subject, RuleInterface $rule, array $configuration, array $params = []): bool - { + public function isValid( + ResourceInterface $subject, + RuleInterface $rule, + array $configuration, + array $params = [] + ): bool { if (!$rule instanceof ImportRuleInterface) { - throw new InvalidArgumentException('Import Rule Condition $subject needs to be instance of ImportRuleInterface'); + throw new InvalidArgumentException( + 'Import Rule Condition $subject needs to be instance of ImportRuleInterface' + ); } Assert::keyExists($params, 'object'); diff --git a/src/DataDefinitionsBundle/Rules/Condition/ExpressionConditionChecker.php b/src/DataDefinitionsBundle/Rules/Condition/ExpressionConditionChecker.php index db056ce8..f326e04c 100644 --- a/src/DataDefinitionsBundle/Rules/Condition/ExpressionConditionChecker.php +++ b/src/DataDefinitionsBundle/Rules/Condition/ExpressionConditionChecker.php @@ -32,8 +32,12 @@ public function __construct(ExpressionLanguage $expressionLanguage, ContainerInt $this->container = $container; } - public function isImportRuleValid(ImportRuleInterface $subject, Concrete $concrete, array $params, array $configuration): bool - { + public function isImportRuleValid( + ImportRuleInterface $subject, + Concrete $concrete, + array $params, + array $configuration + ): bool { $expression = $configuration['expression']; return $this->expressionLanguage->evaluate( diff --git a/src/DataDefinitionsBundle/Rules/Condition/ImportRuleConditionCheckerInterface.php b/src/DataDefinitionsBundle/Rules/Condition/ImportRuleConditionCheckerInterface.php index 5a15eefb..e1b4f58f 100644 --- a/src/DataDefinitionsBundle/Rules/Condition/ImportRuleConditionCheckerInterface.php +++ b/src/DataDefinitionsBundle/Rules/Condition/ImportRuleConditionCheckerInterface.php @@ -22,5 +22,10 @@ interface ImportRuleConditionCheckerInterface extends ConditionCheckerInterface { - public function isImportRuleValid(ImportRuleInterface $subject, Concrete $concrete, array $params, array $configuration): bool; + public function isImportRuleValid( + ImportRuleInterface $subject, + Concrete $concrete, + array $params, + array $configuration + ): bool; } diff --git a/src/DataDefinitionsBundle/Runner/ExportRunnerInterface.php b/src/DataDefinitionsBundle/Runner/ExportRunnerInterface.php index 4fc7a50a..781f987a 100644 --- a/src/DataDefinitionsBundle/Runner/ExportRunnerInterface.php +++ b/src/DataDefinitionsBundle/Runner/ExportRunnerInterface.php @@ -16,12 +16,11 @@ namespace Wvision\Bundle\DataDefinitionsBundle\Runner; -use Pimcore\Model\DataObject\Concrete; -use Wvision\Bundle\DataDefinitionsBundle\Model\ExportDefinitionInterface; +use Wvision\Bundle\DataDefinitionsBundle\Context\RunnerContextInterface; interface ExportRunnerInterface { - public function exportPreRun(Concrete $object, array $data, ExportDefinitionInterface $definition, array $params); + public function exportPreRun(RunnerContextInterface $context); - public function exportPostRun(Concrete $object, array $data, ExportDefinitionInterface $definition, array $params); + public function exportPostRun(RunnerContextInterface $context); } diff --git a/src/DataDefinitionsBundle/Runner/ImportStartFinishRunnerInterface.php b/src/DataDefinitionsBundle/Runner/ImportStartFinishRunnerInterface.php index c2610f35..27aa57b7 100644 --- a/src/DataDefinitionsBundle/Runner/ImportStartFinishRunnerInterface.php +++ b/src/DataDefinitionsBundle/Runner/ImportStartFinishRunnerInterface.php @@ -16,13 +16,11 @@ namespace Wvision\Bundle\DataDefinitionsBundle\Runner; -use Pimcore\Model\DataObject\Concrete; -use Wvision\Bundle\DataDefinitionsBundle\Model\DataDefinitionInterface; -use Wvision\Bundle\DataDefinitionsBundle\Provider\ImportDataSetInterface; +use Wvision\Bundle\DataDefinitionsBundle\Context\RunnerContextInterface; interface ImportStartFinishRunnerInterface { - public function startImport(ImportDataSetInterface $data, DataDefinitionInterface $definition, array $params); + public function startImport(RunnerContextInterface $context); - public function finishImport(ImportDataSetInterface $data, DataDefinitionInterface $definition, array $params); + public function finishImport(RunnerContextInterface $context); } diff --git a/src/DataDefinitionsBundle/Runner/RunnerInterface.php b/src/DataDefinitionsBundle/Runner/RunnerInterface.php index 4dcffc4d..fdf44003 100644 --- a/src/DataDefinitionsBundle/Runner/RunnerInterface.php +++ b/src/DataDefinitionsBundle/Runner/RunnerInterface.php @@ -16,12 +16,11 @@ namespace Wvision\Bundle\DataDefinitionsBundle\Runner; -use Pimcore\Model\DataObject\Concrete; -use Wvision\Bundle\DataDefinitionsBundle\Model\DataDefinitionInterface; +use Wvision\Bundle\DataDefinitionsBundle\Context\RunnerContextInterface; interface RunnerInterface { - public function preRun(Concrete $object, array $data, DataDefinitionInterface $definition, array $params); + public function preRun(RunnerContextInterface $context); - public function postRun(Concrete $object, array $data, DataDefinitionInterface $definition, array $params); + public function postRun(RunnerContextInterface $context); } diff --git a/src/DataDefinitionsBundle/Runner/SaveRunnerInterface.php b/src/DataDefinitionsBundle/Runner/SaveRunnerInterface.php index 38d8181c..831716ee 100644 --- a/src/DataDefinitionsBundle/Runner/SaveRunnerInterface.php +++ b/src/DataDefinitionsBundle/Runner/SaveRunnerInterface.php @@ -16,10 +16,9 @@ namespace Wvision\Bundle\DataDefinitionsBundle\Runner; -use Pimcore\Model\DataObject\Concrete; -use Wvision\Bundle\DataDefinitionsBundle\Model\DataDefinitionInterface; +use Wvision\Bundle\DataDefinitionsBundle\Context\RunnerContextInterface; interface SaveRunnerInterface extends RunnerInterface { - public function shouldSaveObject(Concrete $object, array $data, DataDefinitionInterface $definition, array $params); + public function shouldSaveObject(RunnerContextInterface $context); } diff --git a/src/DataDefinitionsBundle/Service/FieldSelection.php b/src/DataDefinitionsBundle/Service/FieldSelection.php index a067bcb3..8ba08ff6 100644 --- a/src/DataDefinitionsBundle/Service/FieldSelection.php +++ b/src/DataDefinitionsBundle/Service/FieldSelection.php @@ -16,7 +16,6 @@ namespace Wvision\Bundle\DataDefinitionsBundle\Service; -use Exception; use Pimcore\Model\DataObject; use Pimcore\Tool; use Wvision\Bundle\DataDefinitionsBundle\Model\ImportMapping\ToColumn; @@ -138,8 +137,10 @@ public function getClassDefinition(DataObject\ClassDefinition $class): array $allowedGroupIds = $field->getAllowedGroupIds(); if ($allowedGroupIds) { - $list->setCondition('ID in ('.implode(',', $allowedGroupIds).') AND storeId = ?', - [$field->getStoreId()]); + $list->setCondition( + 'ID in ('.implode(',', $allowedGroupIds).') AND storeId = ?', + [$field->getStoreId()] + ); } else { $list->setCondition('storeId = ?', [$field->getStoreId()]); } diff --git a/src/DataDefinitionsBundle/Setter/ClassificationStoreFieldGetter.php b/src/DataDefinitionsBundle/Setter/ClassificationStoreFieldGetter.php index cad06b80..ca72a938 100644 --- a/src/DataDefinitionsBundle/Setter/ClassificationStoreFieldGetter.php +++ b/src/DataDefinitionsBundle/Setter/ClassificationStoreFieldGetter.php @@ -18,19 +18,18 @@ use Pimcore\Model\DataObject; use Pimcore\Model\DataObject\Classificationstore; -use Pimcore\Model\DataObject\Concrete; use Pimcore\Tool; +use Wvision\Bundle\DataDefinitionsBundle\Context\GetterContextInterface; use Wvision\Bundle\DataDefinitionsBundle\Getter\GetterInterface; -use Wvision\Bundle\DataDefinitionsBundle\Model\ExportMapping; class ClassificationStoreFieldGetter implements GetterInterface { - public function get(Concrete $object, ExportMapping $map, $data) + public function get(GetterContextInterface $context) { - $classificationStoreGetter = sprintf('get%s', ucfirst($map->getFromColumn())); + $classificationStoreGetter = sprintf('get%s', ucfirst($context->getMapping()->getFromColumn())); - if (method_exists($object, $classificationStoreGetter)) { - $classificationStore = $object->$classificationStoreGetter(); + if (method_exists($context->getObject(), $classificationStoreGetter)) { + $classificationStore = $context->getObject()->$classificationStoreGetter(); if ($classificationStore instanceof Classificationstore) { $groups = $classificationStore->getActiveGroups(); @@ -48,8 +47,11 @@ public function get(Concrete $object, ExportMapping $map, $data) $keyConfig = DataObject\Classificationstore\KeyConfig::getById($keyRelation->getKeyId()); foreach (Tool::getValidLanguages() as $language) { - $value = $classificationStore->getLocalizedKeyValue($groupId, $keyConfig->getId(), - $language); + $value = $classificationStore->getLocalizedKeyValue( + $groupId, + $keyConfig->getId(), + $language + ); if (is_null($value)) { continue; diff --git a/src/DataDefinitionsBundle/Setter/ClassificationStoreSetter.php b/src/DataDefinitionsBundle/Setter/ClassificationStoreSetter.php index fff2b192..eb9729fe 100644 --- a/src/DataDefinitionsBundle/Setter/ClassificationStoreSetter.php +++ b/src/DataDefinitionsBundle/Setter/ClassificationStoreSetter.php @@ -17,24 +17,23 @@ namespace Wvision\Bundle\DataDefinitionsBundle\Setter; use Pimcore\Model\DataObject\Classificationstore; -use Pimcore\Model\DataObject\Concrete; +use Wvision\Bundle\DataDefinitionsBundle\Context\GetterContextInterface; +use Wvision\Bundle\DataDefinitionsBundle\Context\SetterContextInterface; use Wvision\Bundle\DataDefinitionsBundle\Getter\GetterInterface; -use Wvision\Bundle\DataDefinitionsBundle\Model\ExportMapping; -use Wvision\Bundle\DataDefinitionsBundle\Model\ImportMapping; class ClassificationStoreSetter implements SetterInterface, GetterInterface { - public function set(Concrete $object, $value, ImportMapping $map, $data): void + public function set(SetterContextInterface $context): void { - $mapConfig = $map->getSetterConfig(); + $mapConfig = $context->getImportMapping()->getSetterConfig(); $fieldName = $mapConfig['field']; $keyConfig = (int)$mapConfig['keyConfig']; $groupConfig = (int)$mapConfig['groupConfig']; $classificationStoreGetter = sprintf('get%s', ucfirst($fieldName)); - if (method_exists($object, $classificationStoreGetter)) { - $classificationStore = $object->$classificationStoreGetter(); + if (method_exists($context->getObject(), $classificationStoreGetter)) { + $classificationStore = $context->getObject()->$classificationStoreGetter(); if ($classificationStore instanceof Classificationstore) { $groups = $classificationStore->getActiveGroups(); @@ -44,22 +43,22 @@ public function set(Concrete $object, $value, ImportMapping $map, $data): void $classificationStore->setActiveGroups($groups); } - $classificationStore->setLocalizedKeyValue($groupConfig, $keyConfig, $value); + $classificationStore->setLocalizedKeyValue($groupConfig, $keyConfig, $context->getValue()); } } } - public function get(Concrete $object, ExportMapping $map, $data) + public function get(GetterContextInterface $context) { - $mapConfig = $map->getGetterConfig(); + $mapConfig = $context->getMapping()->getGetterConfig(); $fieldName = $mapConfig['field']; $keyConfig = (int)$mapConfig['keyConfig']; $groupConfig = (int)$mapConfig['groupConfig']; $classificationStoreGetter = sprintf('get%s', ucfirst($fieldName)); - if (method_exists($object, $classificationStoreGetter)) { - $classificationStore = $object->$classificationStoreGetter(); + if (method_exists($context->getObject(), $classificationStoreGetter)) { + $classificationStore = $context->getObject()->$classificationStoreGetter(); if ($classificationStore instanceof Classificationstore) { $groups = $classificationStore->getActiveGroups(); diff --git a/src/DataDefinitionsBundle/Setter/CoreShop/StorePriceSetter.php b/src/DataDefinitionsBundle/Setter/CoreShop/StorePriceSetter.php index 7872748e..db954b10 100644 --- a/src/DataDefinitionsBundle/Setter/CoreShop/StorePriceSetter.php +++ b/src/DataDefinitionsBundle/Setter/CoreShop/StorePriceSetter.php @@ -19,10 +19,9 @@ use CoreShop\Component\Core\Model\StoreInterface; use CoreShop\Component\Store\Repository\StoreRepositoryInterface; use InvalidArgumentException; -use Pimcore\Model\DataObject\Concrete; +use Wvision\Bundle\DataDefinitionsBundle\Context\GetterContextInterface; +use Wvision\Bundle\DataDefinitionsBundle\Context\SetterContextInterface; use Wvision\Bundle\DataDefinitionsBundle\Getter\GetterInterface; -use Wvision\Bundle\DataDefinitionsBundle\Model\ExportMapping; -use Wvision\Bundle\DataDefinitionsBundle\Model\ImportMapping; use Wvision\Bundle\DataDefinitionsBundle\Setter\SetterInterface; use function is_array; @@ -35,9 +34,9 @@ public function __construct(StoreRepositoryInterface $storeRepository) $this->storeRepository = $storeRepository; } - public function set(Concrete $object, $value, ImportMapping $map, $data) + public function set(SetterContextInterface $context) { - $config = $map->getSetterConfig(); + $config = $context->getImportMapping()->getSetterConfig(); if (!array_key_exists('stores', $config) || !is_array($config['stores'])) { return; @@ -50,19 +49,19 @@ public function set(Concrete $object, $value, ImportMapping $map, $data) throw new InvalidArgumentException(sprintf('Store with ID %s not found', $config['store'])); } - $setter = sprintf('set%s', ucfirst($map->getToColumn())); + $setter = sprintf('set%s', ucfirst($context->getImportMapping()->getToColumn())); - if (!method_exists($object, $setter)) { + if (!method_exists($context->getObject(), $setter)) { throw new InvalidArgumentException(sprintf('Expected a %s function but can not find it', $setter)); } - $object->$setter($value, $store); + $context->getObject()->$setter($context->getValue(), $store); } } - public function get(Concrete $object, ExportMapping $map, $data) + public function get(GetterContextInterface $context) { - $config = $map->getGetterConfig(); + $config = $context->getMapping()->getGetterConfig(); if (!array_key_exists('stores', $config) || !is_array($config['stores'])) { return []; @@ -77,13 +76,13 @@ public function get(Concrete $object, ExportMapping $map, $data) throw new InvalidArgumentException(sprintf('Store with ID %s not found', $config['store'])); } - $getter = sprintf('get%s', ucfirst($map->getFromColumn())); + $getter = sprintf('get%s', ucfirst($context->getMapping()->getFromColumn())); - if (!method_exists($object, $getter)) { + if (!method_exists($context->getObject(), $getter)) { throw new InvalidArgumentException(sprintf('Expected a %s function but can not find it', $getter)); } - $values[$store->getId()] = $object->$getter($store); + $values[$store->getId()] = $context->getObject()->$getter($store); } return $values; diff --git a/src/DataDefinitionsBundle/Setter/CoreShop/StoreValuesSetter.php b/src/DataDefinitionsBundle/Setter/CoreShop/StoreValuesSetter.php index 3ed28c76..ef54efcd 100644 --- a/src/DataDefinitionsBundle/Setter/CoreShop/StoreValuesSetter.php +++ b/src/DataDefinitionsBundle/Setter/CoreShop/StoreValuesSetter.php @@ -19,10 +19,9 @@ use CoreShop\Component\Core\Model\StoreInterface; use CoreShop\Component\Store\Repository\StoreRepositoryInterface; use InvalidArgumentException; -use Pimcore\Model\DataObject\Concrete; +use Wvision\Bundle\DataDefinitionsBundle\Context\GetterContextInterface; +use Wvision\Bundle\DataDefinitionsBundle\Context\SetterContextInterface; use Wvision\Bundle\DataDefinitionsBundle\Getter\GetterInterface; -use Wvision\Bundle\DataDefinitionsBundle\Model\ExportMapping; -use Wvision\Bundle\DataDefinitionsBundle\Model\ImportMapping; use Wvision\Bundle\DataDefinitionsBundle\Setter\SetterInterface; use function is_array; @@ -35,9 +34,9 @@ public function __construct(StoreRepositoryInterface $storeRepository) $this->storeRepository = $storeRepository; } - public function set(Concrete $object, $value, ImportMapping $map, $data) + public function set(SetterContextInterface $context) { - $config = $map->getSetterConfig(); + $config = $context->getImportMapping()->getSetterConfig(); if (!array_key_exists('stores', $config) || !is_array($config['stores'])) { return; @@ -50,19 +49,19 @@ public function set(Concrete $object, $value, ImportMapping $map, $data) throw new InvalidArgumentException(sprintf('Store with ID %s not found', $config['store'])); } - $setter = sprintf('set%sOfType', ucfirst($map->getToColumn())); + $setter = sprintf('set%sOfType', ucfirst($context->getImportMapping()->getToColumn())); - if (!method_exists($object, $setter)) { + if (!method_exists($context->getObject(), $setter)) { throw new InvalidArgumentException(sprintf('Expected a %s function but can not find it', $setter)); } - $object->$setter($config['type'], $value, $store); + $context->getObject()->$setter($config['type'], $context->getValue(), $store); } } - public function get(Concrete $object, ExportMapping $map, $data) + public function get(GetterContextInterface $context) { - $config = $map->getGetterConfig(); + $config = $context->getMapping()->getGetterConfig(); if (!array_key_exists('stores', $config) || !is_array($config['stores'])) { return []; @@ -77,13 +76,13 @@ public function get(Concrete $object, ExportMapping $map, $data) throw new InvalidArgumentException(sprintf('Store with ID %s not found', $config['store'])); } - $getter = sprintf('get%sOfType', ucfirst($map->getFromColumn())); + $getter = sprintf('get%sOfType', ucfirst($context->getMapping()->getFromColumn())); - if (!method_exists($object, $getter)) { + if (!method_exists($context->getObject(), $getter)) { throw new InvalidArgumentException(sprintf('Expected a %s function but can not find it', $getter)); } - $values[$store->getId()] = $object->$getter($config['type'], $store); + $values[$store->getId()] = $context->getObject()->$getter($config['type'], $store); } return $values; diff --git a/src/DataDefinitionsBundle/Setter/FieldCollectionSetter.php b/src/DataDefinitionsBundle/Setter/FieldCollectionSetter.php index ca49c52f..56593fa0 100644 --- a/src/DataDefinitionsBundle/Setter/FieldCollectionSetter.php +++ b/src/DataDefinitionsBundle/Setter/FieldCollectionSetter.php @@ -16,26 +16,24 @@ namespace Wvision\Bundle\DataDefinitionsBundle\Setter; -use Exception; -use Pimcore\Model\DataObject\Concrete; use Pimcore\Model\DataObject\Fieldcollection; use Pimcore\Model\DataObject\Fieldcollection\Data\AbstractData as AbstractFieldCollection; +use Wvision\Bundle\DataDefinitionsBundle\Context\GetterContextInterface; +use Wvision\Bundle\DataDefinitionsBundle\Context\SetterContextInterface; use Wvision\Bundle\DataDefinitionsBundle\Getter\GetterInterface; -use Wvision\Bundle\DataDefinitionsBundle\Model\ExportMapping; -use Wvision\Bundle\DataDefinitionsBundle\Model\ImportMapping; class FieldCollectionSetter implements SetterInterface, GetterInterface { - public function set(Concrete $object, $value, ImportMapping $map, $data): void + public function set(SetterContextInterface $context): void { - $keyParts = explode('~', $map->getToColumn()); + $keyParts = explode('~', $context->getImportMapping()->getToColumn()); - $config = $map->getSetterConfig(); + $config = $context->getImportMapping()->getSetterConfig(); $keys = $config['keys']; $fieldName = $config['field']; $class = $config['class']; $keys = explode(',', $keys); - $fieldCollectionClass = 'Pimcore\Model\DataObject\Fieldcollection\Data\\' . ucfirst($class); + $fieldCollectionClass = 'Pimcore\Model\DataObject\Fieldcollection\Data\\'.ucfirst($class); $field = $keyParts[3]; $mappedKeys = []; @@ -51,8 +49,8 @@ public function set(Concrete $object, $value, ImportMapping $map, $data): void $getter = sprintf('get%s', ucfirst($fieldName)); $setter = sprintf('set%s', ucfirst($fieldName)); - if (method_exists($object, $getter)) { - $fieldCollection = $object->$getter(); + if (method_exists($context->getObject(), $getter)) { + $fieldCollection = $context->getObject()->$getter(); if (!$fieldCollection instanceof Fieldcollection) { $fieldCollection = new Fieldcollection(); @@ -62,9 +60,13 @@ public function set(Concrete $object, $value, ImportMapping $map, $data): void $found = false; foreach ($items as $item) { - if (is_a($item, $fieldCollectionClass) && $this->isValidKey($mappedKeys, $item, $data)) { + if (is_a($item, $fieldCollectionClass) && $this->isValidKey( + $mappedKeys, + $item, + $context->getDataRow() + )) { if ($item instanceof AbstractFieldCollection) { - $item->setValue($field, $value); + $item->setValue($field, $context->getValue()); } $found = true; @@ -77,24 +79,24 @@ public function set(Concrete $object, $value, ImportMapping $map, $data): void if ($item instanceof AbstractFieldCollection) { foreach ($mappedKeys as $key) { - $item->setValue($key['to'], $data[$key['from']]); + $item->setValue($key['to'], $context->getDataRow()[$key['from']]); } - $item->setValue($field, $value); + $item->setValue($field, $context->getValue()); $fieldCollection->add($item); } } - $object->$setter($fieldCollection); + $context->getObject()->$setter($fieldCollection); } } - public function get(Concrete $object, ExportMapping $map, $data) + public function get(GetterContextInterface $context) { - $keyParts = explode('~', $map->getFromColumn()); + $keyParts = explode('~', $context->getMapping()->getFromColumn()); - $config = $map->getGetterConfig(); + $config = $context->getMapping()->getGetterConfig(); $fieldName = $config['field']; $class = $config['class']; $fieldCollectionClass = 'Pimcore\Model\DataObject\Fieldcollection\Data\\'.ucfirst($class); @@ -102,8 +104,8 @@ public function get(Concrete $object, ExportMapping $map, $data) $getter = sprintf('get%s', ucfirst($fieldName)); - if (method_exists($object, $getter)) { - $fieldCollection = $object->$getter(); + if (method_exists($context->getObject(), $getter)) { + $fieldCollection = $context->getObject()->$getter(); if (!$fieldCollection instanceof Fieldcollection) { return null; diff --git a/src/DataDefinitionsBundle/Setter/KeySetter.php b/src/DataDefinitionsBundle/Setter/KeySetter.php index 4a7cb05c..1b95cdca 100644 --- a/src/DataDefinitionsBundle/Setter/KeySetter.php +++ b/src/DataDefinitionsBundle/Setter/KeySetter.php @@ -17,19 +17,18 @@ namespace Wvision\Bundle\DataDefinitionsBundle\Setter; use Pimcore\Model\DataObject; -use Pimcore\Model\DataObject\Concrete; -use Wvision\Bundle\DataDefinitionsBundle\Model\ImportMapping; +use Wvision\Bundle\DataDefinitionsBundle\Context\SetterContextInterface; class KeySetter implements SetterInterface { - public function set(Concrete $object, $value, ImportMapping $map, $data): void + public function set(SetterContextInterface $context): void { - $setter = explode('~', $map->getToColumn()); + $setter = explode('~', $context->getImportMapping()->getToColumn()); $setter = preg_replace('/^o_/', '', $setter[0]); $setter = sprintf('set%s', ucfirst($setter)); - if (method_exists($object, $setter)) { - $object->$setter(DataObject\Service::getValidKey($value, "object")); + if (method_exists($context->getObject(), $setter)) { + $context->getObject()->$setter(DataObject\Service::getValidKey($context->getValue(), "object")); } } } diff --git a/src/DataDefinitionsBundle/Setter/LocalizedfieldSetter.php b/src/DataDefinitionsBundle/Setter/LocalizedfieldSetter.php index 98ddddfb..d41287a7 100644 --- a/src/DataDefinitionsBundle/Setter/LocalizedfieldSetter.php +++ b/src/DataDefinitionsBundle/Setter/LocalizedfieldSetter.php @@ -16,34 +16,33 @@ namespace Wvision\Bundle\DataDefinitionsBundle\Setter; -use Pimcore\Model\DataObject\Concrete; +use Wvision\Bundle\DataDefinitionsBundle\Context\GetterContextInterface; +use Wvision\Bundle\DataDefinitionsBundle\Context\SetterContextInterface; use Wvision\Bundle\DataDefinitionsBundle\Getter\GetterInterface; -use Wvision\Bundle\DataDefinitionsBundle\Model\ExportMapping; -use Wvision\Bundle\DataDefinitionsBundle\Model\ImportMapping; class LocalizedfieldSetter implements SetterInterface, GetterInterface { - public function set(Concrete $object, $value, ImportMapping $map, $data): void + public function set(SetterContextInterface $context): void { - $config = $map->getSetterConfig(); + $config = $context->getImportMapping()->getSetterConfig(); - $setter = explode('~', $map->getToColumn()); + $setter = explode('~', $context->getImportMapping()->getToColumn()); $setter = sprintf('set%s', ucfirst($setter[0])); - if (method_exists($object, $setter)) { - $object->$setter($value, $config['language']); + if (method_exists($context->getObject(), $setter)) { + $context->getObject()->$setter($context->getValue(), $config['language']); } } - public function get(Concrete $object, ExportMapping $map, $data) + public function get(GetterContextInterface $context) { - $config = $map->getGetterConfig(); + $config = $context->getMapping()->getGetterConfig(); - $getter = explode('~', $map->getFromColumn()); + $getter = explode('~', $context->getMapping()->getFromColumn()); $getter = sprintf('get%s', ucfirst($getter[0])); - if (method_exists($object, $getter)) { - return $object->$getter($config['language']); + if (method_exists($context->getObject(), $getter)) { + return $context->getObject()->$getter($config['language']); } return null; diff --git a/src/DataDefinitionsBundle/Setter/ObjectTypeSetter.php b/src/DataDefinitionsBundle/Setter/ObjectTypeSetter.php index ef9bee12..95335c52 100644 --- a/src/DataDefinitionsBundle/Setter/ObjectTypeSetter.php +++ b/src/DataDefinitionsBundle/Setter/ObjectTypeSetter.php @@ -17,25 +17,25 @@ namespace Wvision\Bundle\DataDefinitionsBundle\Setter; use Pimcore\Model\DataObject\Concrete; -use Wvision\Bundle\DataDefinitionsBundle\Model\ImportMapping; +use Wvision\Bundle\DataDefinitionsBundle\Context\SetterContextInterface; class ObjectTypeSetter implements SetterInterface { - public function set(Concrete $object, $value, ImportMapping $map, $data) + public function set(SetterContextInterface $context) { - if ($value === Concrete::OBJECT_TYPE_FOLDER) { - $object->setType(Concrete::OBJECT_TYPE_FOLDER); + if ($context->getValue() === Concrete::OBJECT_TYPE_FOLDER) { + $context->getObject()->setType(Concrete::OBJECT_TYPE_FOLDER); return; } - if ($value === Concrete::OBJECT_TYPE_VARIANT) { - $object->setType(Concrete::OBJECT_TYPE_VARIANT); + if ($context->getValue() === Concrete::OBJECT_TYPE_VARIANT) { + $context->getObject()->setType(Concrete::OBJECT_TYPE_VARIANT); return; } - $object->setType(Concrete::OBJECT_TYPE_OBJECT); + $context->getObject()->setType(Concrete::OBJECT_TYPE_OBJECT); } } diff --git a/src/DataDefinitionsBundle/Setter/ObjectbrickSetter.php b/src/DataDefinitionsBundle/Setter/ObjectbrickSetter.php index 45ffe440..e0acf912 100644 --- a/src/DataDefinitionsBundle/Setter/ObjectbrickSetter.php +++ b/src/DataDefinitionsBundle/Setter/ObjectbrickSetter.php @@ -16,21 +16,19 @@ namespace Wvision\Bundle\DataDefinitionsBundle\Setter; -use Pimcore\Model\DataObject\Concrete; use Pimcore\Model\DataObject\Objectbrick; use Pimcore\Model\DataObject\Objectbrick\Data\AbstractData; +use Wvision\Bundle\DataDefinitionsBundle\Context\GetterContextInterface; +use Wvision\Bundle\DataDefinitionsBundle\Context\SetterContextInterface; use Wvision\Bundle\DataDefinitionsBundle\Getter\GetterInterface; -use Wvision\Bundle\DataDefinitionsBundle\Model\ExportMapping; -use Wvision\Bundle\DataDefinitionsBundle\Model\ImportMapping; -use Wvision\Bundle\DataDefinitionsBundle\Model\MappingInterface; class ObjectbrickSetter implements SetterInterface, GetterInterface { - public function set(Concrete $object, $value, ImportMapping $map, $data) + public function set(SetterContextInterface $context) { - $keyParts = explode('~', $map->getToColumn()); + $keyParts = explode('~', $context->getImportMapping()->getToColumn()); - $config = $map->getSetterConfig(); + $config = $context->getImportMapping()->getSetterConfig(); $fieldName = $config['brickField']; $class = $config['class']; $brickField = $keyParts[3]; @@ -38,12 +36,12 @@ public function set(Concrete $object, $value, ImportMapping $map, $data) $brickGetter = sprintf('get%s', ucfirst($fieldName)); $brickSetter = sprintf('set%s', ucfirst($fieldName)); - if (method_exists($object, $brickGetter)) { - $brick = $object->$brickGetter(); + if (method_exists($context->getObject(), $brickGetter)) { + $brick = $context->getObject()->$brickGetter(); if (!$brick instanceof Objectbrick) { - $brick = new Objectbrick($object, $fieldName); - $object->$brickSetter($brick); + $brick = new Objectbrick($context->getObject(), $fieldName); + $context->getObject()->$brickSetter($brick); } if ($brick instanceof Objectbrick) { @@ -55,7 +53,7 @@ public function set(Concrete $object, $value, ImportMapping $map, $data) if (!$brickFieldObject instanceof AbstractData) { $brickFieldObjectClass = 'Pimcore\Model\DataObject\Objectbrick\Data\\'.$class; - $brickFieldObject = new $brickFieldObjectClass($object); + $brickFieldObject = new $brickFieldObjectClass($context->getObject()); $brick->$brickClassSetter($brickFieldObject); } @@ -63,25 +61,25 @@ public function set(Concrete $object, $value, ImportMapping $map, $data) $setter = sprintf('set%s', ucfirst($brickField)); if (method_exists($brickFieldObject, $setter)) { - $brickFieldObject->$setter($value); + $brickFieldObject->$setter($context->getValue()); } } } } - public function get(Concrete $object, ExportMapping $map, $data) + public function get(GetterContextInterface $context) { - $keyParts = explode('~', $map->getFromColumn()); + $keyParts = explode('~', $context->getMapping()->getFromColumn()); - $config = $map->getGetterConfig(); + $config = $context->getMapping()->getGetterConfig(); $fieldName = $config['brickField']; $class = $config['class']; $brickField = $keyParts[3]; $brickGetter = sprintf('get%s', ucfirst($fieldName)); - if (method_exists($object, $brickGetter)) { - $brick = $object->$brickGetter(); + if (method_exists($context->getObject(), $brickGetter)) { + $brick = $context->getObject()->$brickGetter(); if (!$brick instanceof Objectbrick) { return; @@ -95,7 +93,7 @@ public function get(Concrete $object, ExportMapping $map, $data) if (!$brickFieldObject instanceof AbstractData) { $brickFieldObjectClass = 'Pimcore\Model\DataObject\Objectbrick\Data\\'.$class; - $brickFieldObject = new $brickFieldObjectClass($object); + $brickFieldObject = new $brickFieldObjectClass($context->getObject()); $brick->$brickClassSetter($brickFieldObject); } diff --git a/src/DataDefinitionsBundle/Setter/RelationSetter.php b/src/DataDefinitionsBundle/Setter/RelationSetter.php index ff409848..d88480a7 100644 --- a/src/DataDefinitionsBundle/Setter/RelationSetter.php +++ b/src/DataDefinitionsBundle/Setter/RelationSetter.php @@ -16,18 +16,17 @@ namespace Wvision\Bundle\DataDefinitionsBundle\Setter; -use Pimcore\Model\DataObject\Concrete; -use Wvision\Bundle\DataDefinitionsBundle\Model\ImportMapping; +use Wvision\Bundle\DataDefinitionsBundle\Context\SetterContextInterface; class RelationSetter implements SetterInterface { - public function set(Concrete $object, $value, ImportMapping $map, $data): void + public function set(SetterContextInterface $context): void { - $fieldName = $map->getToColumn(); + $fieldName = $context->getImportMapping()->getToColumn(); $getter = sprintf('get%s', ucfirst($fieldName)); $setter = sprintf('set%s', ucfirst($fieldName)); - $existingElements = $object->$getter(); + $existingElements = $context->getObject()->$getter(); if (!is_array($existingElements)) { $existingElements = []; } @@ -38,6 +37,7 @@ public function set(Concrete $object, $value, ImportMapping $map, $data): void $existingKeys[] = (string)$existingElement; } + $value = $context->getValue(); if (!is_iterable($value)) { $value = [$value]; @@ -51,6 +51,6 @@ public function set(Concrete $object, $value, ImportMapping $map, $data): void } } - $object->$setter($existingElements); + $context->getObject()->$setter($existingElements); } } diff --git a/src/DataDefinitionsBundle/Setter/SetterInterface.php b/src/DataDefinitionsBundle/Setter/SetterInterface.php index 1cec7bd4..9b19b17e 100644 --- a/src/DataDefinitionsBundle/Setter/SetterInterface.php +++ b/src/DataDefinitionsBundle/Setter/SetterInterface.php @@ -16,10 +16,9 @@ namespace Wvision\Bundle\DataDefinitionsBundle\Setter; -use Pimcore\Model\DataObject\Concrete; -use Wvision\Bundle\DataDefinitionsBundle\Model\ImportMapping; +use Wvision\Bundle\DataDefinitionsBundle\Context\SetterContextInterface; interface SetterInterface { - public function set(Concrete $object, $value, ImportMapping $map, array $data); + public function set(SetterContextInterface $context); } diff --git a/tests/DataDefinitionsBundle/Behat/Service/Filter/SimpleFilter.php b/tests/DataDefinitionsBundle/Behat/Service/Filter/SimpleFilter.php index e4c3bbea..c28eee64 100644 --- a/tests/DataDefinitionsBundle/Behat/Service/Filter/SimpleFilter.php +++ b/tests/DataDefinitionsBundle/Behat/Service/Filter/SimpleFilter.php @@ -3,13 +3,14 @@ namespace Wvision\Bundle\DataDefinitionsBundle\Behat\Service\Filter; use Pimcore\Model\DataObject\Concrete; +use Wvision\Bundle\DataDefinitionsBundle\Context\FilterContextInterface; use Wvision\Bundle\DataDefinitionsBundle\Filter\FilterInterface; use Wvision\Bundle\DataDefinitionsBundle\Model\DataDefinitionInterface; class SimpleFilter implements FilterInterface { - public function filter(DataDefinitionInterface $definition, array $data, Concrete $object, array $params): bool + public function filter(FilterContextInterface $context): bool { - return $data['doFilter'] !== '1'; + return $context->getDataRow()['doFilter'] !== '1'; } } From b2bc2c62b1ab734edd26fbe09ba837eb93e13a68 Mon Sep 17 00:00:00 2001 From: Dominik Pfaffenbauer Date: Fri, 15 Jul 2022 10:29:26 +0200 Subject: [PATCH 27/65] allow to read import files from all storages --- .../Provider/AbstractFileProvider.php | 55 ++++++++++++++++++- .../Resources/config/services.yml | 16 ++++++ .../Service/StorageLocator.php | 35 ++++++++++++ 3 files changed, 105 insertions(+), 1 deletion(-) create mode 100644 src/DataDefinitionsBundle/Service/StorageLocator.php diff --git a/src/DataDefinitionsBundle/Provider/AbstractFileProvider.php b/src/DataDefinitionsBundle/Provider/AbstractFileProvider.php index d8e198ce..4677cb00 100644 --- a/src/DataDefinitionsBundle/Provider/AbstractFileProvider.php +++ b/src/DataDefinitionsBundle/Provider/AbstractFileProvider.php @@ -16,10 +16,20 @@ namespace Wvision\Bundle\DataDefinitionsBundle\Provider; +use Pimcore\File; +use Pimcore\Helper\LongRunningHelper; use Pimcore\Model\Asset; +use Wvision\Bundle\DataDefinitionsBundle\Service\StorageLocator; abstract class AbstractFileProvider { + public function __construct( + protected StorageLocator $storageLocator, + protected LongRunningHelper $longRunningHelper, + ) + { + } + protected function getFile(array $params): string { // if (!str_starts_with($file, '/')) { @@ -29,7 +39,21 @@ protected function getFile(array $params): string if (isset($params['asset'])) { $asset = Asset::getByPath($params['asset']); - return $asset->getTemporaryFile(); + if (!$asset) { + throw new \RuntimeException(sprintf('Asset "%s" not found', $params['asset'])); + } + + return $this->createTemporaryFileFromStream($asset->getStream()); + } + + if (isset($params['storage'], $params['file'])) { + $storage = $this->storageLocator->getStorage($params['storage']); + + if (!$storage->fileExists($params['file'])) { + throw new \RuntimeException(sprintf('File "%s" in Storage "%s" not found', $params['file'], $params['storage'])); + } + + return $this->createTemporaryFileFromStream($storage->readStream($params['file'])); } if (isset($params['file'])) { @@ -38,4 +62,33 @@ protected function getFile(array $params): string throw new \RuntimeException('No file or asset given'); } + + protected function createTemporaryFileFromStream($stream) + { + if (is_string($stream)) { + $src = fopen($stream, 'rb'); + $fileExtension = File::getFileExtension($stream); + } else { + $src = $stream; + $streamMeta = stream_get_meta_data($src); + $fileExtension = File::getFileExtension($streamMeta['uri']); + } + + $tmpFilePath = File::getLocalTempFilePath($fileExtension); + + $dest = fopen($tmpFilePath, 'wb', false, File::getContext()); + if (!$dest) { + throw new \Exception(sprintf('Unable to create temporary file in %s', $tmpFilePath)); + } + + stream_copy_to_stream($src, $dest); + fclose($dest); + + $this->longRunningHelper->addTmpFilePath($tmpFilePath); + register_shutdown_function(static function () use ($tmpFilePath) { + @unlink($tmpFilePath); + }); + + return $tmpFilePath; + } } diff --git a/src/DataDefinitionsBundle/Resources/config/services.yml b/src/DataDefinitionsBundle/Resources/config/services.yml index ee74ed39..10c853c4 100644 --- a/src/DataDefinitionsBundle/Resources/config/services.yml +++ b/src/DataDefinitionsBundle/Resources/config/services.yml @@ -271,16 +271,25 @@ services: ### PROVIDER Wvision\Bundle\DataDefinitionsBundle\Provider\CsvProvider: + arguments: + - '@Wvision\Bundle\DataDefinitionsBundle\Service\StorageLocator' + - '@Pimcore\Helper\LongRunningHelper' tags: - { name: data_definitions.import_provider, type: csv, form-type: Wvision\Bundle\DataDefinitionsBundle\Form\Type\ImportProvider\CsvProviderType } - { name: data_definitions.export_provider, type: csv, form-type: Wvision\Bundle\DataDefinitionsBundle\Form\Type\ExportProvider\CsvProviderType } Wvision\Bundle\DataDefinitionsBundle\Provider\ExcelProvider: + arguments: + - '@Wvision\Bundle\DataDefinitionsBundle\Service\StorageLocator' + - '@Pimcore\Helper\LongRunningHelper' tags: - { name: data_definitions.import_provider, type: excel, form-type: Wvision\Bundle\DataDefinitionsBundle\Form\Type\ImportProvider\ExcelProviderType } - { name: data_definitions.export_provider, type: excel, form-type: Wvision\Bundle\DataDefinitionsBundle\Form\Type\NoConfigurationType } Wvision\Bundle\DataDefinitionsBundle\Provider\JsonProvider: + arguments: + - '@Wvision\Bundle\DataDefinitionsBundle\Service\StorageLocator' + - '@Pimcore\Helper\LongRunningHelper' tags: - { name: data_definitions.import_provider, type: json, form-type: Wvision\Bundle\DataDefinitionsBundle\Form\Type\ImportProvider\JsonProviderType } - { name: data_definitions.export_provider, type: json, form-type: Wvision\Bundle\DataDefinitionsBundle\Form\Type\NoConfigurationType } @@ -296,6 +305,9 @@ services: - { name: data_definitions.import_provider, type: sql, form-type: Wvision\Bundle\DataDefinitionsBundle\Form\Type\ImportProvider\SqlProviderType } Wvision\Bundle\DataDefinitionsBundle\Provider\XmlProvider: + arguments: + - '@Wvision\Bundle\DataDefinitionsBundle\Service\StorageLocator' + - '@Pimcore\Helper\LongRunningHelper' tags: - { name: data_definitions.import_provider, type: xml, form-type: Wvision\Bundle\DataDefinitionsBundle\Form\Type\ImportProvider\XmlProviderType } - { name: data_definitions.export_provider, type: xml, form-type: Wvision\Bundle\DataDefinitionsBundle\Form\Type\ExportProvider\XmlProviderType } @@ -358,3 +370,7 @@ services: Wvision\Bundle\DataDefinitionsBundle\Persister\Persister: tags: - { name: data_definitions.persister, type: persister } + + Wvision\Bundle\DataDefinitionsBundle\Service\StorageLocator: + arguments: + $locator: !tagged_locator { tag: flysystem.storage } \ No newline at end of file diff --git a/src/DataDefinitionsBundle/Service/StorageLocator.php b/src/DataDefinitionsBundle/Service/StorageLocator.php new file mode 100644 index 00000000..851611c8 --- /dev/null +++ b/src/DataDefinitionsBundle/Service/StorageLocator.php @@ -0,0 +1,35 @@ +locator = $locator; + } + + public function getStorage(string $name): FilesystemOperator + { + return $this->locator->get($name); + } +} From 13871e5467fbb06cda53607992c08ad92718fc59 Mon Sep 17 00:00:00 2001 From: Dominik Pfaffenbauer Date: Tue, 19 Jul 2022 13:09:44 +0200 Subject: [PATCH 28/65] add config to context add basic context rename setter to mapping --- src/DataDefinitionsBundle/Context/Context.php | 57 ++++++++ .../Context/ContextFactory.php | 26 ++-- .../Context/ContextFactoryInterface.php | 12 +- .../Context/ContextInterface.php | 30 ++++ .../Context/FetcherContext.php | 18 +-- .../Context/FetcherContextInterface.php | 4 +- .../Context/FilterContext.php | 18 +-- .../Context/FilterContextInterface.php | 6 +- .../Context/GetterContext.php | 18 +-- .../Context/GetterContextInterface.php | 6 +- .../Context/InterpreterContext.php | 18 +-- .../Context/InterpreterContextInterface.php | 7 +- .../Context/LoaderContext.php | 18 +-- .../Context/LoaderContextInterface.php | 4 +- .../Context/RunnerContext.php | 18 +-- .../Context/RunnerContextInterface.php | 6 +- .../Context/SetterContext.php | 20 +-- .../Context/SetterContextInterface.php | 8 +- .../DependencyInjection/Configuration.php | 133 +++++++++--------- .../Exporter/Exporter.php | 18 +-- .../Fetcher/FetcherInterface.php | 5 +- .../Fetcher/ObjectsFetcher.php | 4 +- .../Importer/Importer.php | 6 +- .../Interpreter/AssetByPathInterpreter.php | 8 +- .../Interpreter/AssetUrlInterpreter.php | 14 +- .../Interpreter/AssetsUrlInterpreter.php | 8 +- .../Interpreter/CarbonInterpreter.php | 8 +- .../Interpreter/CheckboxInterpreter.php | 6 +- .../Interpreter/ConditionalInterpreter.php | 14 +- .../CoreShop/CurrencyInterpreter.php | 6 +- .../Interpreter/CoreShop/MoneyInterpreter.php | 24 ++-- .../Interpreter/CoreShop/PriceInterpreter.php | 8 +- .../CoreShop/StoresInterpreter.php | 8 +- .../Interpreter/DefaultValueInterpreter.php | 8 +- .../Interpreter/DefinitionInterpreter.php | 7 +- .../DoNotSetOnEmptyInterpreter.php | 6 +- .../Interpreter/ExpressionInterpreter.php | 9 +- .../Interpreter/ExternalImageInterpreter.php | 6 +- .../Interpreter/HrefInterpreter.php | 10 +- .../Interpreter/ImportRuleInterpreter.php | 8 +- .../Interpreter/InterpreterInterface.php | 5 +- .../Interpreter/IteratorInterpreter.php | 11 +- .../Interpreter/LinkInterpreter.php | 6 +- .../Interpreter/MappingInterpreter.php | 10 +- .../Interpreter/MetadataInterpreter.php | 10 +- .../Interpreter/MultiHrefInterpreter.php | 8 +- .../Interpreter/NestedInterpreter.php | 15 +- .../Interpreter/ObjectResolverInterpreter.php | 12 +- .../Interpreter/QuantityValueInterpreter.php | 8 +- .../Interpreter/SpecificObjectInterpreter.php | 8 +- .../Interpreter/TwigInterpreter.php | 10 +- .../Interpreter/TypeCastingInterpreter.php | 8 +- .../ArtifactGenerationProviderInterface.php | 4 +- .../Setter/ClassificationStoreSetter.php | 2 +- .../Setter/CoreShop/StorePriceSetter.php | 4 +- .../Setter/CoreShop/StoreValuesSetter.php | 4 +- .../Setter/FieldCollectionSetter.php | 4 +- .../Setter/KeySetter.php | 2 +- .../Setter/LocalizedfieldSetter.php | 4 +- .../Setter/ObjectbrickSetter.php | 4 +- .../Setter/RelationSetter.php | 2 +- 61 files changed, 361 insertions(+), 398 deletions(-) create mode 100644 src/DataDefinitionsBundle/Context/Context.php create mode 100644 src/DataDefinitionsBundle/Context/ContextInterface.php diff --git a/src/DataDefinitionsBundle/Context/Context.php b/src/DataDefinitionsBundle/Context/Context.php new file mode 100644 index 00000000..5a259ff4 --- /dev/null +++ b/src/DataDefinitionsBundle/Context/Context.php @@ -0,0 +1,57 @@ +definition; + } + + public function getParams(): array + { + return $this->params; + } + + public function withConfiguration(array $configuration): self + { + $context = clone $this; + $context->setConfiguration($configuration); + + return $context; + } + + protected function setConfiguration(array $configuration): void + { + $this->configuration = $configuration; + } + + public function getConfiguration(): array + { + return $this->configuration; + } +} diff --git a/src/DataDefinitionsBundle/Context/ContextFactory.php b/src/DataDefinitionsBundle/Context/ContextFactory.php index b3cafb67..2549e894 100644 --- a/src/DataDefinitionsBundle/Context/ContextFactory.php +++ b/src/DataDefinitionsBundle/Context/ContextFactory.php @@ -29,9 +29,10 @@ class ContextFactory implements ContextFactoryInterface { public function createFetcherContext( ExportDefinitionInterface $definition, - array $params + array $params, + array $configuration, ): FetcherContextInterface { - return new FetcherContext($definition, $params); + return new FetcherContext($definition, $params, $configuration); } public function createLoaderContext( @@ -39,9 +40,9 @@ public function createLoaderContext( array $params, array $dataRow, ImportDataSetInterface $dataSet, - string $class + string $class, ): LoaderContextInterface { - return new LoaderContext($definition, $params, $dataRow, $dataSet, $class); + return new LoaderContext($definition, $params, [], $dataRow, $dataSet, $class); } public function createFilterContext( @@ -49,9 +50,9 @@ public function createFilterContext( array $params, array $dataRow, ImportDataSetInterface $dataSet, - Concrete $object + Concrete $object, ): FilterContextInterface { - return new FilterContext($definition, $params, $dataRow, $dataSet, $object); + return new FilterContext($definition, $params, [], $dataRow, $dataSet, $object); } public function createGetterContext( @@ -60,7 +61,7 @@ public function createGetterContext( Concrete $object, ExportMapping $mapping, ): GetterContextInterface { - return new GetterContext($definition, $params, $object, $mapping); + return new GetterContext($definition, $params, [], $object, $mapping); } public function createSetterContext( @@ -72,19 +73,20 @@ public function createSetterContext( ImportDataSetInterface $dataSet, mixed $value, ): SetterContextInterface { - return new SetterContext($definition, $params, $object, $mapping, $dataRow, $dataSet, $value); + return new SetterContext($definition, $params, [], $object, $mapping, $dataRow, $dataSet, $value); } public function createInterpreterContext( DataDefinitionInterface $definition, array $params, + array $configuration, array $dataRow, ?ImportDataSetInterface $dataSet, Concrete $object, mixed $value, - MappingInterface $mapping + MappingInterface $mapping, ): InterpreterContextInterface { - return new InterpreterContext($definition, $params, $dataRow, $dataSet, $object, $value, $mapping); + return new InterpreterContext($definition, $params, $configuration, $dataRow, $dataSet, $object, $value, $mapping); } public function createRunnerContext( @@ -92,8 +94,8 @@ public function createRunnerContext( array $params, ?array $dataRow, ?ImportDataSetInterface $dataSet, - ?Concrete $object + ?Concrete $object, ): RunnerContextInterface { - return new RunnerContext($definition, $params, $dataRow, $dataSet, $object); + return new RunnerContext($definition, $params, [], $dataRow, $dataSet, $object); } } diff --git a/src/DataDefinitionsBundle/Context/ContextFactoryInterface.php b/src/DataDefinitionsBundle/Context/ContextFactoryInterface.php index 4e5491f8..f9ed17c5 100644 --- a/src/DataDefinitionsBundle/Context/ContextFactoryInterface.php +++ b/src/DataDefinitionsBundle/Context/ContextFactoryInterface.php @@ -29,7 +29,8 @@ interface ContextFactoryInterface { public function createFetcherContext( ExportDefinitionInterface $definition, - array $params + array $params, + array $configuration, ): FetcherContextInterface; public function createLoaderContext( @@ -37,7 +38,7 @@ public function createLoaderContext( array $params, array $dataRow, ImportDataSetInterface $dataSet, - string $class + string $class, ): LoaderContextInterface; public function createFilterContext( @@ -45,7 +46,7 @@ public function createFilterContext( array $params, array $dataRow, ImportDataSetInterface $dataSet, - Concrete $object + Concrete $object, ): FilterContextInterface; public function createGetterContext( @@ -68,11 +69,12 @@ public function createSetterContext( public function createInterpreterContext( DataDefinitionInterface $definition, array $params, + array $configuration, array $dataRow, ?ImportDataSetInterface $dataSet, Concrete $object, mixed $value, - MappingInterface $mapping + MappingInterface $mapping, ): InterpreterContextInterface; public function createRunnerContext( @@ -80,6 +82,6 @@ public function createRunnerContext( array $params, ?array $dataRow, ?ImportDataSetInterface $dataSet, - ?Concrete $object + ?Concrete $object, ): RunnerContextInterface; } diff --git a/src/DataDefinitionsBundle/Context/ContextInterface.php b/src/DataDefinitionsBundle/Context/ContextInterface.php new file mode 100644 index 00000000..d4630abd --- /dev/null +++ b/src/DataDefinitionsBundle/Context/ContextInterface.php @@ -0,0 +1,30 @@ +definition; - } + /** + * @var ExportDefinitionInterface $definition + */ + $definition = $this->definition; - public function getParams(): array - { - return $this->params; + return $definition; } } diff --git a/src/DataDefinitionsBundle/Context/FetcherContextInterface.php b/src/DataDefinitionsBundle/Context/FetcherContextInterface.php index 62120ff9..a7212142 100644 --- a/src/DataDefinitionsBundle/Context/FetcherContextInterface.php +++ b/src/DataDefinitionsBundle/Context/FetcherContextInterface.php @@ -18,9 +18,7 @@ use Wvision\Bundle\DataDefinitionsBundle\Model\ExportDefinitionInterface; -interface FetcherContextInterface +interface FetcherContextInterface extends ContextInterface { public function getDefinition(): ExportDefinitionInterface; - - public function getParams(): array; } diff --git a/src/DataDefinitionsBundle/Context/FilterContext.php b/src/DataDefinitionsBundle/Context/FilterContext.php index 9761fb2d..876441d3 100644 --- a/src/DataDefinitionsBundle/Context/FilterContext.php +++ b/src/DataDefinitionsBundle/Context/FilterContext.php @@ -20,25 +20,17 @@ use Wvision\Bundle\DataDefinitionsBundle\Model\DataDefinitionInterface; use Wvision\Bundle\DataDefinitionsBundle\Provider\ImportDataSetInterface; -class FilterContext implements FilterContextInterface +class FilterContext extends Context implements FilterContextInterface { public function __construct( - protected DataDefinitionInterface $definition, - protected array $params, + DataDefinitionInterface $definition, + array $params, + array $configuration, protected array $dataRow, protected ImportDataSetInterface $dataSet, protected Concrete $object ) { - } - - public function getDefinition(): DataDefinitionInterface - { - return $this->definition; - } - - public function getParams(): array - { - return $this->params; + parent::__construct($definition, $params, $configuration); } public function getDataRow(): array diff --git a/src/DataDefinitionsBundle/Context/FilterContextInterface.php b/src/DataDefinitionsBundle/Context/FilterContextInterface.php index b65a6eb2..a77800e8 100644 --- a/src/DataDefinitionsBundle/Context/FilterContextInterface.php +++ b/src/DataDefinitionsBundle/Context/FilterContextInterface.php @@ -20,12 +20,8 @@ use Wvision\Bundle\DataDefinitionsBundle\Model\DataDefinitionInterface; use Wvision\Bundle\DataDefinitionsBundle\Provider\ImportDataSetInterface; -interface FilterContextInterface +interface FilterContextInterface extends ContextInterface { - public function getDefinition(): DataDefinitionInterface; - - public function getParams(): array; - public function getDataSet(): ImportDataSetInterface; public function getDataRow(): array; diff --git a/src/DataDefinitionsBundle/Context/GetterContext.php b/src/DataDefinitionsBundle/Context/GetterContext.php index f85976c4..159f7cb2 100644 --- a/src/DataDefinitionsBundle/Context/GetterContext.php +++ b/src/DataDefinitionsBundle/Context/GetterContext.php @@ -20,24 +20,16 @@ use Wvision\Bundle\DataDefinitionsBundle\Model\DataDefinitionInterface; use Wvision\Bundle\DataDefinitionsBundle\Model\ExportMapping; -class GetterContext implements GetterContextInterface +class GetterContext extends Context implements GetterContextInterface { public function __construct( - protected DataDefinitionInterface $definition, - protected array $params, + DataDefinitionInterface $definition, + array $params, + array $configuration, protected Concrete $object, protected ExportMapping $mapping ) { - } - - public function getDefinition(): DataDefinitionInterface - { - return $this->definition; - } - - public function getParams(): array - { - return $this->params; + parent::__construct($definition, $params, $configuration); } public function getObject(): Concrete diff --git a/src/DataDefinitionsBundle/Context/GetterContextInterface.php b/src/DataDefinitionsBundle/Context/GetterContextInterface.php index 5735ada5..a92f6ebb 100644 --- a/src/DataDefinitionsBundle/Context/GetterContextInterface.php +++ b/src/DataDefinitionsBundle/Context/GetterContextInterface.php @@ -20,12 +20,8 @@ use Wvision\Bundle\DataDefinitionsBundle\Model\DataDefinitionInterface; use Wvision\Bundle\DataDefinitionsBundle\Model\ExportMapping; -interface GetterContextInterface +interface GetterContextInterface extends ContextInterface { - public function getDefinition(): DataDefinitionInterface; - - public function getParams(): array; - public function getObject(): Concrete; public function getMapping(): ExportMapping; diff --git a/src/DataDefinitionsBundle/Context/InterpreterContext.php b/src/DataDefinitionsBundle/Context/InterpreterContext.php index c26434e9..553bd6d4 100644 --- a/src/DataDefinitionsBundle/Context/InterpreterContext.php +++ b/src/DataDefinitionsBundle/Context/InterpreterContext.php @@ -21,27 +21,19 @@ use Wvision\Bundle\DataDefinitionsBundle\Model\MappingInterface; use Wvision\Bundle\DataDefinitionsBundle\Provider\ImportDataSetInterface; -class InterpreterContext implements InterpreterContextInterface +class InterpreterContext extends Context implements InterpreterContextInterface { public function __construct( - protected DataDefinitionInterface $definition, - protected array $params, + DataDefinitionInterface $definition, + array $params, + array $configuration, protected array $dataRow, protected ?ImportDataSetInterface $dataSet, protected Concrete $object, protected mixed $value, protected MappingInterface $mapping ) { - } - - public function getDefinition(): DataDefinitionInterface - { - return $this->definition; - } - - public function getParams(): array - { - return $this->params; + parent::__construct($definition, $params, $configuration); } public function getDataRow(): array diff --git a/src/DataDefinitionsBundle/Context/InterpreterContextInterface.php b/src/DataDefinitionsBundle/Context/InterpreterContextInterface.php index 36ba6ce9..2d8629fc 100644 --- a/src/DataDefinitionsBundle/Context/InterpreterContextInterface.php +++ b/src/DataDefinitionsBundle/Context/InterpreterContextInterface.php @@ -17,16 +17,11 @@ namespace Wvision\Bundle\DataDefinitionsBundle\Context; use Pimcore\Model\DataObject\Concrete; -use Wvision\Bundle\DataDefinitionsBundle\Model\DataDefinitionInterface; use Wvision\Bundle\DataDefinitionsBundle\Model\MappingInterface; use Wvision\Bundle\DataDefinitionsBundle\Provider\ImportDataSetInterface; -interface InterpreterContextInterface +interface InterpreterContextInterface extends ContextInterface { - public function getDefinition(): DataDefinitionInterface; - - public function getParams(): array; - public function getDataRow(): array; public function getDataSet(): ?ImportDataSetInterface; diff --git a/src/DataDefinitionsBundle/Context/LoaderContext.php b/src/DataDefinitionsBundle/Context/LoaderContext.php index da4b30f9..e14207ed 100644 --- a/src/DataDefinitionsBundle/Context/LoaderContext.php +++ b/src/DataDefinitionsBundle/Context/LoaderContext.php @@ -19,25 +19,27 @@ use Wvision\Bundle\DataDefinitionsBundle\Model\ImportDefinitionInterface; use Wvision\Bundle\DataDefinitionsBundle\Provider\ImportDataSetInterface; -class LoaderContext implements LoaderContextInterface +class LoaderContext extends Context implements LoaderContextInterface { public function __construct( - protected ImportDefinitionInterface $definition, - protected array $params, + ImportDefinitionInterface $definition, + array $params, + array $configuration, protected array $dataRow, protected ImportDataSetInterface $dataSet, protected string $class ) { + parent::__construct($definition, $params, $configuration); } public function getDefinition(): ImportDefinitionInterface { - return $this->definition; - } + /** + * @var ImportDefinitionInterface $definition + */ + $definition = $this->definition; - public function getParams(): array - { - return $this->params; + return $definition; } public function getDataRow(): array diff --git a/src/DataDefinitionsBundle/Context/LoaderContextInterface.php b/src/DataDefinitionsBundle/Context/LoaderContextInterface.php index 1c2b77f6..3dd61c11 100644 --- a/src/DataDefinitionsBundle/Context/LoaderContextInterface.php +++ b/src/DataDefinitionsBundle/Context/LoaderContextInterface.php @@ -19,12 +19,10 @@ use Wvision\Bundle\DataDefinitionsBundle\Model\ImportDefinitionInterface; use Wvision\Bundle\DataDefinitionsBundle\Provider\ImportDataSetInterface; -interface LoaderContextInterface +interface LoaderContextInterface extends ContextInterface { public function getDefinition(): ImportDefinitionInterface; - public function getParams(): array; - public function getDataRow(): array; public function getDataSet(): ImportDataSetInterface; diff --git a/src/DataDefinitionsBundle/Context/RunnerContext.php b/src/DataDefinitionsBundle/Context/RunnerContext.php index dcfef120..06463707 100644 --- a/src/DataDefinitionsBundle/Context/RunnerContext.php +++ b/src/DataDefinitionsBundle/Context/RunnerContext.php @@ -20,25 +20,17 @@ use Wvision\Bundle\DataDefinitionsBundle\Model\DataDefinitionInterface; use Wvision\Bundle\DataDefinitionsBundle\Provider\ImportDataSetInterface; -class RunnerContext implements RunnerContextInterface +class RunnerContext extends Context implements RunnerContextInterface { public function __construct( - protected DataDefinitionInterface $definition, - protected array $params, + DataDefinitionInterface $definition, + array $params, + array $configuration, protected ?array $dataRow, protected ?ImportDataSetInterface $dataSet, protected ?Concrete $object ) { - } - - public function getDefinition(): DataDefinitionInterface - { - return $this->definition; - } - - public function getParams(): array - { - return $this->params; + parent::__construct($definition, $params, $configuration); } public function getDataRow(): ?array diff --git a/src/DataDefinitionsBundle/Context/RunnerContextInterface.php b/src/DataDefinitionsBundle/Context/RunnerContextInterface.php index 62d42e58..af9948d9 100644 --- a/src/DataDefinitionsBundle/Context/RunnerContextInterface.php +++ b/src/DataDefinitionsBundle/Context/RunnerContextInterface.php @@ -20,12 +20,8 @@ use Wvision\Bundle\DataDefinitionsBundle\Model\DataDefinitionInterface; use Wvision\Bundle\DataDefinitionsBundle\Provider\ImportDataSetInterface; -interface RunnerContextInterface +interface RunnerContextInterface extends ContextInterface { - public function getDefinition(): DataDefinitionInterface; - - public function getParams(): array; - public function getDataRow(): ?array; public function getDataSet(): ?ImportDataSetInterface; diff --git a/src/DataDefinitionsBundle/Context/SetterContext.php b/src/DataDefinitionsBundle/Context/SetterContext.php index bd91c065..a4285951 100644 --- a/src/DataDefinitionsBundle/Context/SetterContext.php +++ b/src/DataDefinitionsBundle/Context/SetterContext.php @@ -21,27 +21,19 @@ use Wvision\Bundle\DataDefinitionsBundle\Model\ImportMapping; use Wvision\Bundle\DataDefinitionsBundle\Provider\ImportDataSetInterface; -class SetterContext implements SetterContextInterface +class SetterContext extends Context implements SetterContextInterface { public function __construct( - protected DataDefinitionInterface $definition, - protected array $params, + DataDefinitionInterface $definition, + array $params, + array $configuration, protected Concrete $object, protected ImportMapping $mapping, protected array $dataRow, protected ImportDataSetInterface $dataSet, protected mixed $value, ) { - } - - public function getDefinition(): DataDefinitionInterface - { - return $this->definition; - } - - public function getParams(): array - { - return $this->params; + parent::__construct($definition, $params, $configuration); } public function getObject(): Concrete @@ -49,7 +41,7 @@ public function getObject(): Concrete return $this->object; } - public function getImportMapping(): ImportMapping + public function getMapping(): ImportMapping { return $this->mapping; } diff --git a/src/DataDefinitionsBundle/Context/SetterContextInterface.php b/src/DataDefinitionsBundle/Context/SetterContextInterface.php index 26b37f37..67969a78 100644 --- a/src/DataDefinitionsBundle/Context/SetterContextInterface.php +++ b/src/DataDefinitionsBundle/Context/SetterContextInterface.php @@ -21,13 +21,9 @@ use Wvision\Bundle\DataDefinitionsBundle\Model\ImportMapping; use Wvision\Bundle\DataDefinitionsBundle\Provider\ImportDataSetInterface; -interface SetterContextInterface +interface SetterContextInterface extends ContextInterface { - public function getDefinition(): DataDefinitionInterface; - - public function getParams(): array; - - public function getImportMapping(): ImportMapping; + public function getMapping(): ImportMapping; public function getObject(): Concrete; diff --git a/src/DataDefinitionsBundle/DependencyInjection/Configuration.php b/src/DataDefinitionsBundle/DependencyInjection/Configuration.php index 321143b2..9eeb03d3 100644 --- a/src/DataDefinitionsBundle/DependencyInjection/Configuration.php +++ b/src/DataDefinitionsBundle/DependencyInjection/Configuration.php @@ -40,7 +40,7 @@ public function getConfigTreeBuilder(): TreeBuilder $rootNode ->children() - ->scalarNode('driver')->defaultValue(CoreShopResourceBundle::DRIVER_PIMCORE)->end() + ->scalarNode('driver')->defaultValue(CoreShopResourceBundle::DRIVER_PIMCORE)->end() ->end(); $this->addPimcoreResourcesSection($rootNode); @@ -53,75 +53,76 @@ private function addModelsSection(ArrayNodeDefinition $node) { $node ->children() - ->arrayNode('resources') - ->addDefaultsIfNotSet() - ->children() - ->arrayNode('import_definition') - ->addDefaultsIfNotSet() - ->children() - ->variableNode('options')->end() - ->scalarNode('permission')->defaultValue('data_definitions_import')->cannotBeOverwritten() - ->end() - ->arrayNode('classes') - ->addDefaultsIfNotSet() - ->children() - ->scalarNode('model')->defaultValue(ImportDefinition::class)->cannotBeEmpty()->end() - ->scalarNode('interface')->defaultValue(ImportDefinitionInterface::class)->cannotBeEmpty()->end() - ->scalarNode('admin_controller')->defaultValue(ImportDefinitionController::class)->cannotBeEmpty()->end() - ->scalarNode('factory')->defaultValue(Factory::class)->cannotBeEmpty()->end() - ->scalarNode('repository')->defaultValue(Repository\DefinitionRepository::class)->cannotBeEmpty()->end() - ->scalarNode('form')->defaultValue(ImportDefinitionType::class)->cannotBeEmpty()->end() - ->end() - ->end() - ->end() - ->end() - ->arrayNode('export_definition') - ->addDefaultsIfNotSet() - ->children() - ->variableNode('options')->end() - ->scalarNode('permission')->defaultValue('data_definitions_export')->cannotBeOverwritten() - ->end() - ->arrayNode('classes') - ->addDefaultsIfNotSet() - ->children() - ->scalarNode('model')->defaultValue(ExportDefinition::class)->cannotBeEmpty()->end() - ->scalarNode('interface')->defaultValue(ExportDefinitionInterface::class)->cannotBeEmpty()->end() - ->scalarNode('admin_controller')->defaultValue(ExportDefinitionController::class)->cannotBeEmpty()->end() - ->scalarNode('factory')->defaultValue(Factory::class)->cannotBeEmpty()->end() - ->scalarNode('repository')->defaultValue(Repository\DefinitionRepository::class)->cannotBeEmpty()->end() - ->scalarNode('form')->defaultValue(ExportDefinitionType::class)->cannotBeEmpty()->end() - ->end() - ->end() - ->end() - ->end() - ->end() - ->end() - ->end(); + ->arrayNode('resources') + ->addDefaultsIfNotSet() + ->children() + ->arrayNode('import_definition') + ->addDefaultsIfNotSet() + ->children() + ->variableNode('options')->end() + ->scalarNode('permission')->defaultValue('data_definitions_import')->cannotBeOverwritten() + ->end() + ->arrayNode('classes') + ->addDefaultsIfNotSet() + ->children() + ->scalarNode('model')->defaultValue(ImportDefinition::class)->cannotBeEmpty()->end() + ->scalarNode('interface')->defaultValue(ImportDefinitionInterface::class)->cannotBeEmpty()->end() + ->scalarNode('admin_controller')->defaultValue(ImportDefinitionController::class)->cannotBeEmpty()->end() + ->scalarNode('factory')->defaultValue(Factory::class)->cannotBeEmpty()->end() + ->scalarNode('repository')->defaultValue(Repository\DefinitionRepository::class)->cannotBeEmpty()->end() + ->scalarNode('form')->defaultValue(ImportDefinitionType::class)->cannotBeEmpty()->end() + ->end() + ->end() + ->end() + ->end() + ->arrayNode('export_definition') + ->addDefaultsIfNotSet() + ->children() + ->variableNode('options')->end() + ->scalarNode('permission')->defaultValue('data_definitions_export')->cannotBeOverwritten() + ->end() + ->arrayNode('classes') + ->addDefaultsIfNotSet() + ->children() + ->scalarNode('model')->defaultValue(ExportDefinition::class)->cannotBeEmpty()->end() + ->scalarNode('interface')->defaultValue(ExportDefinitionInterface::class)->cannotBeEmpty()->end() + ->scalarNode('admin_controller')->defaultValue(ExportDefinitionController::class)->cannotBeEmpty()->end() + ->scalarNode('factory')->defaultValue(Factory::class)->cannotBeEmpty()->end() + ->scalarNode('repository')->defaultValue(Repository\DefinitionRepository::class)->cannotBeEmpty()->end() + ->scalarNode('form')->defaultValue(ExportDefinitionType::class)->cannotBeEmpty()->end() + ->end() + ->end() + ->end() + ->end() + ->end() + ->end() + ->end() + ; } private function addPimcoreResourcesSection(ArrayNodeDefinition $node) { $node->children() ->arrayNode('pimcore_admin') - ->addDefaultsIfNotSet() - ->children() - ->arrayNode('js') - ->useAttributeAsKey('name') - ->prototype('scalar')->end() - ->end() - ->arrayNode('css') - ->useAttributeAsKey('name') - ->prototype('scalar')->end() - ->end() - ->arrayNode('install') - ->addDefaultsIfNotSet() - ->ignoreExtraKeys(false) - ->children() - ->scalarNode('sql')->defaultValue(['@DataDefinitionsBundle/Resources/install/pimcore/sql/data.sql'])->end() - ->end() - ->end() - ->end() - ->end() - ->end(); + ->addDefaultsIfNotSet() + ->children() + ->arrayNode('js') + ->useAttributeAsKey('name') + ->prototype('scalar')->end() + ->end() + ->arrayNode('css') + ->useAttributeAsKey('name') + ->prototype('scalar')->end() + ->end() + ->arrayNode('install') + ->addDefaultsIfNotSet() + ->ignoreExtraKeys(false) + ->children() + ->scalarNode('sql')->defaultValue(['@DataDefinitionsBundle/Resources/install/pimcore/sql/data.sql'])->end() + ->end() + ->end() + ->end() + ->end() + ->end(); } -} +} \ No newline at end of file diff --git a/src/DataDefinitionsBundle/Exporter/Exporter.php b/src/DataDefinitionsBundle/Exporter/Exporter.php index 4d31b39e..f8e135ad 100644 --- a/src/DataDefinitionsBundle/Exporter/Exporter.php +++ b/src/DataDefinitionsBundle/Exporter/Exporter.php @@ -58,14 +58,11 @@ public function __construct( public function doExport(ExportDefinitionInterface $definition, array $params) { - $fetcherContext = $this->contextFactory->createFetcherContext($definition, $params); + $fetcherContext = $this->contextFactory->createFetcherContext($definition, $params, is_array($definition->getFetcherConfig()) ? $definition->getFetcherConfig() : []); $fetcher = $this->getFetcher($definition); $provider = $this->getProvider($definition); - $total = $fetcher->count( - $fetcherContext, - is_array($definition->getFetcherConfig()) ? $definition->getFetcherConfig() : [] - ); + $total = $fetcher->count($fetcherContext); $this->eventDispatcher->dispatch( new ExportDefinitionEvent($definition, $total, $params), @@ -130,8 +127,7 @@ function () use ($definition, $params, $total, $fetcher, $provider, $fetcherCont $objects = $fetcher->fetch( $fetcherContext, $perLoop, - $i * $perLoop, - is_array($definition->getFetcherConfig()) ? $definition->getFetcherConfig() : [] + $i * $perLoop ); foreach ($objects as $object) { @@ -196,7 +192,7 @@ private function exportRow( $data = []; $runner = null; - $runnerContext = $this->contextFactory->createRunnerContext($definition, $params, null, null, $object); + $runnerContext = $this->contextFactory->createRunnerContext($definition, $params, null, $object); $this->eventDispatcher->dispatch( new ExportDefinitionEvent($definition, sprintf('Export Object %s', $object->getId()), $params), @@ -287,16 +283,14 @@ private function getObjectValue( $context = $this->contextFactory->createInterpreterContext( $definition, $params, + $map->getInterpreterConfig(), $data, null, $object, $value, $map ); - $value = $interpreter->interpret( - $context, - $map->getInterpreterConfig() - ); + $value = $interpreter->interpret($context); } catch (UnexpectedValueException $ex) { $this->logger->info( sprintf( diff --git a/src/DataDefinitionsBundle/Fetcher/FetcherInterface.php b/src/DataDefinitionsBundle/Fetcher/FetcherInterface.php index 6a33f3b2..53ace9d6 100644 --- a/src/DataDefinitionsBundle/Fetcher/FetcherInterface.php +++ b/src/DataDefinitionsBundle/Fetcher/FetcherInterface.php @@ -23,10 +23,9 @@ interface FetcherInterface public function fetch( FetcherContextInterface $context, int $limit, - int $offset, - array $configuration + int $offset ); - public function count(FetcherContextInterface $context, array $configuration): int; + public function count(FetcherContextInterface $context): int; } diff --git a/src/DataDefinitionsBundle/Fetcher/ObjectsFetcher.php b/src/DataDefinitionsBundle/Fetcher/ObjectsFetcher.php index 116bec1e..8a904bdb 100644 --- a/src/DataDefinitionsBundle/Fetcher/ObjectsFetcher.php +++ b/src/DataDefinitionsBundle/Fetcher/ObjectsFetcher.php @@ -24,7 +24,7 @@ class ObjectsFetcher implements FetcherInterface { - public function fetch(FetcherContextInterface $context, int $limit, int $offset, array $configuration) + public function fetch(FetcherContextInterface $context, int $limit, int $offset) { $list = $this->getClassListing($context->getDefinition(), $context->getParams()); $list->setLimit($limit); @@ -33,7 +33,7 @@ public function fetch(FetcherContextInterface $context, int $limit, int $offset, return $list->load(); } - public function count(FetcherContextInterface $context, array $configuration): int + public function count(FetcherContextInterface $context): int { return $this->getClassListing($context->getDefinition(), $context->getParams())->getTotalCount(); } diff --git a/src/DataDefinitionsBundle/Importer/Importer.php b/src/DataDefinitionsBundle/Importer/Importer.php index e4ece5a7..9bb17261 100644 --- a/src/DataDefinitionsBundle/Importer/Importer.php +++ b/src/DataDefinitionsBundle/Importer/Importer.php @@ -473,16 +473,14 @@ private function setObjectValue( $context = $this->contextFactory->createInterpreterContext( $definition, $params, + $map->getInterpreterConfig() ?? [], $data, $dataSet, $object, $value, $map ); - $value = $interpreter->interpret( - $context, - $map->getInterpreterConfig() ?? [] - ); + $value = $interpreter->interpret($context); } catch (UnexpectedValueException $ex) { $this->logger->info( sprintf( diff --git a/src/DataDefinitionsBundle/Interpreter/AssetByPathInterpreter.php b/src/DataDefinitionsBundle/Interpreter/AssetByPathInterpreter.php index 093a68c3..b1271b9a 100644 --- a/src/DataDefinitionsBundle/Interpreter/AssetByPathInterpreter.php +++ b/src/DataDefinitionsBundle/Interpreter/AssetByPathInterpreter.php @@ -21,11 +21,9 @@ class AssetByPathInterpreter implements InterpreterInterface { - public function interpret( - InterpreterContextInterface $context, - array $configuration - ) { - $assetFullPath = $configuration['path'].'/'.$context->getValue(); + public function interpret(InterpreterContextInterface $context): mixed + { + $assetFullPath = $context->getConfiguration()['path'].'/'.$context->getValue(); return Asset::getByPath($assetFullPath); } diff --git a/src/DataDefinitionsBundle/Interpreter/AssetUrlInterpreter.php b/src/DataDefinitionsBundle/Interpreter/AssetUrlInterpreter.php index d2588a24..66340099 100644 --- a/src/DataDefinitionsBundle/Interpreter/AssetUrlInterpreter.php +++ b/src/DataDefinitionsBundle/Interpreter/AssetUrlInterpreter.php @@ -35,17 +35,15 @@ public function __construct( $this->requestFactory = $requestFactory; } - public function interpret( - InterpreterContextInterface $context, - array $configuration - ) { - $path = $configuration['path']; + public function interpret(InterpreterContextInterface $context): mixed + { + $path = $context->getConfiguration()['path']; if (filter_var($context->getValue(), FILTER_VALIDATE_URL)) { $asset = null; $filename = $this->getFileName($context->getValue()); - if ($configuration['deduplicate_by_url']) { + if ($context->getConfiguration()['deduplicate_by_url']) { if ($asset = $this->getDuplicatedAsset($context->getValue())) { $filename = $asset->getFilename(); $assetPath = $asset->getPath(); @@ -73,12 +71,12 @@ public function interpret( } else { $save = false; - if ($configuration['relocate_existing_objects'] && $asset->getParent() !== $parent) { + if ($context->getConfiguration()['relocate_existing_objects'] && $asset->getParent() !== $parent) { $asset->setParent($parent); $save = true; } - if ($configuration['rename_existing_objects'] && $asset->getFilename() !== $filename) { + if ($context->getConfiguration()['rename_existing_objects'] && $asset->getFilename() !== $filename) { $asset->setFilename($filename); $save = true; } diff --git a/src/DataDefinitionsBundle/Interpreter/AssetsUrlInterpreter.php b/src/DataDefinitionsBundle/Interpreter/AssetsUrlInterpreter.php index 5ee9b3ee..9d6d6dbc 100644 --- a/src/DataDefinitionsBundle/Interpreter/AssetsUrlInterpreter.php +++ b/src/DataDefinitionsBundle/Interpreter/AssetsUrlInterpreter.php @@ -20,13 +20,11 @@ class AssetsUrlInterpreter extends AssetUrlInterpreter { - public function interpret( - InterpreterContextInterface $context, - array $configuration - ) { + public function interpret(InterpreterContextInterface $context): mixed + { $assets = []; foreach ((array)$context->getValue() as $item) { - $asset = parent::interpret($context, $configuration); + $asset = parent::interpret($context); if ($asset) { $assets[] = $asset; diff --git a/src/DataDefinitionsBundle/Interpreter/CarbonInterpreter.php b/src/DataDefinitionsBundle/Interpreter/CarbonInterpreter.php index 841a96e0..1f07cd58 100644 --- a/src/DataDefinitionsBundle/Interpreter/CarbonInterpreter.php +++ b/src/DataDefinitionsBundle/Interpreter/CarbonInterpreter.php @@ -21,12 +21,10 @@ class CarbonInterpreter implements InterpreterInterface { - public function interpret( - InterpreterContextInterface $context, - array $configuration - ) { + public function interpret(InterpreterContextInterface $context): bool|null|\Carbon\Carbon + { if ($context->getValue()) { - $format = $configuration['date_format']; + $format = $context->getConfiguration()['date_format']; if (!empty($format)) { return Carbon::createFromFormat($format, $context->getValue()); } diff --git a/src/DataDefinitionsBundle/Interpreter/CheckboxInterpreter.php b/src/DataDefinitionsBundle/Interpreter/CheckboxInterpreter.php index 312b2f71..6c07d48d 100644 --- a/src/DataDefinitionsBundle/Interpreter/CheckboxInterpreter.php +++ b/src/DataDefinitionsBundle/Interpreter/CheckboxInterpreter.php @@ -20,10 +20,8 @@ class CheckboxInterpreter implements InterpreterInterface { - public function interpret( - InterpreterContextInterface $context, - array $configuration - ) { + public function interpret(InterpreterContextInterface $context): ?bool + { if (is_string($context->getValue())) { if ($context->getValue() === "") { return null; diff --git a/src/DataDefinitionsBundle/Interpreter/ConditionalInterpreter.php b/src/DataDefinitionsBundle/Interpreter/ConditionalInterpreter.php index 167168d2..3b3c6a84 100644 --- a/src/DataDefinitionsBundle/Interpreter/ConditionalInterpreter.php +++ b/src/DataDefinitionsBundle/Interpreter/ConditionalInterpreter.php @@ -37,10 +37,8 @@ public function __construct( $this->container = $container; } - public function interpret( - InterpreterContextInterface $context, - array $configuration - ) { + public function interpret(InterpreterContextInterface $context): mixed + { $params = [ 'value' => $context->getValue(), 'object' => $context->getObject(), @@ -49,16 +47,16 @@ public function interpret( 'data_set' => $context->getDataSet(), 'definition' => $context->getDefinition(), 'params' => $context->getParams(), - 'configuration' => $configuration, + 'configuration' => $context->getConfiguration(), 'container' => $this->container, ]; - $condition = $configuration['condition']; + $condition = $context->getConfiguration()['condition']; if ($this->expressionLanguage->evaluate($condition, $params)) { - $interpreter = $configuration['true_interpreter']; + $interpreter = $context->getConfiguration()['true_interpreter']; } else { - $interpreter = $configuration['false_interpreter']; + $interpreter = $context->getConfiguration()['false_interpreter']; } $interpreterObject = $this->interpreterRegistry->get($interpreter['type']); diff --git a/src/DataDefinitionsBundle/Interpreter/CoreShop/CurrencyInterpreter.php b/src/DataDefinitionsBundle/Interpreter/CoreShop/CurrencyInterpreter.php index d633b7dd..474de8b0 100644 --- a/src/DataDefinitionsBundle/Interpreter/CoreShop/CurrencyInterpreter.php +++ b/src/DataDefinitionsBundle/Interpreter/CoreShop/CurrencyInterpreter.php @@ -27,10 +27,8 @@ public function __construct(CurrencyRepositoryInterface $currencyRepository) $this->currencyRepository = $currencyRepository; } - public function interpret( - InterpreterContextInterface $context, - array $configuration - ) { + public function interpret(InterpreterContextInterface $context): mixed + { return $this->currencyRepository->getByCode($context->getValue()); } } diff --git a/src/DataDefinitionsBundle/Interpreter/CoreShop/MoneyInterpreter.php b/src/DataDefinitionsBundle/Interpreter/CoreShop/MoneyInterpreter.php index 98f6a5ad..656ab825 100644 --- a/src/DataDefinitionsBundle/Interpreter/CoreShop/MoneyInterpreter.php +++ b/src/DataDefinitionsBundle/Interpreter/CoreShop/MoneyInterpreter.php @@ -20,12 +20,10 @@ public function __construct(CurrencyRepositoryInterface $currencyRepository) $this->currencyRepository = $currencyRepository; } - public function interpret( - InterpreterContextInterface $context, - array $configuration - ) { - $value = $this->getValue($context->getValue(), $configuration); - $currency = $this->resolveCurrency($value, $configuration); + public function interpret(InterpreterContextInterface $context) + { + $value = $this->getValue($context->getValue(), $context->getConfiguration()); + $currency = $this->resolveCurrency($value, $context->getConfiguration()); if (null === $currency) { return null; @@ -36,13 +34,13 @@ public function interpret( /** * @param $value - * @param $configuration + * @param $context->getConfiguration() * * @return int */ - private function getValue($value, $configuration) + private function getValue($value, $context->getConfiguration()) { - $inputIsFloat = $configuration['isFloat']; + $inputIsFloat = $context->getConfiguration()['isFloat']; $value = preg_replace("/[^0-9,.]+/", "", $value); @@ -60,11 +58,11 @@ private function getValue($value, $configuration) /** * @param string $value - * @param array $configuration + * @param array $context->getConfiguration() * * @return CurrencyInterface|null */ - private function resolveCurrency($value, $configuration) + private function resolveCurrency($value, $context->getConfiguration()) { $currency = null; @@ -74,8 +72,8 @@ private function resolveCurrency($value, $configuration) $currency = $this->currencyRepository->getByCode($currencyCode); } - if ($currency === null && isset($configuration['currency']) && null !== $configuration['currency']) { - $currency = $this->currencyRepository->find($configuration['currency']); + if ($currency === null && isset($context->getConfiguration()['currency']) && null !== $context->getConfiguration()['currency']) { + $currency = $this->currencyRepository->find($context->getConfiguration()['currency']); } return $currency; diff --git a/src/DataDefinitionsBundle/Interpreter/CoreShop/PriceInterpreter.php b/src/DataDefinitionsBundle/Interpreter/CoreShop/PriceInterpreter.php index 53d8da7a..2f2c01d5 100644 --- a/src/DataDefinitionsBundle/Interpreter/CoreShop/PriceInterpreter.php +++ b/src/DataDefinitionsBundle/Interpreter/CoreShop/PriceInterpreter.php @@ -20,11 +20,9 @@ final class PriceInterpreter implements InterpreterInterface { - public function interpret( - InterpreterContextInterface $context, - array $configuration - ) { - $inputIsFloat = $configuration['isFloat']; + public function interpret(InterpreterContextInterface $context): mixed + { + $inputIsFloat = $context->getConfiguration()['isFloat']; $value = $context->getValue(); if (is_string($value)) { diff --git a/src/DataDefinitionsBundle/Interpreter/CoreShop/StoresInterpreter.php b/src/DataDefinitionsBundle/Interpreter/CoreShop/StoresInterpreter.php index 3cce2968..7be1fe7b 100644 --- a/src/DataDefinitionsBundle/Interpreter/CoreShop/StoresInterpreter.php +++ b/src/DataDefinitionsBundle/Interpreter/CoreShop/StoresInterpreter.php @@ -19,11 +19,9 @@ final class StoresInterpreter implements InterpreterInterface { - public function interpret( - InterpreterContextInterface $context, - array $configuration - ) { - return $configuration['stores']; + public function interpret(InterpreterContextInterface $context): mixed + { + return $context->getConfiguration()['stores']; } } diff --git a/src/DataDefinitionsBundle/Interpreter/DefaultValueInterpreter.php b/src/DataDefinitionsBundle/Interpreter/DefaultValueInterpreter.php index 4f142cf1..0d4a4a20 100644 --- a/src/DataDefinitionsBundle/Interpreter/DefaultValueInterpreter.php +++ b/src/DataDefinitionsBundle/Interpreter/DefaultValueInterpreter.php @@ -20,10 +20,8 @@ class DefaultValueInterpreter implements InterpreterInterface { - public function interpret( - InterpreterContextInterface $context, - array $configuration - ) { - return $configuration['value']; + public function interpret(InterpreterContextInterface $context): mixed + { + return $context->getConfiguration()['value']; } } diff --git a/src/DataDefinitionsBundle/Interpreter/DefinitionInterpreter.php b/src/DataDefinitionsBundle/Interpreter/DefinitionInterpreter.php index 7a3cd0d1..09bf4536 100644 --- a/src/DataDefinitionsBundle/Interpreter/DefinitionInterpreter.php +++ b/src/DataDefinitionsBundle/Interpreter/DefinitionInterpreter.php @@ -33,11 +33,8 @@ public function __construct(RepositoryInterface $definitionRepository, ImporterI $this->importer = $importer; } - public function interpret( - InterpreterContextInterface $context, - array $configuration - ) { - $subDefinition = $this->definitionRepository->find($configuration['definition']); + public function interpret(InterpreterContextInterface $context): mixed { + $subDefinition = $this->definitionRepository->find($context->getConfiguration()['definition']); if (!$subDefinition instanceof ImportDefinitionInterface) { return null; diff --git a/src/DataDefinitionsBundle/Interpreter/DoNotSetOnEmptyInterpreter.php b/src/DataDefinitionsBundle/Interpreter/DoNotSetOnEmptyInterpreter.php index 21346ad8..ed32d7fb 100644 --- a/src/DataDefinitionsBundle/Interpreter/DoNotSetOnEmptyInterpreter.php +++ b/src/DataDefinitionsBundle/Interpreter/DoNotSetOnEmptyInterpreter.php @@ -21,10 +21,8 @@ class DoNotSetOnEmptyInterpreter implements InterpreterInterface { - public function interpret( - InterpreterContextInterface $context, - array $configuration - ) { + public function interpret(InterpreterContextInterface $context): mixed + { if ($context->getValue() === "" || $context->getValue() === null) { throw new DoNotSetException(); } diff --git a/src/DataDefinitionsBundle/Interpreter/ExpressionInterpreter.php b/src/DataDefinitionsBundle/Interpreter/ExpressionInterpreter.php index 0745ccb8..cb6de4d6 100644 --- a/src/DataDefinitionsBundle/Interpreter/ExpressionInterpreter.php +++ b/src/DataDefinitionsBundle/Interpreter/ExpressionInterpreter.php @@ -33,11 +33,8 @@ public function __construct(ExpressionLanguage $expressionLanguage, ContainerInt $this->container = $container; } - public function interpret( - InterpreterContextInterface $context, - array $configuration - ) { - $expression = $configuration['expression']; + public function interpret(InterpreterContextInterface $context): mixed { + $expression = $context->getConfiguration()['expression']; try { return $this->expressionLanguage->evaluate($expression, [ @@ -48,7 +45,7 @@ public function interpret( 'data_set' => $context->getDataSet(), 'definition' => $context->getDefinition(), 'params' => $context->getParams(), - 'configuration' => $configuration, + 'configuration' => $context->getConfiguration(), 'container' => $this->container, ]); } catch (Throwable $exception) { diff --git a/src/DataDefinitionsBundle/Interpreter/ExternalImageInterpreter.php b/src/DataDefinitionsBundle/Interpreter/ExternalImageInterpreter.php index f418a066..1156fa91 100644 --- a/src/DataDefinitionsBundle/Interpreter/ExternalImageInterpreter.php +++ b/src/DataDefinitionsBundle/Interpreter/ExternalImageInterpreter.php @@ -23,10 +23,8 @@ class ExternalImageInterpreter implements InterpreterInterface { - public function interpret( - InterpreterContextInterface $context, - array $configuration - ) { + public function interpret(InterpreterContextInterface $context): mixed + { if (($context->getDefinition() instanceof ExportDefinitionInterface) && $context->getValue( ) instanceof ExternalImage) { return $context->getValue()->getUrl(); diff --git a/src/DataDefinitionsBundle/Interpreter/HrefInterpreter.php b/src/DataDefinitionsBundle/Interpreter/HrefInterpreter.php index b1acb2a0..0dd719e7 100644 --- a/src/DataDefinitionsBundle/Interpreter/HrefInterpreter.php +++ b/src/DataDefinitionsBundle/Interpreter/HrefInterpreter.php @@ -23,12 +23,10 @@ class HrefInterpreter implements InterpreterInterface { - public function interpret( - InterpreterContextInterface $context, - array $configuration - ) { - $type = $configuration['type'] ?: 'object'; - $objectClass = $configuration['class']; + public function interpret(InterpreterContextInterface $context): mixed + { + $type = $context->getConfiguration()['type'] ?: 'object'; + $objectClass = $context->getConfiguration()['class']; if (!$context->getValue()) { return null; diff --git a/src/DataDefinitionsBundle/Interpreter/ImportRuleInterpreter.php b/src/DataDefinitionsBundle/Interpreter/ImportRuleInterpreter.php index e30a7371..5b9f4d7b 100644 --- a/src/DataDefinitionsBundle/Interpreter/ImportRuleInterpreter.php +++ b/src/DataDefinitionsBundle/Interpreter/ImportRuleInterpreter.php @@ -36,11 +36,9 @@ public function __construct( $this->ruleProcessor = $ruleProcessor; } - public function interpret( - InterpreterContextInterface $context, - array $configuration - ) { - $rules = $configuration['rules']; + public function interpret(InterpreterContextInterface $context): mixed + { + $rules = $context->getConfiguration()['rules']; $ruleObjects = []; foreach ($rules as $rule) { diff --git a/src/DataDefinitionsBundle/Interpreter/InterpreterInterface.php b/src/DataDefinitionsBundle/Interpreter/InterpreterInterface.php index 8960d6c4..72e37ba5 100644 --- a/src/DataDefinitionsBundle/Interpreter/InterpreterInterface.php +++ b/src/DataDefinitionsBundle/Interpreter/InterpreterInterface.php @@ -20,8 +20,5 @@ interface InterpreterInterface { - public function interpret( - InterpreterContextInterface $context, - array $configuration - ); + public function interpret(InterpreterContextInterface $context): mixed; } diff --git a/src/DataDefinitionsBundle/Interpreter/IteratorInterpreter.php b/src/DataDefinitionsBundle/Interpreter/IteratorInterpreter.php index 465f10a5..e928fdfb 100644 --- a/src/DataDefinitionsBundle/Interpreter/IteratorInterpreter.php +++ b/src/DataDefinitionsBundle/Interpreter/IteratorInterpreter.php @@ -29,16 +29,14 @@ public function __construct( ) { } - public function interpret( - InterpreterContextInterface $context, - array $configuration - ) { + public function interpret(InterpreterContextInterface $context): mixed + { if (null === $context->getValue()) { return []; } Assert::isArray($context->getValue(), 'IteratorInterpreter can only be used with array values'); - $interpreter = $configuration['interpreter']; + $interpreter = $context->getConfiguration()['interpreter']; $interpreterObject = $this->interpreterRegistry->get($interpreter['type']); $value = $context->getValue(); @@ -48,6 +46,7 @@ public function interpret( $context = $this->contextFactory->createInterpreterContext( $context->getDefinition(), $context->getParams(), + $interpreter['interpreterConfig'], $context->getDataRow(), $context->getDataSet(), $context->getObject(), @@ -55,7 +54,7 @@ public function interpret( $context->getMapping() ); - $result[] = $interpreterObject->interpret($context, $interpreter['interpreterConfig']); + $result[] = $interpreterObject->interpret($context); } return $result; diff --git a/src/DataDefinitionsBundle/Interpreter/LinkInterpreter.php b/src/DataDefinitionsBundle/Interpreter/LinkInterpreter.php index 6808cd5a..933b4816 100644 --- a/src/DataDefinitionsBundle/Interpreter/LinkInterpreter.php +++ b/src/DataDefinitionsBundle/Interpreter/LinkInterpreter.php @@ -24,10 +24,8 @@ class LinkInterpreter implements InterpreterInterface { - public function interpret( - InterpreterContextInterface $context, - array $configuration - ) { + public function interpret(InterpreterContextInterface $context): mixed + { if (($context->getDefinition() instanceof ExportDefinitionInterface) && $context->getValue() instanceof Link) { return $context->getValue()->getHref(); } diff --git a/src/DataDefinitionsBundle/Interpreter/MappingInterpreter.php b/src/DataDefinitionsBundle/Interpreter/MappingInterpreter.php index 4d802828..9cd7a39f 100644 --- a/src/DataDefinitionsBundle/Interpreter/MappingInterpreter.php +++ b/src/DataDefinitionsBundle/Interpreter/MappingInterpreter.php @@ -20,11 +20,9 @@ class MappingInterpreter implements InterpreterInterface { - public function interpret( - InterpreterContextInterface $context, - array $configuration - ) { - $interpreterMap = $configuration['mapping']; + public function interpret(InterpreterContextInterface $context): mixed + { + $interpreterMap = $context->getConfiguration()['mapping']; $resolvedMap = []; if (!is_array($interpreterMap)) { @@ -39,7 +37,7 @@ public function interpret( return $resolvedMap[$context->getValue()]; } - if ($configuration['return_null_when_not_found']) { + if ($context->getConfiguration()['return_null_when_not_found']) { return null; } diff --git a/src/DataDefinitionsBundle/Interpreter/MetadataInterpreter.php b/src/DataDefinitionsBundle/Interpreter/MetadataInterpreter.php index 4d797426..1c53100a 100644 --- a/src/DataDefinitionsBundle/Interpreter/MetadataInterpreter.php +++ b/src/DataDefinitionsBundle/Interpreter/MetadataInterpreter.php @@ -22,14 +22,12 @@ class MetadataInterpreter implements InterpreterInterface { - public function interpret( - InterpreterContextInterface $context, - array $configuration - ) { - $class = "\\Pimcore\\Model\\DataObject\\Data\\".$configuration['class']; + public function interpret(InterpreterContextInterface $context): mixed + { + $class = "\\Pimcore\\Model\\DataObject\\Data\\".$context->getConfiguration()['class']; $fieldname = $context->getMapping()->getToColumn(); - $metadata = $configuration['metadata']; + $metadata = $context->getConfiguration()['metadata']; $metadata = json_decode($metadata, true, 512, JSON_THROW_ON_ERROR); if (!is_array($metadata)) { $metadata = []; diff --git a/src/DataDefinitionsBundle/Interpreter/MultiHrefInterpreter.php b/src/DataDefinitionsBundle/Interpreter/MultiHrefInterpreter.php index 3e97241e..68bae641 100644 --- a/src/DataDefinitionsBundle/Interpreter/MultiHrefInterpreter.php +++ b/src/DataDefinitionsBundle/Interpreter/MultiHrefInterpreter.php @@ -22,11 +22,9 @@ class MultiHrefInterpreter implements InterpreterInterface { - public function interpret( - InterpreterContextInterface $context, - array $configuration - ) { - $objectClass = $configuration['class']; + public function interpret(InterpreterContextInterface $context): mixed + { + $objectClass = $context->getConfiguration()['class']; $class = 'Pimcore\Model\DataObject\\'.ucfirst($objectClass); diff --git a/src/DataDefinitionsBundle/Interpreter/NestedInterpreter.php b/src/DataDefinitionsBundle/Interpreter/NestedInterpreter.php index 7c92ea1b..8ba7bea4 100644 --- a/src/DataDefinitionsBundle/Interpreter/NestedInterpreter.php +++ b/src/DataDefinitionsBundle/Interpreter/NestedInterpreter.php @@ -29,20 +29,19 @@ public function __construct( ) { } - public function interpret( - InterpreterContextInterface $context, - array $configuration - ) { - Assert::keyExists($configuration, 'interpreters'); - Assert::isArray($configuration['interpreters'], 'Interpreter Config needs to be array'); + public function interpret(InterpreterContextInterface $context): mixed + { + Assert::keyExists($context->getConfiguration(), 'interpreters'); + Assert::isArray($context->getConfiguration()['interpreters'], 'Interpreter Config needs to be array'); $value = $context->getValue(); - foreach ($configuration['interpreters'] as $interpreter) { + foreach ($context->getConfiguration()['interpreters'] as $interpreter) { $interpreterObject = $this->interpreterRegistry->get($interpreter['type']); $newContext = $this->contextFactory->createInterpreterContext( $context->getDefinition(), $context->getParams(), + $interpreter['interpreterConfig'], $context->getDataRow(), $context->getDataSet(), $context->getObject(), @@ -50,7 +49,7 @@ public function interpret( $context->getMapping() ); - $value = $interpreterObject->interpret($newContext, $interpreter['interpreterConfig']); + $value = $interpreterObject->interpret($newContext); } return $value; diff --git a/src/DataDefinitionsBundle/Interpreter/ObjectResolverInterpreter.php b/src/DataDefinitionsBundle/Interpreter/ObjectResolverInterpreter.php index 059cb18e..d2cb8b6e 100644 --- a/src/DataDefinitionsBundle/Interpreter/ObjectResolverInterpreter.php +++ b/src/DataDefinitionsBundle/Interpreter/ObjectResolverInterpreter.php @@ -21,22 +21,20 @@ class ObjectResolverInterpreter implements InterpreterInterface { - public function interpret( - InterpreterContextInterface $context, - array $configuration - ) { + public function interpret(InterpreterContextInterface $context): mixed + { if (!$context->getValue()) { return null; } - $class = 'Pimcore\Model\DataObject\\'.ucfirst($configuration['class']); - $lookup = 'getBy'.ucfirst($configuration['field']); + $class = 'Pimcore\Model\DataObject\\'.ucfirst($context->getConfiguration()['class']); + $lookup = 'getBy'.ucfirst($context->getConfiguration()['field']); /** * @var Listing $listing */ $listing = $class::$lookup($context->getValue()); - $listing->setUnpublished($configuration['match_unpublished']); + $listing->setUnpublished($context->getConfiguration()['match_unpublished']); if ($listing->count() === 1) { return $listing->current(); diff --git a/src/DataDefinitionsBundle/Interpreter/QuantityValueInterpreter.php b/src/DataDefinitionsBundle/Interpreter/QuantityValueInterpreter.php index 7ba856e0..686e46d6 100644 --- a/src/DataDefinitionsBundle/Interpreter/QuantityValueInterpreter.php +++ b/src/DataDefinitionsBundle/Interpreter/QuantityValueInterpreter.php @@ -21,12 +21,10 @@ class QuantityValueInterpreter implements InterpreterInterface { - public function interpret( - InterpreterContextInterface $context, - array $configuration - ) { + public function interpret(InterpreterContextInterface $context): mixed + { $value = $context->getValue() !== '' ? $context->getValue() : null; - $unit = $configuration['unit']; + $unit = $context->getConfiguration()['unit']; return new QuantityValue($value, $unit); } diff --git a/src/DataDefinitionsBundle/Interpreter/SpecificObjectInterpreter.php b/src/DataDefinitionsBundle/Interpreter/SpecificObjectInterpreter.php index 3c852332..ad3604d4 100644 --- a/src/DataDefinitionsBundle/Interpreter/SpecificObjectInterpreter.php +++ b/src/DataDefinitionsBundle/Interpreter/SpecificObjectInterpreter.php @@ -21,11 +21,9 @@ class SpecificObjectInterpreter implements InterpreterInterface { - public function interpret( - InterpreterContextInterface $context, - array $configuration - ) { - $objectId = $configuration['objectId']; + public function interpret(InterpreterContextInterface $context): mixed + { + $objectId = $context->getConfiguration()['objectId']; return DataObject::getById($objectId); } diff --git a/src/DataDefinitionsBundle/Interpreter/TwigInterpreter.php b/src/DataDefinitionsBundle/Interpreter/TwigInterpreter.php index d55082be..ac9c5058 100644 --- a/src/DataDefinitionsBundle/Interpreter/TwigInterpreter.php +++ b/src/DataDefinitionsBundle/Interpreter/TwigInterpreter.php @@ -28,11 +28,9 @@ public function __construct(Environment $twig) $this->twig = $twig; } - public function interpret( - InterpreterContextInterface $context, - array $configuration - ) { - return $this->twig->createTemplate($configuration['template'])->render([ + public function interpret(InterpreterContextInterface $context): mixed + { + return $this->twig->createTemplate($context->getConfiguration()['template'])->render([ 'value' => $context->getValue(), 'object' => $context->getObject(), 'map' => $context->getMapping(), @@ -40,7 +38,7 @@ public function interpret( 'data_set' => $context->getDataSet(), 'definition' => $context->getDefinition(), 'params' => $context->getParams(), - 'configuration' => $configuration, + 'configuration' => $context->getConfiguration(), ]); } } diff --git a/src/DataDefinitionsBundle/Interpreter/TypeCastingInterpreter.php b/src/DataDefinitionsBundle/Interpreter/TypeCastingInterpreter.php index f3bd19a0..c803c365 100644 --- a/src/DataDefinitionsBundle/Interpreter/TypeCastingInterpreter.php +++ b/src/DataDefinitionsBundle/Interpreter/TypeCastingInterpreter.php @@ -25,11 +25,9 @@ class TypeCastingInterpreter implements InterpreterInterface protected const TYPE_STRING = 'string'; protected const TYPE_BOOLEAN = 'boolean'; - public function interpret( - InterpreterContextInterface $context, - array $configuration - ) { - $type = $configuration['toType']; + public function interpret(InterpreterContextInterface $context): mixed + { + $type = $context->getConfiguration()['toType']; switch ($type) { case static::TYPE_INT: diff --git a/src/DataDefinitionsBundle/ProcessManager/ArtifactGenerationProviderInterface.php b/src/DataDefinitionsBundle/ProcessManager/ArtifactGenerationProviderInterface.php index 5cc46d93..e168e0e6 100644 --- a/src/DataDefinitionsBundle/ProcessManager/ArtifactGenerationProviderInterface.php +++ b/src/DataDefinitionsBundle/ProcessManager/ArtifactGenerationProviderInterface.php @@ -24,8 +24,8 @@ interface ArtifactGenerationProviderInterface /** * @param array $configuration * @param ExportDefinitionInterface $definition - * @param $params + * @param array $params * @return Asset */ - public function generateArtifact(array $configuration, ExportDefinitionInterface $definition, $params): ?Asset; + public function generateArtifact(array $configuration, ExportDefinitionInterface $definition, array $params): ?Asset; } diff --git a/src/DataDefinitionsBundle/Setter/ClassificationStoreSetter.php b/src/DataDefinitionsBundle/Setter/ClassificationStoreSetter.php index eb9729fe..0c7a2564 100644 --- a/src/DataDefinitionsBundle/Setter/ClassificationStoreSetter.php +++ b/src/DataDefinitionsBundle/Setter/ClassificationStoreSetter.php @@ -25,7 +25,7 @@ class ClassificationStoreSetter implements SetterInterface, GetterInterface { public function set(SetterContextInterface $context): void { - $mapConfig = $context->getImportMapping()->getSetterConfig(); + $mapConfig = $context->getMapping()->getSetterConfig(); $fieldName = $mapConfig['field']; $keyConfig = (int)$mapConfig['keyConfig']; $groupConfig = (int)$mapConfig['groupConfig']; diff --git a/src/DataDefinitionsBundle/Setter/CoreShop/StorePriceSetter.php b/src/DataDefinitionsBundle/Setter/CoreShop/StorePriceSetter.php index db954b10..84486df4 100644 --- a/src/DataDefinitionsBundle/Setter/CoreShop/StorePriceSetter.php +++ b/src/DataDefinitionsBundle/Setter/CoreShop/StorePriceSetter.php @@ -36,7 +36,7 @@ public function __construct(StoreRepositoryInterface $storeRepository) public function set(SetterContextInterface $context) { - $config = $context->getImportMapping()->getSetterConfig(); + $config = $context->getMapping()->getSetterConfig(); if (!array_key_exists('stores', $config) || !is_array($config['stores'])) { return; @@ -49,7 +49,7 @@ public function set(SetterContextInterface $context) throw new InvalidArgumentException(sprintf('Store with ID %s not found', $config['store'])); } - $setter = sprintf('set%s', ucfirst($context->getImportMapping()->getToColumn())); + $setter = sprintf('set%s', ucfirst($context->getMapping()->getToColumn())); if (!method_exists($context->getObject(), $setter)) { throw new InvalidArgumentException(sprintf('Expected a %s function but can not find it', $setter)); diff --git a/src/DataDefinitionsBundle/Setter/CoreShop/StoreValuesSetter.php b/src/DataDefinitionsBundle/Setter/CoreShop/StoreValuesSetter.php index ef54efcd..66e605c4 100644 --- a/src/DataDefinitionsBundle/Setter/CoreShop/StoreValuesSetter.php +++ b/src/DataDefinitionsBundle/Setter/CoreShop/StoreValuesSetter.php @@ -36,7 +36,7 @@ public function __construct(StoreRepositoryInterface $storeRepository) public function set(SetterContextInterface $context) { - $config = $context->getImportMapping()->getSetterConfig(); + $config = $context->getMapping()->getSetterConfig(); if (!array_key_exists('stores', $config) || !is_array($config['stores'])) { return; @@ -49,7 +49,7 @@ public function set(SetterContextInterface $context) throw new InvalidArgumentException(sprintf('Store with ID %s not found', $config['store'])); } - $setter = sprintf('set%sOfType', ucfirst($context->getImportMapping()->getToColumn())); + $setter = sprintf('set%sOfType', ucfirst($context->getMapping()->getToColumn())); if (!method_exists($context->getObject(), $setter)) { throw new InvalidArgumentException(sprintf('Expected a %s function but can not find it', $setter)); diff --git a/src/DataDefinitionsBundle/Setter/FieldCollectionSetter.php b/src/DataDefinitionsBundle/Setter/FieldCollectionSetter.php index 56593fa0..a626a370 100644 --- a/src/DataDefinitionsBundle/Setter/FieldCollectionSetter.php +++ b/src/DataDefinitionsBundle/Setter/FieldCollectionSetter.php @@ -26,9 +26,9 @@ class FieldCollectionSetter implements SetterInterface, GetterInterface { public function set(SetterContextInterface $context): void { - $keyParts = explode('~', $context->getImportMapping()->getToColumn()); + $keyParts = explode('~', $context->getMapping()->getToColumn()); - $config = $context->getImportMapping()->getSetterConfig(); + $config = $context->getMapping()->getSetterConfig(); $keys = $config['keys']; $fieldName = $config['field']; $class = $config['class']; diff --git a/src/DataDefinitionsBundle/Setter/KeySetter.php b/src/DataDefinitionsBundle/Setter/KeySetter.php index 1b95cdca..22d416e2 100644 --- a/src/DataDefinitionsBundle/Setter/KeySetter.php +++ b/src/DataDefinitionsBundle/Setter/KeySetter.php @@ -23,7 +23,7 @@ class KeySetter implements SetterInterface { public function set(SetterContextInterface $context): void { - $setter = explode('~', $context->getImportMapping()->getToColumn()); + $setter = explode('~', $context->getMapping()->getToColumn()); $setter = preg_replace('/^o_/', '', $setter[0]); $setter = sprintf('set%s', ucfirst($setter)); diff --git a/src/DataDefinitionsBundle/Setter/LocalizedfieldSetter.php b/src/DataDefinitionsBundle/Setter/LocalizedfieldSetter.php index d41287a7..d1355e89 100644 --- a/src/DataDefinitionsBundle/Setter/LocalizedfieldSetter.php +++ b/src/DataDefinitionsBundle/Setter/LocalizedfieldSetter.php @@ -24,9 +24,9 @@ class LocalizedfieldSetter implements SetterInterface, GetterInterface { public function set(SetterContextInterface $context): void { - $config = $context->getImportMapping()->getSetterConfig(); + $config = $context->getMapping()->getSetterConfig(); - $setter = explode('~', $context->getImportMapping()->getToColumn()); + $setter = explode('~', $context->getMapping()->getToColumn()); $setter = sprintf('set%s', ucfirst($setter[0])); if (method_exists($context->getObject(), $setter)) { diff --git a/src/DataDefinitionsBundle/Setter/ObjectbrickSetter.php b/src/DataDefinitionsBundle/Setter/ObjectbrickSetter.php index e0acf912..06d9028a 100644 --- a/src/DataDefinitionsBundle/Setter/ObjectbrickSetter.php +++ b/src/DataDefinitionsBundle/Setter/ObjectbrickSetter.php @@ -26,9 +26,9 @@ class ObjectbrickSetter implements SetterInterface, GetterInterface { public function set(SetterContextInterface $context) { - $keyParts = explode('~', $context->getImportMapping()->getToColumn()); + $keyParts = explode('~', $context->getMapping()->getToColumn()); - $config = $context->getImportMapping()->getSetterConfig(); + $config = $context->getMapping()->getSetterConfig(); $fieldName = $config['brickField']; $class = $config['class']; $brickField = $keyParts[3]; diff --git a/src/DataDefinitionsBundle/Setter/RelationSetter.php b/src/DataDefinitionsBundle/Setter/RelationSetter.php index d88480a7..2cf943fb 100644 --- a/src/DataDefinitionsBundle/Setter/RelationSetter.php +++ b/src/DataDefinitionsBundle/Setter/RelationSetter.php @@ -22,7 +22,7 @@ class RelationSetter implements SetterInterface { public function set(SetterContextInterface $context): void { - $fieldName = $context->getImportMapping()->getToColumn(); + $fieldName = $context->getMapping()->getToColumn(); $getter = sprintf('get%s', ucfirst($fieldName)); $setter = sprintf('set%s', ucfirst($fieldName)); From 2a806802d95d7f99905745304a802d3fec477b64 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Dalibor=20Karlovi=C4=87?= Date: Wed, 20 Jul 2022 15:38:53 +0200 Subject: [PATCH 29/65] fix: streamline process manager run invocations --- .../DataDefinitionProcessTrait.php | 49 +++++++++++++++++++ .../ExportDefinitionProcess.php | 23 ++------- .../ImportDefinitionProcess.php | 25 ++-------- 3 files changed, 57 insertions(+), 40 deletions(-) create mode 100644 src/DataDefinitionsBundle/ProcessManager/DataDefinitionProcessTrait.php diff --git a/src/DataDefinitionsBundle/ProcessManager/DataDefinitionProcessTrait.php b/src/DataDefinitionsBundle/ProcessManager/DataDefinitionProcessTrait.php new file mode 100644 index 00000000..593b4727 --- /dev/null +++ b/src/DataDefinitionsBundle/ProcessManager/DataDefinitionProcessTrait.php @@ -0,0 +1,49 @@ +getSettings(); + if (isset($settings['params'])) { + $params = array_replace(json_decode($settings['params'], true), $params); + } + + $currentUser = Admin::getCurrentUser(); + + if ($currentUser && !isset($params['userId'])) { + $params['userId'] = $currentUser->getId(); + } + + $settings['command'] = [ + 'data-definitions:export', + '-d', + $settings['definition'], + '-p', + json_encode($params), + ]; + + $executable->setSettings($settings); + + return parent::run($executable, $params); + } +} diff --git a/src/DataDefinitionsBundle/ProcessManager/ExportDefinitionProcess.php b/src/DataDefinitionsBundle/ProcessManager/ExportDefinitionProcess.php index 70413ecf..376f558c 100644 --- a/src/DataDefinitionsBundle/ProcessManager/ExportDefinitionProcess.php +++ b/src/DataDefinitionsBundle/ProcessManager/ExportDefinitionProcess.php @@ -21,25 +21,10 @@ final class ExportDefinitionProcess extends Pimcore { - public function run(ExecutableInterface $executable, array $params = null): int - { - $settings = $executable->getSettings(); - if (isset($settings['params'])) { - $settings['params'] = array_replace(json_decode($settings['params'], true), (array)$params); - } else { - $settings['params'] = (array)$params; - } - - $settings['command'] = [ - 'data-definitions:export', - '-d', - $settings['definition'], - '-p', - json_encode($settings['params']), - ]; + use DataDefinitionProcessTrait; - $executable->setSettings($settings); - - return parent::run($executable, $params); + public function run(ExecutableInterface $executable, array $params = []): int + { + return $this->runDefinition('data-definitions:export', $executable, $params); } } diff --git a/src/DataDefinitionsBundle/ProcessManager/ImportDefinitionProcess.php b/src/DataDefinitionsBundle/ProcessManager/ImportDefinitionProcess.php index e4869b6b..995e5e2f 100644 --- a/src/DataDefinitionsBundle/ProcessManager/ImportDefinitionProcess.php +++ b/src/DataDefinitionsBundle/ProcessManager/ImportDefinitionProcess.php @@ -22,27 +22,10 @@ final class ImportDefinitionProcess extends Pimcore { - public function run(ExecutableInterface $executable, array $params = null): int - { - $settings = $executable->getSettings(); - $params = json_decode($settings['params'], true); - - $currentUser = Admin::getCurrentUser(); - - if ($currentUser && !isset($params['userId'])) { - $params['userId'] = $currentUser->getId(); - } + use DataDefinitionProcessTrait; - $settings['command'] = [ - 'data-definitions:import', - '-d', - $settings['definition'], - '-p', - json_encode($params), - ]; - - $executable->setSettings($settings); - - return parent::run($executable); + public function run(ExecutableInterface $executable, array $params = []): int + { + return $this->runDefinition('data-definitions:import', $executable, $params); } } From 1f8980259051d07f257005df98e30525174f5a4a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Dalibor=20Karlovi=C4=87?= Date: Wed, 20 Jul 2022 15:45:44 +0200 Subject: [PATCH 30/65] fix: streamline process manager run invocations --- .../ProcessManager/DataDefinitionProcessTrait.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/DataDefinitionsBundle/ProcessManager/DataDefinitionProcessTrait.php b/src/DataDefinitionsBundle/ProcessManager/DataDefinitionProcessTrait.php index 593b4727..495a64ca 100644 --- a/src/DataDefinitionsBundle/ProcessManager/DataDefinitionProcessTrait.php +++ b/src/DataDefinitionsBundle/ProcessManager/DataDefinitionProcessTrait.php @@ -35,7 +35,7 @@ private function runDefinition(string $type, ExecutableInterface $executable, ar } $settings['command'] = [ - 'data-definitions:export', + $type, '-d', $settings['definition'], '-p', From 9768baf3fbf1504e2ce32d72a7f040f756cf38f2 Mon Sep 17 00:00:00 2001 From: Dominik Pfaffenbauer Date: Wed, 20 Jul 2022 15:47:32 +0200 Subject: [PATCH 31/65] stan --- src/DataDefinitionsBundle/Exporter/Exporter.php | 2 +- .../Interpreter/ConditionalInterpreter.php | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/DataDefinitionsBundle/Exporter/Exporter.php b/src/DataDefinitionsBundle/Exporter/Exporter.php index f8e135ad..bc5b8641 100644 --- a/src/DataDefinitionsBundle/Exporter/Exporter.php +++ b/src/DataDefinitionsBundle/Exporter/Exporter.php @@ -192,7 +192,7 @@ private function exportRow( $data = []; $runner = null; - $runnerContext = $this->contextFactory->createRunnerContext($definition, $params, null, $object); + $runnerContext = $this->contextFactory->createRunnerContext($definition, $params, null, null, $object); $this->eventDispatcher->dispatch( new ExportDefinitionEvent($definition, sprintf('Export Object %s', $object->getId()), $params), diff --git a/src/DataDefinitionsBundle/Interpreter/ConditionalInterpreter.php b/src/DataDefinitionsBundle/Interpreter/ConditionalInterpreter.php index 3b3c6a84..371a0643 100644 --- a/src/DataDefinitionsBundle/Interpreter/ConditionalInterpreter.php +++ b/src/DataDefinitionsBundle/Interpreter/ConditionalInterpreter.php @@ -65,6 +65,6 @@ public function interpret(InterpreterContextInterface $context): mixed return $context->getValue(); } - return $interpreterObject->interpret($context, $interpreter['interpreterConfig']); + return $interpreterObject->interpret($context); } } From c0ec6f920236b3e8ea419ff7a2686d806902fb63 Mon Sep 17 00:00:00 2001 From: Dominik Pfaffenbauer Date: Wed, 20 Jul 2022 15:54:52 +0200 Subject: [PATCH 32/65] Conditional fixes --- .../Interpreter/ConditionalInterpreter.php | 30 ++++++++++++------- .../Resources/config/services.yml | 1 + 2 files changed, 20 insertions(+), 11 deletions(-) diff --git a/src/DataDefinitionsBundle/Interpreter/ConditionalInterpreter.php b/src/DataDefinitionsBundle/Interpreter/ConditionalInterpreter.php index 371a0643..6b907899 100644 --- a/src/DataDefinitionsBundle/Interpreter/ConditionalInterpreter.php +++ b/src/DataDefinitionsBundle/Interpreter/ConditionalInterpreter.php @@ -19,22 +19,17 @@ use CoreShop\Component\Registry\ServiceRegistryInterface; use Symfony\Component\DependencyInjection\ContainerInterface; use Symfony\Component\ExpressionLanguage\ExpressionLanguage; +use Wvision\Bundle\DataDefinitionsBundle\Context\ContextFactoryInterface; use Wvision\Bundle\DataDefinitionsBundle\Context\InterpreterContextInterface; class ConditionalInterpreter implements InterpreterInterface { - private ServiceRegistryInterface $interpreterRegistry; - protected ExpressionLanguage $expressionLanguage; - protected ContainerInterface $container; - public function __construct( - ServiceRegistryInterface $interpreterRegistry, - ExpressionLanguage $expressionLanguage, - ContainerInterface $container + protected ServiceRegistryInterface $interpreterRegistry, + protected ExpressionLanguage $expressionLanguage, + protected ContainerInterface $container, + protected ContextFactoryInterface $contextFactory ) { - $this->interpreterRegistry = $interpreterRegistry; - $this->expressionLanguage = $expressionLanguage; - $this->container = $container; } public function interpret(InterpreterContextInterface $context): mixed @@ -65,6 +60,19 @@ public function interpret(InterpreterContextInterface $context): mixed return $context->getValue(); } - return $interpreterObject->interpret($context); + $interpreterObject = $this->interpreterRegistry->get($interpreter['type']); + + $newContext = $this->contextFactory->createInterpreterContext( + $context->getDefinition(), + $context->getParams(), + $interpreter['interpreterConfig'], + $context->getDataRow(), + $context->getDataSet(), + $context->getObject(), + $context->getValue(), + $context->getMapping() + ); + + return $interpreterObject->interpret($newContext); } } diff --git a/src/DataDefinitionsBundle/Resources/config/services.yml b/src/DataDefinitionsBundle/Resources/config/services.yml index 9759df65..95a9cc03 100644 --- a/src/DataDefinitionsBundle/Resources/config/services.yml +++ b/src/DataDefinitionsBundle/Resources/config/services.yml @@ -242,6 +242,7 @@ services: - '@data_definitions.registry.interpreter' - '@coreshop.expression_language' - '@service_container' + - '@Wvision\Bundle\DataDefinitionsBundle\Context\ContextFactoryInterface' tags: - { name: data_definitions.interpreter, type: conditional, form-type: Wvision\Bundle\DataDefinitionsBundle\Form\Type\Interpreter\ConditionalInterpreterType } From acecefc5ed4688060f3749c1b4ac20f34beb8443 Mon Sep 17 00:00:00 2001 From: Dominik Pfaffenbauer Date: Wed, 20 Jul 2022 16:34:34 +0200 Subject: [PATCH 33/65] fix coreshop interpreter --- .../CoreShop/CurrencyInterpreter.php | 2 + .../Interpreter/CoreShop/MoneyInterpreter.php | 43 +++++++++---------- .../Interpreter/CoreShop/PriceInterpreter.php | 5 ++- .../CoreShop/StoresInterpreter.php | 2 + 4 files changed, 28 insertions(+), 24 deletions(-) diff --git a/src/DataDefinitionsBundle/Interpreter/CoreShop/CurrencyInterpreter.php b/src/DataDefinitionsBundle/Interpreter/CoreShop/CurrencyInterpreter.php index 474de8b0..bf967024 100644 --- a/src/DataDefinitionsBundle/Interpreter/CoreShop/CurrencyInterpreter.php +++ b/src/DataDefinitionsBundle/Interpreter/CoreShop/CurrencyInterpreter.php @@ -12,6 +12,8 @@ * @license https://github.com/w-vision/DataDefinitions/blob/master/gpl-3.0.txt GNU General Public License version 3 (GPLv3) */ +declare(strict_types=1); + namespace Wvision\Bundle\DataDefinitionsBundle\Interpreter\CoreShop; use CoreShop\Component\Currency\Repository\CurrencyRepositoryInterface; diff --git a/src/DataDefinitionsBundle/Interpreter/CoreShop/MoneyInterpreter.php b/src/DataDefinitionsBundle/Interpreter/CoreShop/MoneyInterpreter.php index 656ab825..363df633 100644 --- a/src/DataDefinitionsBundle/Interpreter/CoreShop/MoneyInterpreter.php +++ b/src/DataDefinitionsBundle/Interpreter/CoreShop/MoneyInterpreter.php @@ -1,15 +1,26 @@ currencyRepository = $currencyRepository; } - public function interpret(InterpreterContextInterface $context) + public function interpret(InterpreterContextInterface $context): mixed { - $value = $this->getValue($context->getValue(), $context->getConfiguration()); - $currency = $this->resolveCurrency($value, $context->getConfiguration()); + $value = $this->getValue((string)$context->getValue(), $context); + $currency = $this->resolveCurrency((string)$value, $context); if (null === $currency) { return null; @@ -31,20 +42,14 @@ public function interpret(InterpreterContextInterface $context) return new Money($value, $currency); } - - /** - * @param $value - * @param $context->getConfiguration() - * - * @return int - */ - private function getValue($value, $context->getConfiguration()) + + private function getValue(string $value, InterpreterContextInterface $context): int { $inputIsFloat = $context->getConfiguration()['isFloat']; $value = preg_replace("/[^0-9,.]+/", "", $value); - if (is_string($value)) { + if (\is_string($value)) { $value = str_replace(',', '.', $value); $value = (float)$value; } @@ -56,13 +61,7 @@ private function getValue($value, $context->getConfiguration()) return (int)$value; } - /** - * @param string $value - * @param array $context->getConfiguration() - * - * @return CurrencyInterface|null - */ - private function resolveCurrency($value, $context->getConfiguration()) + private function resolveCurrency(string $value, InterpreterContextInterface$context): ?CurrencyInterface { $currency = null; diff --git a/src/DataDefinitionsBundle/Interpreter/CoreShop/PriceInterpreter.php b/src/DataDefinitionsBundle/Interpreter/CoreShop/PriceInterpreter.php index 2f2c01d5..8ca7b85c 100644 --- a/src/DataDefinitionsBundle/Interpreter/CoreShop/PriceInterpreter.php +++ b/src/DataDefinitionsBundle/Interpreter/CoreShop/PriceInterpreter.php @@ -12,11 +12,12 @@ * @license https://github.com/w-vision/DataDefinitions/blob/master/gpl-3.0.txt GNU General Public License version 3 (GPLv3) */ +declare(strict_types=1); + namespace Wvision\Bundle\DataDefinitionsBundle\Interpreter\CoreShop; use Wvision\Bundle\DataDefinitionsBundle\Context\InterpreterContextInterface; use Wvision\Bundle\DataDefinitionsBundle\Interpreter\InterpreterInterface; -use function is_string; final class PriceInterpreter implements InterpreterInterface { @@ -25,7 +26,7 @@ public function interpret(InterpreterContextInterface $context): mixed $inputIsFloat = $context->getConfiguration()['isFloat']; $value = $context->getValue(); - if (is_string($value)) { + if (\is_string($value)) { $value = str_replace(',', '.', $value); $value = (float)$value; } diff --git a/src/DataDefinitionsBundle/Interpreter/CoreShop/StoresInterpreter.php b/src/DataDefinitionsBundle/Interpreter/CoreShop/StoresInterpreter.php index 7be1fe7b..3615a72f 100644 --- a/src/DataDefinitionsBundle/Interpreter/CoreShop/StoresInterpreter.php +++ b/src/DataDefinitionsBundle/Interpreter/CoreShop/StoresInterpreter.php @@ -12,6 +12,8 @@ * @license https://github.com/w-vision/DataDefinitions/blob/master/gpl-3.0.txt GNU General Public License version 3 (GPLv3) */ +declare(strict_types=1); + namespace Wvision\Bundle\DataDefinitionsBundle\Interpreter\CoreShop; use Wvision\Bundle\DataDefinitionsBundle\Context\InterpreterContextInterface; From c8759275419e72931421c88f8e7302d9a6569826 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Dalibor=20Karlovi=C4=87?= Date: Thu, 22 Sep 2022 15:35:10 +0200 Subject: [PATCH 34/65] fix: allow importer/exporter to run GC each 50 items --- src/DataDefinitionsBundle/Exporter/Exporter.php | 3 +-- src/DataDefinitionsBundle/Importer/Importer.php | 2 +- 2 files changed, 2 insertions(+), 3 deletions(-) diff --git a/src/DataDefinitionsBundle/Exporter/Exporter.php b/src/DataDefinitionsBundle/Exporter/Exporter.php index bc5b8641..736fbc7a 100644 --- a/src/DataDefinitionsBundle/Exporter/Exporter.php +++ b/src/DataDefinitionsBundle/Exporter/Exporter.php @@ -119,7 +119,6 @@ private function runExport( UnpublishedHelper::hideUnpublished( function () use ($definition, $params, $total, $fetcher, $provider, $fetcherContext) { $count = 0; - $countToClean = 1000; $perLoop = 50; $perRun = ceil($total / $perLoop); @@ -134,7 +133,7 @@ function () use ($definition, $params, $total, $fetcher, $provider, $fetcherCont try { $this->exportRow($definition, $object, $params, $provider); - if (($count + 1) % $countToClean === 0) { + if (($count + 1) % $perLoop === 0) { Pimcore::collectGarbage(); $this->logger->info('Clean Garbage'); $this->eventDispatcher->dispatch( diff --git a/src/DataDefinitionsBundle/Importer/Importer.php b/src/DataDefinitionsBundle/Importer/Importer.php index 9bb17261..0cd2b6ba 100644 --- a/src/DataDefinitionsBundle/Importer/Importer.php +++ b/src/DataDefinitionsBundle/Importer/Importer.php @@ -235,7 +235,7 @@ private function runImport( } $count = 0; - $countToClean = 1000; + $countToClean = 50; $objectIds = []; $exceptions = []; From 4096c0a28903f8d575a926b667dad1e3d0581035 Mon Sep 17 00:00:00 2001 From: Dominik Pfaffenbauer Date: Sat, 24 Sep 2022 11:54:49 +0200 Subject: [PATCH 35/65] [Pimcore] 10.5 min requirement --- composer.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/composer.json b/composer.json index 90835d1a..f091d699 100755 --- a/composer.json +++ b/composer.json @@ -38,7 +38,7 @@ "jms/serializer": "^3.17.1", "league/csv": "^9.7", "nyholm/psr7": "^1.5", - "pimcore/pimcore": "^10.2", + "pimcore/pimcore": "^10.5", "psr/http-client-implementation": "^1.0", "psr/http-factory-implementation": "^1.0" }, From 6fea55cd398035a94c0a45e3ae0ddeedd13248d3 Mon Sep 17 00:00:00 2001 From: Dominik Pfaffenbauer Date: Sat, 24 Sep 2022 12:25:47 +0200 Subject: [PATCH 36/65] run tests for Pimcore 10.5 and PHP 8.1 --- .github/workflows/behat.yml | 4 ++-- .github/workflows/static.yml | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/.github/workflows/behat.yml b/.github/workflows/behat.yml index b83b4eba..e2c18e7f 100644 --- a/.github/workflows/behat.yml +++ b/.github/workflows/behat.yml @@ -36,8 +36,8 @@ jobs: name: "${{ matrix.pimcore }}, PHP ${{ matrix.php }}" strategy: matrix: - php: [ 8.0 ] - pimcore: [ ^10.2, ^10.3, ^10.4, 10.x-dev ] + php: [ 8.0, 8.1 ] + pimcore: [ ^10.5 ] steps: - uses: actions/checkout@v2 diff --git a/.github/workflows/static.yml b/.github/workflows/static.yml index cb642ebd..81e955ec 100644 --- a/.github/workflows/static.yml +++ b/.github/workflows/static.yml @@ -14,8 +14,8 @@ jobs: strategy: matrix: - php: [ 8.0 ] - pimcore: [ ^10.2, 10.x-dev ] + php: [ 8.0, 8.1 ] + pimcore: [ ^10.5 ] database: [ 'mysql:8.0' ] dependencies: [ highest, lowest ] From a1d473571e8a0d334a3e7b9dd175671b0527cc56 Mon Sep 17 00:00:00 2001 From: Dominik Pfaffenbauer Date: Tue, 27 Sep 2022 08:06:48 +0200 Subject: [PATCH 37/65] [Pimcore] 10.5 min requirement --- src/DataDefinitionsBundle/DataDefinitionsBundle.php | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/src/DataDefinitionsBundle/DataDefinitionsBundle.php b/src/DataDefinitionsBundle/DataDefinitionsBundle.php index d2f84309..0cdc04af 100644 --- a/src/DataDefinitionsBundle/DataDefinitionsBundle.php +++ b/src/DataDefinitionsBundle/DataDefinitionsBundle.php @@ -20,6 +20,7 @@ use CoreShop\Bundle\ResourceBundle\AbstractResourceBundle; use CoreShop\Bundle\ResourceBundle\CoreShopResourceBundle; use CoreShop\Bundle\RuleBundle\CoreShopRuleBundle; +use Pimcore\Extension\Bundle\Installer\InstallerInterface; use Pimcore\Extension\Bundle\PimcoreBundleInterface; use Pimcore\HttpKernel\BundleCollection\BundleCollection; use Symfony\Component\DependencyInjection\ContainerBuilder; @@ -38,7 +39,7 @@ use Wvision\Bundle\DataDefinitionsBundle\DependencyInjection\Compiler\RunnerRegistryCompilerPass; use Wvision\Bundle\DataDefinitionsBundle\DependencyInjection\Compiler\SetterRegistryCompilerPass; -class DataDefinitionsBundle extends AbstractResourceBundle implements PimcoreBundleInterface +class DataDefinitionsBundle extends AbstractResourceBundle { public static function registerDependentBundles(BundleCollection $collection): void { @@ -95,12 +96,12 @@ public function getDescription(): string return 'Data Definitions allows you to create reusable Definitions for Importing all kinds of data into DataObjects.'; } - public function getInstaller() + public function getInstaller(): ?InstallerInterface { return $this->container->get(Installer::class); } - public function getAdminIframePath() + public function getAdminIframePath(): ?string { return null; } From a108d8ebb516a808ce4e63beba0c14d6b12c1071 Mon Sep 17 00:00:00 2001 From: Dominik Pfaffenbauer Date: Tue, 27 Sep 2022 08:11:34 +0200 Subject: [PATCH 38/65] [Pimcore] 10.5 min requirement --- .github/workflows/static.yml | 3 +++ 1 file changed, 3 insertions(+) diff --git a/.github/workflows/static.yml b/.github/workflows/static.yml index 81e955ec..54d4d198 100644 --- a/.github/workflows/static.yml +++ b/.github/workflows/static.yml @@ -18,6 +18,9 @@ jobs: pimcore: [ ^10.5 ] database: [ 'mysql:8.0' ] dependencies: [ highest, lowest ] + exclude: + - php: 8.1 + dependencies: lowest services: database: From 31c1e4344f095564160d7f55b5bdc289dc69218c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Dalibor=20Karlovi=C4=87?= Date: Thu, 29 Sep 2022 11:42:07 +0200 Subject: [PATCH 39/65] fix: display exception in process manager logs --- src/DataDefinitionsBundle/Importer/Importer.php | 2 +- .../ProcessManager/AbstractProcessManagerListener.php | 4 ++++ 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/src/DataDefinitionsBundle/Importer/Importer.php b/src/DataDefinitionsBundle/Importer/Importer.php index 0cd2b6ba..a2c37c9d 100644 --- a/src/DataDefinitionsBundle/Importer/Importer.php +++ b/src/DataDefinitionsBundle/Importer/Importer.php @@ -277,7 +277,7 @@ private function runImport( $this->eventDispatcher->dispatch( $definition, - 'data_definitions.import.status', + 'data_definitions.import.failure', sprintf('Error: %s', $ex->getMessage()), $params ); diff --git a/src/DataDefinitionsBundle/ProcessManager/AbstractProcessManagerListener.php b/src/DataDefinitionsBundle/ProcessManager/AbstractProcessManagerListener.php index d5375591..651b7e25 100644 --- a/src/DataDefinitionsBundle/ProcessManager/AbstractProcessManagerListener.php +++ b/src/DataDefinitionsBundle/ProcessManager/AbstractProcessManagerListener.php @@ -195,6 +195,10 @@ public function onFailureEvent(DefinitionEventInterface $event): void } $this->process->setCompleted(time()); $this->process->save(); + + if (is_string($event->getSubject())) { + $this->processLogger->info($this->process, ImportDefinitionsReport::EVENT_STATUS_ERROR.$event->getSubject()); + } } } } From f005e02d32a5bb4255bb815f1ea61346010660b6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Dalibor=20Karlovi=C4=87?= Date: Thu, 29 Sep 2022 12:04:27 +0200 Subject: [PATCH 40/65] fix: make GC always run, even with exceptions --- .../Importer/Importer.php | 26 +++++++++---------- 1 file changed, 13 insertions(+), 13 deletions(-) diff --git a/src/DataDefinitionsBundle/Importer/Importer.php b/src/DataDefinitionsBundle/Importer/Importer.php index a2c37c9d..6d3079e2 100644 --- a/src/DataDefinitionsBundle/Importer/Importer.php +++ b/src/DataDefinitionsBundle/Importer/Importer.php @@ -257,19 +257,6 @@ private function runImport( if ($object instanceof Concrete) { $objectIds[] = $object->getId(); } - - if (($count + 1) % $countToClean === 0) { - Pimcore::collectGarbage(); - $this->logger->info('Clean Garbage'); - $this->eventDispatcher->dispatch( - $definition, - 'data_definitions.import.status', - 'Collect Garbage', - $params - ); - } - - $count++; } catch (Throwable $ex) { $this->logger->error($ex); @@ -285,6 +272,19 @@ private function runImport( if ($definition->getStopOnException()) { throw $ex; } + } finally { + if (($count + 1) % $countToClean === 0) { + Pimcore::collectGarbage(); + $this->logger->info('Clean Garbage'); + $this->eventDispatcher->dispatch( + $definition, + 'data_definitions.import.status', + 'Collect Garbage', + $params + ); + } + + $count++; } $this->eventDispatcher->dispatch($definition, 'data_definitions.import.progress', '', $params); From 2ac39b3cd6376ba09d25d25570d3361feec1bffe Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Dalibor=20Karlovi=C4=87?= Date: Thu, 29 Sep 2022 16:57:59 +0200 Subject: [PATCH 41/65] fix: write to log file before throttling the status update --- .../ProcessManager/AbstractProcessManagerListener.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/DataDefinitionsBundle/ProcessManager/AbstractProcessManagerListener.php b/src/DataDefinitionsBundle/ProcessManager/AbstractProcessManagerListener.php index 651b7e25..1da7de90 100644 --- a/src/DataDefinitionsBundle/ProcessManager/AbstractProcessManagerListener.php +++ b/src/DataDefinitionsBundle/ProcessManager/AbstractProcessManagerListener.php @@ -145,6 +145,8 @@ public function onProgressEvent(DefinitionEventInterface $event): void public function onStatusEvent(DefinitionEventInterface $event): void { if ($this->process) { + $this->processLogger->info($this->process, ImportDefinitionsReport::EVENT_STATUS.$event->getSubject()); + $now = new \DateTimeImmutable(); if ($this->lastStatusAt instanceof \DateTimeInterface) { $diff = $now->getTimestamp() - $this->lastStatusAt->getTimestamp(); @@ -160,8 +162,6 @@ public function onStatusEvent(DefinitionEventInterface $event): void } $this->process->setMessage($event->getSubject()); $this->process->save(); - - $this->processLogger->info($this->process, ImportDefinitionsReport::EVENT_STATUS.$event->getSubject()); } } From acb31e57a31753eb7f3388489aac637f59fc18c8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Dalibor=20Karlovi=C4=87?= Date: Thu, 13 Oct 2022 16:31:13 +0200 Subject: [PATCH 42/65] feat: deduplicate assets by hash --- .../Interpreter/AssetUrlInterpreterType.php | 2 + .../Interpreter/AssetsUrlInterpreterType.php | 2 + .../Interpreter/AssetUrlInterpreter.php | 158 ++++++++++-------- .../pimcore/js/interpreters/asseturl.js | 30 +++- 4 files changed, 122 insertions(+), 70 deletions(-) diff --git a/src/DataDefinitionsBundle/Form/Type/Interpreter/AssetUrlInterpreterType.php b/src/DataDefinitionsBundle/Form/Type/Interpreter/AssetUrlInterpreterType.php index 8c615b5f..e06c8d1a 100644 --- a/src/DataDefinitionsBundle/Form/Type/Interpreter/AssetUrlInterpreterType.php +++ b/src/DataDefinitionsBundle/Form/Type/Interpreter/AssetUrlInterpreterType.php @@ -28,6 +28,8 @@ public function buildForm(FormBuilderInterface $builder, array $options): void $builder ->add('path', TextType::class) ->add('deduplicate_by_url', CheckboxType::class) + ->add('deduplicate_by_hash', CheckboxType::class) + ->add('use_content_disposition', CheckboxType::class) ->add('relocate_existing_objects', CheckboxType::class) ->add('rename_existing_objects', CheckboxType::class); } diff --git a/src/DataDefinitionsBundle/Form/Type/Interpreter/AssetsUrlInterpreterType.php b/src/DataDefinitionsBundle/Form/Type/Interpreter/AssetsUrlInterpreterType.php index 03471ced..ced41619 100644 --- a/src/DataDefinitionsBundle/Form/Type/Interpreter/AssetsUrlInterpreterType.php +++ b/src/DataDefinitionsBundle/Form/Type/Interpreter/AssetsUrlInterpreterType.php @@ -28,6 +28,8 @@ public function buildForm(FormBuilderInterface $builder, array $options): void $builder ->add('path', TextType::class) ->add('deduplicate_by_url', CheckboxType::class) + ->add('deduplicate_by_hash', CheckboxType::class) + ->add('use_content_disposition', CheckboxType::class) ->add('relocate_existing_objects', CheckboxType::class) ->add('rename_existing_objects', CheckboxType::class); } diff --git a/src/DataDefinitionsBundle/Interpreter/AssetUrlInterpreter.php b/src/DataDefinitionsBundle/Interpreter/AssetUrlInterpreter.php index 66340099..3870d049 100644 --- a/src/DataDefinitionsBundle/Interpreter/AssetUrlInterpreter.php +++ b/src/DataDefinitionsBundle/Interpreter/AssetUrlInterpreter.php @@ -24,6 +24,7 @@ class AssetUrlInterpreter implements InterpreterInterface { protected const METADATA_ORIGIN_URL = 'origin_url'; + protected const METADATA_ORIGIN_HASH = 'origin_hash'; protected \Psr\Http\Client\ClientInterface $httpClient; protected \Psr\Http\Message\RequestFactoryInterface $requestFactory; @@ -38,105 +39,122 @@ public function __construct( public function interpret(InterpreterContextInterface $context): mixed { $path = $context->getConfiguration()['path']; + $url = $context->getValue(); - if (filter_var($context->getValue(), FILTER_VALIDATE_URL)) { - $asset = null; - $filename = $this->getFileName($context->getValue()); - - if ($context->getConfiguration()['deduplicate_by_url']) { - if ($asset = $this->getDuplicatedAsset($context->getValue())) { - $filename = $asset->getFilename(); - $assetPath = $asset->getPath(); - } else { - $assetPath = $path; - } - } else { - $assetPath = $path; - } + if (filter_var($url, FILTER_VALIDATE_URL) === false) { + throw new \InvalidArgumentException(sprintf('Provided asset URL value %1$s is not a valid URL', $url)); + } - $parent = Asset\Service::createFolderByPath($assetPath); + $asset = null; + if ($context->getConfiguration()['deduplicate_by_url']) { + $asset = $this->deduplicateAssetByUrl($url); + } - if (!$asset instanceof Asset) { - // Download - $fileData = $this->getFileContents($context->getValue()); + $fileHash = null; + if ($asset === null) { + $fileData = $this->getFileContents($url); + $fileHash = md5($fileData); - if ($fileData) { - $asset = Asset::create($parent->getId(), [ - 'filename' => $filename, - 'data' => $fileData, - ], false); - $asset->addMetadata(self::METADATA_ORIGIN_URL, 'input', $context->getValue()); - $asset->save(); - } - } else { - $save = false; + if ($context->getConfiguration()['deduplicate_by_hash']) { + $asset = $this->deduplicateAssetByHash($fileHash); + } + } - if ($context->getConfiguration()['relocate_existing_objects'] && $asset->getParent() !== $parent) { - $asset->setParent($parent); - $save = true; - } + if ($asset === null) { + // asset doesn't exist already + $parent = Asset\Service::createFolderByPath($path); + $filename = $this->getFileName($url); + $asset = Asset::create($parent->getId(), [ + 'filename' => $filename, + 'data' => $fileData, + ], false); + } - if ($context->getConfiguration()['rename_existing_objects'] && $asset->getFilename() !== $filename) { - $asset->setFilename($filename); - $save = true; - } + $save = false; + $currentUrl = $asset->getMetadata(self::METADATA_ORIGIN_URL) ?? ''; + if (strpos($currentUrl, $url) === false) { + $url = $currentUrl ? $currentUrl .'|'. $url : $url; + $asset->addMetadata(self::METADATA_ORIGIN_URL, 'input', $url); + $save = true; + } - if ($save) { - $asset->save(); - } - } + // $fileHash might not be available here if we deduplicated by URL + if ($fileHash !== null && $asset->getMetadata(self::METADATA_ORIGIN_HASH) !== $fileHash) { + $asset->addMetadata(self::METADATA_ORIGIN_HASH, 'input', $fileHash); + $save = true; + } + if ($context->getConfiguration()['relocate_existing_objects'] && $asset->getParent() !== $parent) { + $asset->setParent($parent); + $save = true; + } + if ($context->getConfiguration()['rename_existing_objects'] && $asset->getFilename() !== $filename) { + $asset->setFilename($filename); + $save = true; + } - return $asset; + if ($save) { + $asset->save(); } - return null; + return $asset; } - private function getFileName(string $url): ?string + private function getFileName(string $url, bool $useContentDisposition = false): ?string { $filename = null; - try { - $request = $this->requestFactory->createRequest('HEAD', $url); - $response = $this->httpClient->sendRequest($request); - $headers = $response->getHeaders(); - - if ( - isset($headers["Content-Disposition"]) && - preg_match( - '/^.*?filename=(?[^\s]+|\x22[^\x22]+\x22)\x3B?.*$/m', - current($headers["Content-Disposition"]), - $match - ) - ) { - $filename = trim($match['f'], ' ";'); + if ($useContentDisposition) { + try { + $request = $this->requestFactory->createRequest('HEAD', $url); + $response = $this->httpClient->sendRequest($request); + $headers = $response->getHeaders(); + + if ( + isset($headers["Content-Disposition"]) && + preg_match( + '/^.*?filename=(?[^\s]+|\x22[^\x22]+\x22)\x3B?.*$/m', + current($headers["Content-Disposition"]), + $match + ) + ) { + $filename = trim($match['f'], ' ";'); + } + } catch (\Psr\Http\Client\ClientExceptionInterface $exception) { } - } catch (\Psr\Http\Client\ClientExceptionInterface $exception) { } - - if (!$filename) { - $filename = File::getValidFilename(basename($url)); + if ($filename === null) { + $filename = basename($url); } - return $filename; + return File::getValidFilename($filename); } - protected function getFileContents(string $value): ?string + protected function getFileContents(string $value): string { try { $request = $this->requestFactory->createRequest('GET', $value); $response = $this->httpClient->sendRequest($request); } catch (\Psr\Http\Client\ClientExceptionInterface $ex) { - return null; + throw new \RuntimeException('Unable to download asset from URL '.$value); } if ($response->getStatusCode() === 200) { return (string)$response->getBody(); } - return null; + throw new \RuntimeException('Unable to download asset from URL '.$value); } - private function getDuplicatedAsset(string $value): ?Asset + private function deduplicateAssetByUrl(string $value): ?Asset + { + return $this->deduplicateAsset(self::METADATA_ORIGIN_URL, $value, true); + } + + private function deduplicateAssetByHash(string $value): ?Asset + { + return $this->deduplicateAsset(self::METADATA_ORIGIN_HASH, $value); + } + + private function deduplicateAsset(string $name, string $value, bool $fuzzy = false) { $listing = new Asset\Listing(); $listing->onCreateQueryBuilder( @@ -144,8 +162,12 @@ function (QueryBuilder $select) { $select->join('assets', 'assets_metadata', 'am', 'id = am.cid'); } ); - $listing->addConditionParam('am.name = ?', static::METADATA_ORIGIN_URL); - $listing->addConditionParam('am.data = ?', $value); + $listing->addConditionParam('am.name = ?', $name); + if ($fuzzy) { + $listing->addConditionParam('am.data LIKE ?', '%'. $value .'%'); + } else { + $listing->addConditionParam('am.data = ?', $value); + } $listing->setLimit(1); $listing->setOrder(['creationDate', 'desc']); diff --git a/src/DataDefinitionsBundle/Resources/public/pimcore/js/interpreters/asseturl.js b/src/DataDefinitionsBundle/Resources/public/pimcore/js/interpreters/asseturl.js index 63370074..3914e374 100644 --- a/src/DataDefinitionsBundle/Resources/public/pimcore/js/interpreters/asseturl.js +++ b/src/DataDefinitionsBundle/Resources/public/pimcore/js/interpreters/asseturl.js @@ -16,12 +16,13 @@ pimcore.registerNS('pimcore.plugin.datadefinitions.interpreters.asset_url'); pimcore.plugin.datadefinitions.interpreters.asset_url = Class.create(pimcore.plugin.datadefinitions.interpreters.abstract, { getLayout: function (fromColumn, toColumn, record, config) { var deduplicateByUrlEnabled = Ext.isDefined(config.deduplicate_by_url) ? config.deduplicate_by_url : false + var deduplicateByHashEnabled = Ext.isDefined(config.deduplicate_by_hash) ? config.deduplicate_by_hash : false var relocateExistingCheckbox = Ext.create({ xtype: 'checkbox', fieldLabel: t('data_definitions_relocate_existing_objects'), name: 'relocate_existing_objects', value: config.deduplicate_by_url && Ext.isDefined(config.relocate_existing_objects) ? config.relocate_existing_objects : false, - disabled: deduplicateByUrlEnabled === false + disabled: deduplicateByUrlEnabled === false || deduplicateByHashEnabled === false }); var renameExistingCheckbox = Ext.create({ @@ -29,7 +30,7 @@ pimcore.plugin.datadefinitions.interpreters.asset_url = Class.create(pimcore.plu fieldLabel: t('data_definitions_rename_existing_objects'), name: 'rename_existing_objects', value: config.deduplicate_by_url && Ext.isDefined(config.rename_existing_objects) ? config.rename_existing_objects : false, - disabled: deduplicateByUrlEnabled === false + disabled: deduplicateByUrlEnabled === false || deduplicateByHashEnabled === false }); return [{ @@ -96,6 +97,31 @@ pimcore.plugin.datadefinitions.interpreters.asset_url = Class.create(pimcore.plu } } }, + { + xtype: 'checkbox', + fieldLabel: t('data_definitions_interpreter_asset_url_deduplicate_by_hash'), + name: 'deduplicate_by_hash', + value: deduplicateByHashEnabled, + listeners: { + change: function (el, enabled) { + var isDeduplicateByHashDisabled = (enabled === false); + + relocateExistingCheckbox + .setValue(false) + .setDisabled(isDeduplicateByHashDisabled); + + renameExistingCheckbox + .setValue(false) + .setDisabled(isDeduplicateByHashDisabled); + } + } + }, + { + xtype: 'checkbox', + fieldLabel: t('data_definitions_interpreter_asset_url_use_content_disposition'), + name: 'use_content_disposition', + value: Ext.isDefined(config.use_content_disposition) ? config.use_content_disposition : false + }, relocateExistingCheckbox, renameExistingCheckbox ]; From 45161a0bef3f2292c2e28bae6942ae480c2cdcdd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Dalibor=20Karlovi=C4=87?= Date: Wed, 19 Oct 2022 11:45:07 +0200 Subject: [PATCH 43/65] feat: deduplicate assets by hash when importing --- .../Interpreter/AssetUrlInterpreter.php | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/src/DataDefinitionsBundle/Interpreter/AssetUrlInterpreter.php b/src/DataDefinitionsBundle/Interpreter/AssetUrlInterpreter.php index 3870d049..7f11653d 100644 --- a/src/DataDefinitionsBundle/Interpreter/AssetUrlInterpreter.php +++ b/src/DataDefinitionsBundle/Interpreter/AssetUrlInterpreter.php @@ -44,26 +44,27 @@ public function interpret(InterpreterContextInterface $context): mixed if (filter_var($url, FILTER_VALIDATE_URL) === false) { throw new \InvalidArgumentException(sprintf('Provided asset URL value %1$s is not a valid URL', $url)); } + $parent = Asset\Service::createFolderByPath($path); + $filename = $this->getFileName($url, $context->getConfiguration()['use_content_disposition'] ?? false); $asset = null; - if ($context->getConfiguration()['deduplicate_by_url']) { + if ($context->getConfiguration()['deduplicate_by_url'] ?? false) { $asset = $this->deduplicateAssetByUrl($url); } $fileHash = null; + $fileData = null; if ($asset === null) { $fileData = $this->getFileContents($url); $fileHash = md5($fileData); - if ($context->getConfiguration()['deduplicate_by_hash']) { + if ($context->getConfiguration()['deduplicate_by_hash'] ?? false) { $asset = $this->deduplicateAssetByHash($fileHash); } } if ($asset === null) { // asset doesn't exist already - $parent = Asset\Service::createFolderByPath($path); - $filename = $this->getFileName($url); $asset = Asset::create($parent->getId(), [ 'filename' => $filename, 'data' => $fileData, @@ -83,11 +84,11 @@ public function interpret(InterpreterContextInterface $context): mixed $asset->addMetadata(self::METADATA_ORIGIN_HASH, 'input', $fileHash); $save = true; } - if ($context->getConfiguration()['relocate_existing_objects'] && $asset->getParent() !== $parent) { + if ($context->getConfiguration()['relocate_existing_objects'] ?? false && $asset->getParent() !== $parent) { $asset->setParent($parent); $save = true; } - if ($context->getConfiguration()['rename_existing_objects'] && $asset->getFilename() !== $filename) { + if ($context->getConfiguration()['rename_existing_objects'] ?? false && $asset->getFilename() !== $filename) { $asset->setFilename($filename); $save = true; } From 8cf783b5890eb76bf898b5e791f256c9af064282 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Dalibor=20Karlovi=C4=87?= Date: Fri, 11 Nov 2022 15:23:12 +0100 Subject: [PATCH 44/65] fix: don't double-count the import file Counting might be expensive, doing it twice doesn't make sense --- src/DataDefinitionsBundle/Importer/Importer.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/DataDefinitionsBundle/Importer/Importer.php b/src/DataDefinitionsBundle/Importer/Importer.php index 6d3079e2..1fa1273d 100644 --- a/src/DataDefinitionsBundle/Importer/Importer.php +++ b/src/DataDefinitionsBundle/Importer/Importer.php @@ -107,8 +107,8 @@ public function doImport(ImportDefinitionInterface $definition, $params): array } - if ((\is_countable($data) || $data instanceof Countable) && \count($data) > 0) { - $this->eventDispatcher->dispatch($definition, 'data_definitions.import.total', \count($data), $params); + if ((\is_countable($data) || $data instanceof Countable) && ($count = \count($data)) > 0) { + $this->eventDispatcher->dispatch($definition, 'data_definitions.import.total', $count, $params); } if ($runner instanceof ImportStartFinishRunnerInterface) { From f35750b71177d92fafb33a4a4e5de7dcc3e86fb4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Dalibor=20Karlovi=C4=87?= Date: Fri, 11 Nov 2022 15:28:02 +0100 Subject: [PATCH 45/65] fix: correctly pass context to asset URL interpreter --- .../Interpreter/AssetsUrlInterpreter.php | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/src/DataDefinitionsBundle/Interpreter/AssetsUrlInterpreter.php b/src/DataDefinitionsBundle/Interpreter/AssetsUrlInterpreter.php index 9d6d6dbc..48f79ec7 100644 --- a/src/DataDefinitionsBundle/Interpreter/AssetsUrlInterpreter.php +++ b/src/DataDefinitionsBundle/Interpreter/AssetsUrlInterpreter.php @@ -16,6 +16,7 @@ namespace Wvision\Bundle\DataDefinitionsBundle\Interpreter; +use Wvision\Bundle\DataDefinitionsBundle\Context\InterpreterContext; use Wvision\Bundle\DataDefinitionsBundle\Context\InterpreterContextInterface; class AssetsUrlInterpreter extends AssetUrlInterpreter @@ -24,7 +25,17 @@ public function interpret(InterpreterContextInterface $context): mixed { $assets = []; foreach ((array)$context->getValue() as $item) { - $asset = parent::interpret($context); + $childContext = new InterpreterContext( + $context->getDefinition(), + $context->getParams(), + $context->getConfiguration(), + $context->getDataRow(), + $context->getDataSet(), + $context->getObject(), + $item, + $context->getMapping() + ); + $asset = parent::interpret($childContext); if ($asset) { $assets[] = $asset; From f7f363a1c8c821035e8f5b6036a05e38a3feb0a9 Mon Sep 17 00:00:00 2001 From: Irina Balaban Date: Mon, 14 Nov 2022 06:28:50 +0100 Subject: [PATCH 46/65] fix: memoize class listing --- src/DataDefinitionsBundle/Fetcher/ObjectsFetcher.php | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/src/DataDefinitionsBundle/Fetcher/ObjectsFetcher.php b/src/DataDefinitionsBundle/Fetcher/ObjectsFetcher.php index 8a904bdb..289fc30f 100644 --- a/src/DataDefinitionsBundle/Fetcher/ObjectsFetcher.php +++ b/src/DataDefinitionsBundle/Fetcher/ObjectsFetcher.php @@ -24,6 +24,8 @@ class ObjectsFetcher implements FetcherInterface { + protected $list; + public function fetch(FetcherContextInterface $context, int $limit, int $offset) { $list = $this->getClassListing($context->getDefinition(), $context->getParams()); @@ -40,6 +42,10 @@ public function count(FetcherContextInterface $context): int private function getClassListing(ExportDefinitionInterface $definition, array $params) { + if ($this->list !== null) { + return $this->list; + } + $class = $definition->getClass(); $classDefinition = ClassDefinition::getByName($class); if (!$classDefinition instanceof ClassDefinition) { @@ -94,7 +100,7 @@ private function getClassListing(ExportDefinitionInterface $definition, array $p $list->setOrderKey('o_id'); $list->setOrder('asc'); - return $list; + return $this->list = $list; } protected function filterQueryParam(string $query) From 5f73bf94d06704c2b8d20ad9fb9bb3842c718285 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Dalibor=20Karlovi=C4=87?= Date: Wed, 16 Nov 2022 13:17:42 +0100 Subject: [PATCH 47/65] fix: correct check --- src/DataDefinitionsBundle/Fetcher/ObjectsFetcher.php | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/src/DataDefinitionsBundle/Fetcher/ObjectsFetcher.php b/src/DataDefinitionsBundle/Fetcher/ObjectsFetcher.php index 289fc30f..ebf3564f 100644 --- a/src/DataDefinitionsBundle/Fetcher/ObjectsFetcher.php +++ b/src/DataDefinitionsBundle/Fetcher/ObjectsFetcher.php @@ -19,12 +19,13 @@ use InvalidArgumentException; use Pimcore\Model\DataObject\ClassDefinition; use Pimcore\Model\DataObject\Concrete; +use Pimcore\Model\DataObject\Listing; use Wvision\Bundle\DataDefinitionsBundle\Context\FetcherContextInterface; use Wvision\Bundle\DataDefinitionsBundle\Model\ExportDefinitionInterface; class ObjectsFetcher implements FetcherInterface { - protected $list; + protected Listing $list; public function fetch(FetcherContextInterface $context, int $limit, int $offset) { @@ -40,9 +41,9 @@ public function count(FetcherContextInterface $context): int return $this->getClassListing($context->getDefinition(), $context->getParams())->getTotalCount(); } - private function getClassListing(ExportDefinitionInterface $definition, array $params) + private function getClassListing(ExportDefinitionInterface $definition, array $params): Listing { - if ($this->list !== null) { + if (isset($this->list)) { return $this->list; } From 36254a0d00abed4906a1076f808905746723936b Mon Sep 17 00:00:00 2001 From: slri Date: Wed, 30 Nov 2022 13:55:38 +0100 Subject: [PATCH 48/65] fix: excel provider export rename() not friendly to streams (#380) Co-authored-by: Irina Balaban --- src/DataDefinitionsBundle/Provider/ExcelProvider.php | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/DataDefinitionsBundle/Provider/ExcelProvider.php b/src/DataDefinitionsBundle/Provider/ExcelProvider.php index da70542e..522c2063 100644 --- a/src/DataDefinitionsBundle/Provider/ExcelProvider.php +++ b/src/DataDefinitionsBundle/Provider/ExcelProvider.php @@ -141,7 +141,8 @@ public function exportData(array $configuration, ExportDefinitionInterface $defi } $file = $this->getFile($params); - rename($this->getExportPath(), $file); + copy($this->getExportPath(), $file); + unlink($this->getExportPath()); } public function provideArtifactStream($configuration, ExportDefinitionInterface $definition, $params) From 5052c0831dc2939ffd33d9f6c5a48434a0bc5cc1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Dalibor=20Karlovi=C4=87?= Date: Fri, 13 Jan 2023 11:19:37 +0100 Subject: [PATCH 49/65] fix: ClassificationStoreSetter doesn't handle empty groups correctly (#382) --- .../Setter/ClassificationStoreSetter.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/DataDefinitionsBundle/Setter/ClassificationStoreSetter.php b/src/DataDefinitionsBundle/Setter/ClassificationStoreSetter.php index 0c7a2564..3559e18b 100644 --- a/src/DataDefinitionsBundle/Setter/ClassificationStoreSetter.php +++ b/src/DataDefinitionsBundle/Setter/ClassificationStoreSetter.php @@ -38,7 +38,7 @@ public function set(SetterContextInterface $context): void if ($classificationStore instanceof Classificationstore) { $groups = $classificationStore->getActiveGroups(); - if (!$groups[$groupConfig]) { + if (!($groups[$groupConfig] ?? false)) { $groups[$groupConfig] = true; $classificationStore->setActiveGroups($groups); } @@ -63,7 +63,7 @@ public function get(GetterContextInterface $context) if ($classificationStore instanceof Classificationstore) { $groups = $classificationStore->getActiveGroups(); - if (!$groups[$groupConfig]) { + if (!($groups[$groupConfig] ?? false)) { $groups[$groupConfig] = true; $classificationStore->setActiveGroups($groups); } From 241bc2a4459ff4bcec643995144d8bee6e35fa4e Mon Sep 17 00:00:00 2001 From: slri Date: Wed, 8 Mar 2023 05:57:48 -0700 Subject: [PATCH 50/65] fix: configure csv writer's escape character to be an empty string by default (#375) * fix: configure csv writer's escape character to be an empty string by default * feat: csv escape character should be configurable --------- Co-authored-by: Irina Balaban --- .../Form/Type/ExportProvider/CsvProviderType.php | 3 ++- src/DataDefinitionsBundle/Provider/CsvProvider.php | 6 ++++++ .../Resources/public/pimcore/js/export_provider/csv.js | 7 +++++++ .../Resources/translations/admin.en.yml | 1 + 4 files changed, 16 insertions(+), 1 deletion(-) diff --git a/src/DataDefinitionsBundle/Form/Type/ExportProvider/CsvProviderType.php b/src/DataDefinitionsBundle/Form/Type/ExportProvider/CsvProviderType.php index 8b39f37a..2ecd4cf3 100644 --- a/src/DataDefinitionsBundle/Form/Type/ExportProvider/CsvProviderType.php +++ b/src/DataDefinitionsBundle/Form/Type/ExportProvider/CsvProviderType.php @@ -26,6 +26,7 @@ public function buildForm(FormBuilderInterface $builder, array $options): void { $builder ->add('delimiter', TextType::class) - ->add('enclosure', TextType::class); + ->add('enclosure', TextType::class) + ->add('escape', TextType::class, ['empty_data' => '']); } } diff --git a/src/DataDefinitionsBundle/Provider/CsvProvider.php b/src/DataDefinitionsBundle/Provider/CsvProvider.php index 49a20805..57b38d68 100644 --- a/src/DataDefinitionsBundle/Provider/CsvProvider.php +++ b/src/DataDefinitionsBundle/Provider/CsvProvider.php @@ -139,6 +139,9 @@ public function exportData(array $configuration, ExportDefinitionInterface $defi $writer = Writer::createFromPath($file, 'w+'); $writer->setDelimiter($configuration['delimiter']); $writer->setEnclosure($configuration['enclosure']); + if (isset($configuration['escape'])) { + $writer->setEscape($configuration['escape']); + } $writer->insertOne($headers); $writer->insertAll($this->exportData); } @@ -161,6 +164,9 @@ public function provideArtifactStream(array $configuration, ExportDefinitionInte $writer = Writer::createFromStream($stream); $writer->setDelimiter($configuration['delimiter']); $writer->setEnclosure($configuration['enclosure']); + if (isset($configuration['escape'])) { + $writer->setEscape($configuration['escape']); + } $writer->insertOne($headers); $writer->insertAll($this->exportData); diff --git a/src/DataDefinitionsBundle/Resources/public/pimcore/js/export_provider/csv.js b/src/DataDefinitionsBundle/Resources/public/pimcore/js/export_provider/csv.js index 37cc4a9c..a594cafa 100644 --- a/src/DataDefinitionsBundle/Resources/public/pimcore/js/export_provider/csv.js +++ b/src/DataDefinitionsBundle/Resources/public/pimcore/js/export_provider/csv.js @@ -27,6 +27,13 @@ pimcore.plugin.datadefinitions.export_provider.csv = Class.create(pimcore.plugin fieldLabel: t('data_definitions_csv_enclosure'), anchor: '100%', value: this.data['enclosure'] ? this.data.enclosure : '"' + }, { + xtype: 'textfield', + name: 'escape', + fieldLabel: t('data_definitions_csv_escape'), + anchor: '100%', + maxLength: 1, + value: this.data['escape'] || '' === this.data['escape'] ? this.data.escape : '\\' }]; } }); diff --git a/src/DataDefinitionsBundle/Resources/translations/admin.en.yml b/src/DataDefinitionsBundle/Resources/translations/admin.en.yml index 9dedb5b1..f784385e 100644 --- a/src/DataDefinitionsBundle/Resources/translations/admin.en.yml +++ b/src/DataDefinitionsBundle/Resources/translations/admin.en.yml @@ -5,6 +5,7 @@ data_definitions_provider_settings: 'Provider Settings' data_definitions_loader: 'Loader' data_definitions_csv_example: 'CSV Example' data_definitions_csv_enclosure: 'Enclosure' +data_definitions_csv_escape: 'Escape' data_definitions_csv_delimiter: 'Delimiter' data_definitions_excel_headers: 'Excel headers' data_definitions_excel_file: 'Excel example file' From 336b4363b0b0008a25e1ba7aa1425b80b1659c64 Mon Sep 17 00:00:00 2001 From: Dominik Pfaffenbauer Date: Tue, 20 Jun 2023 14:51:33 +0200 Subject: [PATCH 51/65] [Next] prepare Pimcore 11 --- composer.json | 16 +- config/config.yaml | 1 - config/migrations.yaml | 19 -- config/packages/security.yaml | 49 ++--- config/routes.yaml | 2 +- config/routes/dev/routes.yaml | 3 +- config/system.yml | 17 -- .../Command/ExportCommand.php | 14 +- .../Command/ImportCommand.php | 13 +- .../AbstractDefinitionController.php | 41 ++++ .../Controller/ExportDefinitionController.php | 16 +- .../Controller/ImportDefinitionController.php | 43 ++-- .../Controller/ImportRuleController.php | 2 +- .../DataDefinitionsBundle.php | 41 ++-- .../DependencyInjection/Configuration.php | 87 ++++++++ .../DataDefinitionsExtension.php | 16 +- .../EventListener/PimcoreSettingsListener.php | 30 +++ .../EventListener/WriteableListener.php | 47 +++++ .../Fetcher/ObjectsFetcher.php | 2 +- .../Importer/Importer.php | 8 + .../Model/AbstractDataDefinition.php | 12 +- .../Model/DataDefinitionInterface.php | 4 - .../Model/ExportDefinition.php | 12 +- .../Model/ExportDefinition/Dao.php | 166 +++++++-------- .../Model/ExportDefinition/Listing.php | 15 +- .../Model/ExportDefinition/Listing/Dao.php | 51 ++--- .../Model/ImportDefinition.php | 12 +- .../Model/ImportDefinition/Dao.php | 190 ++++++++---------- .../Model/ImportDefinition/Listing.php | 12 +- .../Model/ImportDefinition/Listing/Dao.php | 50 ++--- .../Provider/CsvProvider.php | 2 +- .../Resources/config/pimcore/config.yml | 4 + .../config/serializer/Model.Definition.yml | 2 +- .../Resources/config/services.yml | 10 +- .../Resources/config/services/forms.yml | 7 +- .../public/pimcore/css/datadefinition.css | 4 +- .../pimcore/js/definition/abstractItem.js | 11 +- .../public/pimcore/js/export/item.js | 4 + .../public/pimcore/js/export/panel.js | 14 ++ .../public/pimcore/js/import/item.js | 4 + .../public/pimcore/js/import/panel.js | 13 ++ .../Resources/public/pimcore/js/startup.js | 8 +- src/Kernel.php | 4 +- 43 files changed, 638 insertions(+), 440 deletions(-) delete mode 100644 config/migrations.yaml create mode 100644 src/DataDefinitionsBundle/Controller/AbstractDefinitionController.php create mode 100644 src/DataDefinitionsBundle/EventListener/PimcoreSettingsListener.php create mode 100644 src/DataDefinitionsBundle/EventListener/WriteableListener.php diff --git a/composer.json b/composer.json index f091d699..04541a11 100755 --- a/composer.json +++ b/composer.json @@ -32,15 +32,18 @@ "php": ">=8.0", "ext-json": "*", "box/spout": "^3.0", - "coreshop/pimcore-bundle": "^3.0", - "coreshop/resource-bundle": "^3.0", - "coreshop/rule-bundle": "^3.0", + "coreshop/pimcore-bundle": "^4.0", + "coreshop/resource-bundle": "^4.0", + "coreshop/rule-bundle": "^4.0", "jms/serializer": "^3.17.1", "league/csv": "^9.7", "nyholm/psr7": "^1.5", - "pimcore/pimcore": "^10.5", + "pimcore/admin-ui-classic-bundle": "^1.0", + "pimcore/pimcore": "^11.0", "psr/http-client-implementation": "^1.0", - "psr/http-factory-implementation": "^1.0" + "psr/http-factory-implementation": "^1.0", + "symfony/dotenv": "^6.3", + "symfony/http-client": "^6.3" }, "require-dev": { "roave/security-advisories": "dev-latest", @@ -65,7 +68,8 @@ }, "autoload-dev": { "psr-4": { - "Wvision\\Bundle\\DataDefinitionsBundle\\Behat\\": "tests/DataDefinitionsBundle/Behat" + "Wvision\\Bundle\\DataDefinitionsBundle\\Behat\\": "tests/DataDefinitionsBundle/Behat", + "Pimcore\\Model\\DataObject\\": "var/classes/DataObject" }, "classmap": [ "src/Kernel.php" diff --git a/config/config.yaml b/config/config.yaml index 3df4a70d..d84a1e5f 100644 --- a/config/config.yaml +++ b/config/config.yaml @@ -1,6 +1,5 @@ imports: - { resource: services.yaml } - - { resource: migrations.yaml } - { resource: system.yml } - { resource: 'local/' } diff --git a/config/migrations.yaml b/config/migrations.yaml deleted file mode 100644 index 9617ac97..00000000 --- a/config/migrations.yaml +++ /dev/null @@ -1,19 +0,0 @@ -doctrine_migrations: - connection: default - migrations_paths: - 'Pimcore\Bundle\CoreBundle\Migrations': '@PimcoreCoreBundle/Migrations' - storage: - table_storage: - table_name: 'migration_versions' - version_column_name: 'version' - version_column_length: 1024 - executed_at_column_name: 'executed_at' - execution_time_column_name: 'execution_time' - all_or_nothing: false - check_database_platform: false - factories: - 'Doctrine\Migrations\MigrationsRepository': 'Pimcore\Migrations\FilteredMigrationsRepository' - 'Doctrine\Migrations\Metadata\Storage\MetadataStorage': 'Pimcore\Migrations\FilteredTableMetadataStorage' - - - diff --git a/config/packages/security.yaml b/config/packages/security.yaml index 9675d5a6..df3e2daf 100644 --- a/config/packages/security.yaml +++ b/config/packages/security.yaml @@ -1,7 +1,9 @@ security: + enable_authenticator_manager: true + providers: pimcore_admin: - id: Pimcore\Bundle\AdminBundle\Security\User\UserProvider + id: Pimcore\Security\User\UserProvider firewalls: dev: @@ -9,46 +11,25 @@ security: security: false # Pimcore WebDAV HTTP basic // DO NOT CHANGE! - pimcore_admin_webdav: - pattern: ^/admin/asset/webdav + pimcore_webdav: + pattern: ^/asset/webdav provider: pimcore_admin http_basic: ~ - # Pimcore admin form login // DO NOT CHANGE! - pimcore_admin: - anonymous: ~ - pattern: ^/admin(/.*)?$ - # admin firewall is stateless as we open the admin - # session on demand for non-blocking parallel requests - stateless: true - provider: pimcore_admin - logout: - path: /admin/logout - target: /admin/login - success_handler: Pimcore\Bundle\AdminBundle\Security\LogoutSuccessHandler - guard: - entry_point: Pimcore\Bundle\AdminBundle\Security\Guard\AdminAuthenticator - authenticators: - - Pimcore\Bundle\AdminBundle\Security\Guard\AdminAuthenticator - two_factor: - auth_form_path: /admin/login/2fa # Path or route name of the two-factor form - check_path: /admin/login/2fa-verify # Path or route name of the two-factor code check - default_target_path: /admin # Where to redirect by default after successful authentication - always_use_default_target_path: false # If it should always redirect to default_target_path - auth_code_parameter_name: _auth_code # Name of the parameter for the two-factor authentication code - trusted_parameter_name: _trusted # Name of the parameter for the trusted device option - multi_factor: false # If ALL active two-factor methods need to be fulfilled (multi-factor authentication) - + # Pimcore Admin Bundle firewall + pimcore_admin: '%pimcore_admin_bundle.firewall_settings%' access_control: # Pimcore admin ACl // DO NOT CHANGE! - - { path: ^/admin/settings/display-custom-logo, roles: IS_AUTHENTICATED_ANONYMOUSLY } - - { path: ^/admin/login/2fa-verify, roles: IS_AUTHENTICATED_2FA_IN_PROGRESS} - - { path: ^/admin/login/2fa, roles: IS_AUTHENTICATED_2FA_IN_PROGRESS} - - { path: ^/admin/login$, roles: IS_AUTHENTICATED_ANONYMOUSLY } - - { path: ^/admin/login/(login|lostpassword|deeplink|csrf-token)$, roles: IS_AUTHENTICATED_ANONYMOUSLY } + - { path: ^/admin/settings/display-custom-logo, roles: PUBLIC_ACCESS } + - { path: ^/admin/login/2fa-verify, roles: IS_AUTHENTICATED_2FA_IN_PROGRESS } + - { path: ^/admin/login/2fa-setup, roles: ROLE_PIMCORE_USER } + - { path: ^/admin/login/2fa, roles: IS_AUTHENTICATED_2FA_IN_PROGRESS } + - { path: ^/admin/login$, roles: PUBLIC_ACCESS } + - { path: ^/admin/login/(login|lostpassword|deeplink|csrf-token)$, roles: PUBLIC_ACCESS } - { path: ^/admin, roles: ROLE_PIMCORE_USER } + - { path: ^/asset/webdav, roles: ROLE_PIMCORE_USER } role_hierarchy: # Pimcore admin // DO NOT CHANGE! - ROLE_PIMCORE_ADMIN: [ROLE_PIMCORE_USER] + ROLE_PIMCORE_ADMIN: [ROLE_PIMCORE_USER] \ No newline at end of file diff --git a/config/routes.yaml b/config/routes.yaml index 3c1894dd..b516051b 100644 --- a/config/routes.yaml +++ b/config/routes.yaml @@ -1,2 +1,2 @@ _pimcore: - resource: "@PimcoreCoreBundle/Resources/config/routing.yml" + resource: "@PimcoreCoreBundle/config/routing.yaml" diff --git a/config/routes/dev/routes.yaml b/config/routes/dev/routes.yaml index 8ee148fe..50d25c70 100644 --- a/config/routes/dev/routes.yaml +++ b/config/routes/dev/routes.yaml @@ -1,3 +1,2 @@ _pimcore_dev: - resource: "@PimcoreCoreBundle/Resources/config/routing_dev.yml" - + resource: "@PimcoreCoreBundle/config/routing_dev.yaml" \ No newline at end of file diff --git a/config/system.yml b/config/system.yml index 5995ca1d..b7a4b2b8 100644 --- a/config/system.yml +++ b/config/system.yml @@ -12,7 +12,6 @@ pimcore: default_language: '' disable_usage_statistics: false debug_admin_translations: false - instance_identifier: '' documents: versions: days: null @@ -32,14 +31,6 @@ pimcore: steps: 10 icc_rgb_profile: '' icc_cmyk_profile: '' - hide_edit_image: false - disable_tree_preview: false - services: - google: - client_id: '' - email: '' - simple_api_key: '' - browser_api_key: '' httpclient: adapter: Socket proxy_host: '' @@ -53,14 +44,6 @@ pimcore: return: name: pimcore email: pimcore@example.com - newsletter: - sender: - name: '' - email: '' - return: - name: '' - email: '' - use_specific: true applicationlog: mail_notification: send_log_summary: false diff --git a/src/DataDefinitionsBundle/Command/ExportCommand.php b/src/DataDefinitionsBundle/Command/ExportCommand.php index 5cb1c0d3..255ca8ee 100644 --- a/src/DataDefinitionsBundle/Command/ExportCommand.php +++ b/src/DataDefinitionsBundle/Command/ExportCommand.php @@ -77,21 +77,21 @@ protected function execute(InputInterface $input, OutputInterface $output) $params = json_decode($input->getOption('params'), true); try { - $definition = $this->repository->find($input->getOption('definition')); - } catch (InvalidArgumentException $e) { $definition = $this->repository->findByName($input->getOption('definition')); - } - $progress = null; - $process = null; + } catch (InvalidArgumentException $e) { - if (!is_array($params)) { - $params = []; } if (!$definition instanceof ExportDefinitionInterface) { throw new Exception('Export Definition not found'); } + $progress = null; + + if (!is_array($params)) { + $params = []; + } + $imStatus = function (ExportDefinitionEvent $e) use (&$progress) { if ($progress instanceof ProgressBar) { $progress->setMessage($e->getSubject()); diff --git a/src/DataDefinitionsBundle/Command/ImportCommand.php b/src/DataDefinitionsBundle/Command/ImportCommand.php index c5f1ee3c..b12cd21e 100644 --- a/src/DataDefinitionsBundle/Command/ImportCommand.php +++ b/src/DataDefinitionsBundle/Command/ImportCommand.php @@ -83,20 +83,19 @@ protected function execute(InputInterface $input, OutputInterface $output) } try { - $definition = $this->repository->find($input->getOption('definition')); - } catch (InvalidArgumentException $e) { $definition = $this->repository->findByName($input->getOption('definition')); - } + } catch (InvalidArgumentException $e) { - $progress = null; - $process = null; - $countProgress = 0; - $startTime = time(); + } if (!$definition instanceof ImportDefinitionInterface) { throw new Exception('Import Definition not found'); } + $progress = null; + $countProgress = 0; + $startTime = time(); + $imStatus = function (ImportDefinitionEvent $e) use ($output, &$progress, &$countProgress, $startTime) { if ($progress instanceof ProgressBar) { $progress->setMessage($e->getSubject()); diff --git a/src/DataDefinitionsBundle/Controller/AbstractDefinitionController.php b/src/DataDefinitionsBundle/Controller/AbstractDefinitionController.php new file mode 100644 index 00000000..4f22d0b2 --- /dev/null +++ b/src/DataDefinitionsBundle/Controller/AbstractDefinitionController.php @@ -0,0 +1,41 @@ +isGrantedOr403(); + + $resources = $this->findOr404((string) $this->getParameterFromRequest($request, 'id')); + + return $this->viewHandler->handle(['data' => $resources, 'success' => true], ['group' => 'Detailed']); + } +} diff --git a/src/DataDefinitionsBundle/Controller/ExportDefinitionController.php b/src/DataDefinitionsBundle/Controller/ExportDefinitionController.php index f4c639aa..9dd71c0c 100644 --- a/src/DataDefinitionsBundle/Controller/ExportDefinitionController.php +++ b/src/DataDefinitionsBundle/Controller/ExportDefinitionController.php @@ -27,7 +27,7 @@ use Wvision\Bundle\DataDefinitionsBundle\Model\ExportDefinitionInterface; use Wvision\Bundle\DataDefinitionsBundle\Model\ExportMapping\FromColumn; -class ExportDefinitionController extends ResourceController +class ExportDefinitionController extends AbstractDefinitionController { public function getConfigAction(): JsonResponse { @@ -416,36 +416,36 @@ protected function getFieldConfiguration(DataObject\ClassDefinition\Data $field, protected function getConfigProviders(): array { - return $this->container->getParameter('data_definitions.export_providers'); + return $this->getParameter('data_definitions.export_providers'); } protected function getConfigInterpreters(): array { - return $this->container->getParameter('data_definitions.interpreters'); + return $this->getParameter('data_definitions.interpreters'); } protected function getConfigRunners(): array { - return $this->container->getParameter('data_definitions.export_runners'); + return $this->getParameter('data_definitions.export_runners'); } protected function getConfigGetters(): array { - return $this->container->getParameter('data_definitions.getters'); + return $this->getParameter('data_definitions.getters'); } protected function getConfigFetchers(): array { - return $this->container->getParameter('data_definitions.fetchers'); + return $this->getParameter('data_definitions.fetchers'); } protected function getImportRuleConditions(): array { - return $this->container->getParameter('data_definitions.import_rule.conditions'); + return $this->getParameter('data_definitions.import_rule.conditions'); } protected function getImportRuleActions(): array { - return $this->container->getParameter('data_definitions.import_rule.actions'); + return $this->getParameter('data_definitions.import_rule.actions'); } } diff --git a/src/DataDefinitionsBundle/Controller/ImportDefinitionController.php b/src/DataDefinitionsBundle/Controller/ImportDefinitionController.php index 3cde1817..220e31d1 100644 --- a/src/DataDefinitionsBundle/Controller/ImportDefinitionController.php +++ b/src/DataDefinitionsBundle/Controller/ImportDefinitionController.php @@ -16,21 +16,23 @@ namespace Wvision\Bundle\DataDefinitionsBundle\Controller; -use CoreShop\Bundle\ResourceBundle\Controller\ResourceController; +use CoreShop\Component\Registry\ServiceRegistryInterface; use Exception; use Pimcore\Model\DataObject; +use Symfony\Component\DependencyInjection\Attribute\Autowire; use Symfony\Component\HttpFoundation\File\UploadedFile; use Symfony\Component\HttpFoundation\JsonResponse; use Symfony\Component\HttpFoundation\Request; use Symfony\Component\HttpFoundation\Response; use Symfony\Component\HttpKernel\Exception\NotFoundHttpException; +use Symfony\Contracts\Service\Attribute\SubscribedService; use Wvision\Bundle\DataDefinitionsBundle\Model\ImportDefinitionInterface; use Wvision\Bundle\DataDefinitionsBundle\Model\ImportMapping; use Wvision\Bundle\DataDefinitionsBundle\Model\ImportMapping\FromColumn; use Wvision\Bundle\DataDefinitionsBundle\Service\FieldSelection; use function is_array; -class ImportDefinitionController extends ResourceController +class ImportDefinitionController extends AbstractDefinitionController { public function getConfigAction(): JsonResponse { @@ -68,7 +70,9 @@ public function testDataAction(Request $request): JsonResponse if ($definition instanceof ImportDefinitionInterface) { try { - if ($this->get('data_definitions.registry.provider')->get($definition->getProvider())->testData( + if ($this->container->get('data_definitions.registry.provider')->get( + $definition->getProvider() + )->testData( $definition->getConfiguration() )) { return $this->viewHandler->handle(['success' => true]); @@ -92,7 +96,7 @@ public function getColumnsAction(Request $request): JsonResponse $customFromColumn->setLabel('Custom'); try { - $fromColumns = $this->get('data_definitions.registry.provider')->get( + $fromColumns = $this->container->get('data_definitions.registry.provider')->get( $definition->getProvider() )->getColumns($definition->getConfiguration()); $fromColumns[] = $customFromColumn; @@ -106,7 +110,7 @@ public function getColumnsAction(Request $request): JsonResponse throw new NotFoundHttpException(); } - $toColumns = $this->get(FieldSelection::class)->getClassDefinition($classDefinition); + $toColumns = $this->container->get(FieldSelection::class)->getClassDefinition($classDefinition); $mappings = $definition->getMapping(); $mappingDefinition = []; $fromColumnsResult = []; @@ -263,53 +267,62 @@ public function duplicateAction(Request $request): JsonResponse return $this->viewHandler->handle(['success' => false]); } + public static function getSubscribedServices(): array + { + return parent::getSubscribedServices() + [ + FieldSelection::class, + new SubscribedService('data_definitions.registry.provider', ServiceRegistryInterface::class, attributes: new Autowire(service: 'data_definitions.registry.provider')) + ]; + } + + protected function getConfigProviders(): array { - return $this->container->getParameter('data_definitions.import_providers'); + return $this->getParameter('data_definitions.import_providers'); } protected function getConfigLoaders(): array { - return $this->container->getParameter('data_definitions.loaders'); + return $this->getParameter('data_definitions.loaders'); } protected function getConfigInterpreters(): array { - return $this->container->getParameter('data_definitions.interpreters'); + return $this->getParameter('data_definitions.interpreters'); } protected function getConfigCleaners(): array { - return $this->container->getParameter('data_definitions.cleaners'); + return $this->getParameter('data_definitions.cleaners'); } protected function getConfigSetters(): array { - return $this->container->getParameter('data_definitions.setters'); + return $this->getParameter('data_definitions.setters'); } protected function getConfigFilters(): array { - return $this->container->getParameter('data_definitions.filters'); + return $this->getParameter('data_definitions.filters'); } protected function getConfigRunners(): array { - return $this->container->getParameter('data_definitions.runners'); + return $this->getParameter('data_definitions.runners'); } protected function getConfigPersisters(): array { - return $this->container->getParameter('data_definitions.persisters'); + return $this->getParameter('data_definitions.persisters'); } protected function getImportRuleConditions(): array { - return $this->container->getParameter('data_definitions.import_rule.conditions'); + return $this->getParameter('data_definitions.import_rule.conditions'); } protected function getImportRuleActions(): array { - return $this->container->getParameter('data_definitions.import_rule.actions'); + return $this->getParameter('data_definitions.import_rule.actions'); } } diff --git a/src/DataDefinitionsBundle/Controller/ImportRuleController.php b/src/DataDefinitionsBundle/Controller/ImportRuleController.php index 4eb20db7..ffa45046 100644 --- a/src/DataDefinitionsBundle/Controller/ImportRuleController.php +++ b/src/DataDefinitionsBundle/Controller/ImportRuleController.php @@ -16,7 +16,7 @@ namespace Wvision\Bundle\DataDefinitionsBundle\Controller; -use Pimcore\Bundle\AdminBundle\Controller\AdminController; +use Pimcore\Bundle\AdminBundle\Controller\GDPR\AdminController; use Symfony\Component\Form\FormFactoryInterface; use Symfony\Component\HttpFoundation\BinaryFileResponse; use Symfony\Component\HttpFoundation\File\UploadedFile; diff --git a/src/DataDefinitionsBundle/DataDefinitionsBundle.php b/src/DataDefinitionsBundle/DataDefinitionsBundle.php index 0cdc04af..fbb00edd 100644 --- a/src/DataDefinitionsBundle/DataDefinitionsBundle.php +++ b/src/DataDefinitionsBundle/DataDefinitionsBundle.php @@ -20,6 +20,8 @@ use CoreShop\Bundle\ResourceBundle\AbstractResourceBundle; use CoreShop\Bundle\ResourceBundle\CoreShopResourceBundle; use CoreShop\Bundle\RuleBundle\CoreShopRuleBundle; +use Pimcore\Bundle\AdminBundle\PimcoreAdminBundle; +use Pimcore\Bundle\SimpleBackendSearchBundle\PimcoreSimpleBackendSearchBundle; use Pimcore\Extension\Bundle\Installer\InstallerInterface; use Pimcore\Extension\Bundle\PimcoreBundleInterface; use Pimcore\HttpKernel\BundleCollection\BundleCollection; @@ -45,6 +47,11 @@ public static function registerDependentBundles(BundleCollection $collection): v { parent::registerDependentBundles($collection); + $collection->addBundles([ + new PimcoreAdminBundle(), + new PimcoreSimpleBackendSearchBundle() + ]); + $collection->addBundles([ new CoreShopRuleBundle(), ], 3500); @@ -57,24 +64,24 @@ public function getSupportedDrivers(): array ]; } - public function build(ContainerBuilder $builder): void + public function build(ContainerBuilder $container): void { - parent::build($builder); - - $builder->addCompilerPass(new CleanerRegistryCompilerPass()); - $builder->addCompilerPass(new FilterRegistryCompilerPass()); - $builder->addCompilerPass(new InterpreterRegistryCompilerPass()); - $builder->addCompilerPass(new ProviderRegistryCompilerPass()); - $builder->addCompilerPass(new RunnerRegistryCompilerPass()); - $builder->addCompilerPass(new SetterRegistryCompilerPass()); - $builder->addCompilerPass(new LoaderRegistryCompilerPass()); - $builder->addCompilerPass(new GetterRegistryCompilerPass()); - $builder->addCompilerPass(new FetcherRegistryCompilerPass()); - $builder->addCompilerPass(new ExportProviderRegistryCompilerPass()); - $builder->addCompilerPass(new ExportRunnerRegistryCompilerPass()); - $builder->addCompilerPass(new ImportRuleConditionPass()); - $builder->addCompilerPass(new ImportRuleActionPass()); - $builder->addCompilerPass(new PersisterRegistryCompilerPass()); + parent::build($container); + + $container->addCompilerPass(new CleanerRegistryCompilerPass()); + $container->addCompilerPass(new FilterRegistryCompilerPass()); + $container->addCompilerPass(new InterpreterRegistryCompilerPass()); + $container->addCompilerPass(new ProviderRegistryCompilerPass()); + $container->addCompilerPass(new RunnerRegistryCompilerPass()); + $container->addCompilerPass(new SetterRegistryCompilerPass()); + $container->addCompilerPass(new LoaderRegistryCompilerPass()); + $container->addCompilerPass(new GetterRegistryCompilerPass()); + $container->addCompilerPass(new FetcherRegistryCompilerPass()); + $container->addCompilerPass(new ExportProviderRegistryCompilerPass()); + $container->addCompilerPass(new ExportRunnerRegistryCompilerPass()); + $container->addCompilerPass(new ImportRuleConditionPass()); + $container->addCompilerPass(new ImportRuleActionPass()); + $container->addCompilerPass(new PersisterRegistryCompilerPass()); } public function getVersion(): string diff --git a/src/DataDefinitionsBundle/DependencyInjection/Configuration.php b/src/DataDefinitionsBundle/DependencyInjection/Configuration.php index 9eeb03d3..45ff383f 100644 --- a/src/DataDefinitionsBundle/DependencyInjection/Configuration.php +++ b/src/DataDefinitionsBundle/DependencyInjection/Configuration.php @@ -18,6 +18,8 @@ use CoreShop\Bundle\ResourceBundle\CoreShopResourceBundle; use CoreShop\Component\Resource\Factory\Factory; +use Pimcore\Bundle\CoreBundle\DependencyInjection\ConfigurationHelper; +use Pimcore\Config\LocationAwareConfigRepository; use Symfony\Component\Config\Definition\Builder\ArrayNodeDefinition; use Symfony\Component\Config\Definition\Builder\TreeBuilder; use Symfony\Component\Config\Definition\ConfigurationInterface; @@ -38,11 +40,96 @@ public function getConfigTreeBuilder(): TreeBuilder $treeBuilder = new TreeBuilder('wvision_data_definitions'); $rootNode = $treeBuilder->getRootNode(); + ConfigurationHelper::addConfigLocationWithWriteTargetNodes($rootNode, [ + 'import_definitions' => '/var/config/import-definitions', + 'export_definitions' => '/var/config/export-definitions' + ]); + $rootNode ->children() ->scalarNode('driver')->defaultValue(CoreShopResourceBundle::DRIVER_PIMCORE)->end() ->end(); + $rootNode + ->children() + ->arrayNode('import_definitions') + ->normalizeKeys(false) + ->prototype('array') + ->children() + ->scalarNode('name')->end() + ->scalarNode('provider')->end() + ->scalarNode('class')->end() + ->scalarNode('runner')->end() + ->booleanNode('stopOnException')->end() + ->scalarNode('failureNotificationDocument')->end() + ->scalarNode('successNotificationDocument')->end() + ->scalarNode('loader')->end() + ->scalarNode('objectPath')->end() + ->scalarNode('cleaner')->end() + ->scalarNode('key')->end() + ->scalarNode('filter')->end() + ->booleanNode('renameExistingObjects')->end() + ->booleanNode('relocateExistingObjects')->end() + ->booleanNode('skipNewObjects')->end() + ->booleanNode('skipExistingObjects')->end() + ->booleanNode('createVersion')->end() + ->booleanNode('omitMandatoryCheck')->end() + ->booleanNode('forceLoadObject')->end() + ->variableNode('configuration')->end() + ->arrayNode('mapping') + ->prototype('array') + ->children() + ->scalarNode('primaryIdentifier')->end() + ->scalarNode('setter')->end() + ->variableNode('setterConfig')->end() + ->scalarNode('fromColumn')->end() + ->scalarNode('toColumn')->end() + ->scalarNode('interpreter')->end() + ->variableNode('interpreterConfig')->end() + ->end() + ->end() + ->end() + ->integerNode('creationDate')->end() + ->integerNode('modificationDate')->end() + ->end() + ->end() + ->end() + ->arrayNode('export_definitions') + ->normalizeKeys(false) + ->prototype('array') + ->children() + ->scalarNode('name')->end() + ->scalarNode('fetcher')->end() + ->variableNode('fetcherConfig')->end() + ->booleanNode('fetchUnpublished')->end() + ->scalarNode('provider')->end() + ->scalarNode('class')->end() + ->scalarNode('loader')->end() + ->variableNode('configuration')->end() + ->scalarNode('runner')->end() + ->booleanNode('stopOnException')->end() + ->scalarNode('failureNotificationDocument')->end() + ->scalarNode('successNotificationDocument')->end() + ->arrayNode('mapping') + ->prototype('array') + ->children() + ->scalarNode('primaryIdentifier')->end() + ->scalarNode('getter')->end() + ->variableNode('getterConfig')->end() + ->scalarNode('fromColumn')->end() + ->scalarNode('toColumn')->end() + ->scalarNode('interpreter')->end() + ->variableNode('interpreterConfig')->end() + ->end() + ->end() + ->end() + ->integerNode('creationDate')->end() + ->integerNode('modificationDate')->end() + ->end() + ->end() + ->end() + ->end(); + $this->addPimcoreResourcesSection($rootNode); $this->addModelsSection($rootNode); diff --git a/src/DataDefinitionsBundle/DependencyInjection/DataDefinitionsExtension.php b/src/DataDefinitionsBundle/DependencyInjection/DataDefinitionsExtension.php index 23f5498b..738f7f34 100644 --- a/src/DataDefinitionsBundle/DependencyInjection/DataDefinitionsExtension.php +++ b/src/DataDefinitionsBundle/DependencyInjection/DataDefinitionsExtension.php @@ -17,9 +17,12 @@ namespace Wvision\Bundle\DataDefinitionsBundle\DependencyInjection; use CoreShop\Bundle\ResourceBundle\DependencyInjection\Extension\AbstractModelExtension; +use Pimcore\Config\LocationAwareConfigRepository; use Symfony\Component\Config\FileLocator; use Symfony\Component\DependencyInjection\ContainerBuilder; +use Symfony\Component\DependencyInjection\Extension\PrependExtensionInterface; use Symfony\Component\DependencyInjection\Loader; +use Symfony\Component\DependencyInjection\Loader\YamlFileLoader; use Wvision\Bundle\DataDefinitionsBundle\Cleaner\CleanerInterface; use Wvision\Bundle\DataDefinitionsBundle\DependencyInjection\Compiler\CleanerRegistryCompilerPass; use Wvision\Bundle\DataDefinitionsBundle\DependencyInjection\Compiler\ExportProviderRegistryCompilerPass; @@ -45,7 +48,7 @@ use Wvision\Bundle\DataDefinitionsBundle\Runner\RunnerInterface; use Wvision\Bundle\DataDefinitionsBundle\Setter\SetterInterface; -class DataDefinitionsExtension extends AbstractModelExtension +class DataDefinitionsExtension extends AbstractModelExtension implements PrependExtensionInterface { public function load(array $configs, ContainerBuilder $container) { @@ -121,5 +124,16 @@ public function load(array $configs, ContainerBuilder $container) $container ->registerForAutoconfiguration(PersisterInterface::class) ->addTag(PersisterRegistryCompilerPass::PERSISTER_TAG); + + $container->setParameter('data_definitions.config_location', $config['config_location'] ?? []); + + $container->setParameter('data_definitions.import_definitions', $config['import_definitions']); + $container->setParameter('data_definitions.export_definitions', $config['export_definitions']); + } + + public function prepend(ContainerBuilder $container): void + { + LocationAwareConfigRepository::loadSymfonyConfigFiles($container, 'data_definitions', 'export_definitions'); + LocationAwareConfigRepository::loadSymfonyConfigFiles($container, 'data_definitions', 'import_definitions'); } } diff --git a/src/DataDefinitionsBundle/EventListener/PimcoreSettingsListener.php b/src/DataDefinitionsBundle/EventListener/PimcoreSettingsListener.php new file mode 100644 index 00000000..82e8bab9 --- /dev/null +++ b/src/DataDefinitionsBundle/EventListener/PimcoreSettingsListener.php @@ -0,0 +1,30 @@ +addSetting('data-definitions-import-definition-writeable', (new ImportDefinition())->isWriteable()); + $settingsEvent->addSetting('data-definitions-export-definition-writeable', (new ExportDefinition())->isWriteable()); + } +} diff --git a/src/DataDefinitionsBundle/EventListener/WriteableListener.php b/src/DataDefinitionsBundle/EventListener/WriteableListener.php new file mode 100644 index 00000000..271c10d0 --- /dev/null +++ b/src/DataDefinitionsBundle/EventListener/WriteableListener.php @@ -0,0 +1,47 @@ +getSubject(); + + if ($subject instanceof ImportDefinition && !$subject->isWriteable()) { + throw new ConfigWriteException(); + } + + if ($subject instanceof ExportDefinition && !$subject->isWriteable()) { + throw new ConfigWriteException(); + } + } + + public static function getSubscribedEvents() + { + return [ + 'data_definitions.import_definition.pre_save' => 'definitionIsWritable', + 'data_definitions.export_definition.pre_save' => 'definitionIsWritable', + ]; + } +} diff --git a/src/DataDefinitionsBundle/Fetcher/ObjectsFetcher.php b/src/DataDefinitionsBundle/Fetcher/ObjectsFetcher.php index ebf3564f..6dfb67a8 100644 --- a/src/DataDefinitionsBundle/Fetcher/ObjectsFetcher.php +++ b/src/DataDefinitionsBundle/Fetcher/ObjectsFetcher.php @@ -98,7 +98,7 @@ private function getClassListing(ExportDefinitionInterface $definition, array $p $list->setCondition(implode(' AND ', $conditionFilters)); // ensure a stable sort across pages - $list->setOrderKey('o_id'); + $list->setOrderKey('id'); $list->setOrder('asc'); return $this->list = $list; diff --git a/src/DataDefinitionsBundle/Importer/Importer.php b/src/DataDefinitionsBundle/Importer/Importer.php index 1fa1273d..4b587db2 100644 --- a/src/DataDefinitionsBundle/Importer/Importer.php +++ b/src/DataDefinitionsBundle/Importer/Importer.php @@ -163,6 +163,10 @@ public function doImport(ImportDefinitionInterface $definition, $params): array public function processSuccessfullImport(ImportDefinitionInterface $definition, $params, $objectIds, $exceptions) { + if (!is_int($definition->getSuccessNotificationDocument())) { + return; + } + $this->sendDocument( $definition, Document::getById($definition->getSuccessNotificationDocument()), @@ -174,6 +178,10 @@ public function processSuccessfullImport(ImportDefinitionInterface $definition, public function processFailedImport(ImportDefinitionInterface $definition, $params, $objectIds, $exceptions) { + if (!is_int($definition->getFailureNotificationDocument())) { + return; + } + $this->sendDocument( $definition, Document::getById($definition->getFailureNotificationDocument()), diff --git a/src/DataDefinitionsBundle/Model/AbstractDataDefinition.php b/src/DataDefinitionsBundle/Model/AbstractDataDefinition.php index c55dbb31..b534767d 100644 --- a/src/DataDefinitionsBundle/Model/AbstractDataDefinition.php +++ b/src/DataDefinitionsBundle/Model/AbstractDataDefinition.php @@ -18,10 +18,16 @@ use Pimcore\Model\AbstractModel; +/** + * @method bool isWriteable() + * @method string getWriteTarget() + * @method void save() + * @method void delete() + */ abstract class AbstractDataDefinition extends AbstractModel implements DataDefinitionInterface { /** - * @var int + * @var int|string|null */ public $id; @@ -80,7 +86,7 @@ abstract class AbstractDataDefinition extends AbstractModel implements DataDefin */ public $successNotificationDocument; - public function getId() + public function getId(): int|string|null { return $this->id; } @@ -128,6 +134,8 @@ public function getName() public function setName($name) { $this->name = $name; + + $this->setId($name); } public function getMapping() diff --git a/src/DataDefinitionsBundle/Model/DataDefinitionInterface.php b/src/DataDefinitionsBundle/Model/DataDefinitionInterface.php index addc6fe6..429ba971 100644 --- a/src/DataDefinitionsBundle/Model/DataDefinitionInterface.php +++ b/src/DataDefinitionsBundle/Model/DataDefinitionInterface.php @@ -20,10 +20,6 @@ interface DataDefinitionInterface extends ResourceInterface { - /** - * @return mixed - */ - public function getId(); /** * @param int $id diff --git a/src/DataDefinitionsBundle/Model/ExportDefinition.php b/src/DataDefinitionsBundle/Model/ExportDefinition.php index 052f0199..8edb9ef9 100644 --- a/src/DataDefinitionsBundle/Model/ExportDefinition.php +++ b/src/DataDefinitionsBundle/Model/ExportDefinition.php @@ -16,6 +16,9 @@ namespace Wvision\Bundle\DataDefinitionsBundle\Model; +/** + * @method ExportDefinition\Dao getDao() + */ class ExportDefinition extends AbstractDataDefinition implements ExportDefinitionInterface { /** @@ -33,7 +36,12 @@ class ExportDefinition extends AbstractDataDefinition implements ExportDefinitio */ public $fetchUnpublished = false; - public static function getById($id) + public static function getById(string $name) + { + return static::getByName($name); + } + + public static function getByName($id) { $definitionEntry = new ExportDefinition(); $definitionEntry->setId((int)$id); @@ -41,7 +49,7 @@ public static function getById($id) * @var \Wvision\Bundle\DataDefinitionsBundle\Model\ExportDefinition\Dao|\Wvision\Bundle\DataDefinitionsBundle\Model\ImportDefinition\Dao */ $dao = $definitionEntry->getDao(); - $dao->getById($id); + $dao->getByName($id); return $definitionEntry; } diff --git a/src/DataDefinitionsBundle/Model/ExportDefinition/Dao.php b/src/DataDefinitionsBundle/Model/ExportDefinition/Dao.php index 898ae3d5..f88fa881 100644 --- a/src/DataDefinitionsBundle/Model/ExportDefinition/Dao.php +++ b/src/DataDefinitionsBundle/Model/ExportDefinition/Dao.php @@ -24,49 +24,28 @@ use function in_array; use function is_array; -class Dao extends Model\Dao\PhpArrayTable +class Dao extends Model\Dao\PimcoreLocationAwareConfigDao { - /** - * Configure Configuration File - */ - public function configure() - { - parent::configure(); - $this->setFile('exportdefinitions'); - } + private const CONFIG_KEY = 'export_definitions'; /** - * Get Configuration By Id - * - * @param null $id - * @throws Exception + * Configure Configuration File */ - public function getById($id = null) + public function configure(): void { - if ($id !== null) { - $this->model->setId($id); - } + $config = \Pimcore::getContainer()->getParameter('data_definitions.config_location'); + $definitions = \Pimcore::getContainer()->getParameter('data_definitions.export_definitions'); - $data = $this->db->getById($this->model->getId()); + $storageConfig = $config[self::CONFIG_KEY]; - if (isset($data['id'])) { - $this->assignVariablesToModel($data); - } else { - throw new InvalidArgumentException( - sprintf( - 'Export Definition with id: %s does not exist', - $this->model->getId() - ) - ); - } + parent::configure([ + 'containerConfig' => $definitions, + 'settingsStoreScope' => 'data_definitions', + 'storageConfig' => $storageConfig, + ]); } - /** - * @param array $data - * @return void - * @throws Exception - */ - protected function assignVariablesToModel($data) + protected function assignVariablesToModel($data): void { parent::assignVariablesToModel($data); @@ -94,27 +73,26 @@ protected function assignVariablesToModel($data) * @param null $name * @throws Exception */ - public function getByName($name = null) + public function getByName(string $id = null): void { - if ($name !== null) { - $this->model->setName($name); + if ($id != null) { + $this->model->setName($id); } - $name = $this->model->getName(); + $data = $this->getDataByName($this->model->getName()); - $data = $this->db->fetchAll(function ($row) use ($name) { - return $row['name'] === $name; - }); + if ($data && $id != null) { + $data['id'] = $id; + } - if ($data[0]['id'] && count($data)) { - $this->assignVariablesToModel($data[0]); + if ($data) { + $this->assignVariablesToModel($data); + $this->model->setName($data['id']); } else { - throw new InvalidArgumentException( - sprintf( - 'Definition with name: %s does not exist', - $this->model->getName() - ) - ); + throw new Model\Exception\NotFoundException(sprintf( + 'Thumbnail with ID "%s" does not exist.', + $this->model->getName() + )); } } @@ -131,56 +109,58 @@ public function save() } $this->model->setModificationDate($ts); - try { - $dataRaw = get_object_vars($this->model); - $data = []; - $allowedProperties = [ - 'id', - 'name', - 'provider', - 'class', - 'configuration', - 'creationDate', - 'modificationDate', - 'mapping', - 'runner', - 'stopOnException', - 'fetchUnpublished', - 'failureNotificationDocument', - 'successNotificationDocument', - 'fetcher', - 'fetcherConfig', - ]; - - foreach ($dataRaw as $key => $value) { - if (in_array($key, $allowedProperties, true)) { - if ($key === 'providerConfiguration') { - if ($value) { - $data[$key] = get_object_vars($value); - } - } elseif ($key === 'mapping') { - if ($value) { - $data[$key] = array(); - - if (is_array($value)) { - foreach ($value as $map) { - $data[$key][] = get_object_vars($map); - } + $dataRaw = get_object_vars($this->model); + $data = []; + $allowedProperties = [ + 'name', + 'provider', + 'class', + 'configuration', + 'creationDate', + 'modificationDate', + 'mapping', + 'runner', + 'stopOnException', + 'fetchUnpublished', + 'failureNotificationDocument', + 'successNotificationDocument', + 'fetcher', + 'fetcherConfig', + ]; + + foreach ($dataRaw as $key => $value) { + if (in_array($key, $allowedProperties, true)) { + if ($key === 'providerConfiguration') { + if ($value) { + $data[$key] = get_object_vars($value); + } + } elseif ($key === 'mapping') { + if ($value) { + $data[$key] = array(); + + if (is_array($value)) { + foreach ($value as $map) { + $data[$key][] = get_object_vars($map); } } - } else { - $data[$key] = $value; } + } else { + $data[$key] = $value; } } - $this->db->insertOrUpdate($data, $this->model->getId()); - } catch (Exception $e) { - throw $e; } + $this->saveData($this->model->getName(), $data); + } - if (!$this->model->getId()) { - $this->model->setId($this->db->getLastInsertId()); - } + protected function prepareDataStructureForYaml(string $id, mixed $data): mixed + { + return [ + 'data_definitions' => [ + 'export_definitions' => [ + $id => $data, + ], + ], + ]; } /** @@ -189,6 +169,6 @@ public function save() */ public function delete() { - $this->db->delete($this->model->getId()); + $this->deleteData($this->model->getName()); } } diff --git a/src/DataDefinitionsBundle/Model/ExportDefinition/Listing.php b/src/DataDefinitionsBundle/Model/ExportDefinition/Listing.php index fa97d043..1a77d772 100644 --- a/src/DataDefinitionsBundle/Model/ExportDefinition/Listing.php +++ b/src/DataDefinitionsBundle/Model/ExportDefinition/Listing.php @@ -17,11 +17,18 @@ namespace Wvision\Bundle\DataDefinitionsBundle\Model\ExportDefinition; use Exception; -use Pimcore\Model; +use Pimcore\Model\AbstractModel; +use Pimcore\Model\Listing\CallableFilterListingInterface; +use Pimcore\Model\Listing\CallableOrderListingInterface; +use Pimcore\Model\Listing\Traits\FilterListingTrait; +use Pimcore\Model\Listing\Traits\OrderListingTrait; use Wvision\Bundle\DataDefinitionsBundle\Model\ExportDefinitionInterface; -class Listing extends Model\Listing\JsonListing +class Listing extends AbstractModel implements CallableFilterListingInterface, CallableOrderListingInterface { + use FilterListingTrait; + use OrderListingTrait; + /** * Contains the results of the list. * They are all an instance of Configuration. @@ -34,10 +41,10 @@ class Listing extends Model\Listing\JsonListing * @return ExportDefinitionInterface[] * @throws Exception */ - public function getObjects(): ?array + public function getObjects() { if (null === $this->definitions) { - $this->load(); + $this->loadList(); } return $this->definitions; diff --git a/src/DataDefinitionsBundle/Model/ExportDefinition/Listing/Dao.php b/src/DataDefinitionsBundle/Model/ExportDefinition/Listing/Dao.php index 315bc1a6..71b22167 100644 --- a/src/DataDefinitionsBundle/Model/ExportDefinition/Listing/Dao.php +++ b/src/DataDefinitionsBundle/Model/ExportDefinition/Listing/Dao.php @@ -16,52 +16,31 @@ namespace Wvision\Bundle\DataDefinitionsBundle\Model\ExportDefinition\Listing; -use Exception; -use Pimcore; use Wvision\Bundle\DataDefinitionsBundle\Model\ExportDefinition; use function count; -class Dao extends Pimcore\Model\Dao\PhpArrayTable +class Dao extends ExportDefinition\Dao { - /** - * Configure - */ - public function configure() + public function loadList(): array { - parent::configure(); - $this->setFile('exportdefinitions'); - } - - /** - * Loads a list of Definitions for the specified parameters, returns an array of Definitions elements. - * - * @return array - * @throws Exception - */ - public function load() - { - $routesData = $this->db->fetchAll($this->model->getFilter(), $this->model->getOrder()); - - $routes = array(); - foreach ($routesData as $routeData) { - $routes[] = ExportDefinition::getById($routeData['id']); + $definitions = []; + foreach ($this->loadIdList() as $name) { + $definitions[] = ExportDefinition::getByName($name); } - $this->model->setObjects($routes); + if ($this->model->getFilter()) { + $definitions = array_filter($definitions, $this->model->getFilter()); + } + if ($this->model->getOrder()) { + usort($definitions, $this->model->getOrder()); + } + $this->model->setObjects($definitions); - return $routes; + return $definitions; } - /** - * Get total count - * - * @return int - * @throws Exception - */ - public function getTotalCount() + public function getTotalCount(): int { - $data = $this->db->fetchAll($this->model->getFilter(), $this->model->getOrder()); - - return count($data); + return count($this->loadList()); } } diff --git a/src/DataDefinitionsBundle/Model/ImportDefinition.php b/src/DataDefinitionsBundle/Model/ImportDefinition.php index 438f43ba..86ec2f14 100644 --- a/src/DataDefinitionsBundle/Model/ImportDefinition.php +++ b/src/DataDefinitionsBundle/Model/ImportDefinition.php @@ -16,6 +16,9 @@ namespace Wvision\Bundle\DataDefinitionsBundle\Model; +/** + * @method ImportDefinition\Dao getDao() + */ class ImportDefinition extends AbstractDataDefinition implements ImportDefinitionInterface { /** @@ -83,7 +86,12 @@ class ImportDefinition extends AbstractDataDefinition implements ImportDefinitio */ public $persister; - public static function getById($id) + public static function getById(string $name) + { + return static::getByName($name); + } + + public static function getByName($id) { $definitionEntry = new ImportDefinition(); $definitionEntry->setId((int)$id); @@ -91,7 +99,7 @@ public static function getById($id) * @var \Wvision\Bundle\DataDefinitionsBundle\Model\ExportDefinition\Dao|\Wvision\Bundle\DataDefinitionsBundle\Model\ImportDefinition\Dao */ $dao = $definitionEntry->getDao(); - $dao->getById($id); + $dao->getByName($id); return $definitionEntry; } diff --git a/src/DataDefinitionsBundle/Model/ImportDefinition/Dao.php b/src/DataDefinitionsBundle/Model/ImportDefinition/Dao.php index 23e965dd..69f68096 100644 --- a/src/DataDefinitionsBundle/Model/ImportDefinition/Dao.php +++ b/src/DataDefinitionsBundle/Model/ImportDefinition/Dao.php @@ -17,56 +17,33 @@ namespace Wvision\Bundle\DataDefinitionsBundle\Model\ImportDefinition; use Exception; -use InvalidArgumentException; use Pimcore\Model; use Wvision\Bundle\DataDefinitionsBundle\Model\ImportMapping; -use function count; use function in_array; use function is_array; -class Dao extends Model\Dao\PhpArrayTable +class Dao extends Model\Dao\PimcoreLocationAwareConfigDao { - /** - * Configure Configuration File - */ - public function configure() - { - parent::configure(); - $this->setFile('importdefinitions'); - } + private const CONFIG_KEY = 'import_definitions'; /** - * Get Configuration By Id - * - * @param null $id - * @throws Exception + * Configure Configuration File */ - public function getById($id = null) + public function configure(): void { - if ($id !== null) { - $this->model->setId($id); - } + $config = \Pimcore::getContainer()->getParameter('data_definitions.config_location'); + $definitions = \Pimcore::getContainer()->getParameter('data_definitions.import_definitions'); - $data = $this->db->getById($this->model->getId()); + $storageConfig = $config[self::CONFIG_KEY]; - if (isset($data['id'])) { - $this->assignVariablesToModel($data); - } else { - throw new InvalidArgumentException( - sprintf( - 'Definition with id: %s does not exist', - $this->model->getId() - ) - ); - } + parent::configure([ + 'containerConfig' => $definitions, + 'settingsStoreScope' => 'data_definitions', + 'storageConfig' => $storageConfig, + ]); } - /** - * @param array $data - * @return void - * @throws Exception - */ - protected function assignVariablesToModel($data) + protected function assignVariablesToModel($data): void { parent::assignVariablesToModel($data); @@ -94,27 +71,26 @@ protected function assignVariablesToModel($data) * @param null $name * @throws Exception */ - public function getByName($name = null) + public function getByName(string $id = null): void { - if ($name !== null) { - $this->model->setName($name); + if ($id != null) { + $this->model->setName($id); } - $name = $this->model->getName(); + $data = $this->getDataByName($this->model->getName()); - $data = $this->db->fetchAll(function ($row) use ($name) { - return $row['name'] === $name; - }); + if ($data && $id != null) { + $data['id'] = $id; + } - if (isset($data[0]['id']) && count($data)) { - $this->assignVariablesToModel($data[0]); + if ($data) { + $this->assignVariablesToModel($data); + $this->model->setName($data['id']); } else { - throw new InvalidArgumentException( - sprintf( - 'Definition with name: %s does not exist', - $this->model->getName() - ) - ); + throw new Model\Exception\NotFoundException(sprintf( + 'Thumbnail with ID "%s" does not exist.', + $this->model->getName() + )); } } @@ -131,67 +107,69 @@ public function save() } $this->model->setModificationDate($ts); - try { - $dataRaw = get_object_vars($this->model); - $data = []; - $allowedProperties = [ - 'id', - 'name', - 'provider', - 'class', - 'configuration', - 'creationDate', - 'modificationDate', - 'mapping', - 'objectPath', - 'cleaner', - 'key', - 'renameExistingObjects', - 'relocateExistingObjects', - 'filter', - 'runner', - 'createVersion', - 'stopOnException', - 'omitMandatoryCheck', - 'failureNotificationDocument', - 'successNotificationDocument', - 'skipExistingObjects', - 'skipNewObjects', - 'forceLoadObject', - 'loader', - 'fetcher', - ]; - - foreach ($dataRaw as $key => $value) { - if (in_array($key, $allowedProperties, true)) { - if ($key === 'providerConfiguration') { - if ($value) { - $data[$key] = get_object_vars($value); - } - } elseif ($key === 'mapping') { - if ($value) { - $data[$key] = array(); - - if (is_array($value)) { - foreach ($value as $map) { - $data[$key][] = get_object_vars($map); - } + $dataRaw = get_object_vars($this->model); + $data = []; + $allowedProperties = [ + 'name', + 'provider', + 'class', + 'configuration', + 'creationDate', + 'modificationDate', + 'mapping', + 'objectPath', + 'cleaner', + 'key', + 'renameExistingObjects', + 'relocateExistingObjects', + 'filter', + 'runner', + 'createVersion', + 'stopOnException', + 'omitMandatoryCheck', + 'failureNotificationDocument', + 'successNotificationDocument', + 'skipExistingObjects', + 'skipNewObjects', + 'forceLoadObject', + 'loader', + 'fetcher', + ]; + + foreach ($dataRaw as $key => $value) { + if (in_array($key, $allowedProperties, true)) { + if ($key === 'providerConfiguration') { + if ($value) { + $data[$key] = get_object_vars($value); + } + } elseif ($key === 'mapping') { + if ($value) { + $data[$key] = array(); + + if (is_array($value)) { + foreach ($value as $map) { + $data[$key][] = get_object_vars($map); } } - } else { - $data[$key] = $value; } + } else { + $data[$key] = $value; } } - - $this->db->insertOrUpdate($data, $this->model->getId()); - } catch (Exception $e) { - throw $e; } - if (!$this->model->getId()) { - $this->model->setId($this->db->getLastInsertId()); - } + $this->saveData($this->model->getName(), $data); + } + + protected function prepareDataStructureForYaml(string $id, mixed $data): mixed + { + return [ + 'data_definitions' => [ + 'import_definitions' => [ + $id => $data, + ], + ], + ]; } /** @@ -200,6 +178,6 @@ public function save() */ public function delete() { - $this->db->delete($this->model->getId()); + $this->deleteData($this->model->getName()); } } diff --git a/src/DataDefinitionsBundle/Model/ImportDefinition/Listing.php b/src/DataDefinitionsBundle/Model/ImportDefinition/Listing.php index fe5abf2b..580e3556 100644 --- a/src/DataDefinitionsBundle/Model/ImportDefinition/Listing.php +++ b/src/DataDefinitionsBundle/Model/ImportDefinition/Listing.php @@ -18,10 +18,18 @@ use Exception; use Pimcore\Model; +use Pimcore\Model\AbstractModel; +use Pimcore\Model\Listing\CallableFilterListingInterface; +use Pimcore\Model\Listing\CallableOrderListingInterface; +use Pimcore\Model\Listing\Traits\FilterListingTrait; +use Pimcore\Model\Listing\Traits\OrderListingTrait; use Wvision\Bundle\DataDefinitionsBundle\Model\ImportDefinitionInterface; -class Listing extends Model\Listing\JsonListing +class Listing extends AbstractModel implements CallableFilterListingInterface, CallableOrderListingInterface { + use FilterListingTrait; + use OrderListingTrait; + /** * Contains the results of the list. * They are all an instance of Configuration. @@ -37,7 +45,7 @@ class Listing extends Model\Listing\JsonListing public function getObjects() { if (null === $this->definitions) { - $this->load(); + $this->loadList(); } return $this->definitions; diff --git a/src/DataDefinitionsBundle/Model/ImportDefinition/Listing/Dao.php b/src/DataDefinitionsBundle/Model/ImportDefinition/Listing/Dao.php index c587dd33..02e5b73b 100644 --- a/src/DataDefinitionsBundle/Model/ImportDefinition/Listing/Dao.php +++ b/src/DataDefinitionsBundle/Model/ImportDefinition/Listing/Dao.php @@ -18,50 +18,32 @@ use Exception; use Pimcore; +use Pimcore\Bundle\StaticRoutesBundle\Model\Staticroute; use Wvision\Bundle\DataDefinitionsBundle\Model\ImportDefinition; use function count; -class Dao extends Pimcore\Model\Dao\PhpArrayTable +class Dao extends ImportDefinition\Dao { - /** - * Configure - */ - public function configure() + public function loadList(): array { - parent::configure(); - $this->setFile('importdefinitions'); - } - - /** - * Loads a list of Definitions for the specified parameters, returns an array of Definitions elements. - * - * @return array - * @throws Exception - */ - public function load() - { - $routesData = $this->db->fetchAll($this->model->getFilter(), $this->model->getOrder()); - - $routes = array(); - foreach ($routesData as $routeData) { - $routes[] = ImportDefinition::getById($routeData['id']); + $definitions = []; + foreach ($this->loadIdList() as $name) { + $definitions[] = ImportDefinition::getByName($name); } - $this->model->setObjects($routes); + if ($this->model->getFilter()) { + $definitions = array_filter($definitions, $this->model->getFilter()); + } + if ($this->model->getOrder()) { + usort($definitions, $this->model->getOrder()); + } + $this->model->setObjects($definitions); - return $routes; + return $definitions; } - /** - * Get total count - * - * @return int - * @throws Exception - */ - public function getTotalCount() + public function getTotalCount(): int { - $data = $this->db->fetchAll($this->model->getFilter(), $this->model->getOrder()); - - return count($data); + return count($this->loadList()); } } diff --git a/src/DataDefinitionsBundle/Provider/CsvProvider.php b/src/DataDefinitionsBundle/Provider/CsvProvider.php index 57b38d68..e0c67f82 100644 --- a/src/DataDefinitionsBundle/Provider/CsvProvider.php +++ b/src/DataDefinitionsBundle/Provider/CsvProvider.php @@ -52,7 +52,7 @@ public function getColumns(array $configuration): array if (count($rows) > 0) { $headerRow = $rows[0]; - $headers = str_getcsv($headerRow, $delimiter, $enclosure ?: chr(8)); + $headers = str_getcsv($headerRow, $delimiter ?? ',', $enclosure ?: chr(8)); if (count($headers) > 0) { //First line are the headers diff --git a/src/DataDefinitionsBundle/Resources/config/pimcore/config.yml b/src/DataDefinitionsBundle/Resources/config/pimcore/config.yml index 16f5c299..aabbb4be 100644 --- a/src/DataDefinitionsBundle/Resources/config/pimcore/config.yml +++ b/src/DataDefinitionsBundle/Resources/config/pimcore/config.yml @@ -75,3 +75,7 @@ data_definitions: import_rules_action_object: '/bundles/datadefinitions/pimcore/js/import_rule/actions/object.js' css: data_definition: '/bundles/datadefinitions/pimcore/css/datadefinition.css' + +framework: + http_client: + enabled: true \ No newline at end of file diff --git a/src/DataDefinitionsBundle/Resources/config/serializer/Model.Definition.yml b/src/DataDefinitionsBundle/Resources/config/serializer/Model.Definition.yml index c7391ba6..f87cd6bb 100755 --- a/src/DataDefinitionsBundle/Resources/config/serializer/Model.Definition.yml +++ b/src/DataDefinitionsBundle/Resources/config/serializer/Model.Definition.yml @@ -4,7 +4,7 @@ Wvision\Bundle\DataDefinitionsBundle\Model\Definition: properties: id: expose: true - type: integer + type: string xml_attribute: true groups: [ List, Detailed ] name: diff --git a/src/DataDefinitionsBundle/Resources/config/services.yml b/src/DataDefinitionsBundle/Resources/config/services.yml index 95a9cc03..990a0075 100644 --- a/src/DataDefinitionsBundle/Resources/config/services.yml +++ b/src/DataDefinitionsBundle/Resources/config/services.yml @@ -381,4 +381,12 @@ services: Wvision\Bundle\DataDefinitionsBundle\Service\StorageLocator: arguments: - $locator: !tagged_locator { tag: flysystem.storage } \ No newline at end of file + $locator: !tagged_locator { tag: flysystem.storage } + + Wvision\Bundle\DataDefinitionsBundle\EventListener\PimcoreSettingsListener: + tags: + - { name: kernel.event_listener, event: pimcore.admin.indexAction.settings, method: indexSettings } + + Wvision\Bundle\DataDefinitionsBundle\EventListener\WriteableListener: + tags: + - { name: kernel.event_subscriber } \ No newline at end of file diff --git a/src/DataDefinitionsBundle/Resources/config/services/forms.yml b/src/DataDefinitionsBundle/Resources/config/services/forms.yml index fb9935eb..dfd4632f 100644 --- a/src/DataDefinitionsBundle/Resources/config/services/forms.yml +++ b/src/DataDefinitionsBundle/Resources/config/services/forms.yml @@ -5,12 +5,7 @@ parameters: data_definitions.form.type.export_mapping.validation_groups: [ data_definitions ] services: - Wvision\Bundle\DataDefinitionsBundle\Form\DataMapper\DefinitionMappingDataMapper: - arguments: - - !service - class: Symfony\Component\Form\Extension\Core\DataMapper\PropertyPathMapper - arguments: - - '@property_accessor' + Wvision\Bundle\DataDefinitionsBundle\Form\DataMapper\DefinitionMappingDataMapper: ~ Wvision\Bundle\DataDefinitionsBundle\Form\Type\ClassChoiceType: tags: diff --git a/src/DataDefinitionsBundle/Resources/public/pimcore/css/datadefinition.css b/src/DataDefinitionsBundle/Resources/public/pimcore/css/datadefinition.css index bb84fe85..da4ec80e 100644 --- a/src/DataDefinitionsBundle/Resources/public/pimcore/css/datadefinition.css +++ b/src/DataDefinitionsBundle/Resources/public/pimcore/css/datadefinition.css @@ -6,7 +6,7 @@ background: url(../img/import_definition.svg) center center no-repeat !important; } -body.pimcore_version_10 .data_definitions_nav_icon_import_definition { +body.pimcore_version_11 .data_definitions_nav_icon_import_definition { background: url(../img/import_definition_white.svg) center center no-repeat !important; } @@ -18,7 +18,7 @@ body.pimcore_version_10 .data_definitions_nav_icon_import_definition { background: url(../img/export_definition.svg) center center no-repeat !important; } -body.pimcore_version_10 .data_definitions_nav_icon_export_definition { +body.pimcore_version_11 .data_definitions_nav_icon_export_definition { background: url(../img/export_definition_white.svg) center center no-repeat !important; } diff --git a/src/DataDefinitionsBundle/Resources/public/pimcore/js/definition/abstractItem.js b/src/DataDefinitionsBundle/Resources/public/pimcore/js/definition/abstractItem.js index 1a2fca67..6b64cf29 100644 --- a/src/DataDefinitionsBundle/Resources/public/pimcore/js/definition/abstractItem.js +++ b/src/DataDefinitionsBundle/Resources/public/pimcore/js/definition/abstractItem.js @@ -14,6 +14,10 @@ pimcore.registerNS('pimcore.plugin.datadefinitions.definition.abstractItem'); pimcore.plugin.datadefinitions.definition.abstractItem = Class.create(coreshop.resource.item, { + saveDisabled: function() { + return false; + }, + getPanel: function () { var me = this, panel = new Ext.TabPanel({ @@ -45,7 +49,8 @@ pimcore.plugin.datadefinitions.definition.abstractItem = Class.create(coreshop.r { text: t('data_definitions_import_definition'), iconCls: 'pimcore_icon_import', - handler: this.upload.bind(this) + handler: this.upload.bind(this), + disabled: this.saveDisabled() }, { text: t('data_definitions_export_definition'), @@ -58,6 +63,7 @@ pimcore.plugin.datadefinitions.definition.abstractItem = Class.create(coreshop.r { text: t('data_definitions_duplicate_definition'), iconCls: 'pimcore_icon_copy', + disabled: this.saveDisabled(), handler: function () { var id = me.data.id; @@ -88,7 +94,8 @@ pimcore.plugin.datadefinitions.definition.abstractItem = Class.create(coreshop.r { text: t('save'), iconCls: 'pimcore_icon_apply', - handler: this.save.bind(this) + handler: this.save.bind(this), + disabled: this.saveDisabled() }], items: this.getItems() }); diff --git a/src/DataDefinitionsBundle/Resources/public/pimcore/js/export/item.js b/src/DataDefinitionsBundle/Resources/public/pimcore/js/export/item.js index 40cb601e..890ba4aa 100644 --- a/src/DataDefinitionsBundle/Resources/public/pimcore/js/export/item.js +++ b/src/DataDefinitionsBundle/Resources/public/pimcore/js/export/item.js @@ -24,6 +24,10 @@ pimcore.plugin.datadefinitions.export.item = Class.create(pimcore.plugin.datadef providers: [], + saveDisabled: function () { + return !pimcore.settings['data-definitions-export-definition-writeable']; + }, + getSettings: function () { var classesStore = new Ext.data.JsonStore({ autoDestroy: true, diff --git a/src/DataDefinitionsBundle/Resources/public/pimcore/js/export/panel.js b/src/DataDefinitionsBundle/Resources/public/pimcore/js/export/panel.js index 0ea8a6c9..d7a2c66b 100755 --- a/src/DataDefinitionsBundle/Resources/public/pimcore/js/export/panel.js +++ b/src/DataDefinitionsBundle/Resources/public/pimcore/js/export/panel.js @@ -38,6 +38,20 @@ pimcore.plugin.datadefinitions.export.panel = Class.create(coreshop.resource.pan filters: [], runners: [], + + getTopBar: function () { + return [ + { + // add button + text: t('add'), + iconCls: 'pimcore_icon_add', + itemId: 'add-button', + handler: this.addItem.bind(this), + disabled: !pimcore.settings['data-definitions-import-definition-writeable'] + } + ]; + }, + getDefaultGridConfiguration: function () { return { region: 'west', diff --git a/src/DataDefinitionsBundle/Resources/public/pimcore/js/import/item.js b/src/DataDefinitionsBundle/Resources/public/pimcore/js/import/item.js index f5aad625..2bbf0843 100644 --- a/src/DataDefinitionsBundle/Resources/public/pimcore/js/import/item.js +++ b/src/DataDefinitionsBundle/Resources/public/pimcore/js/import/item.js @@ -25,6 +25,10 @@ pimcore.plugin.datadefinitions.import.item = Class.create(pimcore.plugin.datadef providers: [], + saveDisabled: function () { + return !pimcore.settings['data-definitions-import-definition-writeable']; + }, + getSettings: function () { var classesStore = new Ext.data.JsonStore({ autoDestroy: true, diff --git a/src/DataDefinitionsBundle/Resources/public/pimcore/js/import/panel.js b/src/DataDefinitionsBundle/Resources/public/pimcore/js/import/panel.js index 0943b337..de5d7ff5 100755 --- a/src/DataDefinitionsBundle/Resources/public/pimcore/js/import/panel.js +++ b/src/DataDefinitionsBundle/Resources/public/pimcore/js/import/panel.js @@ -39,6 +39,19 @@ pimcore.plugin.datadefinitions.import.panel = Class.create(coreshop.resource.pan runners: [], persisters: [], + getTopBar: function () { + return [ + { + // add button + text: t('add'), + iconCls: 'pimcore_icon_add', + itemId: 'add-button', + handler: this.addItem.bind(this), + disabled: !pimcore.settings['data-definitions-import-definition-writeable'] + } + ]; + }, + getDefaultGridConfiguration: function () { return { region: 'west', diff --git a/src/DataDefinitionsBundle/Resources/public/pimcore/js/startup.js b/src/DataDefinitionsBundle/Resources/public/pimcore/js/startup.js index 8246ce92..9208129e 100755 --- a/src/DataDefinitionsBundle/Resources/public/pimcore/js/startup.js +++ b/src/DataDefinitionsBundle/Resources/public/pimcore/js/startup.js @@ -13,16 +13,18 @@ pimcore.registerNS('pimcore.plugin.data_definitions'); -pimcore.plugin.data_definitions = Class.create(pimcore.plugin.admin, { +pimcore.plugin.data_definitions = Class.create({ getClassName: function () { return 'pimcore.plugin.data_definitions'; }, initialize: function () { - pimcore.plugin.broker.registerPlugin(this); + document.addEventListener(pimcore.events.pimcoreReady, (e) => { + this.pimcoreReady(); + }); }, - pimcoreReady: function (params, broker) { + pimcoreReady: function () { var user = pimcore.globalmanager.get('user'); diff --git a/src/Kernel.php b/src/Kernel.php index 2e2ba14d..e5d88e27 100644 --- a/src/Kernel.php +++ b/src/Kernel.php @@ -17,13 +17,13 @@ class Kernel extends PimcoreKernel { - public function registerBundlesToCollection(BundleCollection $collection) + public function registerBundlesToCollection(BundleCollection $collection): void { $collection->addBundle(new \Wvision\Bundle\DataDefinitionsBundle\DataDefinitionsBundle()); $collection->addBundle(new \FriendsOfBehat\SymfonyExtension\Bundle\FriendsOfBehatSymfonyExtensionBundle()); } - public function boot() + public function boot(): void { \Pimcore::setKernel($this); From 297a2b621aafe583e753763c9063000d65ce93fc Mon Sep 17 00:00:00 2001 From: Dominik Pfaffenbauer Date: Tue, 20 Jun 2023 14:53:22 +0200 Subject: [PATCH 52/65] run tests on next --- .github/workflows/behat.yml | 4 ++-- .github/workflows/static.yml | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/.github/workflows/behat.yml b/.github/workflows/behat.yml index e2c18e7f..9a984fb4 100644 --- a/.github/workflows/behat.yml +++ b/.github/workflows/behat.yml @@ -1,9 +1,9 @@ name: Behat on: push: - branches: [ master ] + branches: [ next ] pull_request: - branches: [ master ] + branches: [ next ] jobs: behat: diff --git a/.github/workflows/static.yml b/.github/workflows/static.yml index 54d4d198..a2b4607a 100644 --- a/.github/workflows/static.yml +++ b/.github/workflows/static.yml @@ -1,9 +1,9 @@ name: Static Tests (Lint, Stan) on: push: - branches: [ master ] + branches: [ next ] pull_request: - branches: [ master ] + branches: [ next ] jobs: lint: From ec962445a1be237e7c6f156d9a461387257f9ee3 Mon Sep 17 00:00:00 2001 From: Dominik Pfaffenbauer Date: Tue, 20 Jun 2023 15:36:01 +0200 Subject: [PATCH 53/65] tests --- .github/workflows/behat.yml | 50 +++++++++++++++++++----------------- .github/workflows/static.yml | 25 +++++++++--------- 2 files changed, 39 insertions(+), 36 deletions(-) diff --git a/.github/workflows/behat.yml b/.github/workflows/behat.yml index 9a984fb4..94adacbc 100644 --- a/.github/workflows/behat.yml +++ b/.github/workflows/behat.yml @@ -11,41 +11,45 @@ jobs: env: APP_ENV: "test" IM_SKIP_DB_SETUP: "1" + PIMCORE_TEST_DB_DSN: "mysql://root:root@127.0.0.1:3306/coreshop_test" PIMCORE_INSTALL_ADMIN_USERNAME: "admin" PIMCORE_INSTALL_ADMIN_PASSWORD: "admin" PIMCORE_INSTALL_MYSQL_HOST_SOCKET: "127.0.0.1" PIMCORE_INSTALL_MYSQL_USERNAME: "root" PIMCORE_INSTALL_MYSQL_PASSWORD: "root" - PIMCORE_INSTALL_MYSQL_DATABASE: "data_defs_test" + PIMCORE_INSTALL_MYSQL_DATABASE: "coreshop_test" PIMCORE_INSTALL_MYSQL_PORT: "3306" PIMCORE_KERNEL_CLASS: 'Kernel' PIMCORE_CLASS_DIRECTORY: 'var/tmp/behat/var/classes' - PIMCORE_WRITE_TARGET_STATICROUTES: 'settings-store' - PIMCORE_TEST_DB_DSN: "mysql://root:root@127.0.0.1:3306/data_defs_test" + + strategy: + matrix: + php: [ 8.1, 8.2 ] + pimcore: [ ^11.0 ] + dependencies: [ highest ] + exclude: + - php: 8.1 + dependencies: lowest services: database: - image: "mariadb:10.5" + image: "mysql:8" env: MYSQL_ROOT_PASSWORD: root - MYSQL_DATABASE: data_defs_test ports: - 3306:3306 options: --health-cmd="mysqladmin ping" --health-interval=10s --health-timeout=5s --health-retries=3 - name: "${{ matrix.pimcore }}, PHP ${{ matrix.php }}" - strategy: - matrix: - php: [ 8.0, 8.1 ] - pimcore: [ ^10.5 ] + name: "${{ matrix.pimcore }}, PHP ${{ matrix.php }}, Deps ${{ matrix.dependencies }}" steps: - - uses: actions/checkout@v2 + - uses: actions/checkout@v3 - name: Install PHP uses: shivammathur/setup-php@v2 with: php-version: ${{ matrix.php }} + ini-values: display_errors=On, display_startup_errors=On, error_reporting=32767 extensions: intl, gd, simpleXML, dom, exif, fileinfo, iconv, mbstring, mysqli, pdo_mysql, zip, zlib - name: Check PHP Version @@ -57,27 +61,27 @@ jobs: - name: Get composer cache directory id: composer-cache - run: echo "::set-output name=dir::$(composer config cache-files-dir)" + run: echo "dir=$(composer config cache-files-dir)" >> $GITHUB_OUTPUT - name: Cache composer dependencies - uses: actions/cache@v1 + uses: actions/cache@v3 with: path: ${{ steps.composer-cache.outputs.dir }} key: ${{ runner.os }}-composer-${{ hashFiles('**/composer.json') }} restore-keys: ${{ runner.os }}-composer- - - name: Cache composer dependencies - uses: actions/cache@v1 - with: - path: ${{ steps.composer-cache.outputs.dir }} - key: ${{ runner.os }}-composer-${{ hashFiles('**/composer.json') }} - restore-keys: ${{ runner.os }}-composer- - - - name: Install dependencies highest + - if: matrix.dependencies == 'highest' + name: Install dependencies highest run: | - composer req guzzlehttp/psr7 pimcore/pimcore:${{ matrix.pimcore }} --no-interaction --no-scripts --no-update + composer req pimcore/pimcore:${{ matrix.pimcore }} --no-interaction --no-scripts --no-update composer update --no-progress --prefer-dist --optimize-autoloader + - if: matrix.dependencies == 'lowest' + name: Install dependencies lowest + run: | + composer req pimcore/pimcore:${{ matrix.pimcore }} --no-interaction --no-scripts --no-update + composer update --no-progress --prefer-dist --optimize-autoloader --prefer-lowest + - name: Cache clear run: bin/console cache:clear @@ -85,7 +89,7 @@ jobs: run: bin/console assets:install --symlink - name: Install Pimcore - run: PIMCORE_KERNEL_CLASS=Kernel vendor/bin/pimcore-install --ignore-existing-config --env=test --skip-database-config + run: PIMCORE_KERNEL_CLASS=Kernel vendor/bin/pimcore-install --env=test --skip-database-config - name: Install DataDefinitions run: bin/console pimcore:bundle:install DataDefinitionsBundle diff --git a/.github/workflows/static.yml b/.github/workflows/static.yml index a2b4607a..efd524cf 100644 --- a/.github/workflows/static.yml +++ b/.github/workflows/static.yml @@ -10,32 +10,31 @@ jobs: runs-on: ubuntu-latest env: APP_ENV: "test" - PIMCORE_TEST_DB_DSN: "mysql://root:root@127.0.0.1:3306/data_defs_test" + PIMCORE_TEST_DB_DSN: "mysql://root:root@127.0.0.1:3306/coreshop_test" strategy: matrix: - php: [ 8.0, 8.1 ] - pimcore: [ ^10.5 ] - database: [ 'mysql:8.0' ] - dependencies: [ highest, lowest ] + php: [ 8.1, 8.2 ] + pimcore: [ ^11.0 ] + dependencies: [ highest ] exclude: - php: 8.1 dependencies: lowest services: database: - image: "${{ matrix.database }}" + image: "mysql:8" env: MYSQL_ROOT_PASSWORD: root - MYSQL_DATABASE: data_defs_test + MYSQL_DATABASE: coreshop_test ports: - 3306:3306 options: --health-cmd="mysqladmin ping" --health-interval=10s --health-timeout=5s --health-retries=3 - name: "${{ matrix.pimcore }}, PHP ${{ matrix.php }}, DB ${{ matrix.database }}, Deps ${{ matrix.dependencies }}" + name: "${{ matrix.pimcore }}, PHP ${{ matrix.php }}, Deps ${{ matrix.dependencies }}" steps: - - uses: actions/checkout@v2 + - uses: actions/checkout@v3 - name: Install PHP uses: shivammathur/setup-php@v2 @@ -49,10 +48,10 @@ jobs: - name: Get composer cache directory id: composer-cache - run: echo "::set-output name=dir::$(composer config cache-files-dir)" + run: echo "dir=$(composer config cache-files-dir)" >> $GITHUB_OUTPUT - name: Cache composer dependencies - uses: actions/cache@v1 + uses: actions/cache@v3 with: path: ${{ steps.composer-cache.outputs.dir }} key: ${{ runner.os }}-composer-${{ hashFiles('**/composer.json') }} @@ -61,13 +60,13 @@ jobs: - if: matrix.dependencies == 'highest' name: Install dependencies highest run: | - composer req guzzlehttp/psr7 pimcore/pimcore:${{ matrix.pimcore }} --no-interaction --no-scripts --no-update + composer req pimcore/pimcore:${{ matrix.pimcore }} --no-interaction --no-scripts --no-update composer update --no-progress --prefer-dist --optimize-autoloader - if: matrix.dependencies == 'lowest' name: Install dependencies lowest run: | - composer req guzzlehttp/psr7 pimcore/pimcore:${{ matrix.pimcore }} --no-interaction --no-scripts --no-update + composer req pimcore/pimcore:${{ matrix.pimcore }} --no-interaction --no-scripts --no-update composer update --no-progress --prefer-dist --optimize-autoloader --prefer-lowest - name: Validate YAML From 16dd8a72737eefe17a47df4ae6cae2cb8deaa00e Mon Sep 17 00:00:00 2001 From: Dominik Pfaffenbauer Date: Mon, 26 Jun 2023 16:04:43 +0200 Subject: [PATCH 54/65] [Messenger] introduce async imports --- .../Command/ImportAsyncCommand.php | 95 +++++++++++++++++++ .../Importer/AsyncImporterInterface.php | 26 +++++ .../Importer/Importer.php | 67 ++++++++++++- .../Messenger/ImportRowMessage.php | 46 +++++++++ .../Messenger/ImportRowMessageHandler.php | 44 +++++++++ .../Resources/config/pimcore/config.yml | 3 + .../Resources/config/pimcore/messenger.yml | 18 ++++ .../Resources/config/services.yml | 8 +- .../Resources/config/services/commands.yml | 8 ++ 9 files changed, 312 insertions(+), 3 deletions(-) create mode 100644 src/DataDefinitionsBundle/Command/ImportAsyncCommand.php create mode 100644 src/DataDefinitionsBundle/Importer/AsyncImporterInterface.php create mode 100644 src/DataDefinitionsBundle/Messenger/ImportRowMessage.php create mode 100644 src/DataDefinitionsBundle/Messenger/ImportRowMessageHandler.php create mode 100755 src/DataDefinitionsBundle/Resources/config/pimcore/messenger.yml diff --git a/src/DataDefinitionsBundle/Command/ImportAsyncCommand.php b/src/DataDefinitionsBundle/Command/ImportAsyncCommand.php new file mode 100644 index 00000000..0f470de5 --- /dev/null +++ b/src/DataDefinitionsBundle/Command/ImportAsyncCommand.php @@ -0,0 +1,95 @@ +eventDispatcher = $eventDispatcher; + $this->repository = $repository; + $this->importer = $importer; + + parent::__construct(); + } + + protected function configure(): void + { + $this + ->setName('data-definitions:async-import') + ->setDescription('Run a Data Definition Import Async.') + ->addOption( + 'definition', + 'd', + InputOption::VALUE_REQUIRED, + 'Import Definition ID or Name' + ) + ->addOption( + 'params', + 'p', + InputOption::VALUE_REQUIRED, + 'JSON Encoded Params' + ); + } + + protected function execute(InputInterface $input, OutputInterface $output) + { + $eventDispatcher = $this->eventDispatcher; + + $params = json_decode($input->getOption('params'), true); + + if (!isset($params['userId'])) { + $params['userId'] = 0; + } + + try { + $definition = $this->repository->find($input->getOption('definition')); + } catch (InvalidArgumentException $e) { + $definition = $this->repository->findByName($input->getOption('definition')); + } + + if (!$definition instanceof ImportDefinitionInterface) { + throw new Exception('Import Definition not found'); + } + + $this->importer->doImportAsync($definition, $params); + + return 0; + } +} diff --git a/src/DataDefinitionsBundle/Importer/AsyncImporterInterface.php b/src/DataDefinitionsBundle/Importer/AsyncImporterInterface.php new file mode 100644 index 00000000..8a1cca58 --- /dev/null +++ b/src/DataDefinitionsBundle/Importer/AsyncImporterInterface.php @@ -0,0 +1,26 @@ +getCreateVersion()) { + Version::enable(); + } else { + Version::disable(); + } + + $dataSet = new ArrayImportDataSet($row); + $runner = null; + $runnerContext = $this->contextFactory->createRunnerContext($definition, $params, $row, $dataSet, null); + + if ($definition->getRunner()) { + /** + * @var RunnerInterface $runner + */ + $runner = $this->runnerRegistry->get($definition->getRunner()); + } + + if ($runner instanceof ImportStartFinishRunnerInterface) { + $runner->startImport($runnerContext); + } + + $filter = null; + $filterType = $definition->getFilter(); + if ($filterType) { + /** + * @var FilterInterface $filter + */ + $filter = $this->filterRegistry->get($filterType); + } + + + $object = $this->importRow( + $definition, + $row, + $dataSet, + $params, + $filter, + $runner + ); + } + + public function doImportAsync(ImportDefinitionInterface $definition, array $params): void + { + /** @var ImportDataSetInterface|array $data */ + $data = $this->getData($definition, $params); + + foreach ($data as $row) { + $this->bus->dispatch( + new ImportRowMessage( + $definition->getId(), + $row, + $params, + ) + ); + } + } + public function doImport(ImportDefinitionInterface $definition, $params): array { $filter = null; diff --git a/src/DataDefinitionsBundle/Messenger/ImportRowMessage.php b/src/DataDefinitionsBundle/Messenger/ImportRowMessage.php new file mode 100644 index 00000000..e821d42a --- /dev/null +++ b/src/DataDefinitionsBundle/Messenger/ImportRowMessage.php @@ -0,0 +1,46 @@ +definitionId = $definitionId; + $this->data = $data; + $this->params = $params; + } + + public function getDefinitionId(): int + { + return $this->definitionId; + } + + public function getData(): array + { + return $this->data; + } + + public function getParams(): array + { + return $this->params; + } +} diff --git a/src/DataDefinitionsBundle/Messenger/ImportRowMessageHandler.php b/src/DataDefinitionsBundle/Messenger/ImportRowMessageHandler.php new file mode 100644 index 00000000..12d8baeb --- /dev/null +++ b/src/DataDefinitionsBundle/Messenger/ImportRowMessageHandler.php @@ -0,0 +1,44 @@ +getDefinitionId()); + + if (!$definition) { + throw new \InvalidArgumentException('Invalid definition id'); + } + + $this->importer->doImportRowAsync( + $definition, + $message->getData(), + $message->getParams(), + ); + } +} diff --git a/src/DataDefinitionsBundle/Resources/config/pimcore/config.yml b/src/DataDefinitionsBundle/Resources/config/pimcore/config.yml index 16f5c299..0aa0fcb6 100644 --- a/src/DataDefinitionsBundle/Resources/config/pimcore/config.yml +++ b/src/DataDefinitionsBundle/Resources/config/pimcore/config.yml @@ -1,3 +1,6 @@ +imports: + - { resource: messenger.yml } + jms_serializer: metadata: directories: diff --git a/src/DataDefinitionsBundle/Resources/config/pimcore/messenger.yml b/src/DataDefinitionsBundle/Resources/config/pimcore/messenger.yml new file mode 100755 index 00000000..fe0ff6cd --- /dev/null +++ b/src/DataDefinitionsBundle/Resources/config/pimcore/messenger.yml @@ -0,0 +1,18 @@ +framework: + messenger: + transports: + data_definitions_import: + dsn: "doctrine://default?queue_name=data_definitions_import" + failure_transport: data_definitions_import_failed + retry_strategy: + max_retries: 5 + delay: 300000 + multiplier: 2 + # we store failed messages here for admins to manually review them later + data_definitions_import_failed: + dsn: "doctrine://default?queue_name=data_definitions_import_failed" + retry_strategy: + max_retries: 0 + + routing: + 'Wvision\Bundle\DataDefinitionsBundle\Messenger\ImportRowMessage': data_definitions_import \ No newline at end of file diff --git a/src/DataDefinitionsBundle/Resources/config/services.yml b/src/DataDefinitionsBundle/Resources/config/services.yml index 95a9cc03..7ca2a596 100644 --- a/src/DataDefinitionsBundle/Resources/config/services.yml +++ b/src/DataDefinitionsBundle/Resources/config/services.yml @@ -381,4 +381,10 @@ services: Wvision\Bundle\DataDefinitionsBundle\Service\StorageLocator: arguments: - $locator: !tagged_locator { tag: flysystem.storage } \ No newline at end of file + $locator: !tagged_locator { tag: flysystem.storage } + + Wvision\Bundle\DataDefinitionsBundle\Messenger\ImportRowMessageHandler: + arguments: + - '@Wvision\Bundle\DataDefinitionsBundle\Importer\ImporterInterface' + tags: + - { name: messenger.message_handler } diff --git a/src/DataDefinitionsBundle/Resources/config/services/commands.yml b/src/DataDefinitionsBundle/Resources/config/services/commands.yml index d8a32392..ea5aa5ef 100644 --- a/src/DataDefinitionsBundle/Resources/config/services/commands.yml +++ b/src/DataDefinitionsBundle/Resources/config/services/commands.yml @@ -19,6 +19,14 @@ services: tags: - { name: 'console.command', command: 'data-definitions:import' } + Wvision\Bundle\DataDefinitionsBundle\Command\ImportAsyncCommand: + arguments: + - '@event_dispatcher' + - '@data_definitions.repository.import_definition' + - '@Wvision\Bundle\DataDefinitionsBundle\Importer\ImporterInterface' + tags: + - { name: 'console.command', command: 'data-definitions:async-import' } + Wvision\Bundle\DataDefinitionsBundle\Command\ExportCommand: arguments: - '@event_dispatcher' From 9957d797e605a84535a227c4b4679b1f8de09e30 Mon Sep 17 00:00:00 2001 From: Dominik Pfaffenbauer Date: Mon, 26 Jun 2023 16:08:12 +0200 Subject: [PATCH 55/65] run tests on 4.0 --- .github/workflows/behat.yml | 4 ++-- .github/workflows/static.yml | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/.github/workflows/behat.yml b/.github/workflows/behat.yml index e2c18e7f..d45dc077 100644 --- a/.github/workflows/behat.yml +++ b/.github/workflows/behat.yml @@ -1,9 +1,9 @@ name: Behat on: push: - branches: [ master ] + branches: [ '4.0' ] pull_request: - branches: [ master ] + branches: [ '4.0' ] jobs: behat: diff --git a/.github/workflows/static.yml b/.github/workflows/static.yml index 54d4d198..f7bcc927 100644 --- a/.github/workflows/static.yml +++ b/.github/workflows/static.yml @@ -1,9 +1,9 @@ name: Static Tests (Lint, Stan) on: push: - branches: [ master ] + branches: [ '4.0' ] pull_request: - branches: [ master ] + branches: [ '4.0' ] jobs: lint: From 4018846085489d89b4e59a45eef89bd63d6b31dc Mon Sep 17 00:00:00 2001 From: Dominik Pfaffenbauer Date: Mon, 26 Jun 2023 16:08:38 +0200 Subject: [PATCH 56/65] [Messenger] introduce async imports --- .../Command/ImportAsyncCommand.php | 14 +++----------- 1 file changed, 3 insertions(+), 11 deletions(-) diff --git a/src/DataDefinitionsBundle/Command/ImportAsyncCommand.php b/src/DataDefinitionsBundle/Command/ImportAsyncCommand.php index 0f470de5..ac964c23 100644 --- a/src/DataDefinitionsBundle/Command/ImportAsyncCommand.php +++ b/src/DataDefinitionsBundle/Command/ImportAsyncCommand.php @@ -33,19 +33,11 @@ final class ImportAsyncCommand extends AbstractCommand { - protected EventDispatcherInterface $eventDispatcher; - protected DefinitionRepository $repository; - protected ImporterInterface $importer; - public function __construct( - EventDispatcherInterface $eventDispatcher, - DefinitionRepository $repository, - AsyncImporterInterface $importer + protected EventDispatcherInterface $eventDispatcher, + protected DefinitionRepository $repository, + protected AsyncImporterInterface $importer ) { - $this->eventDispatcher = $eventDispatcher; - $this->repository = $repository; - $this->importer = $importer; - parent::__construct(); } From e6619f56781f1d3201a4aa1ec731e9ebc01c83a2 Mon Sep 17 00:00:00 2001 From: Dominik Pfaffenbauer Date: Mon, 26 Jun 2023 16:13:28 +0200 Subject: [PATCH 57/65] [Messenger] introduce async imports --- src/DataDefinitionsBundle/Resources/config/services.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/src/DataDefinitionsBundle/Resources/config/services.yml b/src/DataDefinitionsBundle/Resources/config/services.yml index 7ca2a596..c5e22e0d 100644 --- a/src/DataDefinitionsBundle/Resources/config/services.yml +++ b/src/DataDefinitionsBundle/Resources/config/services.yml @@ -31,6 +31,7 @@ services: - '@logger' - '@pimcore.model.factory' - '@coreshop.expression_language' + - '@messenger.bus.default' tags: - { name: monolog.logger, channel: import_definition } - { name: 'kernel.event_listener', event: 'data_definitions.stop', method: 'stop' } From e2491d79ce4e5a82607a9365dc6885c7eef369d2 Mon Sep 17 00:00:00 2001 From: Dominik Pfaffenbauer Date: Mon, 26 Jun 2023 16:16:14 +0200 Subject: [PATCH 58/65] [Messenger] introduce async imports --- src/DataDefinitionsBundle/Resources/config/services.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/DataDefinitionsBundle/Resources/config/services.yml b/src/DataDefinitionsBundle/Resources/config/services.yml index c5e22e0d..ca0aef39 100644 --- a/src/DataDefinitionsBundle/Resources/config/services.yml +++ b/src/DataDefinitionsBundle/Resources/config/services.yml @@ -31,7 +31,7 @@ services: - '@logger' - '@pimcore.model.factory' - '@coreshop.expression_language' - - '@messenger.bus.default' + - '@messenger.default_bus' tags: - { name: monolog.logger, channel: import_definition } - { name: 'kernel.event_listener', event: 'data_definitions.stop', method: 'stop' } From 5222843ae6b4a7b8a3b4a8a59f6a6d701abe6000 Mon Sep 17 00:00:00 2001 From: Dominik Pfaffenbauer Date: Mon, 26 Jun 2023 16:28:33 +0200 Subject: [PATCH 59/65] [Messenger] introduce async imports --- src/Kernel.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/Kernel.php b/src/Kernel.php index 2e2ba14d..19a89cb8 100644 --- a/src/Kernel.php +++ b/src/Kernel.php @@ -25,8 +25,8 @@ public function registerBundlesToCollection(BundleCollection $collection) public function boot() { - \Pimcore::setKernel($this); - parent::boot(); + + \Pimcore::setKernel($this); } } From dfe971c24149b5cf7dfa8a7f1e55c018c64b942c Mon Sep 17 00:00:00 2001 From: Dominik Pfaffenbauer Date: Thu, 6 Jul 2023 12:39:07 +0200 Subject: [PATCH 60/65] Next --- behat-bootstrap.php | 18 +++++++--- composer.json | 5 ++- config/packages/test/config.yaml | 9 +++++ features/cleaner/deleter.feature | 2 +- features/cleaner/none.feature | 2 +- features/cleaner/unpublisher.feature | 2 +- src/BehatKernel.php | 32 +++++++++++++++++ .../Command/ExportCommand.php | 1 + .../Command/ImportCommand.php | 2 ++ .../Importer/Importer.php | 2 +- .../Model/ExportDefinition/Listing.php | 3 ++ .../Model/ImportDefinition/Listing.php | 3 ++ src/DataDefinitionsBundle/Model/Log/Dao.php | 2 +- .../Model/Log/Listing.php | 17 ++++------ .../Model/Log/Listing/Dao.php | 8 ++--- .../Provider/AbstractFileProvider.php | 4 +-- .../Provider/XmlProvider.php | 2 +- .../Rules/Model/ImportRule.php | 2 +- .../Behat/Context/Domain/PimcoreContext.php | 4 +-- .../Behat/Context/Hook/IMSetupContext.php | 34 +++++++++++++------ .../Behat/Context/Hook/PimcoreDaoContext.php | 28 ++++++++++----- .../Context/Setup/PimcoreClassContext.php | 22 ++++++------ .../Context/Transform/PimcoreClassContext.php | 6 ++-- .../Resources/config/profiles/default.yml | 4 +-- .../config/services/contexts/hook.yml | 1 + 25 files changed, 149 insertions(+), 66 deletions(-) create mode 100644 src/BehatKernel.php diff --git a/behat-bootstrap.php b/behat-bootstrap.php index 5a946700..db37a032 100755 --- a/behat-bootstrap.php +++ b/behat-bootstrap.php @@ -1,10 +1,20 @@ addBundle(new \Wvision\Bundle\DataDefinitionsBundle\DataDefinitionsBundle()); + $collection->addBundle(new \FriendsOfBehat\SymfonyExtension\Bundle\FriendsOfBehatSymfonyExtensionBundle()); + } + + public function boot(): void + { + parent::boot(); + + \Pimcore::setKernel($this); + } +} diff --git a/src/DataDefinitionsBundle/Command/ExportCommand.php b/src/DataDefinitionsBundle/Command/ExportCommand.php index 255ca8ee..dbe1d666 100644 --- a/src/DataDefinitionsBundle/Command/ExportCommand.php +++ b/src/DataDefinitionsBundle/Command/ExportCommand.php @@ -76,6 +76,7 @@ protected function execute(InputInterface $input, OutputInterface $output) $eventDispatcher = $this->eventDispatcher; $params = json_decode($input->getOption('params'), true); + $definition = null; try { $definition = $this->repository->findByName($input->getOption('definition')); } catch (InvalidArgumentException $e) { diff --git a/src/DataDefinitionsBundle/Command/ImportCommand.php b/src/DataDefinitionsBundle/Command/ImportCommand.php index b12cd21e..2278bf3f 100644 --- a/src/DataDefinitionsBundle/Command/ImportCommand.php +++ b/src/DataDefinitionsBundle/Command/ImportCommand.php @@ -82,6 +82,8 @@ protected function execute(InputInterface $input, OutputInterface $output) $params['userId'] = 0; } + $definition = null; + try { $definition = $this->repository->findByName($input->getOption('definition')); } catch (InvalidArgumentException $e) { diff --git a/src/DataDefinitionsBundle/Importer/Importer.php b/src/DataDefinitionsBundle/Importer/Importer.php index 4b587db2..40e5ebec 100644 --- a/src/DataDefinitionsBundle/Importer/Importer.php +++ b/src/DataDefinitionsBundle/Importer/Importer.php @@ -412,7 +412,7 @@ private function importRow( $params['versionNote'] = sprintf('%s - %s', $definition->getId(), $definition->getName()); $object->setUserModification($params['userId'] ?? 0); - $object->setOmitMandatoryCheck($definition->getOmitMandatoryCheck()); + $object->setOmitMandatoryCheck($definition->getOmitMandatoryCheck() ?: false); $this->saveObject($object, $definition, $params); diff --git a/src/DataDefinitionsBundle/Model/ExportDefinition/Listing.php b/src/DataDefinitionsBundle/Model/ExportDefinition/Listing.php index 1a77d772..19c8b1e0 100644 --- a/src/DataDefinitionsBundle/Model/ExportDefinition/Listing.php +++ b/src/DataDefinitionsBundle/Model/ExportDefinition/Listing.php @@ -24,6 +24,9 @@ use Pimcore\Model\Listing\Traits\OrderListingTrait; use Wvision\Bundle\DataDefinitionsBundle\Model\ExportDefinitionInterface; +/** + * @method loadList() + */ class Listing extends AbstractModel implements CallableFilterListingInterface, CallableOrderListingInterface { use FilterListingTrait; diff --git a/src/DataDefinitionsBundle/Model/ImportDefinition/Listing.php b/src/DataDefinitionsBundle/Model/ImportDefinition/Listing.php index 580e3556..cbec7d43 100644 --- a/src/DataDefinitionsBundle/Model/ImportDefinition/Listing.php +++ b/src/DataDefinitionsBundle/Model/ImportDefinition/Listing.php @@ -25,6 +25,9 @@ use Pimcore\Model\Listing\Traits\OrderListingTrait; use Wvision\Bundle\DataDefinitionsBundle\Model\ImportDefinitionInterface; +/** + * @method loadList() + */ class Listing extends AbstractModel implements CallableFilterListingInterface, CallableOrderListingInterface { use FilterListingTrait; diff --git a/src/DataDefinitionsBundle/Model/Log/Dao.php b/src/DataDefinitionsBundle/Model/Log/Dao.php index e1e35e91..596ec91d 100644 --- a/src/DataDefinitionsBundle/Model/Log/Dao.php +++ b/src/DataDefinitionsBundle/Model/Log/Dao.php @@ -40,7 +40,7 @@ public function getById($id = null) $this->model->setId($id); } - $data = $this->db->fetchRow('SELECT * FROM '.$this->tableName.' WHERE id = ?', $this->model->getId()); + $data = $this->db->fetchAssociative('SELECT * FROM '.$this->tableName.' WHERE id = ?', [$this->model->getId()]); if (!$data['id']) { throw new InvalidArgumentException(sprintf('Object with the ID %s does not exist', $this->model->getId())); diff --git a/src/DataDefinitionsBundle/Model/Log/Listing.php b/src/DataDefinitionsBundle/Model/Log/Listing.php index 52f06ee9..eef5296b 100644 --- a/src/DataDefinitionsBundle/Model/Log/Listing.php +++ b/src/DataDefinitionsBundle/Model/Log/Listing.php @@ -24,12 +24,7 @@ class Listing extends Model\Listing\AbstractListing implements PaginateListingInterface { - /** - * List of Logs. - * - * @var array - */ - public $data; + public ?array $data; /** * @var string @@ -48,7 +43,7 @@ class Listing extends Model\Listing\AbstractListing implements PaginateListingIn * * @return bool */ - public function isValidOrderKey($key) + public function isValidOrderKey($key): bool { return in_array($key, $this->validOrderKeys, true); } @@ -92,10 +87,10 @@ public function count(): int * * @param int $offset * @param int $itemCountPerPage - * @return mixed + * @return array * @throws Exception */ - public function getItems($offset, $itemCountPerPage) + public function getItems($offset, $itemCountPerPage): array { $this->setOffset($offset); $this->setLimit($itemCountPerPage); @@ -164,10 +159,10 @@ public function current(): mixed /** * Key * - * @return mixed + * @return int|string|null * @throws Exception */ - public function key(): mixed + public function key(): int|string|null { $this->getData(); diff --git a/src/DataDefinitionsBundle/Model/Log/Listing/Dao.php b/src/DataDefinitionsBundle/Model/Log/Listing/Dao.php index ff77c639..3d15e660 100644 --- a/src/DataDefinitionsBundle/Model/Log/Listing/Dao.php +++ b/src/DataDefinitionsBundle/Model/Log/Listing/Dao.php @@ -49,7 +49,7 @@ protected function getTableName() * @return Log[] * @throws Exception */ - public function load() + public function load(): array { // load id's $list = $this->loadIdList(); @@ -85,7 +85,7 @@ public function getQueryBuilder(...$columns): DoctrineQueryBuilder public function loadIdList() { $queryBuilder = $this->getQueryBuilder(['id']); - $assetIds = $this->db->fetchCol( + $assetIds = $this->db->fetchFirstColumn( (string)$queryBuilder, $this->model->getConditionVariables(), $this->model->getConditionVariableTypes() @@ -105,7 +105,7 @@ public function getCount(): int { return (int)$this->db->fetchOne( 'SELECT COUNT(*) as amount FROM '.$this->getTableName().$this->getCondition().$this->getOffsetLimit(), - $this->model->getConditionVariables() + [$this->model->getConditionVariables()] ); } @@ -119,7 +119,7 @@ public function getTotalCount(): int { return (int)$this->db->fetchOne( 'SELECT COUNT(*) as amount FROM '.$this->getTableName().$this->getCondition(), - $this->model->getConditionVariables() + [$this->model->getConditionVariables()] ); } } diff --git a/src/DataDefinitionsBundle/Provider/AbstractFileProvider.php b/src/DataDefinitionsBundle/Provider/AbstractFileProvider.php index 4677cb00..4454f059 100644 --- a/src/DataDefinitionsBundle/Provider/AbstractFileProvider.php +++ b/src/DataDefinitionsBundle/Provider/AbstractFileProvider.php @@ -67,11 +67,11 @@ protected function createTemporaryFileFromStream($stream) { if (is_string($stream)) { $src = fopen($stream, 'rb'); - $fileExtension = File::getFileExtension($stream); + $fileExtension = pathinfo($stream, PATHINFO_EXTENSION); } else { $src = $stream; $streamMeta = stream_get_meta_data($src); - $fileExtension = File::getFileExtension($streamMeta['uri']); + $fileExtension = pathinfo($streamMeta['uri'], PATHINFO_EXTENSION); } $tmpFilePath = File::getLocalTempFilePath($fileExtension); diff --git a/src/DataDefinitionsBundle/Provider/XmlProvider.php b/src/DataDefinitionsBundle/Provider/XmlProvider.php index 360903d8..92f679dd 100755 --- a/src/DataDefinitionsBundle/Provider/XmlProvider.php +++ b/src/DataDefinitionsBundle/Provider/XmlProvider.php @@ -135,7 +135,7 @@ public function exportData(array $configuration, ExportDefinitionInterface $defi throw new RuntimeException(sprintf('Passed XSLT file "%1$s" not found', $path)); } - $extension = File::getFileExtension($configuration['xsltPath']); + $extension = pathinfo($configuration['xsltPath'], PATHINFO_EXTENSION); $workingPath = File::getLocalTempFilePath($extension); file_put_contents($workingPath, $storage->read($path)); diff --git a/src/DataDefinitionsBundle/Rules/Model/ImportRule.php b/src/DataDefinitionsBundle/Rules/Model/ImportRule.php index 16bf733f..e8fa3a01 100644 --- a/src/DataDefinitionsBundle/Rules/Model/ImportRule.php +++ b/src/DataDefinitionsBundle/Rules/Model/ImportRule.php @@ -24,7 +24,7 @@ class ImportRule implements ImportRuleInterface protected int $id; - public function getId() + public function getId(): ?int { return $this->id; } diff --git a/tests/DataDefinitionsBundle/Behat/Context/Domain/PimcoreContext.php b/tests/DataDefinitionsBundle/Behat/Context/Domain/PimcoreContext.php index a691ed8e..94a74ed1 100644 --- a/tests/DataDefinitionsBundle/Behat/Context/Domain/PimcoreContext.php +++ b/tests/DataDefinitionsBundle/Behat/Context/Domain/PimcoreContext.php @@ -64,7 +64,7 @@ public function thereAreUnpublishedDataObjects(int $count, ClassDefinition $defi * @var DataObject\Listing $list */ $list = $fqcn::getList(); - $list->setCondition('o_published=0'); + $list->setCondition('published=0'); Assert::eq($count, $list->getTotalCount(), sprintf( @@ -88,7 +88,7 @@ public function thereArePublishedDataObjects(int $count, ClassDefinition $defini * @var DataObject\Listing $list */ $list = $fqcn::getList(); - $list->setCondition('o_published=1'); + $list->setCondition('published=1'); Assert::eq($count, $list->getTotalCount(), sprintf( diff --git a/tests/DataDefinitionsBundle/Behat/Context/Hook/IMSetupContext.php b/tests/DataDefinitionsBundle/Behat/Context/Hook/IMSetupContext.php index fa471a0c..2709f863 100644 --- a/tests/DataDefinitionsBundle/Behat/Context/Hook/IMSetupContext.php +++ b/tests/DataDefinitionsBundle/Behat/Context/Hook/IMSetupContext.php @@ -17,6 +17,8 @@ use Behat\Behat\Context\Context; use Wvision\Bundle\DataDefinitionsBundle\Installer; use Pimcore\Db\PhpArrayFileTable; +use Wvision\Bundle\DataDefinitionsBundle\Model\ExportDefinition; +use Wvision\Bundle\DataDefinitionsBundle\Model\ImportDefinition; final class IMSetupContext implements Context { @@ -46,18 +48,30 @@ public static function setupImportDefinitions() */ public function purgeDefinitions() { - if (file_exists(PIMCORE_CONFIGURATION_DIRECTORY.'/importdefinitions.php')) { - unlink(PIMCORE_CONFIGURATION_DIRECTORY.'/importdefinitions.php'); - } + $importDefinitions = new ImportDefinition\Listing(); - if (file_exists(PIMCORE_CONFIGURATION_DIRECTORY.'/exportdefinitions.php')) { - unlink(PIMCORE_CONFIGURATION_DIRECTORY.'/exportdefinitions.php'); + foreach ($importDefinitions->getObjects() as $definition) { + $definition->delete(); } - $obj = new PhpArrayFileTable(); - $refObject = new \ReflectionObject($obj); - $refProperty = $refObject->getProperty('tables'); - $refProperty->setAccessible(true); - $refProperty->setValue(null, []); + $exportDefinitions = new ExportDefinition\Listing(); + + foreach ($exportDefinitions->getObjects() as $definition) { + $definition->delete(); + } +// +// if (file_exists(PIMCORE_CONFIGURATION_DIRECTORY.'/importdefinitions.php')) { +// unlink(PIMCORE_CONFIGURATION_DIRECTORY.'/importdefinitions.php'); +// } +// +// if (file_exists(PIMCORE_CONFIGURATION_DIRECTORY.'/exportdefinitions.php')) { +// unlink(PIMCORE_CONFIGURATION_DIRECTORY.'/exportdefinitions.php'); +// } +// +// $obj = new PhpArrayFileTable(); +// $refObject = new \ReflectionObject($obj); +// $refProperty = $refObject->getProperty('tables'); +// $refProperty->setAccessible(true); +// $refProperty->setValue(null, []); } } diff --git a/tests/DataDefinitionsBundle/Behat/Context/Hook/PimcoreDaoContext.php b/tests/DataDefinitionsBundle/Behat/Context/Hook/PimcoreDaoContext.php index b6b1c4fc..5dd74b03 100644 --- a/tests/DataDefinitionsBundle/Behat/Context/Hook/PimcoreDaoContext.php +++ b/tests/DataDefinitionsBundle/Behat/Context/Hook/PimcoreDaoContext.php @@ -23,14 +23,24 @@ use Pimcore\Model\DataObject\Fieldcollection; use Pimcore\Model\DataObject\Listing; use Pimcore\Model\DataObject\Objectbrick; +use Symfony\Component\HttpKernel\KernelInterface; final class PimcoreDaoContext implements Context { - private $connection; + public function __construct( + private Connection $connection, + private KernelInterface $kernel, + ) + { + + } - public function __construct(Connection $connection) + /** + * @BeforeScenario + */ + public function setKernel(): void { - $this->connection = $connection; + \Pimcore::setKernel($this->kernel); } /** @@ -39,14 +49,14 @@ public function __construct(Connection $connection) public function purgeObjects() { Cache::clearAll(); - Cache\Runtime::clear(); + Cache\RuntimeCache::clear(); /** * @var Listing $list */ $list = new DataObject\Listing(); $list->setUnpublished(true); - $list->setCondition('o_id <> 1'); + $list->setCondition('id <> 1'); $list->load(); foreach ($list->getObjects() as $obj) { @@ -60,7 +70,7 @@ public function purgeObjects() public function purgeAssets() { Cache::clearAll(); - Cache\Runtime::clear(); + Cache\RuntimeCache::clear(); /** * @var Asset\Listing $list @@ -107,7 +117,7 @@ public function purgeBricks() public function clearRuntimeCacheScenario() { //Clearing it here is totally fine, since each scenario has its own separated context of objects - \Pimcore\Cache\Runtime::clear(); + Cache\RuntimeCache::clear(); } /** @@ -117,7 +127,7 @@ public function clearRuntimeCacheStep() { //We should not clear Pimcore Objects here, otherwise we lose the reference to it //and end up having the same object twice - $copy = \Pimcore\Cache\Runtime::getInstance()->getArrayCopy(); + $copy = \Pimcore\Cache\RuntimeCache::getInstance()->getArrayCopy(); $keepItems = []; foreach ($copy as $key => $value) { @@ -126,7 +136,7 @@ public function clearRuntimeCacheStep() } } - \Pimcore\Cache\Runtime::clear($keepItems); + \Pimcore\Cache\RuntimeCache::clear($keepItems); } /** diff --git a/tests/DataDefinitionsBundle/Behat/Context/Setup/PimcoreClassContext.php b/tests/DataDefinitionsBundle/Behat/Context/Setup/PimcoreClassContext.php index 0385632a..bd92c194 100644 --- a/tests/DataDefinitionsBundle/Behat/Context/Setup/PimcoreClassContext.php +++ b/tests/DataDefinitionsBundle/Behat/Context/Setup/PimcoreClassContext.php @@ -79,7 +79,7 @@ public function createClassNamed($className) "bodyStyle": null, "datatype": "layout", "permissions": null, - "childs": [ + "children": [ { "fieldtype": "panel", "labelWidth": 100, @@ -95,7 +95,7 @@ public function createClassNamed($className) "bodyStyle": null, "datatype": "layout", "permissions": null, - "childs": [], + "children": [], "locked": false } ], @@ -159,7 +159,7 @@ public function createBrickNamed($brickName) "bodyStyle": null, "datatype": "layout", "permissions": null, - "childs": [ + "children": [ { "fieldtype": "panel", "labelWidth": 100, @@ -175,7 +175,7 @@ public function createBrickNamed($brickName) "bodyStyle": null, "datatype": "layout", "permissions": null, - "childs": [], + "children": [], "locked": false } ], @@ -217,7 +217,7 @@ public function createCollectionNamed($collection) "bodyStyle": null, "datatype": "layout", "permissions": null, - "childs": [ + "children": [ { "fieldtype": "panel", "labelWidth": 100, @@ -233,7 +233,7 @@ public function createCollectionNamed($collection) "bodyStyle": null, "datatype": "layout", "permissions": null, - "childs": [], + "children": [], "locked": false } ], @@ -318,9 +318,9 @@ public function definitionHasExternalImageField($definition, $name) $jsonDefinition = sprintf(' { "fieldtype": "externalImage", - "previewWidth": "", - "inputWidth": "", - "previewHeight": "", + "previewWidth": null, + "inputWidth": null, + "previewHeight": null, "name": "%s", "title": "%s", "tooltip": "", @@ -522,7 +522,7 @@ public function definitionHasLocalizedInputField($definition, $name) { "fieldtype": "localizedfields", "phpdocType": "\\Pimcore\\Model\\DataObject\\Localizedfield", - "childs": [ + "children": [ { "fieldtype": "input", "width": null, @@ -587,7 +587,7 @@ public function definitionHasLocalizedTextareaField($definition, $name) { "fieldtype": "localizedfields", "phpdocType": "\\Pimcore\\Model\\DataObject\\Localizedfield", - "childs": [ + "children": [ { "fieldtype": "textarea", "width": "", diff --git a/tests/DataDefinitionsBundle/Behat/Context/Transform/PimcoreClassContext.php b/tests/DataDefinitionsBundle/Behat/Context/Transform/PimcoreClassContext.php index ce2ff728..dce8bc31 100644 --- a/tests/DataDefinitionsBundle/Behat/Context/Transform/PimcoreClassContext.php +++ b/tests/DataDefinitionsBundle/Behat/Context/Transform/PimcoreClassContext.php @@ -17,7 +17,7 @@ use Behat\Behat\Context\Context; use Wvision\Bundle\DataDefinitionsBundle\Behat\Service\ClassStorageInterface; use Wvision\Bundle\DataDefinitionsBundle\Behat\Service\SharedStorageInterface; -use Pimcore\Cache\Runtime; +use Pimcore\Cache\RuntimeCache; use Pimcore\Model\DataObject; use Pimcore\Model\DataObject\ClassDefinition; use Pimcore\Model\DataObject\Concrete; @@ -42,7 +42,7 @@ public function __construct( */ public function class($name) { - Runtime::clear(); + RuntimeCache::clear(); $name = $this->classStorage->get($name); @@ -129,7 +129,7 @@ public function objectOfTheClass($name) */ public function definition() { - Runtime::clear(); + RuntimeCache::clear(); $name = $this->sharedStorage->get('pimcore_definition_name'); $class = $this->sharedStorage->get('pimcore_definition_class'); diff --git a/tests/DataDefinitionsBundle/Behat/Resources/config/profiles/default.yml b/tests/DataDefinitionsBundle/Behat/Resources/config/profiles/default.yml index aee25a91..e88d3ecd 100644 --- a/tests/DataDefinitionsBundle/Behat/Resources/config/profiles/default.yml +++ b/tests/DataDefinitionsBundle/Behat/Resources/config/profiles/default.yml @@ -9,6 +9,6 @@ default: FriendsOfBehat\SymfonyExtension: bootstrap: behat-bootstrap.php kernel: - path: src/Kernel.php - class: Kernel + path: src/BehatKernel.php + class: BehatKernel environment: test diff --git a/tests/DataDefinitionsBundle/Behat/Resources/config/services/contexts/hook.yml b/tests/DataDefinitionsBundle/Behat/Resources/config/services/contexts/hook.yml index 8b689ee8..d11a7946 100644 --- a/tests/DataDefinitionsBundle/Behat/Resources/config/services/contexts/hook.yml +++ b/tests/DataDefinitionsBundle/Behat/Resources/config/services/contexts/hook.yml @@ -6,6 +6,7 @@ services: class: Wvision\Bundle\DataDefinitionsBundle\Behat\Context\Hook\PimcoreDaoContext arguments: - '@doctrine.dbal.default_connection' + - '@kernel' tags: - { name: fob.context_service } From f5b6e64b56b09ea720d85a602d2a5062bc39df85 Mon Sep 17 00:00:00 2001 From: Bram Gerritsen Date: Thu, 20 Jul 2023 07:59:08 +0200 Subject: [PATCH 61/65] Add missing type casting interpreter definition --- src/DataDefinitionsBundle/Resources/config/services.yml | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/DataDefinitionsBundle/Resources/config/services.yml b/src/DataDefinitionsBundle/Resources/config/services.yml index 990a0075..05e07d3f 100644 --- a/src/DataDefinitionsBundle/Resources/config/services.yml +++ b/src/DataDefinitionsBundle/Resources/config/services.yml @@ -269,6 +269,10 @@ services: tags: - { name: data_definitions.interpreter, type: donotsetonempty, form-type: Wvision\Bundle\DataDefinitionsBundle\Form\Type\NoConfigurationType } + Wvision\Bundle\DataDefinitionsBundle\Interpreter\TypeCastingInterpreter: + tags: + - { name: data_definitions.interpreter, type: type_casting, form-type: Wvision\Bundle\DataDefinitionsBundle\Form\Type\NoConfigurationType } + Wvision\Bundle\DataDefinitionsBundle\Interpreter\LinkInterpreter: tags: - { name: data_definitions.interpreter, type: link, form-type: Wvision\Bundle\DataDefinitionsBundle\Form\Type\NoConfigurationType } @@ -389,4 +393,4 @@ services: Wvision\Bundle\DataDefinitionsBundle\EventListener\WriteableListener: tags: - - { name: kernel.event_subscriber } \ No newline at end of file + - { name: kernel.event_subscriber } From 238af7e62b775a17e4c3b424bd8748292727bcdd Mon Sep 17 00:00:00 2001 From: Bram Date: Fri, 21 Jul 2023 08:59:29 +0200 Subject: [PATCH 62/65] add float to possible types and add GUI config form --- .../TypeCastingInterpreterType.php | 37 +++++++++++++++++ .../Interpreter/TypeCastingInterpreter.php | 9 ++-- .../Resources/config/pimcore/config.yml | 1 + .../Resources/config/services.yml | 6 +-- .../pimcore/js/interpreters/typecasting.js | 41 +++++++++++++++++++ 5 files changed, 88 insertions(+), 6 deletions(-) create mode 100644 src/DataDefinitionsBundle/Form/Type/Interpreter/TypeCastingInterpreterType.php create mode 100644 src/DataDefinitionsBundle/Resources/public/pimcore/js/interpreters/typecasting.js diff --git a/src/DataDefinitionsBundle/Form/Type/Interpreter/TypeCastingInterpreterType.php b/src/DataDefinitionsBundle/Form/Type/Interpreter/TypeCastingInterpreterType.php new file mode 100644 index 00000000..400c7295 --- /dev/null +++ b/src/DataDefinitionsBundle/Form/Type/Interpreter/TypeCastingInterpreterType.php @@ -0,0 +1,37 @@ +add('toType', ChoiceType::class, [ + 'choices' => [ + TypeCastingInterpreter::TYPE_INT => TypeCastingInterpreter::TYPE_INT, + TypeCastingInterpreter::TYPE_STRING => TypeCastingInterpreter::TYPE_STRING, + TypeCastingInterpreter::TYPE_BOOLEAN => TypeCastingInterpreter::TYPE_BOOLEAN, + ], + ]); + } +} diff --git a/src/DataDefinitionsBundle/Interpreter/TypeCastingInterpreter.php b/src/DataDefinitionsBundle/Interpreter/TypeCastingInterpreter.php index c803c365..94840c79 100644 --- a/src/DataDefinitionsBundle/Interpreter/TypeCastingInterpreter.php +++ b/src/DataDefinitionsBundle/Interpreter/TypeCastingInterpreter.php @@ -21,9 +21,10 @@ class TypeCastingInterpreter implements InterpreterInterface { - protected const TYPE_INT = 'int'; - protected const TYPE_STRING = 'string'; - protected const TYPE_BOOLEAN = 'boolean'; + public const TYPE_INT = 'int'; + public const TYPE_FLOAT = 'float'; + public const TYPE_STRING = 'string'; + public const TYPE_BOOLEAN = 'boolean'; public function interpret(InterpreterContextInterface $context): mixed { @@ -32,6 +33,8 @@ public function interpret(InterpreterContextInterface $context): mixed switch ($type) { case static::TYPE_INT: return (int)$context->getValue(); + case static::TYPE_FLOAT: + return (float)$context->getValue(); case static::TYPE_STRING: return (string)$context->getValue(); case static::TYPE_BOOLEAN: diff --git a/src/DataDefinitionsBundle/Resources/config/pimcore/config.yml b/src/DataDefinitionsBundle/Resources/config/pimcore/config.yml index aabbb4be..de1f6b2f 100644 --- a/src/DataDefinitionsBundle/Resources/config/pimcore/config.yml +++ b/src/DataDefinitionsBundle/Resources/config/pimcore/config.yml @@ -53,6 +53,7 @@ data_definitions: interpreter_twig: '/bundles/datadefinitions/pimcore/js/interpreters/twig.js' interpreter_carbon: '/bundles/datadefinitions/pimcore/js/interpreters/carbon.js' interpreter_metadata: '/bundles/datadefinitions/pimcore/js/interpreters/metadata.js' + interpreter_typecasting: '/bundles/datadefinitions/pimcore/js/interpreters/typecasting.js' setter_abstract: '/bundles/datadefinitions/pimcore/js/setters/abstract.js' setter_fieldcollection: '/bundles/datadefinitions/pimcore/js/setters/fieldcollection.js' setter_objectbrick: '/bundles/datadefinitions/pimcore/js/setters/objectbrick.js' diff --git a/src/DataDefinitionsBundle/Resources/config/services.yml b/src/DataDefinitionsBundle/Resources/config/services.yml index 05e07d3f..e1f9bb93 100644 --- a/src/DataDefinitionsBundle/Resources/config/services.yml +++ b/src/DataDefinitionsBundle/Resources/config/services.yml @@ -270,8 +270,8 @@ services: - { name: data_definitions.interpreter, type: donotsetonempty, form-type: Wvision\Bundle\DataDefinitionsBundle\Form\Type\NoConfigurationType } Wvision\Bundle\DataDefinitionsBundle\Interpreter\TypeCastingInterpreter: - tags: - - { name: data_definitions.interpreter, type: type_casting, form-type: Wvision\Bundle\DataDefinitionsBundle\Form\Type\NoConfigurationType } + tags: + - { name: data_definitions.interpreter, type: type_casting, form-type: Wvision\Bundle\DataDefinitionsBundle\Form\Type\Interpreter\TypeCastingInterpreterType } Wvision\Bundle\DataDefinitionsBundle\Interpreter\LinkInterpreter: tags: @@ -393,4 +393,4 @@ services: Wvision\Bundle\DataDefinitionsBundle\EventListener\WriteableListener: tags: - - { name: kernel.event_subscriber } + - { name: kernel.event_subscriber } \ No newline at end of file diff --git a/src/DataDefinitionsBundle/Resources/public/pimcore/js/interpreters/typecasting.js b/src/DataDefinitionsBundle/Resources/public/pimcore/js/interpreters/typecasting.js new file mode 100644 index 00000000..cd846392 --- /dev/null +++ b/src/DataDefinitionsBundle/Resources/public/pimcore/js/interpreters/typecasting.js @@ -0,0 +1,41 @@ +/** + * Data Definitions. + * + * LICENSE + * + * This source file is subject to the GNU General Public License version 3 (GPLv3) + * For the full copyright and license information, please view the LICENSE.md and gpl-3.0.txt + * files that are distributed with this source code. + * + * @copyright Copyright (c) 2016-2019 w-vision AG (https://www.w-vision.ch) + * @license https://github.com/w-vision/DataDefinitions/blob/master/gpl-3.0.txt GNU General Public License version 3 (GPLv3) + */ + +pimcore.registerNS('pimcore.plugin.datadefinitions.interpreters.type_casting'); + +pimcore.plugin.datadefinitions.interpreters.type_casting = Class.create(pimcore.plugin.datadefinitions.interpreters.abstract, { + getLayout: function (fromColumn, toColumn, record, config) { + const typeStore = new Ext.data.ArrayStore({ + fields: ['key', 'value'], + data: [ + ['int', 'integer'], + ['float', 'float'], + ['string', 'string'], + ['boolean', 'boolean'] + ] + }); + + return [ + { + xtype: 'combo', + fieldLabel: t('type'), + name: 'toType', + displayField: 'value', + valueField: 'key', + store: typeStore, + width: 500, + value: config.Totype ? config.Totype : 'int' + }, + ]; + } +}); From 2ebbfb4f1389cf5b302615ec50245ce6b16e5507 Mon Sep 17 00:00:00 2001 From: Bram Date: Fri, 21 Jul 2023 09:00:48 +0200 Subject: [PATCH 63/65] add float --- .../Form/Type/Interpreter/TypeCastingInterpreterType.php | 1 + 1 file changed, 1 insertion(+) diff --git a/src/DataDefinitionsBundle/Form/Type/Interpreter/TypeCastingInterpreterType.php b/src/DataDefinitionsBundle/Form/Type/Interpreter/TypeCastingInterpreterType.php index 400c7295..7922be43 100644 --- a/src/DataDefinitionsBundle/Form/Type/Interpreter/TypeCastingInterpreterType.php +++ b/src/DataDefinitionsBundle/Form/Type/Interpreter/TypeCastingInterpreterType.php @@ -29,6 +29,7 @@ public function buildForm(FormBuilderInterface $builder, array $options): void ->add('toType', ChoiceType::class, [ 'choices' => [ TypeCastingInterpreter::TYPE_INT => TypeCastingInterpreter::TYPE_INT, + TypeCastingInterpreter::TYPE_FLOAT => TypeCastingInterpreter::TYPE_FLOAT, TypeCastingInterpreter::TYPE_STRING => TypeCastingInterpreter::TYPE_STRING, TypeCastingInterpreter::TYPE_BOOLEAN => TypeCastingInterpreter::TYPE_BOOLEAN, ], From 79370b5c5f077a509880e4fc3639800c19ada73f Mon Sep 17 00:00:00 2001 From: Dominik Pfaffenbauer Date: Wed, 27 Sep 2023 16:38:20 +0200 Subject: [PATCH 64/65] [Writable] only allow writable definitions to be saved --- .../EventListener/PimcoreSettingsListener.php | 3 +-- .../Resources/config/serializer/Model.ExportDefinition.yml | 5 +++++ .../Resources/config/serializer/Model.ImportDefinition.yml | 5 +++++ .../Resources/public/pimcore/js/export/item.js | 2 +- .../Resources/public/pimcore/js/import/item.js | 2 +- 5 files changed, 13 insertions(+), 4 deletions(-) diff --git a/src/DataDefinitionsBundle/EventListener/PimcoreSettingsListener.php b/src/DataDefinitionsBundle/EventListener/PimcoreSettingsListener.php index 82e8bab9..9b48546d 100644 --- a/src/DataDefinitionsBundle/EventListener/PimcoreSettingsListener.php +++ b/src/DataDefinitionsBundle/EventListener/PimcoreSettingsListener.php @@ -24,7 +24,6 @@ class PimcoreSettingsListener { public function indexSettings(IndexActionSettingsEvent $settingsEvent): void { - $settingsEvent->addSetting('data-definitions-import-definition-writeable', (new ImportDefinition())->isWriteable()); - $settingsEvent->addSetting('data-definitions-export-definition-writeable', (new ExportDefinition())->isWriteable()); + } } diff --git a/src/DataDefinitionsBundle/Resources/config/serializer/Model.ExportDefinition.yml b/src/DataDefinitionsBundle/Resources/config/serializer/Model.ExportDefinition.yml index fb48406b..30e861c6 100755 --- a/src/DataDefinitionsBundle/Resources/config/serializer/Model.ExportDefinition.yml +++ b/src/DataDefinitionsBundle/Resources/config/serializer/Model.ExportDefinition.yml @@ -14,3 +14,8 @@ Wvision\Bundle\DataDefinitionsBundle\Model\ExportDefinition: expose: true type: boolean groups: [ Detailed ] + virtual_properties: + isWriteable: + exp: object.isWriteable() + type: boolean + serialized_name: isWriteable \ No newline at end of file diff --git a/src/DataDefinitionsBundle/Resources/config/serializer/Model.ImportDefinition.yml b/src/DataDefinitionsBundle/Resources/config/serializer/Model.ImportDefinition.yml index 1ec31c51..df9641c6 100755 --- a/src/DataDefinitionsBundle/Resources/config/serializer/Model.ImportDefinition.yml +++ b/src/DataDefinitionsBundle/Resources/config/serializer/Model.ImportDefinition.yml @@ -50,3 +50,8 @@ Wvision\Bundle\DataDefinitionsBundle\Model\ImportDefinition: expose: true type: boolean groups: [ Detailed ] + virtual_properties: + isWriteable: + exp: object.isWriteable() + type: boolean + serialized_name: isWriteable \ No newline at end of file diff --git a/src/DataDefinitionsBundle/Resources/public/pimcore/js/export/item.js b/src/DataDefinitionsBundle/Resources/public/pimcore/js/export/item.js index 890ba4aa..1e1b2799 100644 --- a/src/DataDefinitionsBundle/Resources/public/pimcore/js/export/item.js +++ b/src/DataDefinitionsBundle/Resources/public/pimcore/js/export/item.js @@ -25,7 +25,7 @@ pimcore.plugin.datadefinitions.export.item = Class.create(pimcore.plugin.datadef providers: [], saveDisabled: function () { - return !pimcore.settings['data-definitions-export-definition-writeable']; + return !this.data.isWriteable; }, getSettings: function () { diff --git a/src/DataDefinitionsBundle/Resources/public/pimcore/js/import/item.js b/src/DataDefinitionsBundle/Resources/public/pimcore/js/import/item.js index 2bbf0843..b10f623a 100644 --- a/src/DataDefinitionsBundle/Resources/public/pimcore/js/import/item.js +++ b/src/DataDefinitionsBundle/Resources/public/pimcore/js/import/item.js @@ -26,7 +26,7 @@ pimcore.plugin.datadefinitions.import.item = Class.create(pimcore.plugin.datadef providers: [], saveDisabled: function () { - return !pimcore.settings['data-definitions-import-definition-writeable']; + return !this.data.isWriteable; }, getSettings: function () { From 32933d60e3750b5b26558ffd894e0848f9133d3b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Dalibor=20Karlovi=C4=87?= Date: Thu, 28 Sep 2023 17:06:00 +0200 Subject: [PATCH 65/65] Update export_contextmenu.js for Pimcore 11 --- .../js/process_manager/export_contextmenu.js | 153 ++++++++---------- 1 file changed, 69 insertions(+), 84 deletions(-) diff --git a/src/DataDefinitionsBundle/Resources/public/pimcore/js/process_manager/export_contextmenu.js b/src/DataDefinitionsBundle/Resources/public/pimcore/js/process_manager/export_contextmenu.js index 8f62748f..71f7242c 100644 --- a/src/DataDefinitionsBundle/Resources/public/pimcore/js/process_manager/export_contextmenu.js +++ b/src/DataDefinitionsBundle/Resources/public/pimcore/js/process_manager/export_contextmenu.js @@ -1,92 +1,77 @@ -pimcore.registerNS("pimcore.plugin.datadefinitions.export.context_menu"); - -pimcore.plugin.datadefinitions.export.context_menu = Class.create(pimcore.plugin.admin, { - getClassName: function () { - return "pimcore.plugin.datadefinitions.export.context_menu"; - }, - - initialize: function () { - pimcore.plugin.broker.registerPlugin(this); - }, +document.addEventListener(pimcore.events.prepareObjectTreeContextMenu, function (event) { + if (!Ext.ClassManager.get('Executable')) { + Ext.define('Executable', { + extend: 'Ext.data.Model', + fields: [ + {name: 'name', type: 'string'}, + ] + }); + } - prepareObjectTreeContextMenu: function (tree, treeClass, menuItem) { - if (!Ext.ClassManager.get('Executable')) { - Ext.define('Executable', { - extend: 'Ext.data.Model', - fields: [ - {name: 'name', type: 'string'}, - ] - }); - } + const tree = event.detail.menu; - var $this = this; - Ext.create('Ext.data.Store', { - model: 'Executable', - proxy: { - type: 'ajax', - url: '/admin/process_manager/executables/list-by-type', - extraParams: { - type: 'exportdefinition' - }, - reader: { - type: 'json', - rootProperty: 'data' - } + Ext.create('Ext.data.Store', { + model: 'Executable', + proxy: { + type: 'ajax', + url: '/admin/process_manager/executables/list-by-type', + extraParams: { + type: 'exportdefinition' }, - sorters: [{ - property: 'name', - direction: 'ASC' - }], - sortRoot: 'data', - autoLoad: true, - listeners: { - refresh: function (store) { - var exportMenu = []; - store.each(function (executable) { - exportMenu.push({ - text: executable.get('name'), - iconCls: "pimcore_icon_object pimcore_icon_overlay_add", - handler: $this.exportObjects.bind($this, executable, menuItem) - }); - }); - - if (exportMenu) { - tree.add([ - {xtype: 'menuseparator'}, - { - text: t("data_definitions_processmanager_export_from_here"), - iconCls: "pimcore_icon_object pimcore_icon_overlay_download", - menu: exportMenu - } - ]); - } - } + reader: { + type: 'json', + rootProperty: 'data' } - }); - }, + }, + sorters: [{ + property: 'name', + direction: 'ASC' + }], + sortRoot: 'data', + autoLoad: true, + listeners: { + refresh: function (store) { + var exportMenu = []; + store.each(function (executable) { + exportMenu.push({ + text: executable.get('name'), + iconCls: "pimcore_icon_object pimcore_icon_overlay_add", + handler: function (menuItem) { + Ext.Ajax.request({ + url: '/admin/process_manager/executables/run', + params: { + id: executable.id, + startupConfig: Ext.encode({ + root: menuItem.$iid, + }), + csrfToken: pimcore.settings['csrfToken'] + }, + method: 'POST', + success: function (result) { + result = Ext.decode(result.responseText); - exportObjects: function (executable, menuItem) { - Ext.Ajax.request({ - url: '/admin/process_manager/executables/run', - params: { - id: executable.id, - startupConfig: Ext.encode({ - root: menuItem.get('id'), - }), - csrfToken: pimcore.settings['csrfToken'] - }, - method: 'POST', - success: function (result) { - result = Ext.decode(result.responseText); + if (result.success) { + Ext.Msg.alert(t('success'), t('processmanager_executable_started')); + } else { + Ext.Msg.alert(t('error'), result.message); + } + }.bind(this) + }); + } + }); + }); - if (result.success) { - Ext.Msg.alert(t('success'), t('processmanager_executable_started')); - } else { - Ext.Msg.alert(t('error'), result.message); + if (exportMenu) { + tree.add([ + {xtype: 'menuseparator'}, + { + text: t("data_definitions_processmanager_export_from_here"), + iconCls: "pimcore_icon_object pimcore_icon_overlay_download", + menu: exportMenu + } + ]); } - }.bind(this) - }); - } + } + } + }); }); - -new pimcore.plugin.datadefinitions.export.context_menu();