clrghouz/app/Console/Commands/NodelistImport.php

52 lines
1011 B
PHP
Raw Normal View History

2019-04-26 04:30:00 +00:00
<?php
namespace App\Console\Commands;
2021-06-25 11:31:57 +00:00
use Carbon\Carbon;
2019-04-26 04:30:00 +00:00
use Illuminate\Console\Command;
2021-06-25 11:31:57 +00:00
use App\Models\{Domain,Nodelist};
use App\Jobs\NodelistImport as Job;
2019-04-26 04:30:00 +00:00
class NodelistImport extends Command
2019-04-26 04:30:00 +00:00
{
/**
* The name and signature of the console command.
*
* @var string
*/
protected $signature = 'nodelist:import'
2021-06-25 11:31:57 +00:00
.' {domain : Domain Name}'
.' {file : Nodelist File}'
.' {--D|delete : Delete old data for the date}';
2019-04-26 04:30:00 +00:00
/**
* 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()
{
2021-06-25 11:31:57 +00:00
$do = Domain::where('name',$this->argument('domain'))->singleOrFail();
$o = Nodelist::firstOrCreate(['date'=>Carbon::now(),'domain_id'=>$do->id]);
2019-04-26 04:30:00 +00:00
2021-06-25 11:31:57 +00:00
return Job::dispatchSync($do,$o,$this->argument('file'),$this->option('delete'));
2019-04-26 04:30:00 +00:00
}
}