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. git-svn-id: https://develop.svn.wordpress.org/trunk@48330 602fd350-edb4-49c9-b593-d223f7449a82
This commit is contained in:
parent
27ccafd0e9
commit
13dee8f174
@ -277,7 +277,7 @@ function wp_privacy_generate_personal_data_export_group_html( $group_data, $grou
|
||||
$group_html .= '</table>';
|
||||
}
|
||||
|
||||
if ( 1 < $groups_count ) {
|
||||
if ( $groups_count > 1 ) {
|
||||
$group_html .= '<div class="return-to-top">';
|
||||
$group_html .= '<a href="#top"><span aria-hidden="true">↑ </span> ' . esc_html__( 'Return to top' ) . '</a>';
|
||||
$group_html .= '</div>';
|
||||
@ -433,7 +433,7 @@ function wp_privacy_generate_personal_data_export_file( $request_id ) {
|
||||
fwrite( $file, '<h1 id="top">' . esc_html__( 'Personal Data Export' ) . '</h1>' );
|
||||
|
||||
// Create TOC.
|
||||
if ( 1 < $groups_count ) {
|
||||
if ( $groups_count > 1 ) {
|
||||
fwrite( $file, '<div id="table_of_contents">' );
|
||||
fwrite( $file, '<h2>' . esc_html__( 'Table of Contents' ) . '</h2>' );
|
||||
fwrite( $file, '<ul>' );
|
||||
@ -464,52 +464,39 @@ function wp_privacy_generate_personal_data_export_file( $request_id ) {
|
||||
/*
|
||||
* Now, generate the ZIP.
|
||||
*
|
||||
* If an archive has already been generated, then remove it and reuse the
|
||||
* filename, to avoid breaking any URLs that may have been previously sent
|
||||
* via email.
|
||||
* If an archive has already been generated, then remove it and reuse the filename,
|
||||
* to avoid breaking any URLs that may have been previously sent via email.
|
||||
*/
|
||||
$error = false;
|
||||
|
||||
// This postmeta is used from version 5.4.
|
||||
// This meta value is used from version 5.5.
|
||||
$archive_filename = get_post_meta( $request_id, '_export_file_name', true );
|
||||
|
||||
// These are used for backward compatibility.
|
||||
$archive_url = get_post_meta( $request_id, '_export_file_url', true );
|
||||
// This one stored an absolute path and is used for backward compatibility.
|
||||
$archive_pathname = get_post_meta( $request_id, '_export_file_path', true );
|
||||
|
||||
// If archive_filename exists, make sure to remove deprecated postmeta.
|
||||
// If a filename meta exists, use it.
|
||||
if ( ! empty( $archive_filename ) ) {
|
||||
$archive_pathname = $exports_dir . $archive_filename;
|
||||
$archive_url = $exports_url . $archive_filename;
|
||||
|
||||
// Remove the deprecated postmeta.
|
||||
delete_post_meta( $request_id, '_export_file_url' );
|
||||
delete_post_meta( $request_id, '_export_file_path' );
|
||||
} elseif ( ! empty( $archive_pathname ) ) {
|
||||
// Check if archive_pathname exists. If not, create the new postmeta and remove the deprecated.
|
||||
// If a full path meta exists, use it and create the new meta value.
|
||||
$archive_filename = basename( $archive_pathname );
|
||||
$archive_url = $exports_url . $archive_filename;
|
||||
|
||||
// Add the new postmeta that is used since version 5.4.
|
||||
update_post_meta( $request_id, '_export_file_name', wp_normalize_path( $archive_filename ) );
|
||||
update_post_meta( $request_id, '_export_file_name', $archive_filename );
|
||||
|
||||
// Remove the deprecated postmeta.
|
||||
// Remove the back-compat meta values.
|
||||
delete_post_meta( $request_id, '_export_file_url' );
|
||||
delete_post_meta( $request_id, '_export_file_path' );
|
||||
} else {
|
||||
// If there's no archive_filename or archive_pathname create a new one.
|
||||
// If there's no filename or full path stored, create a new file.
|
||||
$archive_filename = $file_basename . '.zip';
|
||||
$archive_url = $exports_url . $archive_filename;
|
||||
$archive_pathname = $exports_dir . $archive_filename;
|
||||
|
||||
// Add the new postmeta that is used since version 5.4.
|
||||
update_post_meta( $request_id, '_export_file_name', wp_normalize_path( $archive_filename ) );
|
||||
|
||||
// Remove the deprecated postmeta.
|
||||
delete_post_meta( $request_id, '_export_file_url' );
|
||||
delete_post_meta( $request_id, '_export_file_path' );
|
||||
update_post_meta( $request_id, '_export_file_name', $archive_filename );
|
||||
}
|
||||
|
||||
$archive_url = $exports_url . $archive_filename;
|
||||
|
||||
if ( ! empty( $archive_pathname ) && file_exists( $archive_pathname ) ) {
|
||||
wp_delete_file( $archive_pathname );
|
||||
}
|
||||
@ -568,10 +555,6 @@ function wp_privacy_send_personal_data_export_email( $request_id ) {
|
||||
// Get the request.
|
||||
$request = wp_get_user_request( $request_id );
|
||||
|
||||
// Get the export file URL.
|
||||
$exports_url = wp_privacy_exports_url();
|
||||
$export_file_name = get_post_meta( $request_id, '_export_file_name', true );
|
||||
|
||||
if ( ! $request || 'export_personal_data' !== $request->action_name ) {
|
||||
return new WP_Error( 'invalid_request', __( 'Invalid request ID when sending personal data export email.' ) );
|
||||
}
|
||||
@ -589,9 +572,12 @@ function wp_privacy_send_personal_data_export_email( $request_id ) {
|
||||
$expiration = apply_filters( 'wp_privacy_export_expiration', 3 * DAY_IN_SECONDS );
|
||||
$expiration_date = date_i18n( get_option( 'date_format' ), time() + $expiration );
|
||||
|
||||
$export_file_url = $exports_url . $export_file_name;
|
||||
$site_name = wp_specialchars_decode( get_option( 'blogname' ), ENT_QUOTES );
|
||||
$site_url = home_url();
|
||||
$exports_url = wp_privacy_exports_url();
|
||||
$export_file_name = get_post_meta( $request_id, '_export_file_name', true );
|
||||
$export_file_url = $exports_url . $export_file_name;
|
||||
|
||||
$site_name = wp_specialchars_decode( get_option( 'blogname' ), ENT_QUOTES );
|
||||
$site_url = home_url();
|
||||
|
||||
/**
|
||||
* Filters the recipient of the personal data export email notification.
|
||||
|
@ -44,13 +44,13 @@ class Tests_Privacy_WpPrivacyProcessPersonalDataExportPage extends WP_UnitTestCa
|
||||
protected static $response_last_page;
|
||||
|
||||
/**
|
||||
* Export Url.
|
||||
* Exports URL.
|
||||
*
|
||||
* @since 5.5.0
|
||||
*
|
||||
* @var string $export_url
|
||||
* @var string $exports_url
|
||||
*/
|
||||
protected static $export_url;
|
||||
protected static $exports_url;
|
||||
|
||||
/**
|
||||
* Export File Name.
|
||||
@ -149,9 +149,9 @@ class Tests_Privacy_WpPrivacyProcessPersonalDataExportPage extends WP_UnitTestCa
|
||||
*/
|
||||
public static function wpSetUpBeforeClass( $factory ) {
|
||||
self::$requester_email = 'requester@example.com';
|
||||
self::$export_url = wp_privacy_exports_url();
|
||||
self::$exports_url = wp_privacy_exports_url();
|
||||
self::$export_file_name = 'wp-personal-data-file-Wv0RfMnGIkl4CFEDEEkSeIdfLmaUrLsl.zip';
|
||||
self::$export_file_url = self::$export_url . self::$export_file_name;
|
||||
self::$export_file_url = self::$exports_url . self::$export_file_name;
|
||||
self::$request_id = wp_create_user_request( self::$requester_email, 'export_personal_data' );
|
||||
self::$page_index_first = 1;
|
||||
self::$page_index_last = 2;
|
||||
|
@ -104,10 +104,10 @@ class Tests_Privacy_WpPrivacySendPersonalDataExportEmail extends WP_UnitTestCase
|
||||
* The function should send an export link to the requester when the user request is confirmed.
|
||||
*/
|
||||
public function test_function_should_send_export_link_to_requester() {
|
||||
$archive_url = wp_privacy_exports_url();
|
||||
$archive_file_name = 'wp-personal-data-file-Wv0RfMnGIkl4CFEDEEkSeIdfLmaUrLsl.zip';
|
||||
$archive_file_url = $archive_url . $archive_file_name;
|
||||
update_post_meta( self::$request_id, '_export_file_name', $archive_file_name );
|
||||
$exports_url = wp_privacy_exports_url();
|
||||
$export_file_name = 'wp-personal-data-file-Wv0RfMnGIkl4CFEDEEkSeIdfLmaUrLsl.zip';
|
||||
$export_file_url = $exports_url . $export_file_name;
|
||||
update_post_meta( self::$request_id, '_export_file_name', $export_file_name );
|
||||
|
||||
$email_sent = wp_privacy_send_personal_data_export_email( self::$request_id );
|
||||
$mailer = tests_retrieve_phpmailer_instance();
|
||||
@ -115,7 +115,7 @@ class Tests_Privacy_WpPrivacySendPersonalDataExportEmail extends WP_UnitTestCase
|
||||
$this->assertSame( 'request-confirmed', get_post_status( self::$request_id ) );
|
||||
$this->assertSame( self::$requester_email, $mailer->get_recipient( 'to' )->address );
|
||||
$this->assertContains( 'Personal Data Export', $mailer->get_sent()->subject );
|
||||
$this->assertContains( $archive_file_url, $mailer->get_sent()->body );
|
||||
$this->assertContains( $export_file_url, $mailer->get_sent()->body );
|
||||
$this->assertContains( 'please download it', $mailer->get_sent()->body );
|
||||
$this->assertTrue( $email_sent );
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user