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 1/5] 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); - } - } -} From 200a6d27dc3498deafee6db52f669d7acd3ff40a Mon Sep 17 00:00:00 2001 From: woutse Date: Wed, 26 Jan 2022 14:39:40 +0100 Subject: [PATCH 2/5] updated logging --- Helper/PayHelper.php | 19 +++++++++++++++++-- Setup/Patch/Data/Install.php | 4 +++- 2 files changed, 20 insertions(+), 3 deletions(-) diff --git a/Helper/PayHelper.php b/Helper/PayHelper.php index caf7ccd7..540c3f18 100644 --- a/Helper/PayHelper.php +++ b/Helper/PayHelper.php @@ -8,6 +8,8 @@ class PayHelper extends \Magento\Framework\App\Helper\AbstractHelper { + const PAY_LOG_PREFIX = 'PAY.: '; + private static $objectManager; private static $store; @@ -68,6 +70,20 @@ public static function logDebug($text, $params = array(), $store = null) self::writeLog($text, 'debug', $params, $store); } + /** + * Logs while bypassing the loglevel setting. + * + * @param $text + * @param array $params + * @param null $store + */ + public static function log($text, $params = array(), $store = null) + { + $objectManager = self::getObjectManager(); + $logger = $objectManager->get(\Psr\Log\LoggerInterface::class); + $logger->notice(PayHelper::PAY_LOG_PREFIX . $text, $params); + } + public static function writeLog($text, $type, $params, $store) { $objectManager = self::getObjectManager(); @@ -77,8 +93,7 @@ public static function writeLog($text, $type, $params, $store) $level = $store->getConfig('payment/paynl/logging_level'); if (self::hasCorrectLevel($level, $type)) { - $prefix = 'PAY.: '; - $text = $prefix . $text; + $text = PayHelper::PAY_LOG_PREFIX . $text; if (!is_array($params)) { $params = array(); } diff --git a/Setup/Patch/Data/Install.php b/Setup/Patch/Data/Install.php index 7c931e3f..40c46da0 100644 --- a/Setup/Patch/Data/Install.php +++ b/Setup/Patch/Data/Install.php @@ -43,11 +43,13 @@ 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.'); + payHelper::log('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'); + } else { + payHelper::logInfo('Installing, keeping defaults.'); } $this->moduleDataSetup->endSetup(); From 56d3d59c9c7cc95e9b9f9a9e2eb710aabc04ccff Mon Sep 17 00:00:00 2001 From: woutse Date: Wed, 26 Jan 2022 15:39:30 +0100 Subject: [PATCH 3/5] updated logging --- Setup/Patch/Data/UpdateFashionGiftcard.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Setup/Patch/Data/UpdateFashionGiftcard.php b/Setup/Patch/Data/UpdateFashionGiftcard.php index ac7a8f45..6ab9aad1 100644 --- a/Setup/Patch/Data/UpdateFashionGiftcard.php +++ b/Setup/Patch/Data/UpdateFashionGiftcard.php @@ -43,7 +43,7 @@ public function apply() { $this->moduleDataSetup->startSetup(); - payHelper::logDebug('Apply patch: updateFashionGiftcard.'); + payHelper::log('Apply patch: updateFashionGiftcard.'); $connection = $this->resourceConnection->getConnection(); $tableName = $this->resourceConnection->getTableName('core_config_data'); From 8253133116dd03592564e1d711a3574d48b41810 Mon Sep 17 00:00:00 2001 From: woutse Date: Wed, 26 Jan 2022 15:51:42 +0100 Subject: [PATCH 4/5] updated logging --- Setup/Patch/Data/UpdateFashionGiftcard.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Setup/Patch/Data/UpdateFashionGiftcard.php b/Setup/Patch/Data/UpdateFashionGiftcard.php index 6ab9aad1..97e887c3 100644 --- a/Setup/Patch/Data/UpdateFashionGiftcard.php +++ b/Setup/Patch/Data/UpdateFashionGiftcard.php @@ -55,7 +55,7 @@ public function apply() if (!$result) { return; } - payHelper::logDebug('updateFashionGiftcard result ' . $result); + payHelper::log('updateFashionGiftcard result ' . $result); if ($result == '1699') { # Update the incorrect profileid. $this->resourceConfig->saveConfig($path, '1669', 'default', 0); From 32d58af98d968a4e751f65ebce432e30f7b9bc9b Mon Sep 17 00:00:00 2001 From: "k.verschoor@pay.nl" Date: Fri, 28 Jan 2022 09:49:13 +0100 Subject: [PATCH 5/5] Remove verson check --- Setup/Patch/Data/UpdateFashionGiftcard.php | 8 +------- 1 file changed, 1 insertion(+), 7 deletions(-) diff --git a/Setup/Patch/Data/UpdateFashionGiftcard.php b/Setup/Patch/Data/UpdateFashionGiftcard.php index ac7a8f45..2162105b 100644 --- a/Setup/Patch/Data/UpdateFashionGiftcard.php +++ b/Setup/Patch/Data/UpdateFashionGiftcard.php @@ -4,12 +4,11 @@ use Magento\Framework\Setup\ModuleDataSetupInterface; use Magento\Framework\Setup\Patch\DataPatchInterface; -use Magento\Framework\Setup\Patch\PatchVersionInterface; use Magento\Framework\App\ResourceConnection; use Magento\Config\Model\ResourceModel\Config; use \Paynl\Payment\Helper\PayHelper; -class UpdateFashionGiftcard implements DataPatchInterface, PatchVersionInterface +class UpdateFashionGiftcard implements DataPatchInterface { /** * @var ModuleDataSetupInterface @@ -64,11 +63,6 @@ public function apply() $this->moduleDataSetup->endSetup(); } - public static function getVersion() - { - return '2.0.1'; - } - public static function getDependencies() { return [];