2022-11-19 11:15:08 +00:00
|
|
|
<?php
|
|
|
|
|
2024-05-27 05:08:39 +00:00
|
|
|
namespace App\Console\Commands\Debug;
|
2022-11-19 11:15:08 +00:00
|
|
|
|
|
|
|
use Illuminate\Console\Command;
|
2022-11-20 00:47:46 +00:00
|
|
|
use Illuminate\Database\QueryException;
|
2022-11-19 11:15:08 +00:00
|
|
|
use Illuminate\Support\Facades\DB;
|
|
|
|
|
2023-09-15 12:57:32 +00:00
|
|
|
use App\Models\{Address,System};
|
2022-11-20 00:47:46 +00:00
|
|
|
|
|
|
|
class AddressMerge extends Command
|
2022-11-19 11:15:08 +00:00
|
|
|
{
|
2023-06-27 07:39:11 +00:00
|
|
|
/**
|
|
|
|
* The name and signature of the console command.
|
|
|
|
*
|
|
|
|
* @var string
|
|
|
|
*/
|
2024-05-27 05:08:39 +00:00
|
|
|
protected $signature = 'debug:address:merge'
|
2022-11-19 11:15:08 +00:00
|
|
|
.' {src : Source Address}'
|
|
|
|
.' {dst : Destination Address}'
|
2022-11-20 00:47:46 +00:00
|
|
|
.' {--F|force : Force}'
|
|
|
|
.' {--I|ignore : Ignore different BBSes}'
|
2022-11-19 11:15:08 +00:00
|
|
|
.' {--d|dryrun : Dry Run}';
|
|
|
|
|
2023-06-27 07:39:11 +00:00
|
|
|
/**
|
|
|
|
* The console command description.
|
|
|
|
*
|
|
|
|
* @var string
|
|
|
|
*/
|
|
|
|
protected $description = 'Permanently remove a duplicate address';
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Execute the console command.
|
|
|
|
*
|
|
|
|
* @return int
|
|
|
|
*/
|
2024-05-27 05:08:39 +00:00
|
|
|
public function handle(): int
|
2023-06-27 07:39:11 +00:00
|
|
|
{
|
2022-11-19 11:15:08 +00:00
|
|
|
$src = Address::withTrashed()->findOrfail($this->argument('src'));
|
|
|
|
$dst = Address::withTrashed()->findOrfail($this->argument('dst'));
|
|
|
|
|
2023-09-15 12:57:32 +00:00
|
|
|
if ((! $this->option('ignore')) && ($src->system_id !== $dst->system_id) && ($src->system->name !== System::default)) {
|
2022-11-19 11:15:08 +00:00
|
|
|
$this->error(sprintf('FTN addresses are from different systems (%s/%s)',$src->system->name,$dst->system->name));
|
2024-05-27 05:08:39 +00:00
|
|
|
|
|
|
|
return self::FAILURE;
|
2022-11-19 11:15:08 +00:00
|
|
|
}
|
|
|
|
|
2022-11-20 00:47:46 +00:00
|
|
|
if ((! $this->option('force')) && ($src->ftn !== $dst->ftn)) {
|
2022-11-19 11:15:08 +00:00
|
|
|
$this->error(sprintf('FTN addresses are not the same (%s:%s)',$src->ftn,$dst->ftn));
|
2024-05-27 05:08:39 +00:00
|
|
|
|
|
|
|
return self::FAILURE;
|
2022-11-19 11:15:08 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if ($src->active) {
|
|
|
|
$this->error(sprintf('Source [%s] is still active',$src->ftn));
|
2024-05-27 05:08:39 +00:00
|
|
|
|
|
|
|
return self::FAILURE;
|
2022-11-19 11:15:08 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
DB::beginTransaction();
|
|
|
|
|
|
|
|
// Find all echomail seenbys
|
2024-05-27 05:08:39 +00:00
|
|
|
$x = DB::update('UPDATE echomail_seenby SET address_id=? WHERE address_id=?',[$dst->id,$src->id]);
|
2022-11-19 11:15:08 +00:00
|
|
|
$this->info(sprintf('Updated [%d] echomail seenby records',$x));
|
|
|
|
|
|
|
|
// Find all echomail paths
|
2024-05-27 05:08:39 +00:00
|
|
|
$x = DB::update('UPDATE echomail_path SET address_id=? WHERE address_id=?',[$dst->id,$src->id]);
|
2022-11-19 11:15:08 +00:00
|
|
|
$this->info(sprintf('Updated [%d] echomail path records',$x));
|
|
|
|
|
|
|
|
// Find all echomails
|
2024-05-27 05:08:39 +00:00
|
|
|
$x = DB::update('UPDATE echomails SET fftn_id=? WHERE fftn_id=?',[$dst->id,$src->id]);
|
2022-11-19 11:15:08 +00:00
|
|
|
$this->info(sprintf('Updated [%d] echomail source records',$x));
|
|
|
|
|
|
|
|
// Find all netmails
|
2024-05-27 05:08:39 +00:00
|
|
|
$x = DB::update('UPDATE netmails SET fftn_id=? WHERE fftn_id=?',[$dst->id,$src->id]);
|
2022-11-19 11:15:08 +00:00
|
|
|
$this->info(sprintf('Updated [%d] netmail source records',$x));
|
|
|
|
|
|
|
|
// Find all netmails
|
2024-05-27 05:08:39 +00:00
|
|
|
$x = DB::update('UPDATE netmails SET tftn_id=? WHERE tftn_id=?',[$dst->id,$src->id]);
|
2022-11-19 11:15:08 +00:00
|
|
|
$this->info(sprintf('Updated [%d] netmail destination records',$x));
|
|
|
|
|
|
|
|
// Find all nodelist
|
2024-05-27 05:08:39 +00:00
|
|
|
$x = DB::update('UPDATE address_nodelist SET address_id=? WHERE address_id=?',[$dst->id,$src->id]);
|
2022-11-19 11:15:08 +00:00
|
|
|
$this->info(sprintf('Updated [%d] nodelist records',$x));
|
|
|
|
|
|
|
|
// Find all file seenbys
|
2024-05-27 05:08:39 +00:00
|
|
|
$x = DB::update('UPDATE file_seenby SET address_id=? WHERE address_id=?',[$dst->id,$src->id]);
|
2022-11-19 11:15:08 +00:00
|
|
|
$this->info(sprintf('Updated [%d] file seenby records',$x));
|
|
|
|
|
|
|
|
// Find all files
|
2024-05-27 05:08:39 +00:00
|
|
|
$x = DB::update('UPDATE files SET fftn_id=? WHERE fftn_id=?',[$dst->id,$src->id]);
|
2022-11-19 11:15:08 +00:00
|
|
|
$this->info(sprintf('Updated [%d] file source records',$x));
|
|
|
|
|
2022-11-20 00:47:46 +00:00
|
|
|
// Resubscribe echoareas
|
|
|
|
try {
|
2024-05-27 05:08:39 +00:00
|
|
|
$x = DB::update('UPDATE address_echoarea SET address_id=? WHERE address_id=?',[$dst->id,$src->id]);
|
2022-11-20 00:47:46 +00:00
|
|
|
|
|
|
|
} catch (QueryException $e) {
|
|
|
|
DB::rollback();
|
|
|
|
$this->error(sprintf('You may need to remove %s:%s (%d) from echoareas',$src->ftn,$src->system->name,$src->id));
|
2024-05-27 05:08:39 +00:00
|
|
|
|
|
|
|
return self::FAILURE;
|
2022-11-20 00:47:46 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
$this->info(sprintf('Updated [%d] echomail subscription records',$x));
|
|
|
|
|
|
|
|
// Resubscribe fileareas
|
|
|
|
try {
|
2024-05-27 05:08:39 +00:00
|
|
|
$x = DB::update('UPDATE address_filearea SET address_id=? WHERE address_id=?',[$dst->id,$src->id]);
|
2022-11-20 00:47:46 +00:00
|
|
|
} catch (QueryException $e) {
|
|
|
|
DB::rollback();
|
|
|
|
$this->error(sprintf('You may need to remove %s:%s (%d) from fileareas',$src->ftn,$src->system->name,$src->id));
|
2024-05-27 05:08:39 +00:00
|
|
|
|
|
|
|
return self::FAILURE;
|
2022-11-20 00:47:46 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
$this->info(sprintf('Updated [%d] filearea subscription records',$x));
|
|
|
|
|
2022-11-19 11:15:08 +00:00
|
|
|
if ($this->option('dryrun')) {
|
|
|
|
$this->warn(sprintf('NOT deleting [%s] - DRY RUN',$src->ftn));
|
|
|
|
DB::rollBack();
|
|
|
|
|
|
|
|
} else {
|
|
|
|
if ($src->forceDelete()) {
|
2024-05-27 05:08:39 +00:00
|
|
|
$this->alert(sprintf('%s deleted.',$src->ftn));
|
2022-11-19 11:15:08 +00:00
|
|
|
DB::commit();
|
|
|
|
|
|
|
|
} else {
|
|
|
|
$this->warn(sprintf('Address [%s] didnt delete?',$src->ftn));
|
|
|
|
DB::rollBack();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2024-05-27 05:08:39 +00:00
|
|
|
return self::SUCCESS;
|
2023-06-27 07:39:11 +00:00
|
|
|
}
|
|
|
|
}
|