Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improved hierarchical term handling #129

Open
wants to merge 4 commits into
base: master
Choose a base branch
from

Conversation

dcavins
Copy link
Contributor

@dcavins dcavins commented Jun 22, 2017

This PR adds handling for hierarchical terms:
• Make sure that newly added terms are added to the $exists array and found by WXR_Importer::term_exists().
• Basic term parent setting when the parent exists before the child term is created.
• Deferred term parent setting when the child term is encountered before the parent term exists.

Please let me know if you have any questions.

This is a great project, thanks for taking it on!

When terms were inserted, they were being added to the `$mapping` cache array, but not to the `$exists` cache array. This causes `WXR::term_exists()` to fail to find any terms added so far in this import.
As each term is processed, set the term parent if the parent can be found.
If the WXR reader encounters a child term before its parent term, it cannot set the child/parent relationship at the time the child term is created. In this case, we save the parent term slug as meta on the child term. Then, after all terms are inserted, loop through and update the parent/child relationships as needed .
Copy link

@pbiron pbiron left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This PR does appear to correct the problem I reported in #121.

It is also better than the fix that I had prepared for that issue because it implements the $this->remapping_required['term'] processing which I hadn't done (mine required the parent term to have occurred prior to the child term in the export file). I'm not 100% sure that the new WXR_Importer::post_process_terms() method is correct but it works on all the tests that I've run. Someone with a better grip on how the rest of the remapping code works should verify this before merge.

Passing term IDs to WP as strings results in WP
making new terms. For existing terms, always cast
the ID as an integer to avoid this issue (and to
ensure a match).
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants