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' protected $signature = 'nodelist:import'
.' {file : File ID | filename}' .' {file : File ID | filename}'
.' {domain? : Domain Name}' .' {domain? : Domain Name}'
.' {--I|ignorecrc : Ignore the CRC}'
.' {--D|delete : Delete old data for the date}' .' {--D|delete : Delete old data for the date}'
.' {--U|unlink : Delete file after import}' .' {--U|unlink : Delete file after import}'
.' {--T|test : Dry run}'; .' {--T|test : Dry run}';
@ -40,7 +41,8 @@ class NodelistImport extends Command
$this->argument('domain'), $this->argument('domain'),
$this->option('delete'), $this->option('delete'),
$this->option('unlink'), $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_file;
private bool $delete_recs; private bool $delete_recs;
private bool $testmode; private bool $testmode;
private bool $ignore_crc;
/** /**
* Import Nodelist constructor. * Import Nodelist constructor.
@ -40,14 +41,16 @@ class NodelistImport implements ShouldQueue
* @param bool $delete_recs * @param bool $delete_recs
* @param bool $delete_file * @param bool $delete_file
* @param bool $test * @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->file = $file;
$this->domain = $domain; $this->domain = $domain;
$this->delete_file = $delete_file; $this->delete_file = $delete_file;
$this->delete_recs = $delete_recs; $this->delete_recs = $delete_recs;
$this->testmode = $test; $this->testmode = $test;
$this->ignore_crc = $ignore_crc;
$this->onQueue(self::QUEUE); $this->onQueue(self::QUEUE);
} }
@ -98,7 +101,7 @@ class NodelistImport implements ShouldQueue
if (! $do) { if (! $do) {
Log::error(sprintf('%s:! Domain not found [%s].',static::LOGKEY,strtolower($matches[1] ?: $this->domain))); 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'); $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]; $so->baud = $fields[6];
*/ */
if ($so->users->count()) { if ($so->users->count() && $so->getDirty()) {
Log::alert(sprintf('%s:! Refusing to update a system managed by a user',self::LOGKEY)); Log::alert(sprintf('%s:! Refusing to update a system managed by a user',self::LOGKEY),['dirty'=>$so->getDirty()]);
continue; 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())->update(['active'=>FALSE]);
Address::whereIN('id',$remove->pluck('id')->toArray())->delete(); 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)); Log::info(sprintf('%s:= Committing nodelist',self::LOGKEY));
DB::commit(); DB::commit();
} else { } else {