HEX
Server: Microsoft-IIS/8.5
System: Windows NT YDAWBH120 6.3 build 9600 (Windows Server 2012 R2 Standard Edition) AMD64
User: tentjecom_web (0)
PHP: 7.4.14
Disabled: NONE
Upload Files
File: D:/HostingSpaces/SBogers10/rentman2019.komma.pro/app/Console/Commands/OneSkyImport.php
<?php

namespace App\Console\Commands;

use App\Komma\OneSky\OneSkyImporterService;
use Illuminate\Console\Command;
use Illuminate\Support\Facades\File;

class OneSkyImport extends Command
{
    /**
     * The name and signature of the console command.
     *
     * @var string
     */
    protected $signature = 'oneSky:import';

    /**
     * The console command description.
     *
     * @var string
     */
    protected $description = 'Import a one sky file';

    /**
     * The One Sky Import service.
     *
     * @var OneSkyImporterService
     */
    protected $oneSkyImporterService;

    /**
     * Create a new command instance.
     *
     * OneSkyImport constructor.
     * @param OneSkyImporterService $oneSkyImportService
     */
    public function __construct(OneSkyImporterService $oneSkyImporterService)
    {
        parent::__construct();

        $this->oneSkyImporterService = $oneSkyImporterService;
    }

    public $importLanguage = 'es';

    public $importModels = [
        'packages',
        'pages',
        'pricing-labels',
        'product-groups',
        'products',
    ];

    /**
     * Execute the console command.
     *
     * @return mixed
     */
    public function handle()
    {
        $this->line('OneSkyImport: Start for language "'.$this->importLanguage.'"');

        foreach ($this->importModels as $importModel) {
            $storagePath = storage_path('App/OneSkyImport/'.$this->importLanguage.'_'.$importModel.'.json');

            if (! File::exists($storagePath)) {
                $this->warn('OneSkyImport: File not found "'.$storagePath.'" for ImportModel "'.$importModel.'"');
                continue;
            }

            $json = json_decode(file_get_contents($storagePath, true));

            $this->oneSkyImporterService->runImport($this->importLanguage, $importModel, $json);
            $this->line('OneSkyImport: Imported '.$importModel);
        }
    }
}