PrepareShipmentDays.php 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899
  1. <?php
  2. /**
  3. * Copyright © Magento, Inc. All rights reserved.
  4. * See COPYING.txt for license details.
  5. */
  6. namespace Magento\Dhl\Setup\Patch\Data;
  7. use Magento\Framework\Locale\Bundle\DataBundle;
  8. use Magento\Framework\Locale\ResolverInterface;
  9. use Magento\Framework\App\ResourceConnection;
  10. use Magento\Framework\Setup\ModuleDataSetupInterface;
  11. use Magento\Framework\Setup\Patch\DataPatchInterface;
  12. use Magento\Framework\Setup\Patch\PatchVersionInterface;
  13. /**
  14. * Class PrepareShipmentDays
  15. * @package Magento\Dhl\Setup\Patch
  16. */
  17. class PrepareShipmentDays implements DataPatchInterface, PatchVersionInterface
  18. {
  19. /**
  20. * @var ModuleDataSetupInterface
  21. */
  22. private $moduleDataSetup;
  23. /**
  24. * @var ResolverInterface
  25. */
  26. private $localeResolver;
  27. /**
  28. * PrepareShipmentDays constructor.
  29. * @param ModuleDataSetupInterface $moduleDataSetup
  30. * @param ResolverInterface $localeResolver
  31. */
  32. public function __construct(
  33. ModuleDataSetupInterface $moduleDataSetup,
  34. \Magento\Framework\Locale\ResolverInterface $localeResolver
  35. ) {
  36. $this->moduleDataSetup = $moduleDataSetup;
  37. $this->localeResolver = $localeResolver;
  38. }
  39. /**
  40. * {@inheritdoc}
  41. */
  42. public function apply()
  43. {
  44. $days = (new DataBundle())->get(
  45. $this->localeResolver->getLocale()
  46. )['calendar']['gregorian']['dayNames']['format']['abbreviated'];
  47. $select = $this->moduleDataSetup->getConnection()->select()->from(
  48. $this->moduleDataSetup->getTable('core_config_data'),
  49. ['config_id', 'value']
  50. )->where(
  51. 'path = ?',
  52. 'carriers/dhl/shipment_days'
  53. );
  54. foreach ($this->moduleDataSetup->getConnection()->fetchAll($select) as $configRow) {
  55. $row = [
  56. 'value' => implode(
  57. ',',
  58. array_intersect_key(iterator_to_array($days), array_flip(explode(',', $configRow['value'])))
  59. )
  60. ];
  61. $this->moduleDataSetup->getConnection()->update(
  62. $this->moduleDataSetup->getTable('core_config_data'),
  63. $row,
  64. ['config_id = ?' => $configRow['config_id']]
  65. );
  66. }
  67. }
  68. /**
  69. * {@inheritdoc}
  70. */
  71. public static function getDependencies()
  72. {
  73. return [];
  74. }
  75. /**
  76. * {@inheritdoc}
  77. */
  78. public static function getVersion()
  79. {
  80. return '2.0.0';
  81. }
  82. /**
  83. * {@inheritdoc}
  84. */
  85. public function getAliases()
  86. {
  87. return [];
  88. }
  89. }