10up / distributor

Share content between your websites.
https://distributorplugin.com
GNU General Public License v2.0
640 stars 156 forks source link

A PHP notice is generated when distributing child terms without parents #219

Open jeremyfelt opened 6 years ago

jeremyfelt commented 6 years ago

In its current state Distributor results in a PHP notice when you attempt to assign a child term from a hierarchy where the parent term does not yet exist on the other site and when that parent term is also not selected for distribution.

https://github.com/10up/distributor/blob/052307f5ec19a9aedf68588d15d77c5610c11eb2/includes/utils.php#L394-L402

The code assumes the parent exists as an already mapped term when it attempts to update the latest term. This is probably okay when both the parent and child have been selected.

For my specific case, I'm less concerned about the relationship on the distributed content, so I would choose to skip dt_update_term_hierarchy for this taxonomy. I'm going to open a pull request suggesting that $taxonomy be provided to that filter so that this can be enabled/disabled based on that value rather than as a blanket decision.

It does seem that handling of the term hierarchy is somewhat of a larger problem than that.

jeremyfelt commented 6 years ago

It would be helpful to know the actual error. :)

PHP message: PHP Notice: Undefined offset: 1102 in /Users/jeremyfelt/Development/cfemedia/wp-content/plugins/distributor/includes/utils.php on line 399

In this case, 1102 is the term ID of the parent that exists on the main site, but not the distributed site. It doesn't exist in the $term_id_mapping array.

arsendovlatyan commented 6 years ago

When parent is not mapped, but we are trying to update term parent in destination, we may damage existing hierarchy and bring secondary level terms to root level.

Please check #262, where this issue is solved.