Fix point address assignment
This commit is contained in:
parent
0473808e67
commit
ae46dee24e
@ -173,24 +173,42 @@ class SystemController extends Controller
|
||||
'required',
|
||||
new TwoByteInteger,
|
||||
function ($attribute,$value,$fail) use ($request) {
|
||||
// Check that the region doesnt already exist
|
||||
if ($request->point_id === 0) {
|
||||
// Check that the host doesnt already exist
|
||||
$o = Address::where(function($query) use ($request,$value) {
|
||||
return $query
|
||||
->where('zone_id',$request->post('zone_id'))
|
||||
->where('host_id',$request->post('host_id'))
|
||||
->where('node_id',$value)
|
||||
->where('point_id',0);
|
||||
});
|
||||
|
||||
if ($o->count()) {
|
||||
$fail(sprintf('Host already exists: %s',$o->get()->pluck('ftn')->join(',')));
|
||||
}
|
||||
}
|
||||
},
|
||||
],
|
||||
'point_id' => [
|
||||
'required',
|
||||
function($attribute,$value,$fail) use ($request) {
|
||||
if (! is_numeric($value) || $value > DomainController::NUMBER_MAX)
|
||||
$fail(sprintf('Point numbers must be between 0 and %d',DomainController::NUMBER_MAX));
|
||||
|
||||
// Check that the host doesnt already exist
|
||||
$o = Address::where(function($query) use ($request,$value) {
|
||||
return $query
|
||||
->where('zone_id',$request->post('zone_id'))
|
||||
->where('host_id',$request->post('host_id'))
|
||||
->where('node_id',$value)
|
||||
->where('point_id',0);
|
||||
->where('node_id',$request->post('node_id'))
|
||||
->where('point_id',$value);
|
||||
});
|
||||
|
||||
if ($o->count()) {
|
||||
$fail(sprintf('Host already exists: %s',$o->get()->pluck('ftn')->join(',')));
|
||||
$fail(sprintf('Point already exists: %s',$o->get()->pluck('ftn')->join(',')));
|
||||
}
|
||||
},
|
||||
}
|
||||
],
|
||||
'point_id' => ['required',function($attribute,$value,$fail) {
|
||||
if (! is_numeric($value) || $value > DomainController::NUMBER_MAX)
|
||||
$fail(sprintf('Point numbers must be between 0 and %d',DomainController::NUMBER_MAX));
|
||||
}],
|
||||
'hub' => 'required|boolean',
|
||||
'hub_id' => 'nullable|exists:addresses,id',
|
||||
]);
|
||||
@ -202,7 +220,7 @@ class SystemController extends Controller
|
||||
$oo->node_id = $request->post('node_id');
|
||||
$oo->point_id = $request->post('point_id');
|
||||
$oo->hub_id = $request->post('hub_id') > 0 ? $request->post('hub_id') : NULL;
|
||||
$oo->role = ((! $oo->point_id) && $request->post('hub')) ? Address::NODE_HC : Address::NODE_ACTIVE;
|
||||
$oo->role = ((! $oo->point_id) && $request->post('hub')) ? Address::NODE_HC : ($request->post('point_id') ? Address::NODE_POINT : Address::NODE_ACTIVE);
|
||||
$oo->active = TRUE;
|
||||
|
||||
$o->addresses()->save($oo);
|
||||
|
Loading…
Reference in New Issue
Block a user