Skip to content

Commit 93be0b6

Browse files
Copilotswissspidy
andcommitted
Fix sqlite_import() passing array instead of string to Process::create()
The command_parts array was being passed directly to \WP_CLI\Process::create() which requires a string command. This caused proc_open() to fail with "expects parameter 1 to be string, array given". Also fixes the .read argument: sqlite3 expects ".read FILENAME" as a single quoted argument, not as two separate arguments. Co-authored-by: swissspidy <841956+swissspidy@users.noreply.github.com>
1 parent 54be7a7 commit 93be0b6

1 file changed

Lines changed: 7 additions & 6 deletions

File tree

src/DB_Command_SQLite.php

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -445,18 +445,19 @@ protected function sqlite_import( $file, $assoc_args ) {
445445
}
446446

447447
$command_parts[] = $db_path;
448-
$command_parts[] = '.read';
449-
$command_parts[] = $import_file;
450448

451-
// Build debug-friendly command string without using shell redirection.
452-
$debug_command = Utils\esc_cmd(
449+
// Build a properly escaped string command. Process::create() requires a string, not an array.
450+
$command = Utils\esc_cmd(
453451
implode( ' ', array_fill( 0, count( $command_parts ), '%s' ) ),
454452
...$command_parts
455453
);
456454

457-
WP_CLI::debug( "Running shell command: {$debug_command}", 'db' );
455+
// Pass the .read dot-command as a single quoted argument (sqlite3 reads it as SQL input).
456+
$command .= ' ' . escapeshellarg( '.read ' . $import_file );
458457

459-
$result = \WP_CLI\Process::create( $command_parts, null, null )->run();
458+
WP_CLI::debug( "Running shell command: {$command}", 'db' );
459+
460+
$result = \WP_CLI\Process::create( $command, null, null )->run();
460461
unlink( $import_file );
461462

462463
if ( 0 !== $result->return_code ) {

0 commit comments

Comments
 (0)