BadgeReconciler
\Benecaster\Membership\BadgeReconciler
Keeps each subscriber’s badge grants in sync with tier badge definitions. Hooks into benecaster_subscription_tier_changed, benecaster_token_generated, benecaster_token_type_changed (a follower promoted to a paying subscriber in place), and admin_init (one-shot backfill on first activation). Manages only tier_auto grant rows — never modifies manual rows. Tokens of a TokenRepository::PAYING_EXEMPT_TOKEN_TYPES type (followers and purchasers) contribute no tier_auto badges, whatever their tier_slug — so a native tier sharing the follower feed’s slug does not hand its badges to followers.
A purchaser is the one exempt type that is not simply skipped. Their token row is active, but they are a cancelled member: the token survived only because they bought something. They earn no new badges, and each badge’s Keep after cancellation setting decides what they keep, exactly as for a revoked subscriber. Skipping them outright would leave a cancelled buyer with fewer badges than a cancelled non-buyer.
Methods
| Method | Visibility | Since | Description |
|---|---|---|---|
reconcile_for_user( int $user_id ): void |
Public | — | Idempotent. Resolves active native-tier tokens (excluding PAYING_EXEMPT_TOKEN_TYPES), computes the expected tier_auto badge set, then inserts missing grants and deletes grants no longer applicable. User-level, not show-scoped. |
on_tier_changed( int $user_id, int $show_id, string $old_tier_slug, string $new_tier_slug ): void |
Public | — | Listener on benecaster_subscription_tier_changed. Calls reconcile_for_user() for the affected user. |
on_token_generated( object $token ): void |
Public | — | Listener on benecaster_token_generated. Calls reconcile_for_user() so a freshly-created subscription gets its tier's badges immediately. |
on_token_type_changed( int $user_id, int $show_id, string $old_type, string $new_type ): void |
Public | — | Listener on benecaster_token_type_changed. Calls reconcile_for_user() so a follower promoted to a paying subscriber receives that tier's badges at once. |
maybe_run_initial_sync(): void |
Public | — | Hooked on admin_init. Runs the one-shot backfill across all existing subscribers when the stored INITIAL_SYNC_OPTION value is behind INITIAL_SYNC_VERSION, then updates the stored value. Bumping INITIAL_SYNC_VERSION re-runs the backfill once on every install, which is how grants that a rule change made wrong get deleted. |
Constants
| Name | Value | Description |
|---|---|---|
INITIAL_SYNC_OPTION |
'benecaster_badge_initial_sync_done' |
Option name storing the version of the backfill that has already run. |
INITIAL_SYNC_VERSION |
'2' |
Current backfill version. Raising it forces the one-shot backfill to run again on every install. |