From b6cca4ecdc4d3489577fc98e5bb12bf72edaab72 Mon Sep 17 00:00:00 2001 From: Wayne Wang Date: Fri, 2 Dec 2022 16:25:27 +0800 Subject: [PATCH 1/4] Exclude unnecessary author ids from oembed_cache posts in export --- src/WP_Export_Query.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/WP_Export_Query.php b/src/WP_Export_Query.php index 262f6e6e..e39570e8 100644 --- a/src/WP_Export_Query.php +++ b/src/WP_Export_Query.php @@ -80,7 +80,7 @@ public function authors() { } $authors = []; - $author_ids = (array) $wpdb->get_col( "SELECT DISTINCT post_author FROM $wpdb->posts WHERE post_status != 'auto-draft'" ); + $author_ids = (array) $wpdb->get_col( "SELECT DISTINCT post_author FROM $wpdb->posts WHERE post_status != 'auto-draft' and post_type != 'oembed_cache'" ); foreach ( $author_ids as $author_id ) { $authors[] = get_userdata( $author_id ); } From 75eafc4773bc01d8c8bde382680b78ebe50d3dc4 Mon Sep 17 00:00:00 2001 From: Wayne Wang Date: Wed, 7 Dec 2022 11:23:30 +0800 Subject: [PATCH 2/4] Change command keyword to uppercase --- src/WP_Export_Query.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/WP_Export_Query.php b/src/WP_Export_Query.php index e39570e8..8b900f7d 100644 --- a/src/WP_Export_Query.php +++ b/src/WP_Export_Query.php @@ -80,7 +80,7 @@ public function authors() { } $authors = []; - $author_ids = (array) $wpdb->get_col( "SELECT DISTINCT post_author FROM $wpdb->posts WHERE post_status != 'auto-draft' and post_type != 'oembed_cache'" ); + $author_ids = (array) $wpdb->get_col( "SELECT DISTINCT post_author FROM $wpdb->posts WHERE post_status != 'auto-draft' AND post_type != 'oembed_cache'" ); foreach ( $author_ids as $author_id ) { $authors[] = get_userdata( $author_id ); } From f8bfbb12d68d5d47d08c39e6daab2323fc63f499 Mon Sep 17 00:00:00 2001 From: Wayne Wang Date: Wed, 7 Dec 2022 12:15:19 +0800 Subject: [PATCH 3/4] Adding functional tests for oembed_cache post author exclusion --- features/export.feature | 31 +++++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) diff --git a/features/export.feature b/features/export.feature index b6849d05..57ae8955 100644 --- a/features/export.feature +++ b/features/export.feature @@ -985,3 +985,34 @@ Feature: Export content. """ Europe """ + + Scenario: Export posts should not include oembed_cache posts user information + Given a WP install + And I run `wp plugin install wordpress-importer --activate` + And I run `wp user create user user@user.com --role=editor --display_name="Test User"` + And I run `wp user create oembed_cache_user oembed_cache@user.com --role=editor --display_name="Oembed User"` + And I run `wp post generate --post_type=post --count=10 --post_author=user` + And I run `wp post generate --post_type=oembed_cache --count=1 --post_author=oembed_cache_user` + + When I run `wp export` + And save STDOUT 'Writing to file %s' as {EXPORT_FILE} + Then the {EXPORT_FILE} file should contain: + """ + + """ + And the {EXPORT_FILE} file should not contain: + """ + + """ + When I run `wp site empty --yes` + And I run `wp user list --field=user_login | xargs -n 1 wp user delete --yes` + Then STDOUT should not be empty + + When I run `wp import {EXPORT_FILE} --authors=create` + Then STDOUT should not be empty + + When I run `wp user get user --field=display_name` + Then STDOUT should be: + """ + Test User + """ From 6a839dfd2fa7290b4fa420ae75422367830bf013 Mon Sep 17 00:00:00 2001 From: Daniel Bachhuber Date: Wed, 7 Dec 2022 14:25:16 -0800 Subject: [PATCH 4/4] WordPress Importer tests require WP 5.2 --- features/export.feature | 1 + 1 file changed, 1 insertion(+) diff --git a/features/export.feature b/features/export.feature index 57ae8955..73c36e3f 100644 --- a/features/export.feature +++ b/features/export.feature @@ -986,6 +986,7 @@ Feature: Export content. Europe """ + @require-wp-5.2 Scenario: Export posts should not include oembed_cache posts user information Given a WP install And I run `wp plugin install wordpress-importer --activate`