38 lines
1.2 KiB
PHP
38 lines
1.2 KiB
PHP
<?php
|
|
|
|
namespace App\Console\Commands;
|
|
|
|
use App\Services\Mne\CompatibilityBackfill;
|
|
use Illuminate\Console\Command;
|
|
use Illuminate\Support\Facades\DB;
|
|
|
|
final class BackfillMneCompatibility extends Command
|
|
{
|
|
protected $signature = 'mne:backfill-compatibility {--batch=100} {--dry-run : Execute validation and roll back all changes}';
|
|
|
|
protected $description = 'Reconcile compatibility identifiers without copying canonical business records';
|
|
|
|
public function handle(CompatibilityBackfill $backfill): int
|
|
{
|
|
$batch = filter_var($this->option('batch'), FILTER_VALIDATE_INT, ['options' => ['min_range' => 1, 'max_range' => 1000]]);
|
|
if ($batch === false) {
|
|
$this->error('Batch must be between 1 and 1000');
|
|
|
|
return self::FAILURE;
|
|
}
|
|
if ($this->option('dry-run')) {
|
|
DB::beginTransaction();
|
|
try {
|
|
$counts = $backfill->run($batch);
|
|
} finally {
|
|
DB::rollBack();
|
|
}
|
|
$this->line(json_encode(['dry_run' => true, 'rolled_back' => true, 'counts' => $counts], JSON_THROW_ON_ERROR));
|
|
} else {
|
|
$this->line(json_encode($backfill->run($batch), JSON_THROW_ON_ERROR));
|
|
}
|
|
|
|
return self::SUCCESS;
|
|
}
|
|
}
|