deliciousbrains / wp-migrate-db

WordPress plugin that exports your database, does a find and replace on URLs and file paths, then allows you to save it to your computer.
https://wordpress.org/plugins/wp-migrate-db/
341 stars 515 forks source link

Error thrown during gzip Import #106

Open sidedwards opened 4 years ago

sidedwards commented 4 years ago

Trying to import a gzip sql file and it gets stuck on "Parsing SQL file, please wait". Here is the error thrown in the logs.

Stack trace:
#0 /app/wp-content/plugins/wp-migrate-db-pro/class/Pro/Import.php(543): DeliciousBrains\WPMDB\Pro\Import->file_is_gzipped('/tmp/5dee95da03...')
#1 /app/wp-content/plugins/wp-migrate-db-pro/class/Pro/Import.php(123): DeliciousBrains\WPMDB\Pro\Import->str_is_gzipped('# WordPress MyS...')
#2 /app/wp-includes/class-wp-hook.php(288): DeliciousBrains\WPMDB\Pro\Import->ajax_get_import_info('')
#3 /app/wp-includes/class-wp-hook.php(312): WP_Hook->apply_filters('', Array)
#4 /app/wp-includes/plugin.php(478): WP_Hook->do_action(Array)
#5 /app/wp-admin/admin-ajax.php(175): do_action('wp_ajax_wpmdb_g...')
#6 {main}
  thrown in /app/wp-content/plugins/wp-migrate-db-pro/class/Pro/Import.php on line 566
/**
 * Checks if the provided file is gzipped
 *
 * @param string $file
 *
 * @return bool
 */
public function file_is_gzipped( $file ) {
    $is_gzipped = false;

    if ( ! $this->filesystem->is_file( $file ) ) {
        return $is_gzipped;
    }

    $content_type = mime_content_type( $file ); // Looks like it's getting stuck here..

    if ( in_array( $content_type, array( 'application/x-gzip', 'application/gzip' ) ) ) {
        $is_gzipped = true;
    }

    return $is_gzipped;
}
jpumfrey commented 3 years ago

This helps to resolve the issue:

public function file_is_gzipped( $file ) {
    $is_gzipped = false;
    if ( ! $this->filesystem->is_file( $file ) ) {
        return $is_gzipped;
    }

    $mime = wp_check_filetype( $file );
    if ( false === $mime['type'] && function_exists( 'mime_content_type' ) ) {
        $mime['type'] = mime_content_type( $file );
    }

    if ( in_array( $mime['type'], array( 'application/x-gzip', 'application/gzip' ) ) ) {
        $is_gzipped = true;
    }

    return $is_gzipped;
}