Skip to content

fix(upgrade): run Activator on version mismatch via plugins_loaded#37

Open
mpge wants to merge 2 commits intomainfrom
fix/plugin-upgrade-path
Open

fix(upgrade): run Activator on version mismatch via plugins_loaded#37
mpge wants to merge 2 commits intomainfrom
fix/plugin-upgrade-path

Conversation

@mpge
Copy link
Copy Markdown
Member

@mpge mpge commented Apr 24, 2026

Summary

  • WordPress only fires register_activation_hook on the one-time activation event, not on auto-update or upload-overwrite upgrades, so existing installs end up running new plugin code against an old schema
  • Adds Activator::maybe_upgrade() that compares get_option('escalated_version') against ESCALATED_VERSION and re-runs activate() on mismatch
  • activate() is already idempotent (dbDelta, upsert loops, exists-guards), so re-running is safe
  • Wires it into plugins_loaded ahead of boot()

Why now

Flagged in the public-ticket-system rollout status doc as a pre-existing infrastructure gap. Surfaced because the public-ticket-system PR series introduces several rounds of schema and permission changes, so existing installs would otherwise silently miss them.

Test plan

  • Adds three unit tests to Test_Activator.php:
    • maybe_upgrade() is a no-op when the stored version matches current
    • maybe_upgrade() re-runs activate() when the stored version differs
    • maybe_upgrade() re-runs activate() when the option is missing entirely (fresh install)
  • Each test drops a table and asserts post-maybe_upgrade table presence matches the expected behavior

mpge added 2 commits April 24, 2026 12:35
WordPress only fires register_activation_hook on the one-time activation
event — not on auto-update or on upload-overwrite upgrades. That means
existing installs that receive new plugin code (e.g. new tables, new
permission rows, new cron events) never get the schema seeded.

Add Activator::maybe_upgrade() that compares get_option('escalated_version')
against ESCALATED_VERSION and re-runs activate() on mismatch. activate()
is already idempotent (dbDelta, upsert loops, exists-guards), so
re-running on every version bump is safe.

Wire it into the plugins_loaded hook so it fires ahead of boot().
WP_UnitTestCase rewrites DROP TABLE -> DROP TEMPORARY TABLE via its
query filter, but dbDelta in the Activator uses a different path, so
the tables are real, not temporary. That mismatch made the original
drop-and-reactivate assertion flaky.

Use a settings-row sentinel instead: deleting the
'ticket_reference_prefix' row proves insert_default_settings() ran (or
didn't) without fighting the test framework's table rewriter.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant