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/app/code/Cnc/Localization/Setup/Patch/Data/

Upload File :
current_dir [ Writeable ] document_root [ Writeable ]

 

Current File : /home/corals/old/app/code/Cnc/Localization/Setup/Patch/Data/ImportLocalization.php
<?php

declare(strict_types=1);

namespace Cnc\Localization\Setup\Patch\Data;

use Kaliop\Core\Model\Import\AbstractImport;
use Magento\Framework\App\Filesystem\DirectoryList;
use Magento\Framework\App\ResourceConnection;
use Magento\Framework\Filesystem\Driver\File;
use Magento\Framework\Module\Dir\Reader;
use Magento\Framework\Setup\Patch\DataPatchInterface;

class ImportLocalization extends AbstractImport implements DataPatchInterface
{
    const LOCALIZATION_FILENAME = 'localization.csv';
    private $resourceConnection;

    public function __construct(
        ResourceConnection $resourceConnection,
        File $fileSystem,
        DirectoryList $directoryList,
        Reader $moduleReader
    ) {
        $this->resourceConnection = $resourceConnection;
        parent::__construct($fileSystem, $directoryList, $moduleReader);
    }

    public static function getDependencies(): array
    {
        return [];
    }

    public function apply(): void
    {
        $handle = $this->openFile('Cnc_Localization', self::LOCALIZATION_FILENAME);

        while (($line = $this->fileSystem->fileGetCsv($handle, ',')) !== false) {
            $this->importLine($line);
        }
    }

    private function importLine($line): void
    {
        $name = $line[0];

        $this->resourceConnection->getConnection()->insert(
            $this->resourceConnection->getTableName('cnc_localization'),
            ['name' => $name]
        );
    }

    public function getAliases(): array
    {
        return [];
    }
}

Spamworldpro Mini