-
Notifications
You must be signed in to change notification settings - Fork 38
Make --dbname and --dbuser optional when SQLite integration is active
#219
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -120,10 +120,10 @@ private static function get_initial_locale() { | |||||||||||||||||||||||||||||||||||||||
| * | ||||||||||||||||||||||||||||||||||||||||
| * ## OPTIONS | ||||||||||||||||||||||||||||||||||||||||
| * | ||||||||||||||||||||||||||||||||||||||||
| * --dbname=<dbname> | ||||||||||||||||||||||||||||||||||||||||
| * [--dbname=<dbname>] | ||||||||||||||||||||||||||||||||||||||||
| * : Set the database name. | ||||||||||||||||||||||||||||||||||||||||
| * | ||||||||||||||||||||||||||||||||||||||||
| * --dbuser=<dbuser> | ||||||||||||||||||||||||||||||||||||||||
| * [--dbuser=<dbuser>] | ||||||||||||||||||||||||||||||||||||||||
| * : Set the database user. | ||||||||||||||||||||||||||||||||||||||||
| * | ||||||||||||||||||||||||||||||||||||||||
| * [--dbpass=<dbpass>] | ||||||||||||||||||||||||||||||||||||||||
|
|
@@ -219,6 +219,18 @@ public function create( $_, $assoc_args ) { | |||||||||||||||||||||||||||||||||||||||
| 'ssl' => false, | ||||||||||||||||||||||||||||||||||||||||
| ]; | ||||||||||||||||||||||||||||||||||||||||
| $assoc_args = array_merge( $defaults, $assoc_args ); | ||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||
| $is_sqlite = self::is_sqlite_integration_active(); | ||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||
| if ( ! $is_sqlite ) { | ||||||||||||||||||||||||||||||||||||||||
| 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.)' ); | ||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||
|
Comment on lines
+226
to
+231
|
||||||||||||||||||||||||||||||||||||||||
| 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 ) ); | |
| } |
Copilot
AI
Apr 2, 2026
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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 ); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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, runwp config createwithout--skip-check(while still omitting--dbname/--dbuser) and assert it succeeds.