Make WordPress Core

Ticket #43905: 43905.2.diff

File 43905.2.diff, 2.5 KB (added by allendav, 6 years ago)

Refreshed patch; also now using wp_delete_file instead of unlink

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

     
    21292129
    21302130        // Now, generate the ZIP.
    21312131        $error            = false;
    2132         $archive_filename = $file_basename . '.zip';
    2133         $archive_pathname = $exports_dir . $archive_filename;
    2134         $archive_url      = $exports_url . $archive_filename;
     2132        // If we already have a path for the archive from a previous export for
     2133        // this request, delete the old archive and use that filename again to create
     2134        // the new one.
     2135        $archive_url      = get_post_meta( $request_id, '_export_file_url', true );
     2136        $archive_pathname = get_post_meta( $request_id, '_export_file_path', true );
    21352137
     2138        if ( empty( $archive_pathname ) || empty( $archive_url ) ) {
     2139                $archive_filename = $file_basename . '.zip';
     2140                $archive_pathname = $exports_dir . $archive_filename;
     2141                $archive_url      = $exports_url . $archive_filename;
     2142
     2143                // Save the url and path in the request.
     2144                update_post_meta( $request_id, '_export_file_url', $archive_url );
     2145                update_post_meta( $request_id, '_export_file_path', $archive_pathname );
     2146        }
     2147
     2148        // If the archive already exists, remove it so we can build it afresh
     2149        if ( ! empty( $archive_pathname ) && file_exists( $archive_pathname ) ) {
     2150                        wp_delete_file( $archive_pathname );
     2151        }
     2152
    21362153        $zip = new ZipArchive;
    21372154        if ( true === $zip->open( $archive_pathname, ZipArchive::CREATE ) ) {
    21382155                if ( ! $zip->addFile( $html_report_pathname, 'index.html' ) ) {
     
    21582175        }
    21592176
    21602177        // And remove the HTML file.
    2161         unlink( $html_report_pathname );
     2178        wp_delete_file( $html_report_pathname );
    21622179
    21632180        if ( $error ) {
    21642181                wp_send_json_error( $error );
    21652182        }
    2166 
    2167         // Save the export file in the request.
    2168         update_post_meta( $request_id, '_export_file_url', $archive_url );
    2169         update_post_meta( $request_id, '_export_file_path', $archive_pathname );
    21702183}
    21712184
    21722185/**
     
    23422355        delete_post_meta( $request_id, '_export_data_raw' );
    23432356        update_post_meta( $request_id, '_export_data_grouped', $groups );
    23442357
    2345         // And now, generate the export file, cleaning up any previous file
    2346         $export_path = get_post_meta( $request_id, '_export_file_path', true );
    2347         if ( ! empty( $export_path ) ) {
    2348                 delete_post_meta( $request_id, '_export_file_path' );
    2349                 @unlink( $export_path );
    2350         }
    2351         delete_post_meta( $request_id, '_export_file_url' );
    2352 
    23532358        // Generate the export file from the collected, grouped personal data.
    23542359        do_action( 'wp_privacy_personal_data_export_file', $request_id );
    23552360