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

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

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;
$so->addresses()->save($o);
$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;