Skip to content

Commit c391c66

Browse files
Fix: Skip sandbox line in MariaDB dump files during import
1 parent c821b92 commit c391c66

File tree

1 file changed

+21
-0
lines changed

1 file changed

+21
-0
lines changed

src/DB_Command.php

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -816,6 +816,27 @@ 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 );
833+
}
834+
$line_number++;
835+
}
836+
fclose( $input );
837+
838+
$result_file = $tmp_path;
839+
}
819840

820841
$query = Utils\get_flag_value( $assoc_args, 'skip-optimization' )
821842
? 'SOURCE %s;'

0 commit comments

Comments
 (0)