Support nodelist archives with more than 1 file in it

This commit is contained in:
2024-06-15 15:12:09 +10:00
parent 941117b342
commit 180c620168
4 changed files with 31 additions and 31 deletions

View File

@@ -80,11 +80,27 @@ class NodelistImport implements ShouldQueue
// Get the file from the host
$file = $this->getFileFromHost(self::importkey,$this->file);
Log::debug(sprintf('%s:+ Loading file [%s].',static::LOGKEY,$file));
$lines = $this->getFileLines($file);
Log::debug(sprintf('%s:- Processing [%d] lines.',static::LOGKEY,$lines));
$z = $this->openFile($file);
$c = 0;
$fh = NULL;
$z = $this->openFile($file,$fh);
while ($c < $z->count()) {
// Nodelist files have an extension of numbers, between 1-365
if (preg_match('/^.+\.[0-3][0-9][0-9]$/',$z->getNameIndex($c))) {
$fh = $z->getStreamIndex($c);
break;
}
$c++;
}
if (is_null($fh))
throw new \Exception('Couldnt find nodelist in file');
$lines = $this->getFileLines($fh);
Log::debug(sprintf('%s:- Processing [%d] lines.',static::LOGKEY,$lines));
// Rewind
$fh = $z->getStreamIndex($c);
// Line 1 tells us the nodelist and the CRC
$line = stream_get_line($fh,0,"\r\n");
@@ -123,9 +139,9 @@ class NodelistImport implements ShouldQueue
$no->addresses()->detach();
elseif ($no->addresses->count()) {
Log::error($x=sprintf('%s:! Nodelist [%s] for [%s] has existing records [%d]',self::LOGKEY,$date,$do->name,$no->addresses->count()));
Log::error(sprintf('%s:! Nodelist [%s] for [%s] has existing records [%d]',self::LOGKEY,$date,$do->name,$no->addresses->count()));
throw new \Exception($x);
return;
}
$mailer_binkp = Mailer::where('name','BINKP')->singleOrFail();
@@ -179,6 +195,7 @@ class NodelistImport implements ShouldQueue
$region = 0;
$host = 0;
$ishub = FALSE;
$ho = NULL;
break;
@@ -186,18 +203,21 @@ class NodelistImport implements ShouldQueue
$region = (int)$fields[1];
$host = (int)$fields[1];
$ishub = FALSE;
$ho = NULL;
break;
case 'Host':
$host = (int)$fields[1];
$ishub = FALSE;
$ho = NULL;
break;
case 'Hub':
$node = (int)$fields[1];
$ishub = TRUE;
$ho = NULL;
break;
@@ -543,7 +563,7 @@ class NodelistImport implements ShouldQueue
->diff(our_nodes($do)->pluck('id'));
$remove = Address::whereIn('id',$remove)->get();
Log::alert(sprintf('%s:%% Deleting [%d] addresses [%s]',self::LOGKEY,$remove->count(),$remove->pluck('ftn4d')->join(',')));
Log::alert(sprintf('%s:%% Deleting [%d] addresses [%s]',self::LOGKEY,$remove->count(),$remove->pluck('ftn2d')->join(',')));
Address::whereIN('id',$remove->pluck('id'))->update(['active'=>FALSE]);
Address::whereIN('id',$remove->pluck('id'))->delete();