[wp-trac] [WordPress Trac] #45381: importer should remap attachment IDs when they appear in a block's attributes
WordPress Trac
noreply at wordpress.org
Mon Nov 19 18:07:45 UTC 2018
#45381: importer should remap attachment IDs when they appear in a block's
attributes
-------------------------+-----------------------------
Reporter: pbiron | Owner: (none)
Type: enhancement | Status: new
Priority: normal | Milestone: Awaiting Review
Component: Import | Version:
Severity: normal | Keywords: dev-feedback
Focuses: |
-------------------------+-----------------------------
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.
--
Ticket URL: <https://core.trac.wordpress.org/ticket/45381>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform
More information about the wp-trac
mailing list