ScanController.php 1.49 KB
<?php

namespace app\commands;

use yii;
use yii\console\Controller;
use yii\helpers\Console;
use app\components\Collection;
use app\jobs\HostJob;

/**
 * Парсинг запрещенных ресурсов в РФ.
 */
class ScanController extends Controller
{
    public $file = '';

    public function beforeAction($action)
    {
        if (!parent::beforeAction($action)) {
            return false;
        }
        return true;
    }

    public function options($actionID)
    {
        return ['file'];
    }

    public function optionAliases()
    {
        return ['f' => 'file'];
    }

    /**
     * Парсинг запрещенных ресурсов в РФ.
     */
    public function actionIndex()
    {
        $ids = [];
        $row = 1;
        $hostsArr = Collection::getHostsByCsv(Yii::$app->params['csv_url']);
        $grabUrls = Yii::$app->params['registrators_urls'];
        foreach ($hostsArr as $host) {
          /*  if ((int)!($row % 10000)) {
                echo $this->ansiFormat('+', Console::FG_BLUE);
                flush();
            }*/
            $ids[] = (int)Yii::$app->queue->push(new HostJob([
                'host' => $host,
                'grabSource' => $grabUrls[array_rand($grabUrls)]
            ]));
            break;
            $row++;
        }

        echo "\n".$this->ansiFormat('Количество полученных хостов', Console::FG_CYAN) . ' => ' . $this->ansiFormat(count($ids), Console::BOLD, Console::FG_GREEN) . "\n";
    }

}