64 lines
1.6 KiB
PHP
64 lines
1.6 KiB
PHP
<?php
|
|
|
|
namespace App\Console\Commands\Filefix;
|
|
|
|
use Illuminate\Console\Command;
|
|
|
|
use App\Jobs\FilefixRescan;
|
|
use App\Models\{Address,Filearea};
|
|
|
|
class Rescan extends Command
|
|
{
|
|
/**
|
|
* The name and signature of the console command.
|
|
*
|
|
* @var string
|
|
*/
|
|
protected $signature = 'filefix:rescan'
|
|
.' {ftn : FTN Address}'
|
|
.' {area : Echoarea Tag}'
|
|
.' {days? : Limit to files received days ago}'
|
|
.' {--j|queue : Queue the Job}'
|
|
.' {--Q|queuename=default : Queue on queue}'
|
|
.' {--R|export : Re-export previously sent files}';
|
|
|
|
/**
|
|
* The console command description.
|
|
*
|
|
* @var string
|
|
*/
|
|
protected $description = 'Resend some files to a node';
|
|
|
|
/**
|
|
* Execute the console command.
|
|
*
|
|
* @return int
|
|
* @throws \Exception
|
|
*/
|
|
public function handle(): int
|
|
{
|
|
if (($this->argument('days')) && (! is_numeric($this->argument('days'))))
|
|
throw new \Exception('Days must be numeric: '.$this->argument('days'));
|
|
|
|
$ao = Address::findFtn($this->argument('ftn'));
|
|
|
|
if (! $ao)
|
|
throw new \Exception('FTN not found: '.$this->argument('ftn'));
|
|
|
|
// Check that the area belongs to the domain for the FTN
|
|
if (! $this->argument('area'))
|
|
throw new \Exception('Areaname is required');
|
|
|
|
$fao = Filearea::where('name',$this->argument('area'))->sole();
|
|
|
|
if ($fao->domain_id !== $ao->zone->domain_id)
|
|
throw new \Exception(sprintf('File area [%s] is not in domain [%s] for FTN [%s]',$fao->name,$ao->zone->domain->name,$ao->ftn));
|
|
|
|
if ($this->option('queue'))
|
|
FilefixRescan::dispatch($ao,$fao,$this->argument('days'))->onQueue($this->option('queuename'));
|
|
else
|
|
FilefixRescan::dispatchSync($ao,$fao,$this->argument('days'));
|
|
|
|
return self::SUCCESS;
|
|
}
|
|
} |