Implement 2D domain processing - mainly for fidonet

This commit is contained in:
2023-09-10 22:48:12 +10:00
parent ed7dc2ab8b
commit 673c444acd
8 changed files with 148 additions and 25 deletions

View File

@@ -402,7 +402,7 @@ class Address extends Model
return $q
->where(function($q) use ($ftn) {
return $q->where('region_id',$ftn['n'])
->where('host_id',0);
->where('host_id',$ftn['n']);
});
})
->where('node_id',$ftn['f'])
@@ -433,7 +433,7 @@ class Address extends Model
return $q->where(function($qq) use ($ftn) {
return $qq
->where('region_id',$ftn['n'])
->where('host_id',0);
->where('host_id',$ftn['n']);
})
->orWhere(function($qq) use ($ftn) {
return $qq
@@ -513,6 +513,50 @@ class Address extends Model
return ($o && $o->system->active) ? $o : NULL;
}
/**
* This is to find an address for a domain (like fidonet), which is technically 2D even though it uses multiple zones.
*
* This was implemented to identify seenby and path kludges
*
* @param Domain $do
* @param int $host
* @param int $node
* @param bool $trashed
* @return self|null
* @throws \Exception
*/
public static function findZone(Domain $do,int $host,int $node,bool $trashed=FALSE): ?self
{
if (! $do->flatten)
throw new \Exception(sprintf('Domain is not set with flatten: %d',$do->id));
$zones = $do->zones->pluck('zone_id');
$o = (new self)
->select('addresses.*')
->join('zones',['zones.id'=>'addresses.zone_id'])
//->join('domains',['domains.id'=>'zones.domain_id'])
->when($trashed,function($query) {
$query->trashed();
},function($query) {
$query->active();
})
->whereIN('zones.zone_id',$zones)
->where(function($q) use ($host) {
return $q
->where(function($q) use ($host) {
return $q->where('region_id',$host)
->where('host_id',$host);
})
->orWhere('host_id',$host);
})
->where('node_id',$node)
->where('zones.domain_id',$do->id)
->single();
return $o;
}
/**
* Create an activation code for this address
*