clrghouz/app/Console/Commands/ImportNodelist.php
2021-06-25 22:21:19 +10:00

52 lines
1011 B
PHP

<?php
namespace App\Console\Commands;
use Carbon\Carbon;
use Illuminate\Console\Command;
use App\Models\{Domain,Nodelist};
use App\Jobs\ImportNodelist as Job;
class ImportNodelist extends Command
{
/**
* The name and signature of the console command.
*
* @var string
*/
protected $signature = 'import:nodelist'
.' {domain : Domain Name}'
.' {file : Nodelist File}'
.' {--D|delete : Delete old data for the date}';
/**
* The console command description.
*
* @var string
*/
protected $description = 'Import Nodelist';
/**
* Create a new command instance.
*
* @return void
*/
public function __construct()
{
parent::__construct();
}
/**
* Execute the console command.
*
* @return mixed
*/
public function handle()
{
$do = Domain::where('name',$this->argument('domain'))->singleOrFail();
$o = Nodelist::firstOrCreate(['date'=>Carbon::now(),'domain_id'=>$do->id]);
return Job::dispatchSync($do,$o,$this->argument('file'),$this->option('delete'));
}
}