fix(upgrade): run Activator on version mismatch via plugins_loaded#37
Open
fix(upgrade): run Activator on version mismatch via plugins_loaded#37
Conversation
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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
register_activation_hookon 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 schemaActivator::maybe_upgrade()that comparesget_option('escalated_version')againstESCALATED_VERSIONand re-runsactivate()on mismatchactivate()is already idempotent (dbDelta, upsert loops, exists-guards), so re-running is safeplugins_loadedahead ofboot()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
Test_Activator.php:maybe_upgrade()is a no-op when the stored version matches currentmaybe_upgrade()re-runsactivate()when the stored version differsmaybe_upgrade()re-runsactivate()when the option is missing entirely (fresh install)maybe_upgradetable presence matches the expected behavior