find_one($customerId); if (!$customer) { echo "❌ Customer ID $customerId not found\n"; $errorCount++; continue; } echo "Deleting: ID $customerId - {$customer['username']} ({$customer['fullname']})... "; // Double-check: Verify no relationships exist $hasRelations = false; // Check tbl_user_recharges $recharges = ORM::for_table('tbl_user_recharges')->where('customer_id', $customerId)->count(); if ($recharges > 0) { echo "❌ HAS RELATIONS (tbl_user_recharges: $recharges records) - SKIPPING\n"; $errorCount++; continue; } // Check tbl_transactions $transactions = ORM::for_table('tbl_transactions')->where('username', $customer['username'])->count(); if ($transactions > 0) { echo "❌ HAS RELATIONS (tbl_transactions: $transactions records) - SKIPPING\n"; $errorCount++; continue; } // Check tbl_customers_fields $fields = ORM::for_table('tbl_customers_fields')->where('customer_id', $customerId)->count(); if ($fields > 0) { echo "❌ HAS RELATIONS (tbl_customers_fields: $fields records) - SKIPPING\n"; $errorCount++; continue; } // Check tbl_payment_gateway $payments = ORM::for_table('tbl_payment_gateway')->where('username', $customer['username'])->count(); if ($payments > 0) { echo "❌ HAS RELATIONS (tbl_payment_gateway: $payments records) - SKIPPING\n"; $errorCount++; continue; } // Safe to delete - proceed with deletion $customer->delete(); echo "✅ DELETED\n"; $deletedCount++; } catch (Exception $e) { echo "❌ ERROR: " . $e->getMessage() . "\n"; $errorCount++; } } echo "\n=== DELETION SUMMARY ===\n"; echo "Total customers processed: " . count($customersToDelete) . "\n"; echo "Successfully deleted: $deletedCount\n"; echo "Errors/Skipped: $errorCount\n"; if ($deletedCount > 0) { echo "\n✅ Deletion completed successfully!\n"; echo "Removed $deletedCount orphaned customers from the database.\n"; } else { echo "\n⚠️ No customers were deleted.\n"; } echo "\n=== VERIFICATION ===\n"; $remainingCustomers = ORM::for_table('tbl_customers')->count(); echo "Remaining customers in database: $remainingCustomers\n"; echo "\n=== DELETION COMPLETE ===\n"; ?>