From 6e133770fc18a3abb2319d2daf4d47d82ff9983f Mon Sep 17 00:00:00 2001 From: Deon George Date: Fri, 15 Sep 2023 14:28:38 +1000 Subject: [PATCH] An enhancement to ensure that flatten domains gets the correct FTN --- app/Classes/FTN/Message.php | 2 +- app/Models/Address.php | 24 +++++++++++++++++++++++- 2 files changed, 24 insertions(+), 2 deletions(-) diff --git a/app/Classes/FTN/Message.php b/app/Classes/FTN/Message.php index 459f5f9..75980c9 100644 --- a/app/Classes/FTN/Message.php +++ b/app/Classes/FTN/Message.php @@ -704,7 +704,7 @@ class Message extends FTNBase // If domain should be flattened, look for node regardless of zone (within the list of zones for the domain) if ($this->fdomain && $this->fdomain->flatten) { - $ao = Address::findZone($this->fdomain,$net&DomainController::NUMBER_MAX,$node&DomainController::NUMBER_MAX); + $ao = Address::findZone($this->fdomain,$net&DomainController::NUMBER_MAX,$node&DomainController::NUMBER_MAX,0); $aoid = $ao?->id; diff --git a/app/Models/Address.php b/app/Models/Address.php index 6e46df4..e0cf560 100644 --- a/app/Models/Address.php +++ b/app/Models/Address.php @@ -419,6 +419,7 @@ class Address extends Model return $o; } + // Look for a normal address $o = ($x=(new self) ->select('addresses.*') ->join('zones',['zones.id'=>'addresses.zone_id']) @@ -450,6 +451,26 @@ class Address extends Model })) ->single(); + if ($o && $o->system->active) + return $o; + + // Check and see if we are a flattened domain, our address might be available with a different zone. + if ($ftn['p'] === 0) { + if ($ftn['d']) + $do = Domain::where(['name'=>$ftn['d']])->single(); + else { + $zo = Zone::where('zone_id',$ftn['z'])->where('default',TRUE)->single(); + $do = $zo?->domain; + } + + if ($do && $do->flatten) { + $o = self::findZone($do,$ftn['n'],$ftn['f'],$ftn['p'],$trashed); + + if ($o && $o->system->active) + return $o; + } + } + if ($create) { if (! $so) throw new \Exception(sprintf('%s:AKA create requested for [%s], but system not provided',self::LOGKEY,$address)); @@ -525,7 +546,7 @@ class Address extends Model * @return self|null * @throws \Exception */ - public static function findZone(Domain $do,int $host,int $node,bool $trashed=FALSE): ?self + public static function findZone(Domain $do,int $host,int $node,int $point,bool $trashed=FALSE): ?self { if (! $do->flatten) throw new \Exception(sprintf('Domain is not set with flatten: %d',$do->id)); @@ -550,6 +571,7 @@ class Address extends Model ->orWhere('host_id',$host); }) ->where('node_id',$node) + ->where('point_id',$point) ->where('zones.domain_id',$do->id) ->single();