diff --git a/src/DB_Command.php b/src/DB_Command.php index fe4d0f49..1a05f64e 100644 --- a/src/DB_Command.php +++ b/src/DB_Command.php @@ -817,6 +817,33 @@ public function import( $args, $assoc_args ) { 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 ( true ) { + $line = fgets( $input ); + if ( false === $line ) { + break; + } + + if ( $line_number > 0 ) { + fwrite( $tmp, $line ); + } + + ++$line_number; // Use pre-increment + } + + fclose( $input ); + $result_file = $tmp_path; + } + $query = Utils\get_flag_value( $assoc_args, 'skip-optimization' ) ? 'SOURCE %s;' : 'SET autocommit = 0; SET unique_checks = 0; SET foreign_key_checks = 0; SOURCE %s; COMMIT;';