UpgradeData.php 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110
  1. <?php
  2. /**
  3. * MageSpecialist
  4. *
  5. * NOTICE OF LICENSE
  6. *
  7. * This source file is subject to the Open Software License (OSL 3.0)
  8. * that is bundled with this package in the file LICENSE.txt.
  9. * It is also available through the world-wide-web at this URL:
  10. * http://opensource.org/licenses/osl-3.0.php
  11. * If you did not receive a copy of the license and are unable to
  12. * obtain it through the world-wide-web, please send an email
  13. * to info@magespecialist.it so we can send you a copy immediately.
  14. *
  15. * @category MSP
  16. * @package MSP_ReCaptcha
  17. * @copyright Copyright (c) 2017 Skeeller srl (http://www.magespecialist.it)
  18. * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
  19. */
  20. namespace MSP\ReCaptcha\Setup;
  21. use Magento\Framework\App\Config\ScopeConfigInterface;
  22. use Magento\Framework\Setup\ModuleContextInterface;
  23. use Magento\Framework\Setup\ModuleDataSetupInterface;
  24. use Magento\Framework\Setup\UpgradeDataInterface;
  25. class UpgradeData implements UpgradeDataInterface
  26. {
  27. /**
  28. * @var ScopeConfigInterface
  29. */
  30. private $scopeConfig;
  31. /**
  32. * UpgradeData constructor.
  33. * @param ScopeConfigInterface $scopeConfig
  34. */
  35. public function __construct(
  36. ScopeConfigInterface $scopeConfig
  37. ) {
  38. $this->scopeConfig = $scopeConfig;
  39. }
  40. /**
  41. * Move config from srcPath to dstPath
  42. * @param ModuleDataSetupInterface $setup
  43. * @param string $srcPath
  44. * @param string $dstPath
  45. */
  46. private function moveConfig(ModuleDataSetupInterface $setup, $srcPath, $dstPath)
  47. {
  48. $value = $this->scopeConfig->getValue($srcPath);
  49. if (is_array($value)) {
  50. foreach (array_keys($value) as $k) {
  51. $this->moveConfig($setup, $srcPath . '/' . $k, $dstPath . '/' . $k);
  52. }
  53. } else {
  54. $connection = $setup->getConnection();
  55. $configData = $setup->getTable('core_config_data');
  56. $connection->update($configData, ['path' => $dstPath], 'path='.$connection->quote($srcPath));
  57. }
  58. }
  59. private function upgradeTo010100(ModuleDataSetupInterface $setup)
  60. {
  61. $this->moveConfig(
  62. $setup,
  63. 'msp_securitysuite/recaptcha',
  64. 'msp_securitysuite_recaptcha/general'
  65. );
  66. }
  67. private function upgradeTo010101(ModuleDataSetupInterface $setup)
  68. {
  69. $this->moveConfig(
  70. $setup,
  71. 'msp_securitysuite_recaptcha/general/enabled_frontend',
  72. 'msp_securitysuite_recaptcha/frontend/enabled'
  73. );
  74. $this->moveConfig(
  75. $setup,
  76. 'msp_securitysuite_recaptcha/general/enabled_backend',
  77. 'msp_securitysuite_recaptcha/backend/enabled'
  78. );
  79. }
  80. /**
  81. * Upgrades data for a module
  82. *
  83. * @param ModuleDataSetupInterface $setup
  84. * @param ModuleContextInterface $context
  85. * @return void
  86. */
  87. public function upgrade(ModuleDataSetupInterface $setup, ModuleContextInterface $context)
  88. {
  89. $setup->startSetup();
  90. if (version_compare($context->getVersion(), '1.1.0') < 0) {
  91. $this->upgradeTo010100($setup);
  92. }
  93. if (version_compare($context->getVersion(), '1.2.0') < 0) {
  94. $this->upgradeTo010101($setup);
  95. }
  96. $setup->endSetup();
  97. }
  98. }