Make WordPress Core

Changeset 48330


Ignore:
Timestamp:
07/06/2020 12:32:15 AM (5 years ago)
Author:
SergeyBiryukov
Message:

Privacy: Simplify the logic for updating the meta values for personal data export requests from absolute to relative paths.

Follow-up to [48127].

See #44038.

Location:
trunk
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/wp-admin/includes/privacy-tools.php

    r48302 r48330  
    278278    }
    279279
    280     if ( 1 < $groups_count ) {
     280    if ( $groups_count > 1 ) {
    281281        $group_html .= '<div class="return-to-top">';
    282282        $group_html .= '<a href="#top"><span aria-hidden="true">&uarr; </span> ' . esc_html__( 'Return to top' ) . '</a>';
     
    434434
    435435    // Create TOC.
    436     if ( 1 < $groups_count ) {
     436    if ( $groups_count > 1 ) {
    437437        fwrite( $file, '<div id="table_of_contents">' );
    438438        fwrite( $file, '<h2>' . esc_html__( 'Table of Contents' ) . '</h2>' );
     
    465465     * Now, generate the ZIP.
    466466     *
    467      * If an archive has already been generated, then remove it and reuse the
    468      * filename, to avoid breaking any URLs that may have been previously sent
    469      * via email.
     467     * If an archive has already been generated, then remove it and reuse the filename,
     468     * to avoid breaking any URLs that may have been previously sent via email.
    470469     */
    471470    $error = false;
    472471
    473     // This postmeta is used from version 5.4.
     472    // This meta value is used from version 5.5.
    474473    $archive_filename = get_post_meta( $request_id, '_export_file_name', true );
    475474
    476     // These are used for backward compatibility.
    477     $archive_url      = get_post_meta( $request_id, '_export_file_url', true );
     475    // This one stored an absolute path and is used for backward compatibility.
    478476    $archive_pathname = get_post_meta( $request_id, '_export_file_path', true );
    479477
    480     // If archive_filename exists, make sure to remove deprecated postmeta.
     478    // If a filename meta exists, use it.
    481479    if ( ! empty( $archive_filename ) ) {
    482480        $archive_pathname = $exports_dir . $archive_filename;
    483         $archive_url      = $exports_url . $archive_filename;
    484 
    485         // Remove the deprecated postmeta.
    486         delete_post_meta( $request_id, '_export_file_url' );
    487         delete_post_meta( $request_id, '_export_file_path' );
    488481    } elseif ( ! empty( $archive_pathname ) ) {
    489         // Check if archive_pathname exists. If not, create the new postmeta and remove the deprecated.
     482        // If a full path meta exists, use it and create the new meta value.
    490483        $archive_filename = basename( $archive_pathname );
    491         $archive_url      = $exports_url . $archive_filename;
    492 
    493         // Add the new postmeta that is used since version 5.4.
    494         update_post_meta( $request_id, '_export_file_name', wp_normalize_path( $archive_filename ) );
    495 
    496         // Remove the deprecated postmeta.
     484
     485        update_post_meta( $request_id, '_export_file_name', $archive_filename );
     486
     487        // Remove the back-compat meta values.
    497488        delete_post_meta( $request_id, '_export_file_url' );
    498489        delete_post_meta( $request_id, '_export_file_path' );
    499490    } else {
    500         // If there's no archive_filename or archive_pathname create a new one.
     491        // If there's no filename or full path stored, create a new file.
    501492        $archive_filename = $file_basename . '.zip';
    502         $archive_url      = $exports_url . $archive_filename;
    503493        $archive_pathname = $exports_dir . $archive_filename;
    504494
    505         // Add the new postmeta that is used since version 5.4.
    506         update_post_meta( $request_id, '_export_file_name', wp_normalize_path( $archive_filename ) );
    507 
    508         // Remove the deprecated postmeta.
    509         delete_post_meta( $request_id, '_export_file_url' );
    510         delete_post_meta( $request_id, '_export_file_path' );
    511     }
     495        update_post_meta( $request_id, '_export_file_name', $archive_filename );
     496    }
     497
     498    $archive_url = $exports_url . $archive_filename;
    512499
    513500    if ( ! empty( $archive_pathname ) && file_exists( $archive_pathname ) ) {
     
    569556    $request = wp_get_user_request( $request_id );
    570557
    571     // Get the export file URL.
    572     $exports_url      = wp_privacy_exports_url();
    573     $export_file_name = get_post_meta( $request_id, '_export_file_name', true );
    574 
    575558    if ( ! $request || 'export_personal_data' !== $request->action_name ) {
    576559        return new WP_Error( 'invalid_request', __( 'Invalid request ID when sending personal data export email.' ) );
     
    590573    $expiration_date = date_i18n( get_option( 'date_format' ), time() + $expiration );
    591574
    592     $export_file_url = $exports_url . $export_file_name;
    593     $site_name       = wp_specialchars_decode( get_option( 'blogname' ), ENT_QUOTES );
    594     $site_url        = home_url();
     575    $exports_url      = wp_privacy_exports_url();
     576    $export_file_name = get_post_meta( $request_id, '_export_file_name', true );
     577    $export_file_url  = $exports_url . $export_file_name;
     578
     579    $site_name = wp_specialchars_decode( get_option( 'blogname' ), ENT_QUOTES );
     580    $site_url  = home_url();
    595581
    596582    /**
  • trunk/tests/phpunit/tests/privacy/wpPrivacyProcessPersonalDataExportPage.php

    r48127 r48330  
    4545
    4646    /**
    47      * Export Url.
     47     * Exports URL.
    4848     *
    4949     * @since 5.5.0
    5050     *
    51      * @var string $export_url
    52      */
    53     protected static $export_url;
     51     * @var string $exports_url
     52     */
     53    protected static $exports_url;
    5454
    5555    /**
     
    150150    public static function wpSetUpBeforeClass( $factory ) {
    151151        self::$requester_email      = 'requester@example.com';
    152         self::$export_url           = wp_privacy_exports_url();
     152        self::$exports_url          = wp_privacy_exports_url();
    153153        self::$export_file_name     = 'wp-personal-data-file-Wv0RfMnGIkl4CFEDEEkSeIdfLmaUrLsl.zip';
    154         self::$export_file_url      = self::$export_url . self::$export_file_name;
     154        self::$export_file_url      = self::$exports_url . self::$export_file_name;
    155155        self::$request_id           = wp_create_user_request( self::$requester_email, 'export_personal_data' );
    156156        self::$page_index_first     = 1;
  • trunk/tests/phpunit/tests/privacy/wpPrivacySendPersonalDataExportEmail.php

    r48127 r48330  
    105105     */
    106106    public function test_function_should_send_export_link_to_requester() {
    107         $archive_url       = wp_privacy_exports_url();
    108         $archive_file_name = 'wp-personal-data-file-Wv0RfMnGIkl4CFEDEEkSeIdfLmaUrLsl.zip';
    109         $archive_file_url  = $archive_url . $archive_file_name;
    110         update_post_meta( self::$request_id, '_export_file_name', $archive_file_name );
     107        $exports_url      = wp_privacy_exports_url();
     108        $export_file_name = 'wp-personal-data-file-Wv0RfMnGIkl4CFEDEEkSeIdfLmaUrLsl.zip';
     109        $export_file_url  = $exports_url . $export_file_name;
     110        update_post_meta( self::$request_id, '_export_file_name', $export_file_name );
    111111
    112112        $email_sent = wp_privacy_send_personal_data_export_email( self::$request_id );
     
    116116        $this->assertSame( self::$requester_email, $mailer->get_recipient( 'to' )->address );
    117117        $this->assertContains( 'Personal Data Export', $mailer->get_sent()->subject );
    118         $this->assertContains( $archive_file_url, $mailer->get_sent()->body );
     118        $this->assertContains( $export_file_url, $mailer->get_sent()->body );
    119119        $this->assertContains( 'please download it', $mailer->get_sent()->body );
    120120        $this->assertTrue( $email_sent );
Note: See TracChangeset for help on using the changeset viewer.