Debugging to try and catch address creation exception (because of two active addresses)

This commit is contained in:
Deon George 2023-09-04 14:15:53 +12:00
parent 61582fa4da
commit 1e17aed170
2 changed files with 12 additions and 6 deletions

View File

@ -133,7 +133,7 @@ class Node
// Ignore any duplicate FTNs that we get
if ($this->ftns->search(function($item) use ($value) { return $item->id === $value->id; }) !== FALSE) {
Log::debug(sprintf('%s: - Ignoring Duplicate FTN [%s]',__METHOD__,$value->ftn));
Log::debug(sprintf('%s:- Ignoring Duplicate FTN [%s]',self::LOGKEY,$value->ftn));
break;
}
@ -144,7 +144,7 @@ class Node
case 'ftn_other':
// Ignore any duplicate FTNs that we get
if ($this->ftns_other->search($value) !== FALSE) {
Log::debug(sprintf('%s: - Ignoring Duplicate FTN [%s]',__METHOD__,$value));
Log::debug(sprintf('%s:- Ignoring Duplicate FTN [%s]',self::LOGKEY,$value));
break;
}

View File

@ -419,7 +419,7 @@ class Address extends Model
return $o;
}
$o = (new self)
$o = ($x=(new self)
->select('addresses.*')
->join('zones',['zones.id'=>'addresses.zone_id'])
->join('domains',['domains.id'=>'zones.domain_id'])
@ -447,7 +447,7 @@ class Address extends Model
})
->when((! $ftn['d']),function($query) {
$query->where('zones.default',TRUE);
})
}))
->single();
if ($create) {
@ -500,8 +500,14 @@ class Address extends Model
$o->host_id = $ftn['n'];
$o->node_id = $ftn['f'];
$o->point_id = $ftn['p'];
$o->role = self::NODE_UNKNOWN;
$o->role = $ftn['p'] ? self::NODE_POINT : self::NODE_UNKNOWN;
try {
$so->addresses()->save($o);
} catch (\Exception $e) {
Log::error(sprintf('%s:! ERROR creating address [%s] (%s)',self::LOGKEY,$x->toSql(),get_class($e)),['bindings'=>$x->getBindings()]);
return NULL;
}
}
return ($o && $o->system->active) ? $o : NULL;