Skip to content

Commit b16d2fa

Browse files
Copilotswissspidy
andauthored
Improve SQLite detection robustness; update synopsis descriptions; add Behat scenario for missing dbname/dbuser
Agent-Logs-Url: https://github.com/wp-cli/config-command/sessions/53294434-a981-4597-8efc-1a642de88b29 Co-authored-by: swissspidy <841956+swissspidy@users.noreply.github.com>
1 parent a63c91a commit b16d2fa

2 files changed

Lines changed: 34 additions & 8 deletions

File tree

features/config-create.feature

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -163,6 +163,27 @@ Feature: Create a wp-config file
163163
Error: Database connection error
164164
"""
165165
166+
@require-mysql
167+
Scenario: Missing --dbname or --dbuser without SQLite integration
168+
Given an empty directory
169+
And WP files
170+
171+
When I try `wp config create --skip-check --dbuser=someuser`
172+
Then the return code should be 1
173+
And STDERR should contain:
174+
"""
175+
Error: Parameter errors:
176+
missing --dbname parameter (Set the database name.)
177+
"""
178+
179+
When I try `wp config create --skip-check --dbname=somedb`
180+
Then the return code should be 1
181+
And STDERR should contain:
182+
"""
183+
Error: Parameter errors:
184+
missing --dbuser parameter (Set the database user.)
185+
"""
186+
166187
@require-mysql
167188
Scenario: Configure with database credentials using socket path
168189
Given an empty directory

src/Config_Command.php

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -121,10 +121,10 @@ private static function get_initial_locale() {
121121
* ## OPTIONS
122122
*
123123
* [--dbname=<dbname>]
124-
* : Set the database name.
124+
* : Set the database name. Required unless the SQLite integration drop-in is detected.
125125
*
126126
* [--dbuser=<dbuser>]
127-
* : Set the database user.
127+
* : Set the database user. Required unless the SQLite integration drop-in is detected.
128128
*
129129
* [--dbpass=<dbpass>]
130130
* : Set the database user password.
@@ -1505,14 +1505,19 @@ private static function is_sqlite_integration_active() {
15051505
$wp_content_dir = defined( 'WP_CONTENT_DIR' ) ? WP_CONTENT_DIR : ABSPATH . 'wp-content';
15061506
$db_dropin_path = $wp_content_dir . '/db.php';
15071507

1508-
if ( file_exists( $db_dropin_path ) ) {
1509-
$db_dropin_contents = file_get_contents( $db_dropin_path, false, null, 0, 8192 );
1510-
if ( false !== $db_dropin_contents && false !== strpos( $db_dropin_contents, 'SQLITE_DB_DROPIN_VERSION' ) ) {
1511-
return true;
1512-
}
1508+
if ( ! is_file( $db_dropin_path ) || ! is_readable( $db_dropin_path ) ) {
1509+
return false;
1510+
}
1511+
1512+
$db_dropin_contents = file_get_contents( $db_dropin_path, false, null, 0, 8192 );
1513+
if ( false === $db_dropin_contents ) {
1514+
return false;
15131515
}
15141516

1515-
return false;
1517+
return 1 === preg_match(
1518+
'/\b(?:define\s*\(\s*[\'"]SQLITE_DB_DROPIN_VERSION[\'"]|const\s+SQLITE_DB_DROPIN_VERSION\b)/',
1519+
$db_dropin_contents
1520+
);
15161521
}
15171522

15181523
/**

0 commit comments

Comments
 (0)