WordPress.org

Make WordPress Core

Opened 11 months ago

Last modified 8 months ago

#45381 new enhancement

importer should remap attachment IDs when they appear in a block's attributes

Reported by: pbiron Owned by:
Milestone: Awaiting Review Priority: normal
Severity: normal Version:
Component: Import Keywords: dev-feedback
Focuses: Cc:
PR Number:

Description

Related: https://github.com/WordPress/gutenberg/issues/10535

One idiosyncrasy of the WordPress Importer is that attachment ids can change in the import process. If an existing WordPress site already has a number of posts, those existing post ids can conflict with the post ids included in the import file.

To accommodate the changing ids, the WordPress Importer has backfill_parents() (ref) and remap_featured_images() (ref). Both of these methods use a mapping of old=>new post ids to update existing references to the old ids.

Along the same lines, Image Blocks will need their attachment ids updated, otherwise they can end up in a crashed state. To replicate what the user will experience, simply insert an Image Block and change its attachment id reference to an invalid id:

I've done some experimenting and the mods to importer to support such remapping are fairly minor. Before submitting a patch I'll have to account for the recent change in the Gallery block (https://github.com/WordPress/gutenberg/pull/11540).

The mods I have work only if the attachments in question are included in the same export/import as the posts that have blocks that reference them. For example, if you export posts separately from Media and do 2 separate imports the IDs are not remapped. If the attachments are not included in the same export as the posts that reference them, then the importer currently does not remap the URLs in post_content either whether the media is referenced in a block or in "classic" content (i.e., they still point to URLs on the exporting host)...so I do not think that is a major flaw in what I've written :-)

I do not see any way around that, but wanted to mention it in case anyone has any bright ideas...before I finalize and submit that patch.

Change History (1)

#1 @selftrips ru
8 months ago

So, problem is solved or not?

Note: See TracTickets for help on using tickets.