Skip to content

Commit b32d432

Browse files
authored
Merge pull request #89 from wp-cli/fix/53-attachment-post-meta
Ensure post attachment meta is exported correctly
2 parents 1215104 + f6c58f1 commit b32d432

File tree

3 files changed

+38
-25
lines changed

3 files changed

+38
-25
lines changed

composer.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
"wp-cli/db-command": "^1.3 || ^2",
2020
"wp-cli/entity-command": "^1.3 || ^2",
2121
"wp-cli/extension-command": "^1.2 || ^2",
22+
"wp-cli/media-command": "^1 || ^2",
2223
"wp-cli/import-command": "^1 || ^2",
2324
"wp-cli/wp-cli-tests": "^3.0.11"
2425
},

features/export.feature

Lines changed: 34 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -736,52 +736,36 @@ Feature: Export content.
736736

737737
Scenario: Export individual post with attachments
738738
Given a WP install
739-
740-
When I run `wp plugin install wordpress-importer --activate`
741-
Then STDOUT should contain:
742-
"""
743-
Success:
744-
"""
739+
And I run `wp plugin install wordpress-importer --activate`
740+
And I run `wp site empty --yes`
745741

746742
When I run `wp post generate --count=10`
747743
And I run `wp post list --format=count`
748744
Then STDOUT should be:
749745
"""
750-
11
746+
10
751747
"""
752748

753749
When I run `wp post create --post_title='Post with attachment to export' --porcelain`
754750
Then STDOUT should be a number
755751
And save STDOUT as {EXPORT_ATTACHMENT_POST_ID}
756752

757-
When I run `wp post create --post_type=attachment --porcelain`
753+
When I run `wp media import 'http://wp-cli.org/behat-data/codeispoetry.png' --post_id={EXPORT_ATTACHMENT_POST_ID} --porcelain`
758754
Then STDOUT should be a number
759755
And save STDOUT as {EXPORT_ATTACHMENT_ID}
760756

761-
When I run `wp post update {EXPORT_ATTACHMENT_ID} --post_parent={EXPORT_ATTACHMENT_POST_ID} --porcelain`
762-
Then STDOUT should contain:
763-
"""
764-
Success: Updated post {EXPORT_ATTACHMENT_ID}
765-
"""
766-
767757
When I run `wp post create --post_title='Post with attachment to ignore' --porcelain`
768758
Then STDOUT should be a number
769759
And save STDOUT as {IGNORE_ATTACHMENT_POST_ID}
770760

771-
When I run `wp post create --post_type=attachment --porcelain`
761+
When I run `wp media import 'http://wp-cli.org/behat-data/white-150-square.jpg' --post_id={IGNORE_ATTACHMENT_POST_ID} --porcelain`
772762
Then STDOUT should be a number
773763
And save STDOUT as {IGNORE_ATTACHMENT_ID}
774764

775-
When I run `wp post update {IGNORE_ATTACHMENT_ID} --post_parent={IGNORE_ATTACHMENT_POST_ID} --porcelain`
776-
Then STDOUT should contain:
777-
"""
778-
Success: Updated post {IGNORE_ATTACHMENT_ID}
779-
"""
780-
781765
When I run `wp post list --post_type=post --format=count`
782766
Then STDOUT should be:
783767
"""
784-
13
768+
12
785769
"""
786770

787771
When I run `wp post list --post_type=attachment --format=count`
@@ -804,6 +788,26 @@ Feature: Export content.
804788
"""
805789
<wp:post_id>{EXPORT_ATTACHMENT_ID}</wp:post_id>
806790
"""
791+
And the {EXPORT_FILE} file should contain:
792+
"""
793+
<wp:meta_key>_wp_attachment_metadata</wp:meta_key>
794+
"""
795+
And the {EXPORT_FILE} file should contain:
796+
"""
797+
codeispoetry.png";s:5:"sizes"
798+
"""
799+
And the {EXPORT_FILE} file should contain:
800+
"""
801+
<wp:meta_key>_wp_attached_file</wp:meta_key>
802+
"""
803+
And the {EXPORT_FILE} file should contain:
804+
"""
805+
codeispoetry.png]]></wp:meta_value>
806+
"""
807+
And the {EXPORT_FILE} file should not contain:
808+
"""
809+
<wp:meta_key>_edit_lock</wp:meta_key>
810+
"""
807811
And the {EXPORT_FILE} file should not contain:
808812
"""
809813
<wp:post_id>{IGNORE_ATTACHMENT_POST_ID}</wp:post_id>
@@ -812,6 +816,14 @@ Feature: Export content.
812816
"""
813817
<wp:post_id>{IGNORE_ATTACHMENT_ID}</wp:post_id>
814818
"""
819+
And the {EXPORT_FILE} file should not contain:
820+
"""
821+
white-150-square.jpg]]></wp:meta_value>
822+
"""
823+
And the {EXPORT_FILE} file should not contain:
824+
"""
825+
white-150-square.jpg";s:5:"sizes"
826+
"""
815827

816828
Scenario: Export categories, tags and terms
817829
Given a WP install

src/WP_Export_Query.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -387,11 +387,11 @@ private static function get_meta_for_post( $post ) {
387387
$meta_for_export = [];
388388
$meta_from_db = $wpdb->get_results( $wpdb->prepare( "SELECT * FROM $wpdb->postmeta WHERE post_id = %d", $post->ID ) );
389389
foreach ( $meta_from_db as $meta ) {
390-
// phpcs:ignore WordPress.NamingConventions.PrefixAllGlobals.NonPrefixedHooknameFound -- Calling native WordPress hook.
391-
if ( apply_filters( 'wxr_export_skip_postmeta', false, $meta->meta_key, $meta ) ) {
390+
if ( '_edit_lock' === $meta->meta_key ) {
392391
continue;
393392
}
394-
if ( in_array( $meta->meta_key, [ '_edit_lock', '_wp_attachment_metadata', '_wp_attached_file' ], true ) ) {
393+
// phpcs:ignore WordPress.NamingConventions.PrefixAllGlobals.NonPrefixedHooknameFound -- Calling native WordPress hook.
394+
if ( apply_filters( 'wxr_export_skip_postmeta', false, $meta->meta_key, $meta ) ) {
395395
continue;
396396
}
397397
$meta_for_export[] = $meta;

0 commit comments

Comments
 (0)