Spamworldpro Mini Shell
Spamworldpro


Server : Apache
System : Linux server2.corals.io 4.18.0-348.2.1.el8_5.x86_64 #1 SMP Mon Nov 15 09:17:08 EST 2021 x86_64
User : corals ( 1002)
PHP Version : 7.4.33
Disable Function : exec,passthru,shell_exec,system
Directory :  /home/corals/old/vendor/extmag/shiplab/Setup/Patch/Data/

Upload File :
current_dir [ Writeable ] document_root [ Writeable ]

 

Current File : /home/corals/old/vendor/extmag/shiplab/Setup/Patch/Data/FixConditionTypeCountryId.php
<?php
/**
 * Copyright © Extmag. All rights reserved.
 */

namespace Extmag\Shiplab\Setup\Patch\Data;

use Exception;
use Magento\Framework\App\ResourceConnection;
use Magento\Framework\Setup\Patch\DataPatchInterface;
use Magento\Framework\Setup\Patch\PatchRevertableInterface;

class FixConditionTypeCountryId implements DataPatchInterface, PatchRevertableInterface
{
    /**
     * @var ResourceConnection
     */
    protected $resourceConnection;

    public function __construct(
        ResourceConnection $resourceConnection
    ) {
        $this->resourceConnection = $resourceConnection;
    }

    /**
     * {@inheritdoc}
     */
    public static function getDependencies()
    {
        return [
            /*SomeDependency::class*/
        ];
    }

    /**
     * {@inheritdoc}
     */
    public function apply()
    {
        $connection = $this->resourceConnection->getConnection();
        $connection->startSetup();

        try {
            if ($connection->isTableExists(
                $this->resourceConnection->getTableName("extmag_shipping_methods"))
            ) {
                $select = $connection->select()
                    ->from($this->resourceConnection->getTableName("extmag_shipping_methods"));
                $items = $connection->fetchAll($select);
                if (!empty($items)) {
                    foreach ($items as $item) {
                        if (!empty($item['conditions_serialized']) && strpos($item['conditions_serialized'],
                                ",\"attribute\":\"country_id\",\"operator\":\"==\",\"value\":") !== false) {
                            $connection->update(
                                $this->resourceConnection->getTableName("extmag_shipping_methods"),
                                [
                                    'conditions_serialized' => str_replace(
                                        ",\"attribute\":\"country_id\",\"operator\":\"==\",\"value\":",
                                        ",\"attribute\":\"country_id\",\"operator\":\"{}\",\"value\":",
                                        $item['conditions_serialized']),
                                ],
                                ['entity_id = ?' => $item['entity_id']]
                            );
                        }
                    }
                }
            }
        } catch (Exception $e) {
            throw new Exception($e->getMessage());
        }

        $connection->endSetup();
    }

    public function revert()
    {
        $this->resourceConnection->getConnection()->startSetup();
        $this->resourceConnection->getConnection()->endSetup();
    }

    /**
     * {@inheritdoc}
     */
    public function getAliases()
    {
        return [];
    }
}

Spamworldpro Mini