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/

Upload File :
current_dir [ Writeable ] document_root [ Writeable ]

 

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

namespace Extmag\Shiplab\Setup;

use Extmag\Shiplab\Model\Configuration;
use Extmag\Shiplab\Model\ConfigurationFactory;
use Extmag\Shiplab\Model\ConfigurationRepository;
use Extmag\Shiplab\Model\ResourceModel\Configuration\Collection;
use Extmag\Shiplab\Model\ResourceModel\Configuration\CollectionFactory;
use Magento\Framework\App\Filesystem\DirectoryList;
use Magento\Framework\Filesystem\Driver\File;
use Magento\Framework\Indexer\ConfigInterface;
use Magento\Framework\Module\Dir;
use Magento\Framework\Module\Dir\Reader;
use Magento\Framework\Setup\InstallDataInterface;
use Magento\Framework\Setup\ModuleContextInterface;
use Magento\Framework\Setup\ModuleDataSetupInterface;
use Magento\Ui\Model\Bookmark;
use Magento\Ui\Model\ResourceModel\BookmarkRepository;
use Exception;
use RecursiveDirectoryIterator;
use RecursiveIteratorIterator;
use SplFileInfo;
use Magento\Framework\Filesystem\Io\File as IoFile;

/**
 * Recurring data upgrade for shiplab module
 */
class RecurringData implements InstallDataInterface
{
    /**
     * @var ConfigInterface
     */
    protected $configInterface;
    /**
     * @var DirectoryList
     */
    protected $directoryList;
    /**
     * @var Reader
     */
    protected $configReader;
    /**
     * @var ConfigurationFactory
     */
    protected $configurationFactory;
    /**
     * @var CollectionFactory
     */
    protected $configurationCollectionFactory;
    /**
     * @var ConfigurationRepository
     */
    protected $configurationRepository;
    /**
     * @var Bookmark
     */
    protected $bookmarks;
    /**
     * @var BookmarkRepository
     */
    protected $bookmarkRepository;
    /**
     * @var File
     */
    protected $file;

    /**
     * @var IoFile
     */
    protected $io;

    /**
     * @param ConfigInterface $configInterface
     * @param DirectoryList $directoryList
     * @param Reader $configReader
     * @param ConfigurationFactory $configurationFactory
     * @param CollectionFactory $configurationCollectionFactory
     * @param ConfigurationRepository $configurationRepository
     * @param \Magento\Ui\Model\ResourceModel\Bookmark\CollectionFactory $bookmarks
     * @param BookmarkRepository $bookmarkRepository
     * @param File $file
     * @param IoFile $io
     */
    public function __construct(
        ConfigInterface $configInterface,
        DirectoryList $directoryList,
        Reader $configReader,
        ConfigurationFactory $configurationFactory,
        CollectionFactory $configurationCollectionFactory,
        ConfigurationRepository $configurationRepository,
        \Magento\Ui\Model\ResourceModel\Bookmark\CollectionFactory $bookmarks,
        BookmarkRepository $bookmarkRepository,
        File $file,
        IoFile $io
    ) {
        $this->configInterface = $configInterface;
        $this->directoryList = $directoryList;
        $this->configReader = $configReader;
        $this->configurationFactory = $configurationFactory;
        $this->configurationCollectionFactory = $configurationCollectionFactory;
        $this->configurationRepository = $configurationRepository;
        $this->bookmarks = $bookmarks;
        $this->bookmarkRepository = $bookmarkRepository;
        $this->file = $file;
        $this->io = $io;
    }

    /**
     * {@inheritdoc}
     */
    public function install(ModuleDataSetupInterface $setup, ModuleContextInterface $context)
    {
        $data = $this->collectShiplabConfig();
        $arr = $this->multi_implode($data);
        /*echo var_export($arr);*/
        foreach ($arr as $key => $value) {
            /**
             * @var Collection $collection
             */
            $collection = $this->configurationCollectionFactory->create();
            $collection->addFieldToFilter('scope', 'default')
                ->addFieldToFilter('scope_id', 0)
                ->addFieldToFilter('path', $key);

            if ($collection->getSize() == 0) {
                /**
                 * @var Configuration $model
                 */
                $model = $this->configurationFactory->create();
                $model->setScope('default');
                $model->setScopeId(0);
                $model->setPath($key);
                $model->setValue($value);
                try {
                    $this->configurationRepository->save($model);
                } catch (Exception $e) {
                }
            }
        }

        $this->checkBookmarks();
        $this->createFolders();
    }

    protected function createFolders()
    {
        $mediaPath = $this->directoryList->getPath('media');
        if (!$this->io->fileExists($mediaPath . '/extmag/upload/carrier_logo', false)) {
            $this->io->mkdir($mediaPath . '/extmag/upload/carrier_logo', 0775);
        }
    }

    protected function multi_implode($array)
    {
        $returnArray = [];
        foreach ($array as $key => $array1) {
            foreach ($array1 as $key1 => $array2) {
                foreach ($array2 as $key2 => $value) {
                    $returnArray[$key . '/' . $key1 . '/' . $key2] = $value;
                }
            }
        }

        return $returnArray;
    }

    protected function checkBookmarks()
    {
        /**
         * @var $collection \Magento\Ui\Model\ResourceModel\Bookmark\Collection
         */
        $collection = $this->bookmarks->create();
        $collection->addFieldToFilter('namespace', 'sales_order_grid');
        /**
         * @var $item Bookmark
         */
        foreach ($collection as $item) {
            $data = $item->getConfig();
            $firstKey = key($data);
            if (!empty($data[$firstKey]['columns']['extmag_shipping_label']['sorting'])) {
                $data[$firstKey]['columns']['extmag_shipping_label']['sorting'] = false;
                $item->setConfig(json_encode($data));
                try {
                    $this->bookmarkRepository->save($item);
                } catch (Exception $e) {
                }
            }
        }
    }

    public function collectShiplabConfig()
    {
        $currentModulePath = $this->configReader->getModuleDir(Dir::MODULE_ETC_DIR, 'Extmag_Shiplab');
        $path = $currentModulePath . '/../../';
        $files = new RecursiveIteratorIterator(
            new RecursiveDirectoryIterator($path),
            RecursiveIteratorIterator::LEAVES_ONLY
        );
        $config = [];
        if (!empty($files)) {
            /**
             * @var SplFileInfo $file
             */
            foreach ($files as $file) {
                if ($file->getBasename() === 'shiplab_config.xml') {
                    $config = array_merge_recursive(
                        $config,
                        json_decode(json_encode(simplexml_load_file($file->getRealPath())), true)
                    );
                    if (!empty($config)) {
                        unset($config['comment']);
                    }
                }
            }
        }

        return $config;
    }
}

Spamworldpro Mini