<?php 

namespace frontend\jobs;
use yii;
use yii\base\BaseObject;
use yii\httpclient\Client;
use backend\models\Galleriesbe;
use backend\models\Sysmodels;
use backend\models\Categoriesbe;
use backend\models\Productsbe;
use backend\models\Lookuptablebe;
use frontend\jobs\Import_dbdataMissing;
use yii\helpers\Json;

class CheckAllMissing extends BaseObject implements \common\components\Queue\JobInterface
{
	/**
     * Runs Imports Missing Invoices and Orders.
     *
     * @param [type] $queue
     * @return void
     */
    public function execute($queue)
    {
		$delay = strtotime('+4 hours') - strtotime('now');
        yii::$app->queue
        ->jobname('Import Missing Data')    
        ->delay($delay)
        ->ttr(3600)
        ->push(new self());
        $sysmodels = Sysmodels::find()->where(['enabled' => 1])->select(['id', 'destination', 'name'])->asArray()->all();
        foreach($sysmodels as $sysmodel){
            yii::$app->queue
            ->jobname('Import ' . $sysmodel['name'] . ' Missing Data')    
            ->delay(120)
            ->ttr(3600)
            ->push(new Import_dbdataMissing(['id' => $sysmodel['id']]));
        }
	}
	
}