Repository navigation
fix: guard CLI cleanup and DB viewer with wp_presence_has_table() - #257
aldorizona10-glitch wants to merge 1 commit into
Conversation
The WP-CLI `cleanup` command and the debug DB viewer were the only two read/write paths that queried the presence table directly without first checking wp_presence_has_table(). Every other path in functions.php and the REST controller guards on it and degrades to an empty result; these two would surface a raw wpdb error if the table were ever missing. In practice cli_init / admin_init provision the table before either can run, so this is a consistency fix rather than a live bug (as noted in WordPress#210, deliberately left out of WordPress#203 to keep that change scoped). - db-viewer.php: wrap the SELECT/COUNT queries; when the table is absent, fall back to an empty row set and a zero count. The template already renders an empty state ("No entries."), so no markup changes are needed. - cli cleanup(): short-circuit to a "0 entries deleted" success before the destructive DELETE (and before the confirmation prompt, since there is nothing to delete). Fixes WordPress#210 ## Use of AI Tools AI assistance: Yes Tool(s): Claude Code Model(s): Claude Opus 4.8 Used for: Investigating the guard pattern and drafting the change
|
The following accounts have interacted with this PR and/or linked issues. I will continue to update these lists as activity occurs. You can also manually ask me to refresh this list by adding the Core Committers: Use this line as a base for the props when committing in SVN: To understand the WordPress project's expectations around crediting contributors, please review the Contributor Attribution page in the Core Handbook. |
▶ Preview in WordPress PlaygroundBoots a fresh WordPress with this PR's presence-api build, seeds 5 demo users, and drops you on the dashboard. Stress-test variant: 40 demo users · Built from |
Codecov Report❌ Patch coverage is ❌ Your patch check has failed because the patch coverage (0.00%) is below the target coverage (80.00%). You can increase the patch coverage or adjust the target coverage. Additional details and impacted files@@ Coverage Diff @@
## main #257 +/- ##
============================================
- Coverage 72.51% 72.39% -0.12%
- Complexity 175 176 +1
============================================
Files 14 14
Lines 1819 1822 +3
============================================
Hits 1319 1319
- Misses 500 503 +3
Flags with carried forward coverage won't be shown. Click here to find out more. 🚀 New features to boost your workflow:
|
|
@i-am-chitti you're right, and apologies for the duplication. I went straight to a PR without commenting on #210 to claim it first, which is exactly what CONTRIBUTING asks — that's on me. Since you called it first and already had it written, I'll close this in favor of your PR. I'll comment to claim before starting next time. Thanks for the nudge. |
|
Thanks @aldorizona10-glitch for the graceful close. We'd independently landed on almost the same guard, which was oddly reassuring. |
What & why
Resolves #210. The WP-CLI
cleanupcommand (includes/cli/class-wp-presence-cli-command.php) and the debug DB viewer (includes/db-viewer.php) were the only two paths that hit the presence table directly without awp_presence_has_table()check. Every other read/write path infunctions.phpand the REST controller guards on it and degrades to an empty result, so these two were the last places that would surface a rawwpdberror if the table were ever missing.As #210 notes,
cli_init/admin_initprovision the table before either can run, so this is a consistency fix, not a live bug — it was deliberately left out of #203 to keep that change scoped.Changes
db-viewer.php— wrap theSELECT/COUNT(*)queries in the availability check; when the table is absent, fall back to an empty row set and a zero count. The template already renders an empty state (No entries.) and the timestampforeachisempty()-guarded, so no markup changes are needed.clicleanup()— short-circuit to a0 entries deleted.success before the destructiveDELETE(and before the confirmation prompt, since there is nothing to delete).No new strings, no schema changes, no behavior change on a provisioned site.
Testing
WP-CLI is not loaded in the PHPUnit suite and CLI coverage is being handled separately (#218 / #256), so I've kept this change focused on the guards rather than adding CLI-invoking tests here. Happy to add coverage if you'd prefer a particular approach.
Use of AI Tools
AI assistance: Yes
Tool(s): Claude Code
Model(s): Claude Opus 4.8
Used for: Investigating the guard pattern and drafting the change