-
Notifications
You must be signed in to change notification settings - Fork 80
Open
Description
Problem
The current subscription migration system (class-angelleye-paypal-ppcp-migration.php) has critical issues:
- Infinite loop bug — Subscriptions with missing payment tokens (e.g., empty
_payment_tokens_id,_ppec_billing_agreement_id) are reprocessed indefinitely since there's no mechanism to mark them as permanently failed. - No state tracking — No lifecycle states for migration progress; impossible to distinguish pending vs completed vs failed subscriptions.
- Order note spam — Each failed retry adds duplicate notes, polluting subscription history with thousands of identical entries.
- No HPOS compatibility — Migration queries don't support WooCommerce High-Performance Order Storage.
- Monolithic architecture — All logic in a single 648-line class with no separation of concerns, no dependency injection, and no tests.
Solution
Refactor into a modular service-based architecture:
- Migration_Controller — Facade/orchestrator with public API (start, stats, retry, reset)
- Subscription_Migration_Service — Core migration logic with proper error handling
- Action_Scheduler_Batch_Processor — Queue management with batch limits and delays
- Payment_Token_Validator — Validates 4 token meta keys with format checking
- Payment_Method_Updater — Handles payment method switching
- HPOS_Migration_State_Storage — HPOS-compatible state persistence
- Migration_Status enum — Categorized statuses:
COMPLETED,FAILED_NO_TOKEN,FAILED_API_ERROR,FAILED_DATA_ERROR,SKIPPED_EXCLUDED,SKIPPED_MANUAL - DTOs —
Migration_Result,Batch_Result,Migration_Stats - Migration_Admin_Page — Dashboard with real-time progress, failure counts by type, retry/reset controls
- Test suite — Unit and integration tests
Key behavioral changes
- Subscriptions get lifecycle states:
NOT_STARTED → IN_PROGRESS → COMPLETED/FAILED_* - Failed subscriptions are categorized and skipped on next run (no infinite loop)
- Order notes only added on first failure attempt
- HPOS auto-detection for compatible storage queries
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
No labels