CampaignsCheckChange.php 1.37 KB
<?php

namespace App\Console\Commands;

use App\Models\Tokens;
use App\Service\Requests\Direct\CheckCampaignsChanges;
use Illuminate\Console\Command;

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

    /**
     * The console command description.
     *
     * @var string
     */
    protected $description = 'Проверка изменений в РК';

    /**
     * Create a new command instance.
     *
     * @return void
     */
    public function __construct()
    {
        parent::__construct();
    }

    /**
     * Execute the console command.
     *
     * @return int
     */
    public function handle()
    {
        $token_main = Tokens::where('type', Tokens::MAIN)->first();

        if ($token_main) {
            $factory = new CheckCampaignsChanges();
            $factory->setToken($token_main)
                ->call();
        }

        $tokens = Tokens::has('dictionaryCampaignsEnabledForExternalUpdated')
            ->with('dictionaryCampaignsEnabledForExternalUpdated')
            ->where('type', '!=', Tokens::MAIN)->get();

        foreach ($tokens as $token) {
            $factory = new CheckCampaignsChanges();
            $factory->setToken($token)
                ->call();
        }

        return 0;
    }
}