Added an address merge UI page
This commit is contained in:
@@ -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'])
|
||||
|
51
app/Http/Requests/AddressMerge.php
Normal file
51
app/Http/Requests/AddressMerge.php
Normal file
@@ -0,0 +1,51 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Requests;
|
||||
|
||||
use Illuminate\Foundation\Http\FormRequest;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Support\Facades\Gate;
|
||||
|
||||
use App\Models\Address;
|
||||
|
||||
class AddressMerge extends FormRequest
|
||||
{
|
||||
protected $stopOnFirstFailure = TRUE;
|
||||
|
||||
public function authorize()
|
||||
{
|
||||
return Gate::allows( 'admin');
|
||||
}
|
||||
|
||||
public function rules(Request $request)
|
||||
{
|
||||
if (! $request->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');
|
||||
},
|
||||
],
|
||||
];
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user