WordPress.org

Make WordPress Core

Ticket #44038: 44038.3.patch

File 44038.3.patch, 4.1 KB (added by nmenescardi, 4 months ago)

It contains some tests an changes in 44038.2 patch

  • src/wp-admin/includes/privacy-tools.php

    diff --git a/src/wp-admin/includes/privacy-tools.php b/src/wp-admin/includes/privacy-tools.php
    index 7e2badcb4e..cf1fb610c3 100644
    a b function wp_privacy_generate_personal_data_export_file( $request_id ) { 
    401401         */
    402402        $error            = false;
    403403        $archive_url      = get_post_meta( $request_id, '_export_file_url', true );
     404        $archive_filename = get_post_meta( $request_id, '_export_file_name', true );
    404405        $archive_pathname = get_post_meta( $request_id, '_export_file_path', true );
    405406
    406         if ( empty( $archive_pathname ) || empty( $archive_url ) ) {
    407                 $archive_filename = $file_basename . '.zip';
    408                 $archive_pathname = $exports_dir . $archive_filename;
    409                 $archive_url      = $exports_url . $archive_filename;
     407        if ( empty( $archive_filename ) && ! empty( $archive_pathname ) ) {
     408                $archive_filename = basename( $archive_pathname );
    410409
    411                 update_post_meta( $request_id, '_export_file_url', $archive_url );
    412                 update_post_meta( $request_id, '_export_file_path', wp_normalize_path( $archive_pathname ) );
     410          update_post_meta( $request_id, '_export_file_name', wp_normalize_path( $archive_filename ) );
     411          delete_post_meta( $request_id, '_export_file_path' );
     412
     413                if ( ! empty( $archive_pathname ) && file_exists( $archive_pathname ) ) {
     414                    wp_delete_file( $archive_pathname );
     415                }
     416               
     417        } elseif ( empty( $archive_pathname ) || empty( $archive_url ) ) {
     418               
     419                        $archive_filename = $file_basename . '.zip';
     420                        $archive_url      = $exports_url . $archive_filename;
     421
     422                        update_post_meta( $request_id, '_export_file_url', $archive_url );
     423                        update_post_meta( $request_id, '_export_file_name', wp_normalize_path( $archive_filename ) );
    413424        }
    414425
     426        $archive_pathname = $exports_dir . $archive_filename;
     427
    415428        if ( ! empty( $archive_pathname ) && file_exists( $archive_pathname ) ) {
    416429                wp_delete_file( $archive_pathname );
    417430        }
  • tests/phpunit/tests/privacy/wpPrivacyGeneratePersonalDataExportFile.php

    diff --git a/tests/phpunit/tests/privacy/wpPrivacyGeneratePersonalDataExportFile.php b/tests/phpunit/tests/privacy/wpPrivacyGeneratePersonalDataExportFile.php
    index 9ca05dadca..d07196cf38 100755
    a b class Tests_Privacy_WpPrivacyGeneratePersonalDataExportFile extends WP_UnitTestC 
    264264                $this->assertContains( '<h2>About</h2>', $report_contents );
    265265                $this->assertContains( $request->email, $report_contents );
    266266        }
     267
     268        /**
     269         * Test export file is generated in a new export dir (absolute path) set using 'wp_privacy_exports_dir' filter
     270         *
     271         * @ticket 44038
     272         */
     273        public function test_export_file_generated_in_new_export_dir_with_absolute_path() {
     274               
     275                $new_absolute_path = trailingslashit( self::$exports_dir . 'another_directory' );
     276
     277                add_filter('wp_privacy_exports_dir', function() use($new_absolute_path) {
     278                        return $new_absolute_path;
     279                });
     280
     281                wp_privacy_generate_personal_data_export_file( self::$export_request_id );
     282
     283                $this->assertTrue( file_exists( $new_absolute_path ) );
     284                $this->assertTrue( file_exists( $new_absolute_path . 'index.html' ) );
     285                $this->assertTrue( file_exists( $this->export_file_name ) );
     286        }
     287
     288        /**
     289         * Test export file is generated in a new export dir (absolute path) set using 'wp_privacy_exports_dir' filter and changing meta to simulate old absolute path stored values
     290         *
     291         * @ticket 44038
     292         */
     293        public function test_export_file_generated_in_new_export_dir_with_absolute_path_changing_meta() {
     294               
     295                $new_absolute_path = trailingslashit( self::$exports_dir . 'another_directory' );
     296
     297                add_filter('wp_privacy_exports_dir', function() use($new_absolute_path) {
     298                        return $new_absolute_path;
     299                });
     300
     301                // Changing meta to simulate old absolute path stored values:
     302                update_post_meta( self::$export_request_id, '_export_file_path', wp_normalize_path( $new_absolute_path ) );
     303
     304                wp_privacy_generate_personal_data_export_file( self::$export_request_id );
     305
     306                $this->assertTrue( file_exists( $new_absolute_path ) );
     307                $this->assertTrue( file_exists( $new_absolute_path . 'index.html' ) );
     308                $this->assertTrue( file_exists( $this->export_file_name ) );
     309        }
    267310}