From 483e35202bb83df080f44e0b0f02d92fe1426620 Mon Sep 17 00:00:00 2001 From: Deon George Date: Sat, 20 Nov 2021 11:11:17 +1100 Subject: [PATCH] Fix for addresses where region_id is set inlieu of host_id, sort system ZC addresses --- app/Models/Address.php | 23 ++++++++++++++++++++++- resources/views/system/addedit.blade.php | 2 +- 2 files changed, 23 insertions(+), 2 deletions(-) diff --git a/app/Models/Address.php b/app/Models/Address.php index ac02c9c..00c46fe 100644 --- a/app/Models/Address.php +++ b/app/Models/Address.php @@ -13,6 +13,15 @@ use App\Classes\FTN\Packet; use App\Http\Controllers\DomainController; use App\Traits\{ScopeActive,UsePostgres}; +/** + * @todo Need to stop this from happening: + * In this example nn:3/1 can be defined 3 different ways. + * + id | zone_id | region_id | host_id | node_id | point_id | status | role | system_id | hub_id + * + ----+---------+-----------+---------+---------+----------+--------+------+-----------+-------- + * + 533 | 6 | 3 | 0 | 1 | 0 | | 4 | 1 | + * + 534 | 6 | 3 | 3 | 1 | 0 | | 2 | 1 | + * + 535 | 6 | 0 | 3 | 1 | 0 | | 2 | 1 | + */ class Address extends Model { use ScopeActive,SoftDeletes,UsePostgres; @@ -184,6 +193,7 @@ class Address extends Model case DomainController::NODE_UNKNOWN: case DomainController::NODE_POINT: + case DomainController::NODE_DOWN: // @todo Points - if the boss is defined, we should return it. return NULL; @@ -298,7 +308,18 @@ class Address extends Model $o = (new self)->active() ->select('addresses.*') ->where('zones.zone_id',$ftn['z']) - ->where('host_id',$ftn['n']) + ->where(function($q) use ($ftn) { + return $q->where(function($qq) use ($ftn) { + return $qq + ->where('region_id',0) + ->where('host_id',$ftn['n']); + }) + ->orWhere(function($qq) use ($ftn) { + return $qq + ->where('region_id',$ftn['n']) + ->where('host_id',0); + }); + }) ->where('node_id',$ftn['f']) ->where('point_id',$ftn['p']) ->join('zones',['zones.id'=>'addresses.zone_id']) diff --git a/resources/views/system/addedit.blade.php b/resources/views/system/addedit.blade.php index de2d086..64dbc32 100644 --- a/resources/views/system/addedit.blade.php +++ b/resources/views/system/addedit.blade.php @@ -15,7 +15,7 @@ use App\Http\Controllers\DomainController as DC; @endif @if($o->zcs->count()) -

This system is the ZC for the following zones: {!! $o->zcs->map(function($item) { return sprintf('%d@%s',$item->zone_id,$item->domain->name); })->join(', ') !!}

+

This system is the ZC for the following zones: {!! $o->zcs->sortBy('zone_id')->map(function($item) { return sprintf('%d@%s',$item->zone_id,$item->domain->name); })->join(', ') !!}

@endif