Make --dbname and --dbuser optional when SQLite integration is active#219
Make --dbname and --dbuser optional when SQLite integration is active#219
--dbname and --dbuser optional when SQLite integration is active#219Conversation
Codecov Report✅ All modified and coverable lines are covered by tests. 📢 Thoughts on this report? Let us know! |
…n and skip MySQL check for SQLite Agent-Logs-Url: https://github.com/wp-cli/config-command/sessions/8f9ece6b-b44b-4ac7-87e2-35bad2b2afff Co-authored-by: swissspidy <841956+swissspidy@users.noreply.github.com>
--dbname and --dbuser optional when SQLite integration is active
There was a problem hiding this comment.
Pull request overview
Updates wp config create to support SQLite-backed WordPress installs by allowing --dbname / --dbuser to be omitted when an SQLite integration drop-in is detected.
Changes:
- Make
--dbnameand--dbuseroptional in the command synopsis. - Detect SQLite integration via
wp-content/db.phpand conditionally skip MySQL parameter validation and MySQLi connection checks. - Add a Behat scenario to validate config creation without MySQL credentials when the SQLite drop-in is present.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 3 comments.
| File | Description |
|---|---|
src/Config_Command.php |
Adds SQLite drop-in detection, conditional required-parameter validation, and bypasses MySQLi check when SQLite is active. |
features/config-create.feature |
Adds a Behat scenario for creating config without --dbname/--dbuser when an SQLite drop-in is present. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| if ( empty( $assoc_args['dbname'] ) ) { | ||
| WP_CLI::error( 'Parameter errors:' . PHP_EOL . 'missing --dbname parameter (Set the database name.)' ); | ||
| } | ||
| if ( empty( $assoc_args['dbuser'] ) ) { | ||
| WP_CLI::error( 'Parameter errors:' . PHP_EOL . 'missing --dbuser parameter (Set the database user.)' ); | ||
| } |
There was a problem hiding this comment.
Current validation for missing --dbname/--dbuser changes behavior compared to WP-CLI’s synopsis validation: (1) using empty() will incorrectly reject values like --dbuser=0, and (2) calling WP_CLI::error() per-field exits on the first missing parameter so you never report both missing options together. Consider collecting missing parameters into an array and emitting a single Parameter errors: message, and check for presence/empty-string rather than empty().
| if ( empty( $assoc_args['dbname'] ) ) { | |
| WP_CLI::error( 'Parameter errors:' . PHP_EOL . 'missing --dbname parameter (Set the database name.)' ); | |
| } | |
| if ( empty( $assoc_args['dbuser'] ) ) { | |
| WP_CLI::error( 'Parameter errors:' . PHP_EOL . 'missing --dbuser parameter (Set the database user.)' ); | |
| } | |
| $param_errors = []; | |
| if ( ! array_key_exists( 'dbname', $assoc_args ) || $assoc_args['dbname'] === '' ) { | |
| $param_errors[] = 'missing --dbname parameter (Set the database name.)'; | |
| } | |
| if ( ! array_key_exists( 'dbuser', $assoc_args ) || $assoc_args['dbuser'] === '' ) { | |
| $param_errors[] = 'missing --dbuser parameter (Set the database user.)'; | |
| } | |
| if ( ! empty( $param_errors ) ) { | |
| WP_CLI::error( 'Parameter errors:' . PHP_EOL . implode( PHP_EOL, $param_errors ) ); | |
| } |
| if ( file_exists( $db_dropin_path ) ) { | ||
| $db_dropin_contents = file_get_contents( $db_dropin_path, false, null, 0, 8192 ); |
There was a problem hiding this comment.
file_get_contents() can emit PHP warnings (e.g., if wp-content/db.php exists but is not readable), which would leak noise into CLI output. Consider adding an is_readable() guard and/or suppressing warnings and handling failures explicitly to keep output clean.
| if ( file_exists( $db_dropin_path ) ) { | |
| $db_dropin_contents = file_get_contents( $db_dropin_path, false, null, 0, 8192 ); | |
| if ( is_readable( $db_dropin_path ) ) { | |
| // Suppress potential warnings and handle failure explicitly to keep CLI output clean. | |
| $db_dropin_contents = @file_get_contents( $db_dropin_path, false, null, 0, 8192 ); |
| define( 'SQLITE_DB_DROPIN_VERSION', '1.0.0' ); | ||
| """ | ||
|
|
||
| When I run `wp config create --skip-salts --skip-check` |
There was a problem hiding this comment.
This scenario includes --skip-check, so it doesn’t actually exercise the new behavior of bypassing the MySQLi connection check when SQLite is detected. To cover the new branch, run wp config create without --skip-check (while still omitting --dbname/--dbuser) and assert it succeeds.
| When I run `wp config create --skip-salts --skip-check` | |
| When I run `wp config create --skip-salts` |
wp config createunconditionally requires--dbnameand--dbuser, making it impossible to create a config for a SQLite-backed WordPress install without supplying MySQL credentials that will never be used.Changes
--dbnameand--dbuserare now[--dbname]/[--dbuser]in the docblock synopsis.is_sqlite_integration_active()checks forSQLITE_DB_DROPIN_VERSIONinwp-content/db.php(reads first 8 KB only).--dbnameor--dbuserstill produces an explicit error — existing MySQL/MariaDB behaviour is unchanged.mysqliconnection check is bypassed entirely when SQLite is detected, so--skip-checkis not required.@require-sqliteBehat scenario: Verifieswp config createsucceeds without--dbname/--dbuserwhen the SQLite drop-in is present.