Lokasi ngalangkungan proxy:   [ UP ]  
[Ngawartoskeun bug]   [Panyetelan cookie]                
Skip to content

fix(posts-import): recognise posts already imported from the same site - #1610

Merged
gregpriday merged 12 commits into
developfrom
bugfix/issue-1519-importing-the-same-wordpress-export
Nov 28, 2026
Merged

gregpriday merged 12 commits into
developfrom
bugfix/issue-1519-importing-the-same-wordpress-export

Conversation

@gregpriday

Copy link
Copy Markdown
Member

Importing a WordPress export again brought every post in a second time as a numbered copy, and the review never said the posts were already there. This change recognises posts imported before from the same site. The review counts them and skips them by default, or updates them in place when the author chooses, so only the new posts are imported.

Resolves #1519

What changes

  • Each imported entry records its WordPress origin: EntryDoc.imported = { site, postId }, set through entry.create's new imported field. The site is the export's base URL with its installation path. A damaged record is a diagnostics warning. The generator reads entries field by field, so the record never reaches the exported site.
  • Matching (alreadyImported in src/main/posts-import/plan.ts) considers only entries recorded as imported from the same site. Post-ID matches across the whole export come first. A post with no ID can then match by the entry's address or an old address kept for it. An entry without the record is never matched: a post written in the project, or a redirect an author pointed at one, says nothing about where it came from. Nothing predates the record, since the project is pre-release.
  • One plan, two ways of importing. Matched posts keep their entry's ID, slug and address, and get no new slug or redirect. selectPlan(plan, 'skip' | 'update') picks what an import brings. Skip leaves out the pictures, new terms and groupings that only skipped posts would have brought. Groupings and terms go to new posts first, so a limit that only updating would hit stops only updating.
  • Update puts the source's title, date, author, excerpt, categories, tags, featured picture and text over the entry. It keeps the slug, old addresses, search settings, custom fields and draft state. It makes a published entry a draft when the source has it as a draft or its text had to be cut. It never publishes. It keeps the entry's own date when the export has none. It keeps the featured picture when the export names one it doesn't include. A post whose text could not be read is never put over its entry.
  • Partial exports: the controller passes the reader the posts imported before (knownPosts). A link to a post the export leaves out goes to that post's entry rather than the old site. The lookup works by ?p= ID at the installation's own root, or by a kept old address, and never across another installation on the same host.
  • Review (PostImportReview.tsx): the review counts the posts already in the project and offers Skip them (the default) or Update them from the export. Its counts, problems and action follow the choice: "Import 1 post", "Import 1 post and update 2", or Close only when there is nothing to import. When updating, matched posts with notes are shown in full. Links to posts that are drafts, or that updating makes drafts, are flagged.
  • commitPostImport(id, opening, addToNavigation, existing) takes the choice. An all-skipped import changes nothing and adds no history step. A mixed import is one step, "Import 3 posts and update 2".
  • The garbled reason is fixed: "Its old address (…) can't keep working, because it is already the old address of “X”."

Testing

  • tests/unit/posts-import.test.ts: a repeated export, its draft included, is recognised and skipped by default, with no operations planned. Update in place keeps the address, old addresses and draft state. New posts link to the ones already here. The other cases: ID matches beat an earlier address row; locally written posts and their redirects are never matched; a partial export keeps links and the featured picture; links are scoped to the installation; dates and draft warnings; the last grouping slot goes to a new post; unreadable posts are never put over their entries. The existing "numbers a slug" test now uses another site's posts, since it used to assert the duplicates.
  • tests/unit/posts-import-controller.test.ts (new) runs real reviewPostImport and commitPostImport. Skipping a repeated export leaves the revision and posts unchanged. A mixed update is one step with the right label and opens the new post. Skip still imports when only updating is blocked.
  • tests/unit/post-import-existing-browser.test.ts (new) covers the review in Chromium: the default choice, the labels, Close-only, problems per choice, and notes when updating. tests/unit/post-import-menu-browser.test.ts now expects the trailing 'skip' argument.
  • Adjacent tests pass. The impact set is 66 of 621 unit test files (about 10%), all green. npm run typecheck is green.
  • Not run: tests/e2e/posts-import.mjs (it only covers a first import, and its assertions still match).

Open

  • An export with no wp:post_id on its posts (WordPress writes one for every item) can't be recognised on a second import.
  • If an update makes two linked posts both drafts, the review still warns about the link between them.
  • In a partial export, a link to an omitted post whose WordPress permalink was the same as its Builder route (so no old address was kept) still goes to the old site, and the review says so. Resolving it by the entry's Builder route was tried and removed, because the old site may have used that address for something else.

…Press site

- Keep the WordPress site and post ID on each imported entry
- Match a later export's posts by that ID, else by a kept old address
- Plan matched posts in place; selectPlan skips or updates them
- Say an old address another post keeps is already its old address
- The review counts the posts already here, skipping them by default
- Commit takes the choice; skipped-only imports change nothing
- Cover the review's choice in a browser test
- Match by ID across the export before any old address
- Own-address matches only for posts of the same site
- Link a partial export's posts to entries imported before
- Keep a featured picture the export lacks; keep the entry's date
- Record the ID on an address-matched update
- Draft-link notes follow the entry's own state; damaged redirects are skipped
- Show what updating changes; count posts left as they are
- Cover the re-import through the controller
- Match by address only entries imported from the same site
- Scope the omitted-post lookup to the site's installation; add own routes
- Warn of links to drafts, and to posts updating makes drafts
- Never write back a saved date the engine refuses
- A ?p= link counts only at the installation's own root
- Drop the lookup by an entry's address here, which the old site may have used
- The commit's arguments are now (id, opening, addToNavigation, existing)
- The menu review's fixture counts no posts already here
@gregpriday

Copy link
Copy Markdown
Member Author

CI's one failure is base-level, not this change: tests/unit/interaction-coverage.test.ts reports No row has the route "item:Posts:Show full titles" (defined at src/renderer/src/panels/PostsPanel.tsx:784). That menu item came in with dd1d7d6 ("fix(posts): show titles on two lines in the Content list") on develop, the test fails the same way on origin/develop, and this branch doesn't touch PostsPanel.tsx. The other 627 test files passed (11,687 tests).

…ess-export

Keeps develop's old-site links and category archive redirects alongside
skipping or updating posts already in the project: each way of importing
names only the links of the posts it brings, and keeps an old category
archive working only while its category comes.
…ess-export

A link to a post already in the project keeps its query and names a section
it can't open, as develop's links to imported posts now do (entryLink).
…importing-the-same-wordpress-export

# Conflicts:
#	src/main/posts-import/plan.ts
#	src/main/posts-import/wxr.ts
@gregpriday
gregpriday merged commit 7adab56 into develop Nov 28, 2026
1 check passed
@gregpriday
gregpriday deleted the bugfix/issue-1519-importing-the-same-wordpress-export branch November 28, 2026 09:56
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.

Importing the same WordPress export again duplicates every post

1 participant