diff --git a/app/Http/Controllers/SystemController.php b/app/Http/Controllers/SystemController.php index 9637aed..6aad27f 100644 --- a/app/Http/Controllers/SystemController.php +++ b/app/Http/Controllers/SystemController.php @@ -3,6 +3,7 @@ namespace App\Http\Controllers; use Carbon\Carbon; +use Illuminate\Database\QueryException; use Illuminate\Http\Request; use Illuminate\Support\Arr; use Illuminate\Support\Collection; @@ -13,7 +14,7 @@ use Illuminate\Support\Facades\Notification; use Illuminate\Support\ViewErrorBag; use App\Classes\FTN\Message; -use App\Http\Requests\{AreafixRequest,SystemRegister}; +use App\Http\Requests\{AddressMerge,AreafixRequest,SystemRegister}; use App\Jobs\AddressPoll; use App\Models\{Address,Echoarea,Filearea,Netmail,Setup,System,SystemZone,Zone}; use App\Notifications\Netmails\AddressLink; @@ -315,6 +316,81 @@ class SystemController extends Controller ->with('o',$o); } + public function address_merge(AddressMerge $request,int $id) + { + if ($request->validated()) { + DB::beginTransaction(); + + // Find all echomail seenbys + $x = DB::update('update echomail_seenby set address_id=? where address_id=?',[$request->dst,$request->src]); + + // Find all echomail paths + $x = DB::update('update echomail_path set address_id=? where address_id=?',[$request->dst,$request->src]); + + // Find all echomails + $x = DB::update('update echomails set fftn_id=? where fftn_id=?',[$request->dst,$request->src]); + + // Find all netmails + $x = DB::update('update netmails set fftn_id=? where fftn_id=?',[$request->dst,$request->src]); + + // Find all netmails + $x = DB::update('update netmails set tftn_id=? where tftn_id=?',[$request->dst,$request->src]); + + // Find all nodelist + $x = DB::update('update address_nodelist set address_id=? where address_id=?',[$request->dst,$request->src]); + + // Find all file seenbys + $x = DB::update('update file_seenby set address_id=? where address_id=?',[$request->dst,$request->src]); + + // Find all files + $x = DB::update('update files set fftn_id=? where fftn_id=?',[$request->dst,$request->src]); + + $src = Address::withTrashed()->findOrFail($request->src); + + // Resubscribe echoareas + try { + $x = DB::update('update address_echoarea set address_id=? where address_id=?',[$request->dst,$request->src]); + + } catch (QueryException $e) { + DB::rollback(); + + return back()->withInput()->withErrors('error',sprintf('You may need to remove %s:%s (%d) from echoareas',$src->ftn,$src->system->name,$src->id)); + } + + // Resubscribe fileareas + try { + $x = DB::update('update address_filearea set address_id=? where address_id=?',[$request->dst,$request->src]); + + } catch (QueryException $e) { + DB::rollback(); + + return back()->withInput()->withErrors('error',sprintf('You may need to remove %s:%s (%d) from fileareas',$src->ftn,$src->system->name,$src->id)); + } + + if ($src->forceDelete()) { + DB::commit(); + return redirect()->to('address/merge/'.$request->dst); + + } else { + return back()->withInput()->withErrors('error',sprintf('Address [%s] didnt delete?',$src->ftn)); + DB::rollBack(); + } + } + $o = Address::withTrashed() + ->findOrFail($id); + + $oo = Address::withTrashed() + ->where('zone_id',$o->zone_id) + ->where('host_id',$o->host_id) + ->where('node_id',$o->node_id) + ->where('point_id',$o->point_id) + ->get(); + + return view('system/address-merge') + ->with('o',$o) + ->with('oo',$oo); + } + public function api_address(Request $request,System $o): Collection { return Address::select(['addresses.id','addresses.zone_id','region_id','host_id','node_id','point_id']) diff --git a/app/Http/Requests/AddressMerge.php b/app/Http/Requests/AddressMerge.php new file mode 100644 index 0000000..3949b42 --- /dev/null +++ b/app/Http/Requests/AddressMerge.php @@ -0,0 +1,51 @@ +isMethod('post')) + return []; + + return [ + 'src' => [ + 'required', + 'exists:addresses,id', + ], + 'dst' => [ + 'required', + 'exists:addresses,id', + 'different:src', + function ($attribute,$value,$fail) use ($request) { + $dst = Address::withTrashed()->findOrFail($value); + $src = Address::withTrashed()->findOrFail($request->src); + + if ((! $dst->active) && ($dst->system_id !== $src->system_id) && ($src->system->name !== 'Discovered System')) + $fail('Destination must be active, or be from the system system'); + }, + function ($attribute,$value,$fail) use ($request) { + $dst = Address::withTrashed()->findOrFail($value); + $src = Address::withTrashed()->findOrFail($request->src); + + if ($src->ftn !== $dst->ftn) + $fail('Source and Destination must be the same FTN'); + }, + ], + ]; + } +} \ No newline at end of file diff --git a/resources/views/error.blade.php b/resources/views/error.blade.php new file mode 100644 index 0000000..94c8091 --- /dev/null +++ b/resources/views/error.blade.php @@ -0,0 +1,12 @@ + + @if($errors->count()) + + There were errors with the submission. + + + @endif + \ No newline at end of file diff --git a/resources/views/system/address-merge.blade.php b/resources/views/system/address-merge.blade.php new file mode 100644 index 0000000..d00dfcc --- /dev/null +++ b/resources/views/system/address-merge.blade.php @@ -0,0 +1,70 @@ + +@extends('layouts.app') + +@section('htmlheader_title') + Address Merge +@endsection + +@section('content') +
+
+

Merge Address {{ $o->ftn }}

+

{{ $o->system->sysop }} : {{ $o->system->name }}

+
+ +
+
+ @csrf + + + + + + + + + + + + + + + @foreach ($oo as $ao) + + + + + + + + + @endforeach + +
FTIDFTNACTIVEMessages
{{ $ao->id }} {{ $ao->system_id }}:{{ $ao->system->name }}{{ $ao->ftn }} + @if($ao->trashed()) + + + @else + + + + @endif + +
    + @foreach(\App\Models\Echomail::select(['id','msgid','from','msg']) + ->where('fftn_id',$ao->id) + ->orderBy('created_at','DESC') + ->limit(5) + ->get() as $eo) +
  • {{ sprintf('%04d: %s (%s) %s',$eo->id,$eo->from,$eo->msgid,$eo->msg) }}
  • + @endforeach +
+
+ + +
+
+ + @include('error') +
+@endsection \ No newline at end of file diff --git a/routes/web.php b/routes/web.php index aa43570..a997f10 100644 --- a/routes/web.php +++ b/routes/web.php @@ -129,6 +129,7 @@ Route::middleware(['auth','verified','activeuser'])->group(function () { }); Route::middleware(['auth','can:admin'])->group(function () { + Route::match(['get','post'],'address/merge/{id}',[SystemController::class,'address_merge']); Route::get('echomail/view/{o}',[EchomailController::class,'view']); Route::get('netmail/view/{o}',[NetmailController::class,'view']); Route::get('user/list',[UserController::class,'home']);