Skip to content

Events Store: Scope table install check to the current database - #539

Merged
rebeccahum merged 3 commits into
mainfrom
rebz0rz/scope-table-install-check
Nov 13, 2026
Merged

rebeccahum merged 3 commits into
mainfrom
rebz0rz/scope-table-install-check

Conversation

@rebeccahum

Copy link
Copy Markdown
Contributor

Description

Events_Store::is_installed() counted information_schema.tables rows for the table name across every schema the DB user can see, and required exactly one. When another database on the same server has a table with the same name, the count is 2, so the plugin never treats itself as installed: every runner command re-runs the install, exits with "Cron Control installation completed. Please try again.", and no events run. Both checks now use a table_exists() helper scoped to TABLE_SCHEMA = DATABASE(), which HyperDB still routes by table name.

Steps to Test

  1. Run the PHPUnit suite as a DB user that can create databases (CI uses root).
  2. test_is_installed_ignores_same_named_table_in_other_database creates the same table in a second database and expects is_installed() to stay true. It fails without this change.

🤖 Generated with Claude Code

is_installed() counted information_schema rows for the table name across
every schema the DB user can see, and required exactly one. A same-named
table in another database on the same server made the count 2, so the
plugin never considered itself installed and re-ran the install on every
request instead of handling cron.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@github-actions

Copy link
Copy Markdown

Dependency Review

✅ No vulnerabilities or license issues or OpenSSF Scorecard issues found.

Scanned Files

None

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 Changes recommended

The test can unconditionally drop a pre-existing database and disrupt parallel runs because it uses a fixed database name without confirming exclusive creation.

1 open issue
What changed in this PR

This PR scopes Events Store installation checks to the current database, preventing same-named tables in other databases from triggering repeated installation attempts and blocking event execution.

Changes:

  • Adds a shared table_exists() helper filtered by TABLE_SCHEMA = DATABASE() for both installation checks.
  • Adds a regression test with a same-named table in a second database.
File Description
includes/​class-events-store.php Centralizes table detection and limits it to the current database.
__tests__/​unit-tests/​test-events-store.php Tests that a same-named table in another database does not affect installation detection.

Review effort: Balanced

Create the second database with a per-run name and plain CREATE DATABASE,
and drop it in finally, so the test only removes a database it created and
parallel runs don't collide.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

@sjinks sjinks left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Two issues in the new regression test affect isolation and whether it exercises the intended case.

CREATE DATABASE, CREATE TABLE and DROP DATABASE implicitly commit, which
ended the test's transaction and made setUp() writes survive the rollback.
Run them on a separate connection instead, and assert the same-named table
was created so the test can't pass without the case it covers.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@rebeccahum
rebeccahum requested a review from sjinks November 12, 2026 20:53
@rebeccahum
rebeccahum merged commit 5fe8b93 into main Nov 13, 2026
17 checks passed
@rebeccahum
rebeccahum deleted the rebz0rz/scope-table-install-check branch November 13, 2026 15:03
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.

3 participants