|
|
|
@@ -8,13 +8,12 @@ use Illuminate\Database\Eloquent\Model;
|
|
|
|
|
use Illuminate\Database\Eloquent\Relations\HasMany;
|
|
|
|
|
use Illuminate\Database\Eloquent\SoftDeletes;
|
|
|
|
|
use Illuminate\Database\QueryException;
|
|
|
|
|
use Illuminate\Support\Facades\Cache;
|
|
|
|
|
use Illuminate\Support\Facades\DB;
|
|
|
|
|
use Illuminate\Support\Facades\Log;
|
|
|
|
|
|
|
|
|
|
use App\Classes\FTN\{Message,Packet};
|
|
|
|
|
use App\Exceptions\InvalidFTNException;
|
|
|
|
|
use App\Traits\ScopeActive;
|
|
|
|
|
use App\Traits\{QueryCacheableConfig,ScopeActive};
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* This represents an FTN AKA.
|
|
|
|
@@ -39,8 +38,8 @@ use App\Traits\ScopeActive;
|
|
|
|
|
|
|
|
|
|
class Address extends Model
|
|
|
|
|
{
|
|
|
|
|
use ScopeActive,SoftDeletes;
|
|
|
|
|
const CACHE_KEY = 15;
|
|
|
|
|
use QueryCacheableConfig,ScopeActive,SoftDeletes;
|
|
|
|
|
const CACHE_KEY = 0;
|
|
|
|
|
|
|
|
|
|
private const LOGKEY = 'MA-';
|
|
|
|
|
|
|
|
|
@@ -798,39 +797,37 @@ class Address extends Model
|
|
|
|
|
*/
|
|
|
|
|
public function children(): Collection
|
|
|
|
|
{
|
|
|
|
|
return Cache::remember(sprintf('children-%d',$this->id),self::CACHE_KEY,function() {
|
|
|
|
|
// If we are a point, our parent is the boss
|
|
|
|
|
switch ($this->role_id) {
|
|
|
|
|
case self::NODE_NN: // Normal Nodes -> Points
|
|
|
|
|
return $this->nodes_point;
|
|
|
|
|
// If we are a point, our parent is the boss
|
|
|
|
|
switch ($this->role_id) {
|
|
|
|
|
case self::NODE_NN: // Normal Nodes -> Points
|
|
|
|
|
return $this->nodes_point;
|
|
|
|
|
|
|
|
|
|
case self::NODE_HC: // Hubs -> Normal Nodes
|
|
|
|
|
return $this->nodes_hub;
|
|
|
|
|
case self::NODE_HC: // Hubs -> Normal Nodes
|
|
|
|
|
return $this->nodes_hub;
|
|
|
|
|
|
|
|
|
|
case self::NODE_NC: // Nets -> Normal Nodes, excluding Hub's Nodes
|
|
|
|
|
return $this->nodes_net->diff($this
|
|
|
|
|
->nodes_net
|
|
|
|
|
->filter(function($item) { return $item->role_id === Address::NODE_HC; })
|
|
|
|
|
->transform(function($item) { return $item->children(); })
|
|
|
|
|
->flatten());
|
|
|
|
|
case self::NODE_NC: // Nets -> Normal Nodes, excluding Hub's Nodes
|
|
|
|
|
return $this->nodes_net->diff($this
|
|
|
|
|
->nodes_net
|
|
|
|
|
->filter(function($item) { return $item->role_id === Address::NODE_HC; })
|
|
|
|
|
->transform(function($item) { return $item->children(); })
|
|
|
|
|
->flatten());
|
|
|
|
|
|
|
|
|
|
case self::NODE_RC: // Regions, excluding NC's Nodes
|
|
|
|
|
return $this->nodes_region->diff($this
|
|
|
|
|
->nodes_region
|
|
|
|
|
->filter(function($item) { return $item->role_id === Address::NODE_NC; })
|
|
|
|
|
->transform(function($item) { return $item->nodes_net; })
|
|
|
|
|
->flatten());
|
|
|
|
|
case self::NODE_RC: // Regions, excluding NC's Nodes
|
|
|
|
|
return $this->nodes_region->diff($this
|
|
|
|
|
->nodes_region
|
|
|
|
|
->filter(function($item) { return $item->role_id === Address::NODE_NC; })
|
|
|
|
|
->transform(function($item) { return $item->nodes_net; })
|
|
|
|
|
->flatten());
|
|
|
|
|
|
|
|
|
|
case self::NODE_ZC: // Zones, excluding RC's Nodes
|
|
|
|
|
return $this->nodes_zone->diff($this
|
|
|
|
|
->nodes_zone
|
|
|
|
|
->filter(function($item) { return $item->role_id === Address::NODE_RC; })
|
|
|
|
|
->transform(function($item) { return $item->nodes_region; })
|
|
|
|
|
->flatten());
|
|
|
|
|
}
|
|
|
|
|
case self::NODE_ZC: // Zones, excluding RC's Nodes
|
|
|
|
|
return $this->nodes_zone->diff($this
|
|
|
|
|
->nodes_zone
|
|
|
|
|
->filter(function($item) { return $item->role_id === Address::NODE_RC; })
|
|
|
|
|
->transform(function($item) { return $item->nodes_region; })
|
|
|
|
|
->flatten());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return new Collection;
|
|
|
|
|
});
|
|
|
|
|
return new Collection;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
@@ -943,38 +940,36 @@ class Address extends Model
|
|
|
|
|
*/
|
|
|
|
|
private function ftn_role(): ?int
|
|
|
|
|
{
|
|
|
|
|
return Cache::remember(sprintf('ftn_role-%d',$this->id),self::CACHE_KEY,function() {
|
|
|
|
|
$role = NULL;
|
|
|
|
|
$role = NULL;
|
|
|
|
|
|
|
|
|
|
// If we have a point address, we're a point
|
|
|
|
|
if ($this->point_id)
|
|
|
|
|
$role = self::NODE_POINT;
|
|
|
|
|
// If we have a point address, we're a point
|
|
|
|
|
if ($this->point_id)
|
|
|
|
|
$role = self::NODE_POINT;
|
|
|
|
|
|
|
|
|
|
// If we have a node_id, we're either a Node or a Hub
|
|
|
|
|
elseif ($this->node_id) {
|
|
|
|
|
$role = ($this->nodes_hub->count())
|
|
|
|
|
? self::NODE_HC
|
|
|
|
|
: ((($this->role & Address::NODE_ALL) === self::NODE_HC) ? self::NODE_HC : self::NODE_NN);
|
|
|
|
|
// If we have a node_id, we're either a Node or a Hub
|
|
|
|
|
elseif ($this->node_id) {
|
|
|
|
|
$role = ($this->nodes_hub->count())
|
|
|
|
|
? self::NODE_HC
|
|
|
|
|
: ((($this->role & Address::NODE_ALL) === self::NODE_HC) ? self::NODE_HC : self::NODE_NN);
|
|
|
|
|
|
|
|
|
|
// point_id and node_id are zero
|
|
|
|
|
// If our region_id !== host_id, and are not zero, and node_id/point_id === 0, we are an NC
|
|
|
|
|
} elseif (($this->region_id !== $this->host_id) && $this->host_id) {
|
|
|
|
|
$role = self::NODE_NC;
|
|
|
|
|
// point_id and node_id are zero
|
|
|
|
|
// If our region_id !== host_id, and are not zero, and node_id/point_id === 0, we are an NC
|
|
|
|
|
} elseif (($this->region_id !== $this->host_id) && $this->host_id) {
|
|
|
|
|
$role = self::NODE_NC;
|
|
|
|
|
|
|
|
|
|
// point_id and node_id are zero
|
|
|
|
|
} elseif (($this->region_id === $this->host_id) && $this->host_id) {
|
|
|
|
|
$role = self::NODE_RC;
|
|
|
|
|
// point_id and node_id are zero
|
|
|
|
|
} elseif (($this->region_id === $this->host_id) && $this->host_id) {
|
|
|
|
|
$role = self::NODE_RC;
|
|
|
|
|
|
|
|
|
|
// point_id and node_id are zero
|
|
|
|
|
} elseif (($this->region_id === $this->host_id) && (! $this->host_id)) {
|
|
|
|
|
$role = self::NODE_ZC;
|
|
|
|
|
}
|
|
|
|
|
// point_id and node_id are zero
|
|
|
|
|
} elseif (($this->region_id === $this->host_id) && (! $this->host_id)) {
|
|
|
|
|
$role = self::NODE_ZC;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (is_null($role))
|
|
|
|
|
Log::alert(sprintf('%s:! Address ROLE [%d] could not be determined for [%s]',self::LOGKEY,($this->role & Address::NODE_ALL),$this->ftn));
|
|
|
|
|
if (is_null($role))
|
|
|
|
|
Log::alert(sprintf('%s:! Address ROLE [%d] could not be determined for [%s]',self::LOGKEY,($this->role & Address::NODE_ALL),$this->ftn));
|
|
|
|
|
|
|
|
|
|
return $role;
|
|
|
|
|
});
|
|
|
|
|
return $role;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|