WordPress / wordpress-importer

The WordPress Importer
https://wordpress.org/plugins/wordpress-importer/
GNU General Public License v2.0
78 stars 76 forks source link

Prevent duplicate postmeta records insertion #76

Open sagarsdeshmukh opened 4 years ago

sagarsdeshmukh commented 4 years ago

Issue

Fix

dd32 commented 3 years ago

Hi @sagarsdeshmukh, I apologise for how long this PR has sat here without any comment.

Does swapping from add_post_meta() to update_post_meta() break the expectation that WordPress can have multiple post meta records per name? For example, you can have name: animal value: cat and name: animal value: dog attached to the same post.

It might be better to explicitly only import postmeta/taxonomies when the post itself is imported, rather than relying upon the behaviour of update vs add.

jmdodd commented 3 years ago

Part of the problem here is that there can actually be multiple identical post meta records per name (maybe for counting thumbs-up/thumbs-down as an example use case):

wp> add_post_meta( 5, 'foo', 'bar' );
=> int(200)
wp> add_post_meta( 5, 'foo', 'bar' );
=> int(201)
wp> get_post_meta( 5, 'foo' );
=> array(2) {
  [0]=>
  string(3) "bar"
  [1]=>
  string(3) "bar"
}

If the import is run multiple times, using add_post_meta will result in multiple instances of each post meta on a post because these are imported regardless of whether the post previously existed, and independent of how many times they already exist on a post.

stevus commented 3 years ago

Should there be a check of existence of the key / value pair that is being imported, and if exists, do nothing? @sagarsdeshmukh @jmdodd that might solve the issue here?

sagarsdeshmukh commented 9 months ago

This PR is being here for long period of time, I would like to ask the core team of this project, do you expect any action/input/changes from my end, please let me know? cc: @ocean90 @jffng @boonebgorges @dd32