Skip to content

Fix activation fatal when leftover wp_stream_db < 3.0.8 (XWPENG-22) - #1969

Open
shadyvb wants to merge 6 commits into
developfrom
fix/xwpeng-22-activation-fatal
Open

Fix activation fatal when leftover wp_stream_db < 3.0.8 (XWPENG-22)#1969
shadyvb wants to merge 6 commits into
developfrom
fix/xwpeng-22-activation-fatal

Conversation

@shadyvb

@shadyvb shadyvb commented Aug 21, 2026

Copy link
Copy Markdown
Contributor

Fixes XWPENG-22.

Base branch: develop

Activating or loading Stream fatals on PHP 8.2+ when a leftover wp_stream_db site option is older than 3.0.8. Install::check() runs inside Plugin::__construct() before $GLOBALS['wp_stream'] (and $plugin->install) exist, so wp_stream_update_auto_308() / _300() called wp_stream_get_instance()->install->install() on null.

This passes the in-construction Install instance from Install::update() into those auto-migration callbacks and uses it for install() when the third argument is a WP_Stream\Install instance. Full 3.0.0 / 3.0.8 schema work still runs (Install::install() / dbDelta).

Commits on this branch

  1. Leftover wp_stream_db migration fix — Pass Install into auto-migration callbacks so activation/bootstrap does not call wp_stream_get_instance()->install before the plugin global exists.
  2. PHP 8.2 / 8.3 CI — Add PHP 8.2 and 8.3 to CI and local Docker switch-to scripts (default local/Docker PHP remains 7.4).
  3. Action Scheduler guards (617e4036) — When an outdated Action Scheduler copy is already in memory, Stream no longer fatals on missing as_has_scheduled_action() / other as_* APIs. AS_Scheduler function_exists()-guards those calls.
  4. Two Factor login guard (5fe97c0c) — Guard failed-login logging when the user cannot be resolved (avoids fatals during Two Factor flows).
  5. wp_stream_get_instance() null guard (9af8a570) — Guard callers when the plugin global is not set.
  6. PHPUnit Install coverage — Tests for empty wp_stream_db during construction (AC 9 clean install) and leftover 3.0.0 (auto_308 path only). Tests for wp_stream_db < 3.0.0 are intentionally skipped so auto_300 cannot RENAME/DROP the PHPUnit schema.

Sub-issue #3 (uninstall) — Skipped in this PR.

Checklist

  • Project documentation has been updated to reflect the changes in this pull request, if applicable.
  • I have tested the changes in the local development environment (see contributing.md).
  • I have added phpunit tests.

Release Changelog

  • Fix: Fatal error on activation when a leftover Stream database version older than 3.0.8 is present.
  • Fix: Fatal error when an outdated Action Scheduler copy is loaded and as_has_scheduled_action() (or other as_* APIs) are missing.
  • Fix: Fatals when Two Factor failed-login logging cannot resolve a user.
  • Fix: Fatals when code calls wp_stream_get_instance() before the plugin global is set.

Release checklist (version bumps, readme.txt, GitHub release) applies at release time, not in this PR.

Test plan

  • PHPUnit Test_Install (single-site and multisite): leftover wp_stream_db=3.0.7 during construction does not fatal; schema includes user_role.
  • PHPUnit Test_Install: empty wp_stream_db during construction installs (AC 9); leftover 3.0.0 uses auto_308 path without fatal.
  • Local WP-CLI: deactivate Stream, set site option wp_stream_db to 3.0.7, network-activate stream-src — succeeds, option becomes current plugin version, no new debug.log lines.
  • Confirm Network Admin → Plugins shows Stream active (no “triggered a fatal error” notice).
  • Confirm Stream → Records loads after leftover-migration bootstrap.
  • CI lint and e2e matrix rows for PHP 7.4 (default image tag latest), 8.2, and 8.3 all pass. Default local/Docker PHP remains 7.4.
  • PHPUnit Test_AS_Scheduler (single-site and multisite): enqueue / recurring / next_scheduled / unschedule when bundled AS is present.
  • Local WP-CLI: stub ActionScheduler class with no as_* functions, then has_scheduled / schedule_recurring / enqueue_async / next_scheduled — no fatal; methods no-op or return false.

Change [ ] to [x] to mark the items as done.

Pass the in-construction Install instance into auto-migration callbacks so wp_stream_update_auto_300/308 no longer call install() via wp_stream_get_instance() before the plugin global exists.
Keep the default WordPress image at PHP 7.4 so activation coverage on 8.2/8.3 does not change local or composer defaults.
Skip as_* APIs that an older in-memory Action Scheduler never defined,
matching the existing unschedule_all / any_pending_or_running guards.
…d (XWPENG-22)

Skip callback_wp_login_failed after get_user_by() returns false so a two_factor_
error cannot read display_name or ID on a non-object.
…ENG-22)

Return null without an undefined-variable Warning if the helper runs
before Plugin construction assigns $GLOBALS['wp_stream'].
… Install construction (XWPENG-22)

Cover the AC 9 clean-install path and leftover 3.0.0 (auto_308 only). Skip wp_stream_db < 3.0.0 so auto_300 cannot RENAME/DROP the test schema.
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