clrghouz/app/Console/Commands/Filefix/Rescan.php

64 lines
1.6 KiB
PHP
Raw Normal View History

2024-04-16 12:30:41 +00:00
<?php
namespace App\Console\Commands\Filefix;
use Illuminate\Console\Command;
2024-11-26 11:05:40 +00:00
use App\Jobs\FilefixRescan;
use App\Models\{Address,Filearea};
2024-04-16 12:30:41 +00:00
class Rescan extends Command
{
/**
* The name and signature of the console command.
*
* @var string
*/
2024-11-26 11:05:40 +00:00
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}';
2024-04-16 12:30:41 +00:00
/**
* The console command description.
*
* @var string
*/
protected $description = 'Resend some files to a node';
/**
* Execute the console command.
*
* @return int
2024-04-16 12:30:41 +00:00
* @throws \Exception
*/
public function handle(): int
2024-04-16 12:30:41 +00:00
{
2024-11-26 11:05:40 +00:00
if (($this->argument('days')) && (! is_numeric($this->argument('days'))))
throw new \Exception('Days must be numeric: '.$this->argument('days'));
2024-04-16 12:30:41 +00:00
$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();
2024-11-26 11:05:40 +00:00
2024-04-16 12:30:41 +00:00
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));
2024-11-26 11:05:40 +00:00
if ($this->option('queue'))
FilefixRescan::dispatch($ao,$fao,$this->argument('days'))->onQueue($this->option('queuename'));
else
FilefixRescan::dispatchSync($ao,$fao,$this->argument('days'));
2024-04-16 12:30:41 +00:00
return self::SUCCESS;
}
}