Fixes for nodelist importing
This commit is contained in:
@@ -58,11 +58,12 @@ class ImportNodelist implements ShouldQueue
|
||||
Log::debug(sprintf('%s:Processing [%d] lines.',static::LOGKEY,$lines));
|
||||
|
||||
$fh = fopen($file,'r');
|
||||
$c =0;
|
||||
$p = $c =0;
|
||||
|
||||
$region = NULL;
|
||||
$host = NULL;
|
||||
$hub_id = NULL;
|
||||
$zo = NULL;
|
||||
|
||||
while (! feof($fh)) {
|
||||
$line = stream_get_line($fh, 0, "\r\n");
|
||||
@@ -89,17 +90,20 @@ class ImportNodelist implements ShouldQueue
|
||||
switch ($fields[0]) {
|
||||
case 'Zone': $zone = $fields[1];
|
||||
// We ignore the Zone entries, since they are dynamically created.
|
||||
$zo = Zone::firstOrCreate([
|
||||
'zone_id'=>$zone,
|
||||
'domain_id'=>$this->do->id,
|
||||
]);
|
||||
Zone::unguard();
|
||||
$zo = Zone::firstOrNew([
|
||||
'zone_id'=>$zone,
|
||||
'domain_id'=>$this->do->id,
|
||||
'active'=>TRUE,
|
||||
]);
|
||||
Zone::reguard();
|
||||
|
||||
$region = 0;
|
||||
$host = 0;
|
||||
$host = $fields[1];
|
||||
$hub_id = NULL;
|
||||
$role = DomainController::NODE_ZC;
|
||||
|
||||
continue 2;
|
||||
break;
|
||||
|
||||
case 'Region':
|
||||
$region = $fields[1];
|
||||
@@ -118,6 +122,7 @@ class ImportNodelist implements ShouldQueue
|
||||
continue 2;
|
||||
|
||||
case 'Hub':
|
||||
$node = $fields[1];
|
||||
$role = DomainController::NODE_HC;
|
||||
|
||||
break;
|
||||
@@ -128,6 +133,12 @@ class ImportNodelist implements ShouldQueue
|
||||
|
||||
break;
|
||||
|
||||
case 'Hold':
|
||||
$node = $fields[1];
|
||||
$role = DomainController::NODE_HOLD;
|
||||
|
||||
break;
|
||||
|
||||
case 'Down':
|
||||
$node = $fields[1];
|
||||
$role = DomainController::NODE_DOWN;
|
||||
@@ -150,7 +161,6 @@ class ImportNodelist implements ShouldQueue
|
||||
|
||||
Address::unguard();
|
||||
$ao = Address::firstOrNew([
|
||||
'zone_id' => $zo->id,
|
||||
'region_id' => $region,
|
||||
'host_id' => $host,
|
||||
'node_id' => $node,
|
||||
@@ -164,36 +174,52 @@ class ImportNodelist implements ShouldQueue
|
||||
|
||||
$role = NULL;
|
||||
|
||||
if ($ao->exists)
|
||||
Log::debug(sprintf('%s:Processing existing address [%s]',self::LOGKEY,$ao->ftn));
|
||||
|
||||
$sysop = trim(str_replace('_',' ',$fields[4]));
|
||||
$system = trim(str_replace('_',' ',$fields[2]));
|
||||
$location = trim(str_replace('_',' ',$fields[3]));
|
||||
|
||||
// Get the System
|
||||
if ($ao->system_id && (($ao->system->sysop === str_replace('_',' ',$fields[4])) || ($ao->system->name !== str_replace('_',' ',$fields[2])))) {
|
||||
if ($ao->system_id && (($ao->system->sysop === $sysop) || ($ao->system->name === $system))) {
|
||||
$so = $ao->system;
|
||||
|
||||
// If the sysop name is different
|
||||
if ($so->sysop !== str_replace('_',' ',$fields[4])) {
|
||||
$so->sysop = str_replace('_',' ',$fields[4]);
|
||||
$so->location = str_replace('_',' ',$fields[3]);
|
||||
if ($so->sysop !== $sysop) {
|
||||
Log::debug(sprintf('%s:Sysop Name changed for BBS [%s:%s] from [%s] to [%s]',
|
||||
self::LOGKEY,$so->id,$so->name,$so->sysop,$sysop));
|
||||
|
||||
$so->sysop = $sysop;
|
||||
|
||||
// We have the same name has changed.
|
||||
} else {
|
||||
$so->name = str_replace('_',' ',$fields[2]);
|
||||
$so->location = str_replace('_',' ',$fields[3]);
|
||||
} elseif ($so->name !== $system) {
|
||||
Log::debug(sprintf('%s:System Name changed for BBS [%s:%s] to [%s]',
|
||||
self::LOGKEY,$so->id,$so->name,$system));
|
||||
|
||||
$so->name = $system;
|
||||
}
|
||||
|
||||
// We'll search and see if we already have that system
|
||||
} else {
|
||||
$so = System::where('name',str_replace('_',' ',$fields[2]))
|
||||
->where('sysop',str_replace('_',' ',$fields[4]))
|
||||
$so = System::where('name',$system)
|
||||
->where('sysop',$sysop)
|
||||
->firstOrNew();
|
||||
|
||||
$so->name = str_replace('_',' ',$fields[2]);
|
||||
$so->sysop = str_replace('_',' ',$fields[4]);
|
||||
$so->location = str_replace('_',' ',$fields[3]);
|
||||
if ($so->exists)
|
||||
Log::debug(sprintf('%s:Linking address [%d:%d/%d] to [%s:%s]',self::LOGKEY,$zo->zone_id,$ao->host_id,$ao->node_id,$so->id,$so->name));
|
||||
else
|
||||
Log::debug(sprintf('%s:New System [%s] with address [%d:%d/%d]',self::LOGKEY,$system,$zo->zone_id,$ao->host_id,$ao->node_id));
|
||||
|
||||
$so->name = $system;
|
||||
$so->sysop = $sysop;
|
||||
$so->active = TRUE;
|
||||
|
||||
if (! $so->exists)
|
||||
$so->notes = sprintf('Created by Nodelist Import: %d',$this->no->id);
|
||||
}
|
||||
|
||||
$so->location = $location;
|
||||
/*
|
||||
if (! in_array($fields[5],['-Unpublished-']))
|
||||
$so->phone = $fields[5];
|
||||
@@ -204,6 +230,19 @@ class ImportNodelist implements ShouldQueue
|
||||
// Save the system record
|
||||
$so->save();
|
||||
|
||||
// If our zone didnt exist, we'll create it with this system
|
||||
if (! $zo->exists) {
|
||||
$zo->system_id = $so->id;
|
||||
$zo->save();
|
||||
}
|
||||
|
||||
$ao->zone_id = $zo->id;
|
||||
|
||||
if ($ao->getDirty()) {
|
||||
dd($ao);
|
||||
$p++;
|
||||
}
|
||||
|
||||
try {
|
||||
$so->addresses()->save($ao);
|
||||
if ($role == DomainController::NODE_HC)
|
||||
@@ -226,6 +265,6 @@ class ImportNodelist implements ShouldQueue
|
||||
if ($this->deletefile and $c)
|
||||
unlink($file);
|
||||
|
||||
Log::info(sprintf('%s:Records Updated: %d',self::LOGKEY,$c));
|
||||
Log::info(sprintf('%s:Updated %d records from %d systems',self::LOGKEY,$p,$c));
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user