From ec5c28a03e3e64f7913fb224191461922c0c7ed5 Mon Sep 17 00:00:00 2001 From: Deon George Date: Thu, 14 Sep 2023 23:05:05 +1000 Subject: [PATCH] Added ignore_crc option to nodelist import --- app/Console/Commands/NodelistImport.php | 4 +++- app/Jobs/NodelistImport.php | 13 ++++++++----- 2 files changed, 11 insertions(+), 6 deletions(-) diff --git a/app/Console/Commands/NodelistImport.php b/app/Console/Commands/NodelistImport.php index 7128fae..38e1abb 100644 --- a/app/Console/Commands/NodelistImport.php +++ b/app/Console/Commands/NodelistImport.php @@ -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'), ); } } \ No newline at end of file diff --git a/app/Jobs/NodelistImport.php b/app/Jobs/NodelistImport.php index c8b9540..1e0927f 100644 --- a/app/Jobs/NodelistImport.php +++ b/app/Jobs/NodelistImport.php @@ -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 {