@@ -816,26 +816,32 @@ public function import( $args, $assoc_args ) {
816816 if ( ! is_readable ( $ result_file ) ) {
817817 WP_CLI ::error ( sprintf ( 'Import file missing or not readable: %s ' , $ result_file ) );
818818 }
819-
820- // Check for MariaDB sandbox directive and skip it if found
821- $ first_line = fgets ( fopen ( $ result_file , 'r ' ) );
822- if ( strpos ( $ first_line , '/*!999999 \\' ) !== false ) {
823- WP_CLI ::debug ( 'MariaDB sandbox directive found. Creating sanitized temp file. ' , 'db ' );
824-
825- $ input = fopen ( $ result_file , 'r ' );
826- $ tmp = tmpfile ();
827- $ tmp_path = stream_get_meta_data ( $ tmp )['uri ' ];
828-
829- $ line_number = 0 ;
830- while ( ( $ line = fgets ( $ input ) ) !== false ) {
831- if ( $ line_number > 0 ) {
832- fwrite ( $ tmp , $ line );
819+
820+ // Check for MariaDB sandbox directive and skip it if found
821+ $ first_line = fgets ( fopen ( $ result_file , 'r ' ) );
822+ if ( strpos ( $ first_line , '/*!999999 \\' ) !== false ) {
823+ WP_CLI ::debug ( 'MariaDB sandbox directive found. Creating sanitized temp file. ' , 'db ' );
824+
825+ $ input = fopen ( $ result_file , 'r ' );
826+ $ tmp = tmpfile ();
827+ $ tmp_path = stream_get_meta_data ( $ tmp )['uri ' ];
828+ $ line_number = 0 ;
829+
830+ while ( true ) {
831+ $ line = fgets ( $ input );
832+ if ( false === $ line ) {
833+ break ;
834+ }
835+
836+ if ( $ line_number > 0 ) {
837+ fwrite ( $ tmp , $ line );
838+ }
839+
840+ ++$ line_number ; // Use pre-increment
833841 }
834- $ line_number ++;
835- }
836- fclose ( $ input );
837842
838- $ result_file = $ tmp_path ;
843+ fclose ( $ input );
844+ $ result_file = $ tmp_path ;
839845 }
840846
841847 $ query = Utils \get_flag_value ( $ assoc_args , 'skip-optimization ' )
0 commit comments