From c391c6663f944f1c82d62ca23ed0f3123cd8c2f6 Mon Sep 17 00:00:00 2001 From: Sandeep Dahiya Date: Wed, 23 Jul 2025 15:33:02 +0530 Subject: [PATCH 1/2] Fix: Skip sandbox line in MariaDB dump files during import --- src/DB_Command.php | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/src/DB_Command.php b/src/DB_Command.php index fe4d0f49..b7186311 100644 --- a/src/DB_Command.php +++ b/src/DB_Command.php @@ -816,6 +816,27 @@ public function import( $args, $assoc_args ) { if ( ! is_readable( $result_file ) ) { WP_CLI::error( sprintf( 'Import file missing or not readable: %s', $result_file ) ); } + + // Check for MariaDB sandbox directive and skip it if found + $first_line = fgets( fopen( $result_file, 'r' ) ); + if ( strpos( $first_line, '/*!999999\\' ) !== false ) { + WP_CLI::debug( 'MariaDB sandbox directive found. Creating sanitized temp file.', 'db' ); + + $input = fopen( $result_file, 'r' ); + $tmp = tmpfile(); + $tmp_path = stream_get_meta_data( $tmp )['uri']; + + $line_number = 0; + while ( ( $line = fgets( $input ) ) !== false ) { + if ( $line_number > 0 ) { + fwrite( $tmp, $line ); + } + $line_number++; + } + fclose( $input ); + + $result_file = $tmp_path; + } $query = Utils\get_flag_value( $assoc_args, 'skip-optimization' ) ? 'SOURCE %s;' From 28a9dd74351feff58b3d733b8d1953af9befe0bd Mon Sep 17 00:00:00 2001 From: Sandeep Dahiya Date: Wed, 23 Jul 2025 15:54:00 +0530 Subject: [PATCH 2/2] Fix: Correct indentation, alignment, and increment usage in MariaDB sandbox check --- src/DB_Command.php | 42 ++++++++++++++++++++++++------------------ 1 file changed, 24 insertions(+), 18 deletions(-) diff --git a/src/DB_Command.php b/src/DB_Command.php index b7186311..1a05f64e 100644 --- a/src/DB_Command.php +++ b/src/DB_Command.php @@ -816,26 +816,32 @@ public function import( $args, $assoc_args ) { if ( ! is_readable( $result_file ) ) { WP_CLI::error( sprintf( 'Import file missing or not readable: %s', $result_file ) ); } - - // Check for MariaDB sandbox directive and skip it if found - $first_line = fgets( fopen( $result_file, 'r' ) ); - if ( strpos( $first_line, '/*!999999\\' ) !== false ) { - WP_CLI::debug( 'MariaDB sandbox directive found. Creating sanitized temp file.', 'db' ); - - $input = fopen( $result_file, 'r' ); - $tmp = tmpfile(); - $tmp_path = stream_get_meta_data( $tmp )['uri']; - - $line_number = 0; - while ( ( $line = fgets( $input ) ) !== false ) { - if ( $line_number > 0 ) { - fwrite( $tmp, $line ); + + // Check for MariaDB sandbox directive and skip it if found + $first_line = fgets( fopen( $result_file, 'r' ) ); + if ( strpos( $first_line, '/*!999999\\' ) !== false ) { + WP_CLI::debug( 'MariaDB sandbox directive found. Creating sanitized temp file.', 'db' ); + + $input = fopen( $result_file, 'r' ); + $tmp = tmpfile(); + $tmp_path = stream_get_meta_data( $tmp )['uri']; + $line_number = 0; + + while ( true ) { + $line = fgets( $input ); + if ( false === $line ) { + break; + } + + if ( $line_number > 0 ) { + fwrite( $tmp, $line ); + } + + ++$line_number; // Use pre-increment } - $line_number++; - } - fclose( $input ); - $result_file = $tmp_path; + fclose( $input ); + $result_file = $tmp_path; } $query = Utils\get_flag_value( $assoc_args, 'skip-optimization' )