diff --git a/Component/Sequence.php b/Component/Sequence.php new file mode 100644 index 0000000..6fc1b4c --- /dev/null +++ b/Component/Sequence.php @@ -0,0 +1,135 @@ +sequenceBuilder = $sequenceBuilder; + $this->entityPool = $entityPool; + $this->sequenceConfig = $sequenceConfig; + $this->storeRepository = $repository; + $this->logger = $logger; + } + + public function execute($data) + { + if (!isset($data['stores'])) { + throw new ComponentException("No stores found."); + } + + foreach ($data['stores'] as $code => $overrides) { + try { + $this->logger->logInfo(__("Starting creating sequence tables for %1", $code)); + $store = $this->storeRepository->get($code); + $this->newSequenceTable($store, $overrides); + $this->logger->logInfo(__("Finished creating sequence tables for %1", $code)); + // todo handle existing sequence tables + } catch (\Exception $exception) { + $this->logger->logError($exception->getMessage()); + } + } + } + + public function getAlias() + { + return $this->alias; + } + + public function getDescription() + { + return $this->description; + } + + protected function newSequenceTable($store, $overrides) + { + $configKeys = ['suffix', 'startValue', 'step', 'warningValue', 'maxValue']; + $configValues = []; + foreach ($configKeys as $key) { + $configValues[$key] = $this->sequenceConfig->get($key); + if (isset($overrides[$key])) { + $configValues[$key] = $overrides[$key]; + } + } + + // Prefix Value + $configValues['prefix'] = $store->getId(); + if (isset($overrides['prefix'])) { + $configValues['prefix'] = $overrides['prefix']; + } + + foreach ($this->entityPool->getEntities() as $entityType) { + try { + $this->logger->logComment(__( + 'Store: %1 '. + 'Prefix: %2, '. + 'Suffix: %3, '. + 'Start Value: %4, '. + 'Step: %5, '. + 'Warning Value: %6, '. + 'Max Value: %7, '. + 'Entity Type: %8', + $store->getCode(), + $configValues['prefix'], + $configValues['suffix'], + $configValues['startValue'], + $configValues['step'], + $configValues['warningValue'], + $configValues['maxValue'], + $entityType + ), 1); + $this->sequenceBuilder->setPrefix($configValues['prefix']) + ->setSuffix($configValues['suffix']) + ->setStartValue($configValues['startValue']) + ->setStoreId($store->getId()) + ->setStep($configValues['step']) + ->setWarningValue($configValues['warningValue']) + ->setMaxValue($configValues['maxValue']) + ->setEntityType($entityType) + ->create(); + $this->logger->logInfo(__("Sequence table created for %1", $entityType), 1); + } catch (\Exception $exception) { + $this->logger->logError($exception->getMessage()); + } + } + } +} diff --git a/Samples/Components/Sequence/sequence.yaml b/Samples/Components/Sequence/sequence.yaml new file mode 100644 index 0000000..9e562e0 --- /dev/null +++ b/Samples/Components/Sequence/sequence.yaml @@ -0,0 +1,7 @@ +stores: + default: + prefix: PREFIX_ + startValue: 5000 + usa_en_us: + prefix: USA_ + startValue: 1000 \ No newline at end of file diff --git a/Samples/master.yaml b/Samples/master.yaml index a6d890e..dd6d280 100644 --- a/Samples/master.yaml +++ b/Samples/master.yaml @@ -18,6 +18,11 @@ config: sources: - ../configurator/Configuration/global.yaml - ../configurator/Configuration/base-website-config.yaml +sequence: + enabled: 1 + method: code + sources: + - ../configurator/Sequence/sequence.yaml attributes: enabled: 1 method: code diff --git a/composer.json b/composer.json index 7c2e17f..c866aee 100644 --- a/composer.json +++ b/composer.json @@ -10,7 +10,6 @@ ], "require": { "symfony/yaml": "~4.0|~5.0", - "symfony/console": "~4.1.0", "firegento/fastsimpleimport": "1.3.1" }, "require-dev": { @@ -21,7 +20,7 @@ "phpunit/phpunit": "^6.2", "magento/magento-coding-standard": "5" }, - "version": "3.0.1", + "version": "3.1.1", "autoload": { "files": [ "registration.php" ], "psr-4": { diff --git a/etc/di.xml b/etc/di.xml index d7857ce..403bb43 100644 --- a/etc/di.xml +++ b/etc/di.xml @@ -24,6 +24,7 @@ CtiDigital\Configurator\Component\Websites CtiDigital\Configurator\Component\Config + CtiDigital\Configurator\Component\Sequence CtiDigital\Configurator\Component\Attributes CtiDigital\Configurator\Component\AttributeSets CtiDigital\Configurator\Component\AdminRoles