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/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..40c46da0 --- /dev/null +++ b/Setup/Patch/Data/Install.php @@ -0,0 +1,67 @@ +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::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(); + } + + 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..6f7fd057 --- /dev/null +++ b/Setup/Patch/Data/UpdateFashionGiftcard.php @@ -0,0 +1,75 @@ +moduleDataSetup = $moduleDataSetup; + $this->resourceConnection = $resourceConnection; + $this->resourceConfig = $resourceConfig; + } + + /** + * @inheritdoc + */ + public function apply() + { + $this->moduleDataSetup->startSetup(); + + payHelper::log('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::log('updateFashionGiftcard result ' . $result); + if ($result == '1699') { + # Update the incorrect profileid. + $this->resourceConfig->saveConfig($path, '1669', 'default', 0); + } + + $this->moduleDataSetup->endSetup(); + } + + public static function getDependencies() + { + return []; + } + + public function getAliases() + { + return []; + } +} diff --git a/Setup/UpgradeData.php b/Setup/UpgradeData.php index ee947d18..e69de29b 100644 --- a/Setup/UpgradeData.php +++ b/Setup/UpgradeData.php @@ -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; - } - - if ($result == '1699') { - # Update the incorrect profileid. - $this->resourceConfig->saveConfig($path, '1669', 'default', 0); - } - } -}