Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit f231dc9

Browse files
committed
[IM] Include closed customers on interface wizard
1 parent 852b4fe commit f231dc9

3 files changed

Lines changed: 26 additions & 288 deletions

File tree

app/Http/Controllers/Interfaces/VirtualInterfaceController.php

Lines changed: 23 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323
* http://www.gnu.org/licenses/gpl-2.0.html
2424
*/
2525

26-
use DB;
26+
use Illuminate\Support\Facades\DB;
2727
use Exception;
2828
use Former;
2929

@@ -309,17 +309,16 @@ public function update( StoreVirtualInterface $r, VirtualInterface $vi ): Redire
309309
AlertContainer::push( 'Virtual Interface updated.', Alert::SUCCESS );
310310
return redirect( route( 'virtual-interface@edit', [ 'vi' => $vi->id ] ) );
311311
}
312-
312+
313313
/**
314314
* Display the wizard form to add a virtual interface
315315
*
316-
* @param Customer|null $cust Id of the customer to preselect
316+
* @param Customer|null $cust Id of the customer to preselect
317317
*
318318
* @return View
319-
*
320-
* @throws
319+
* @throws JsonException
321320
*/
322-
public function wizard( Customer $cust = null ): View
321+
public function wizard( ?Customer $cust ): View
323322
{
324323
if( $cust ) {
325324
Former::populate( [
@@ -328,48 +327,55 @@ public function wizard( Customer $cust = null ): View
328327
}
329328

330329
return view( 'interfaces/virtual/wizard' )->with([
331-
'custs' => CustomerAggregator::reformatNameWithDetail( Customer::trafficking()->current()->orderBy('name')->get() ),
330+
'custs' => CustomerAggregator::reformatNameWithDetail( Customer::trafficking()->orderBy('name')->get() ),
332331
'vli' => false,
333332
'vlans' => Vlan::orderBy( 'number' )->get(),
334333
'pi_switches' => Switcher::where( 'active', true )
335334
->orderBy( 'name' )->get(),
336335
'resoldCusts' => $this->resellerMode() ? json_encode( Customer::join('cust AS reseller', 'reseller.reseller', 'cust.id')
337336
->orderBy('reseller.name')->get(), JSON_THROW_ON_ERROR) : json_encode([], JSON_THROW_ON_ERROR),
338-
'selectedCust' => $cust ?: false
337+
'selectedCust' => $cust ?? false
339338
]);
340339
}
341-
340+
342341
/**
343342
* Create an interface wizard
344343
*
345-
* @param StoreVirtualInterfaceWizard $r instance of the current HTTP request
344+
* @param StoreVirtualInterfaceWizard $r instance of the current HTTP request
346345
*
347346
* @return RedirectResponse
347+
* @throws Throwable
348348
*/
349349
public function storeWizard( StoreVirtualInterfaceWizard $r ): RedirectResponse
350350
{
351+
DB::beginTransaction();
352+
351353
$v = Vlan::find( $r->vlanid );
354+
352355
$vi = VirtualInterface::create( $r->all() );
353-
356+
354357
PhysicalInterface::create( array_merge( $r->all(), [
355358
'virtualinterfaceid' => $vi->id,
356359
] ) );
357-
360+
358361
SwitchPort::find( $r->switchportid )->update( [ 'type' => SwitchPort::TYPE_PEERING ] );
359-
362+
360363
$vli = VlanInterface::make( array_merge( $r->all(),
361364
[
362365
'virtualinterfaceid' => $vi->id,
363366
'busyhost' => false
364367
]
365368
) );
366-
369+
367370
if( !$this->setIp( $r, $v, $vli, false ) || !$this->setIp( $r, $v, $vli, true ) ) {
368-
return redirect(route( 'virtual-interface@wizard' ) )->withInput( $r->all() );
371+
DB::rollBack();
372+
return redirect( route( 'virtual-interface@wizard' ) )->withInput( $r->all() );
369373
}
370-
374+
371375
$vli->save();
372-
376+
377+
DB::commit();
378+
373379
// add a warning if we're filtering on irrdb but have not configured one for the customer
374380
$this->warnIfIrrdbFilteringButNoIrrdbSourceSet( $vli );
375381

0 commit comments

Comments
 (0)