Added ignore_crc option to nodelist import

This commit is contained in:
Deon George 2023-09-14 23:05:05 +10:00
parent ff8c370d86
commit ec5c28a03e
2 changed files with 11 additions and 6 deletions

View File

@ -17,6 +17,7 @@ class NodelistImport extends Command
protected $signature = 'nodelist:import'
.' {file : File ID | filename}'
.' {domain? : Domain Name}'
.' {--I|ignorecrc : Ignore the CRC}'
.' {--D|delete : Delete old data for the date}'
.' {--U|unlink : Delete file after import}'
.' {--T|test : Dry run}';
@ -40,7 +41,8 @@ class NodelistImport extends Command
$this->argument('domain'),
$this->option('delete'),
$this->option('unlink'),
$this->option('test')
$this->option('test'),
$this->option('ignorecrc'),
);
}
}

View File

@ -31,6 +31,7 @@ class NodelistImport implements ShouldQueue
private bool $delete_file;
private bool $delete_recs;
private bool $testmode;
private bool $ignore_crc;
/**
* Import Nodelist constructor.
@ -40,14 +41,16 @@ class NodelistImport implements ShouldQueue
* @param bool $delete_recs
* @param bool $delete_file
* @param bool $test
* @param bool $ignore_crc
*/
public function __construct(File|string $file,string $domain=NULL,bool $delete_recs=FALSE,bool $delete_file=TRUE,bool $test=FALSE)
public function __construct(File|string $file,string $domain=NULL,bool $delete_recs=FALSE,bool $delete_file=TRUE,bool $test=FALSE,bool $ignore_crc = FALSE)
{
$this->file = $file;
$this->domain = $domain;
$this->delete_file = $delete_file;
$this->delete_recs = $delete_recs;
$this->testmode = $test;
$this->ignore_crc = $ignore_crc;
$this->onQueue(self::QUEUE);
}
@ -98,7 +101,7 @@ class NodelistImport implements ShouldQueue
if (! $do) {
Log::error(sprintf('%s:! Domain not found [%s].',static::LOGKEY,strtolower($matches[1] ?: $this->domain)));
throw new \Exception('Nodelist Domain not found: '.$this->file->id);
throw new \Exception('Nodelist Domain not found: '.$this->file);
}
$date = Carbon::createFromFormat('D, M d, Y H:i',$matches[2].'0:00');
@ -441,8 +444,8 @@ class NodelistImport implements ShouldQueue
$so->baud = $fields[6];
*/
if ($so->users->count()) {
Log::alert(sprintf('%s:! Refusing to update a system managed by a user',self::LOGKEY));
if ($so->users->count() && $so->getDirty()) {
Log::alert(sprintf('%s:! Refusing to update a system managed by a user',self::LOGKEY),['dirty'=>$so->getDirty()]);
continue;
}
@ -500,7 +503,7 @@ class NodelistImport implements ShouldQueue
Address::whereIN('id',$remove->pluck('id')->toArray())->update(['active'=>FALSE]);
Address::whereIN('id',$remove->pluck('id')->toArray())->delete();
if ((! $this->testmode) && ($x=crc16(substr($tocrc,0,-3))) === $file_crc) {
if ((! $this->testmode) && ($this->ignore_crc || ($x=crc16(substr($tocrc,0,-3))) === $file_crc)) {
Log::info(sprintf('%s:= Committing nodelist',self::LOGKEY));
DB::commit();
} else {