Make WordPress Core

Ticket #43905: 43905.diff

File 43905.diff, 2.7 KB (added by allendav, 7 years ago)

Once a filename has been generated for a request export, keep using it.

  • src/wp-admin/includes/file.php

     
    20402040                fclose( $file );
    20412041        }
    20422042
     2043        // Create the temporary HTML report.
    20432044        $stripped_email       = str_replace( '@', '-at-', $email_address );
    20442045        $stripped_email       = sanitize_title( $stripped_email ); // slugify the email address
    20452046        $obscura              = md5( rand() );
     
    21252126        fclose( $file );
    21262127
    21272128        // Now, generate the ZIP.
    2128         $archive_filename = $file_basename . '.zip';
    2129         $archive_pathname = $exports_dir . $archive_filename;
    2130         $archive_url      = $exports_url . $archive_filename;
     2129        // If we already have a path for the archive from a previous export for
     2130        // this request, delete the old archive and use that filename again to create
     2131        // the new one.
     2132        $archive_url      = get_post_meta( $request_id, '_export_file_url', true );
     2133        $archive_pathname = get_post_meta( $request_id, '_export_file_path', true );
    21312134
     2135        if ( empty( $archive_pathname ) || empty( $archive_url ) ) {
     2136                $archive_filename = $file_basename . '.zip';
     2137                $archive_pathname = $exports_dir . $archive_filename;
     2138                $archive_url      = $exports_url . $archive_filename;
     2139
     2140                // Save the url and path in the request.
     2141                update_post_meta( $request_id, '_export_file_url', $archive_url );
     2142                update_post_meta( $request_id, '_export_file_path', $archive_pathname );
     2143        }
     2144
     2145        // If the archive already exists, unlink it so we can build it afresh
     2146        if ( ! empty( $archive_pathname ) && file_exists( $archive_pathname ) ) {
     2147                @unlink( $archive_pathname );
     2148        }
     2149
    21322150        $zip = new ZipArchive;
    21332151
    21342152        if ( TRUE === $zip->open( $archive_pathname, ZipArchive::CREATE ) ) {
     
    21382156                wp_send_json_error( __( 'Unable to open export file (archive) for writing' ) );
    21392157        }
    21402158
    2141         // And remove the HTML file.
     2159        // And remove the temporary HTML file.
    21422160        unlink( $html_report_pathname );
    2143 
    2144         // Save the export file in the request.
    2145         update_post_meta( $request_id, '_export_file_url', $archive_url );
    2146         update_post_meta( $request_id, '_export_file_path', $archive_pathname );
    21472161}
    21482162
    21492163/**
     
    23112325        delete_post_meta( $request_id, '_export_data_raw' );
    23122326        update_post_meta( $request_id, '_export_data_grouped', $groups );
    23132327
    2314         // And now, generate the export file, cleaning up any previous file
    2315         $export_path = get_post_meta( $request_id, '_export_file_path', true );
    2316         if ( ! empty( $export_path ) ) {
    2317                 delete_post_meta( $request_id, '_export_file_path' );
    2318                 @unlink( $export_path );
    2319         }
    2320         delete_post_meta( $request_id, '_export_file_url' );
    2321 
    23222328        // Generate the export file from the collected, grouped personal data.
    23232329        do_action( 'wp_privacy_personal_data_export_file', $request_id );
    23242330