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

importer: use page if a post and page clash with slugs #175

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from
Draft
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 21 additions & 0 deletions wagtail_wordpress_import/importers/wordpress.py
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,27 @@ def run(self, *args, **kwargs):
wp_post_id=wordpress_item.cleaned_data.get("wp_post_id")
)
except self.page_model_class.DoesNotExist:
try:
# We are creating a new page as the wp_post_id doesn't exist
# however we may have a collision of slugs between page and post types
# https://core.trac.wordpress.org/ticket/13459
slug_post = self.page_model_class.objects.get(
Copy link
Author

Choose a reason for hiding this comment

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

note if wp_post_parent support from #176 was added, this would need to consider a slug_post with the same parent as the page and not just any slug page

slug=wordpress_item.cleaned_data.get("slug")
)

# If the existing type is a post and the new type is a page
# then override by deleting the existing post
# https://core.trac.wordpress.org/ticket/13459
if slug_post.wp_post_type == "post" and wordpress_item.cleaned_data.get("wp_post_type") == "page":
slug_post.delete()
# If the existing type is a page and the new type is a post
# then ignore as page is stronger than post
elif slug_post.wp_post_type == "page" and wordpress_item.cleaned_data.get("wp_post_type") == "post":
self.logger.skipped += 1
continue
except self.page_model_class.DoesNotExist:
pass

page = self.page_model_class()

# add categories for this page if categories plugin is enabled
Expand Down