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