@@ -382,32 +382,23 @@ protected function sqlite_import( $file, $assoc_args ) {
382382 WP_CLI ::error ( 'Database does not exist. ' );
383383 }
384384
385- $ import_file = $ file ;
385+ $ contents = ( string ) file_get_contents ( $ file ) ;
386386
387387 if ( '- ' === $ file ) {
388- $ sql = file_get_contents ( 'php://stdin ' );
389- if ( false === $ sql ) {
388+ $ contents = file_get_contents ( 'php://stdin ' );
389+ if ( false === $ contents ) {
390390 WP_CLI ::error ( 'Failed to read from stdin. ' );
391391 }
392392
393- $ import_file = tempnam ( sys_get_temp_dir (), 'temp.db ' );
394-
395- if ( false === $ import_file ) {
396- WP_CLI ::error ( 'Failed to read from stdin. ' );
397- }
398-
399- file_put_contents ( $ import_file , $ sql );
400393 $ file = 'STDIN ' ;
401394 } elseif ( ! is_readable ( $ file ) ) {
402395 WP_CLI ::error ( sprintf ( 'Import file missing or not readable: %s ' , $ file ) );
403396 }
404397
405398 // Ignore errors about unique constraints and existing indexes.
406- $ contents = (string ) file_get_contents ( $ import_file );
407399 $ contents = str_replace ( 'INSERT INTO ' , 'INSERT OR IGNORE INTO ' , $ contents );
408400 $ contents = str_replace ( 'CREATE INDEX " ' , 'CREATE INDEX IF NOT EXISTS " ' , $ contents );
409401 $ contents = str_replace ( 'CREATE UNIQUE INDEX " ' , 'CREATE UNIQUE INDEX IF NOT EXISTS " ' , $ contents );
410- file_put_contents ( $ import_file , $ contents );
411402
412403 // Build sqlite3 command as an argument array to avoid shell injection.
413404 $ command = array ( 'sqlite3 ' );
0 commit comments