From a929eede8efd99c96da461bf4c5a3a9733d5cefd Mon Sep 17 00:00:00 2001 From: "k.verschoor@pay.nl" Date: Tue, 18 Jan 2022 13:51:43 +0100 Subject: [PATCH] Remove install/upgrade scripts and turn them into patches --- Setup/InstallSchema.php | 47 ---------- Setup/Patch/Data/Install.php | 65 +++++++++++++ Setup/Patch/Data/UpdateFashionGiftcard.php | 81 ++++++++++++++++ Setup/UpgradeData.php | 102 --------------------- 4 files changed, 146 insertions(+), 149 deletions(-) delete mode 100644 Setup/InstallSchema.php create mode 100644 Setup/Patch/Data/Install.php create mode 100644 Setup/Patch/Data/UpdateFashionGiftcard.php delete mode 100644 Setup/UpgradeData.php diff --git a/Setup/InstallSchema.php b/Setup/InstallSchema.php deleted file mode 100644 index 7edaec32..00000000 --- a/Setup/InstallSchema.php +++ /dev/null @@ -1,47 +0,0 @@ -configWriter = $configWriter; - $this->store = $store; - } - - public function install(\Magento\Framework\Setup\SchemaSetupInterface $setup, \Magento\Framework\Setup\ModuleContextInterface $context) - { - $setup->startSetup(); - - payHelper::logDebug('Installing module.'); - $this->configWriter->save('payment/paynl/order_description_prefix', 'Order '); - - $this->configWriter->save('payment/paynl/image_style', 'newest'); - $this->configWriter->save('payment/paynl/pay_style_checkout', 1); - $this->configWriter->save('payment/paynl/icon_size', 'small'); - - $setup->endSetup(); - } -} diff --git a/Setup/Patch/Data/Install.php b/Setup/Patch/Data/Install.php new file mode 100644 index 00000000..7c931e3f --- /dev/null +++ b/Setup/Patch/Data/Install.php @@ -0,0 +1,65 @@ +moduleDataSetup = $moduleDataSetup; + $this->configWriter = $configWriter; + $this->store = $store; + } + + /** + * @inheritdoc + */ + public function apply() + { + $this->moduleDataSetup->startSetup(); + + if (empty($this->store->getConfig('payment/paynl/apitoken')) && empty($this->store->getConfig('payment/paynl/serviceid'))) { + payHelper::logDebug('Installing module.'); + $this->configWriter->save('payment/paynl/order_description_prefix', 'Order '); + $this->configWriter->save('payment/paynl/image_style', 'newest'); + $this->configWriter->save('payment/paynl/pay_style_checkout', 1); + $this->configWriter->save('payment/paynl/icon_size', 'small'); + } + + $this->moduleDataSetup->endSetup(); + } + + public static function getDependencies() + { + return []; + } + + public function getAliases() + { + return []; + } +} diff --git a/Setup/Patch/Data/UpdateFashionGiftcard.php b/Setup/Patch/Data/UpdateFashionGiftcard.php new file mode 100644 index 00000000..ac7a8f45 --- /dev/null +++ b/Setup/Patch/Data/UpdateFashionGiftcard.php @@ -0,0 +1,81 @@ +moduleDataSetup = $moduleDataSetup; + $this->resourceConnection = $resourceConnection; + $this->resourceConfig = $resourceConfig; + } + + /** + * @inheritdoc + */ + public function apply() + { + $this->moduleDataSetup->startSetup(); + + payHelper::logDebug('Apply patch: updateFashionGiftcard.'); + + $connection = $this->resourceConnection->getConnection(); + $tableName = $this->resourceConnection->getTableName('core_config_data'); + + $path = 'payment/paynl_payment_fashiongiftcard/payment_option_id'; + $query = "SELECT `value` FROM " . $tableName . " WHERE scope = 'default' AND `path`= '" . $path . "'"; + + $result = $connection->fetchOne($query, ['path' => $path]); + if (!$result) { + return; + } + payHelper::logDebug('updateFashionGiftcard result ' . $result); + if ($result == '1699') { + # Update the incorrect profileid. + $this->resourceConfig->saveConfig($path, '1669', 'default', 0); + } + + $this->moduleDataSetup->endSetup(); + } + + public static function getVersion() + { + return '2.0.1'; + } + + public static function getDependencies() + { + return []; + } + + public function getAliases() + { + return []; + } +} diff --git a/Setup/UpgradeData.php b/Setup/UpgradeData.php deleted file mode 100644 index 3c7ee13f..00000000 --- a/Setup/UpgradeData.php +++ /dev/null @@ -1,102 +0,0 @@ -salesSetupFactory = $salesSetupFactory; - $this->resourceConnection = $resourceConnection; - $this->resourceConfig = $resourceConfig; - $this->configWriter = $configWriter; - $this->storeManager = $storeManager; - } - - /** - * @param ModuleDataSetupInterface $setup - * @param ModuleContextInterface $context - */ - public function upgrade(ModuleDataSetupInterface $setup, ModuleContextInterface $context) - { - $setup->startSetup(); - - payHelper::logDebug('Upgrade. Module version: ' . $context->getVersion()); - - # Update fashiongiftcard when current install is lower then 2.0.1 - if (version_compare($context->getVersion(), '2.0.1', '<')) { - # Update fashiongiftcard profileid - $this->updateFashionGiftcard(); - } - - $setup->endSetup(); - } - - private function updateFashionGiftcard() - { - payHelper::logDebug('updateFashionGiftcard'); - - $connection = $this->resourceConnection->getConnection(); - $tableName = $this->resourceConnection->getTableName('core_config_data'); - - $path = 'payment/paynl_payment_fashiongiftcard/payment_option_id'; - $query = "SELECT `value` FROM " . $tableName . " WHERE scope = 'default' AND `path`= '" . $path . "'"; - - $result = $connection->fetchOne($query, ['path' => $path]); - if (!$result) { - return; - } - payHelper::logDebug('updateFashionGiftcard result ' . $result); - if ($result == '1699') { - # Update the incorrect profileid. - $this->resourceConfig->saveConfig($path, '1669', 'default', 0); - } - } -}