Commit 4806bcdc authored by Mahmoud Aglan's avatar Mahmoud Aglan

feat(subscriptions): comprehensive data migration and validation service

Adds SubscriptionDataMigration service that:
- Fixes orphaned person_id references (matched wrong ID to dependent)
- Removes exact duplicate subscription rows
- Corrects zero/wrong amounts using historical rate table
- Creates missing subscriptions for all members from join date to present
- Applies overdue fines proportionally per SubscriptionCalculator rules

CLI commands:
  php cli.php subscriptions:migrate          Run the migration
  php cli.php subscriptions:migrate --dry-run Preview changes
  php cli.php subscriptions:validate         Check data integrity
Co-Authored-By: 's avatarClaude Opus 4.6 <noreply@anthropic.com>
parent 7e05dc96
......@@ -146,6 +146,53 @@ switch ($command) {
}
break;
case 'subscriptions:migrate':
$dryRun = in_array('--dry-run', $argv);
echo "📋 Subscription Data Migration" . ($dryRun ? " (DRY RUN)" : "") . "\n";
echo str_repeat('─', 50) . "\n";
$app = \App\Core\App::getInstance();
$app->setDb($db);
$app->boot();
$migration = new \App\Modules\Subscriptions\Services\SubscriptionDataMigration($db);
$result = $migration->run($dryRun);
echo " Members processed: {$result['members_processed']}\n";
echo " Subscriptions created: {$result['subscriptions_created']}\n";
echo " Orphaned IDs fixed: {$result['orphaned_ids_fixed']}\n";
echo " Duplicates removed: {$result['duplicates_removed']}\n";
echo " Amount corrections: {$result['amount_corrections']}\n";
echo " Fines applied: {$result['fines_applied']}\n";
if (!empty($result['errors'])) {
echo "\n ⚠️ Errors:\n";
foreach ($result['errors'] as $err) {
echo " - {$err}\n";
}
}
echo "\n✅ " . ($dryRun ? "Dry run complete. No changes made." : "Migration complete.") . "\n";
break;
case 'subscriptions:validate':
echo "🔍 Subscription Data Validation\n";
echo str_repeat('─', 50) . "\n";
$app = \App\Core\App::getInstance();
$app->setDb($db);
$app->boot();
$migration = new \App\Modules\Subscriptions\Services\SubscriptionDataMigration($db);
$issues = $migration->validate();
if (empty($issues)) {
echo " ✅ All subscription data is consistent.\n";
} else {
foreach ($issues as $issue) {
echo " ⚠️ [{$issue['type']}] — {$issue['count']} issue(s)\n";
}
}
break;
case 'routes':
$app = \App\Core\App::getInstance();
$app->boot();
......@@ -311,6 +358,9 @@ switch ($command) {
echo " php cli.php seed Run all pending seeds\n";
echo " php cli.php seed:run <Name> Run specific seed\n";
echo " php cli.php cron Run background jobs\n";
echo " php cli.php subscriptions:migrate Run subscription data migration\n";
echo " php cli.php subscriptions:migrate --dry-run Preview without changes\n";
echo " php cli.php subscriptions:validate Validate subscription data integrity\n";
echo " php cli.php routes List all routes\n";
echo " php cli.php export:book Generate Book of the ERP PDF\n";
echo " php cli.php permissions:orphans Registered but unused permissions\n";
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment