|
| 1 | +<?php |
| 2 | +/** |
| 3 | + * Copyright 2025 Adobe |
| 4 | + * All Rights Reserved. |
| 5 | + */ |
| 6 | + |
| 7 | +namespace Magento\Fedex\Setup\Patch\Data; |
| 8 | + |
| 9 | +use Magento\Framework\Setup\Patch\DataPatchInterface; |
| 10 | +use Magento\Framework\Setup\ModuleDataSetupInterface; |
| 11 | +use Magento\Framework\Setup\Patch\PatchVersionInterface; |
| 12 | + |
| 13 | +class UpdateFedexInternationalPriority implements DataPatchInterface, PatchVersionInterface |
| 14 | +{ |
| 15 | + /** |
| 16 | + * @var ModuleDataSetupInterface |
| 17 | + */ |
| 18 | + private $moduleDataSetup; |
| 19 | + |
| 20 | + /** |
| 21 | + * UpdateFedexInternationalPriority constructor. |
| 22 | + * @param ModuleDataSetupInterface $moduleDataSetup |
| 23 | + */ |
| 24 | + public function __construct( |
| 25 | + ModuleDataSetupInterface $moduleDataSetup |
| 26 | + ) { |
| 27 | + $this->moduleDataSetup = $moduleDataSetup; |
| 28 | + } |
| 29 | + |
| 30 | + /** |
| 31 | + * {@inheritdoc} |
| 32 | + * Apply the patch to update INTERNATIONAL_PRIORITY to FEDEX_INTERNATIONAL_PRIORITY |
| 33 | + */ |
| 34 | + public function apply() |
| 35 | + { |
| 36 | + $conn = $this->moduleDataSetup->getConnection(); |
| 37 | + $configDataTable = $this->moduleDataSetup->getTable('core_config_data'); |
| 38 | + $paths = [ |
| 39 | + 'carriers/fedex/allowed_methods', |
| 40 | + 'carriers/fedex/free_method' |
| 41 | + ]; |
| 42 | + foreach ($paths as $path) { |
| 43 | + $select = $conn->select() |
| 44 | + ->from($configDataTable) |
| 45 | + ->where('path = ?', $path); |
| 46 | + $rows = $conn->fetchAll($select); |
| 47 | + foreach ($rows as $row) { |
| 48 | + $values = explode(',', $row['value']); |
| 49 | + $updated = false; |
| 50 | + foreach ($values as &$value) { |
| 51 | + if (trim($value) === 'INTERNATIONAL_PRIORITY') { |
| 52 | + $value = 'FEDEX_INTERNATIONAL_PRIORITY'; |
| 53 | + $updated = true; |
| 54 | + } |
| 55 | + } |
| 56 | + unset($value); |
| 57 | + if ($updated) { |
| 58 | + $newValue = implode(',', $values); |
| 59 | + $conn->update( |
| 60 | + $configDataTable, |
| 61 | + ['value' => $newValue], |
| 62 | + ['config_id = ?' => $row['config_id']] |
| 63 | + ); |
| 64 | + } |
| 65 | + } |
| 66 | + } |
| 67 | + } |
| 68 | + |
| 69 | + /** |
| 70 | + * {@inheritdoc} |
| 71 | + */ |
| 72 | + public static function getDependencies() |
| 73 | + { |
| 74 | + return [ |
| 75 | + ConfigureFedexDefaults::class |
| 76 | + ]; |
| 77 | + } |
| 78 | + |
| 79 | + /** |
| 80 | + * {@inheritdoc} |
| 81 | + */ |
| 82 | + public static function getVersion() |
| 83 | + { |
| 84 | + return '2.0.1'; |
| 85 | + } |
| 86 | + |
| 87 | + /** |
| 88 | + * {@inheritdoc} |
| 89 | + */ |
| 90 | + public function getAliases() |
| 91 | + { |
| 92 | + return []; |
| 93 | + } |
| 94 | +} |
0 commit comments