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/magento/module-store/Model/Config/Importer/

Upload File :
current_dir [ Writeable ] document_root [ Writeable ]

 

Current File : /home/corals/old/vendor/magento/module-store/Model/Config/Importer/DataDifferenceCalculator.php
<?php
/**
 * Copyright © Magento, Inc. All rights reserved.
 * See COPYING.txt for license details.
 */
namespace Magento\Store\Model\Config\Importer;

use Magento\Framework\App\Config\ConfigSourceInterface;
use Magento\Store\Model\ScopeInterface;

/**
 * Calculates difference between current configuration and new one.
 */
class DataDifferenceCalculator
{
    /**
     * The config source to retrieve current config.
     *
     * @var ConfigSourceInterface
     */
    private $runtimeConfigSource;

    /**
     * Scopes identifier
     *
     * @var string[]
     */
    private $identifiers = [
        'websites' => 'website_id',
        'groups' => 'group_id',
        'stores' => 'store_id',
    ];

    /**
     * @param ConfigSourceInterface $runtimeConfigSource The config source to retrieve current config
     */
    public function __construct(ConfigSourceInterface $runtimeConfigSource)
    {
        $this->runtimeConfigSource = $runtimeConfigSource;
    }

    /**
     * Update data by checking ID
     *
     * @param string $scope
     * @param array $data
     * @param array $runtimeScopeData
     * @return array
     */
    private function updateDataById(string $scope, array $data, array $runtimeScopeData): array
    {
        $diffData = array_diff_key($data, $runtimeScopeData);
        foreach ($diffData as $code => $datum) {
            foreach ($runtimeScopeData as $runTimeScopeCode => $runtimeScopeDatum) {
                if (isset($datum[$this->identifiers[$scope]])
                    && $datum[$this->identifiers[$scope]] === $runtimeScopeDatum[$this->identifiers[$scope]]
                ) {
                    $data[$runTimeScopeCode] = $data[$code];
                    unset($data[$code]);
                }
            }
        }

        return $data;
    }

    /**
     * Calculates items to delete.
     *
     * @param string $scope The data scope
     * @param array $data The new data
     * @return array
     */
    public function getItemsToDelete($scope, array $data)
    {
        $data = $this->changeDataKeyToCode($data);
        $runtimeScopeData = $this->changeDataKeyToCode(
            $this->getRuntimeData($scope)
        );
        $data = $this->updateDataById($scope, $data, $runtimeScopeData);

        return array_diff_key($runtimeScopeData, $data);
    }

    /**
     * Calculates items to create.
     *
     * @param string $scope The data scope
     * @param array $data The new data
     * @return array
     */
    public function getItemsToCreate($scope, array $data)
    {
        $data = $this->changeDataKeyToCode($data);
        $runtimeScopeData = $this->changeDataKeyToCode(
            $this->getRuntimeData($scope)
        );
        $data = $this->updateDataById($scope, $data, $runtimeScopeData);

        return array_diff_key($data, $runtimeScopeData);
    }

    /**
     * Calculates items to update.
     *
     * @param string $scope The data scope
     * @param array $data The new data
     * @return array
     */
    public function getItemsToUpdate($scope, array $data)
    {
        $itemsToUpdate = [];
        $data = $this->changeDataKeyToCode($data);
        $data = $this->setDefaultValues($scope, $data);
        $runtimeScopeData = $this->changeDataKeyToCode(
            $this->getRuntimeData($scope)
        );
        $data = $this->updateDataById($scope, $data, $runtimeScopeData);
        foreach ($runtimeScopeData as $entityCode => $entityData) {
            if (isset($data[$entityCode]) && array_diff_assoc($entityData, $data[$entityCode])) {
                $itemsToUpdate[$entityCode] = array_replace($entityData, $data[$entityCode]);
            }
        }

        return $itemsToUpdate;
    }

    /**
     * Sets default values for some fields if their value is empty.
     *
     * @param string $scope The data scope
     * @param array $data The data of scopes (websites, groups, stores)
     * @return array
     */
    private function setDefaultValues($scope, array $data)
    {
        $fieldset = [];
        switch ($scope) {
            case ScopeInterface::SCOPE_WEBSITES:
                $fieldset = ['default_group_id'];
                break;
            case ScopeInterface::SCOPE_GROUPS:
                $fieldset = ['website_id', 'default_store_id', 'root_category_id'];
                break;
            case ScopeInterface::SCOPE_STORES:
                $fieldset = ['website_id', 'group_id'];
                break;
        }

        foreach ($data as $entityCode => $entityData) {
            foreach ($fieldset as $field) {
                $entityData[$field] = !empty($entityData[$field]) ? $entityData[$field] : '0';
            }

            $data[$entityCode] = $entityData;
        }

        return $data;
    }

    /**
     * Retrieves runtime data for specific scope.
     *
     * @param string $scope The scope of config data
     * @return array
     */
    private function getRuntimeData($scope)
    {
        $runtimeData = $this->runtimeConfigSource->get();

        return (array)$runtimeData[$scope];
    }

    /**
     * Create array of data keys.
     *
     * @param array $data The data
     * @return array
     */
    private function changeDataKeyToCode(array $data)
    {
        return array_combine(
            array_column($data, 'code'),
            array_values($data)
        );
    }
}

Spamworldpro Mini