UpgradeData.php 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. <?php
  2. /**
  3. * Copyright 2016 Amazon.com, Inc. or its affiliates. All Rights Reserved.
  4. *
  5. * Licensed under the Apache License, Version 2.0 (the "License").
  6. * You may not use this file except in compliance with the License.
  7. * A copy of the License is located at
  8. *
  9. * http://aws.amazon.com/apache2.0
  10. *
  11. * or in the "license" file accompanying this file. This file is distributed
  12. * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
  13. * express or implied. See the License for the specific language governing
  14. * permissions and limitations under the License.
  15. */
  16. namespace Amazon\Core\Setup;
  17. use Magento\Framework\Setup\ModuleContextInterface;
  18. use Magento\Framework\Setup\ModuleDataSetupInterface;
  19. use Magento\Framework\Setup\UpgradeDataInterface;
  20. /**
  21. * Class UpgradeData
  22. * Ensures default authorization mode is set if upgrading from earlier versions
  23. */
  24. class UpgradeData implements UpgradeDataInterface
  25. {
  26. /**
  27. * @param ModuleDataSetupInterface $setup
  28. * @param ModuleContextInterface $context
  29. */
  30. public function upgrade(ModuleDataSetupInterface $setup, ModuleContextInterface $context)
  31. {
  32. // Used update query because all scopes needed to have this value updated and this is a fast, simple approach
  33. if (version_compare($context->getVersion(), '2.1.1', '<')) {
  34. $select = $setup->getConnection()->select()->from(
  35. $setup->getTable('core_config_data'),
  36. ['config_id', 'value']
  37. )->where(
  38. 'path = ?',
  39. 'payment/amazon_payment/authorization_mode'
  40. );
  41. foreach ($setup->getConnection()->fetchAll($select) as $configRow) {
  42. if ($configRow['value'] === 'asynchronous') {
  43. $row = [
  44. 'value' => 'synchronous_possible'
  45. ];
  46. $setup->getConnection()->update(
  47. $setup->getTable('core_config_data'),
  48. $row,
  49. ['config_id = ?' => $configRow['config_id']]
  50. );
  51. }
  52. }
  53. }
  54. }
  55. }