Improvements for deterining an Address for a 2D FTN
All checks were successful
Create Docker Image / Build Docker Image (x86_64) (push) Successful in 36s
Create Docker Image / Build Docker Image (arm64) (push) Successful in 1m50s
Create Docker Image / Final Docker Image Manifest (push) Successful in 9s

This commit is contained in:
Deon George 2024-10-18 11:26:06 +11:00
parent b1560015ae
commit 03c6cadbf9

View File

@ -254,6 +254,9 @@ class Address extends Model
$ftn = self::parseFTN($address); $ftn = self::parseFTN($address);
$do = $ftn['d'] ? Domain::where('name',$ftn['d'])->single() : NULL; $do = $ftn['d'] ? Domain::where('name',$ftn['d'])->single() : NULL;
if ($ftn['z'] === 0)
Log::alert(sprintf('%s:! newFTN was parsed an FTN [%s] with a zero zone',self::LOGKEY,$address));
$zo = Zone::where('zone_id',$ftn['z']) $zo = Zone::where('zone_id',$ftn['z'])
->when($do,fn($query)=>$query->where('domain_id',$do->id)) ->when($do,fn($query)=>$query->where('domain_id',$do->id))
->single(); ->single();
@ -337,34 +340,39 @@ class Address extends Model
$region_id = 0; $region_id = 0;
$zone_id = NULL; $zone_id = NULL;
// We can only work out region if we have a domain // We can only work out region/zone if we have a domain - this is for 2D parsing
if ($matches[5] ?? NULL) { if ($matches[5] ?? NULL) {
$o = new self; $o = new self;
$o->host_id = $matches[2]; $o->host_id = $matches[2];
$o->node_id = $matches[3]; $o->node_id = $matches[3];
$o->point_id = empty($matches[4]) ? 0 : (int)$matches[4]; $o->point_id = empty($matches[4]) ? 0 : (int)$matches[4];
$zo = Zone::select('zones.*')->where('zone_id',$matches[1])->join('domains',['domains.id'=>'zones.domain_id'])->where('domains.name',$matches[5])->single(); if ($matches[1] !== "0") {
$zo = Zone::select('zones.*')
->where('zone_id',$matches[1])
->join('domains',['domains.id'=>'zones.domain_id'])
->where('domains.name',$matches[5])
->single();
// Try and find out the zone from the host_id
} else {
$zo = Zone::select('zones.*')
->where(fn($query)=>$query->where('host_id',$matches[2])->orWhere('region_id',$matches[2]))
->join('domains',['domains.id'=>'zones.domain_id'])
->join('addresses',['addresses.zone_id'=>'zones.id'])
->where('domains.name',$matches[5])
->first();
}
$o->zone_id = $zo?->id; $o->zone_id = $zo?->id;
$parent = $o->parent(); $parent = $o->parent();
$zone_id = $parent?->zone->zone_id;
// For flattened domains
if ($zo?->domain->flatten && is_null($zone_id))
foreach ($zo->domain->zones as $zoo) {
$o->zone_id = $zoo->id;
$parent = $o->parent();
if ($parent)
break;
}
$region_id = $parent?->region_id; $region_id = $parent?->region_id;
$zone_id = $parent?->zone->zone_id; $zone_id = $parent?->zone->zone_id;
} }
return [ return [
'z' => (int)$zone_id ?: $matches[1], 'z' => (int)($zone_id ?: $matches[1]),
'r' => (int)$region_id, 'r' => (int)$region_id,
'n' => (int)$matches[2], 'n' => (int)$matches[2],
'f' => (int)$matches[3], 'f' => (int)$matches[3],