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: Image Blocks can end up in a crashed state after import #10535

Closed
danielbachhuber opened this issue Oct 11, 2018 · 6 comments
Closed
Labels
[Feature] Media Anything that impacts the experience of managing media [Type] Bug An existing feature does not function as intended [Type] Plugin Interoperability Incompatibilities between a specific plugin and the block editor. Close with workaround notes.
Milestone

Comments

@danielbachhuber
Copy link
Member

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:

crashedimage

@danielbachhuber danielbachhuber added [Type] Bug An existing feature does not function as intended [Type] Plugin Interoperability Incompatibilities between a specific plugin and the block editor. Close with workaround notes. labels Oct 11, 2018
@danielbachhuber danielbachhuber added this to the WordPress 5.0 milestone Oct 11, 2018
@joemcgill joemcgill added the [Feature] Media Anything that impacts the experience of managing media label Oct 30, 2018
@antpb
Copy link
Contributor

antpb commented Nov 16, 2018

As discussed in the #core-media meeting yesterday, we do not see any immediate ways that Gutenberg can fix this for importer. The change would need to happen on the importer side and it would need to compare attributes to validate the new ids.

The one thing that Gutenberg does need to do is have easy to consume attributes that allow the importer to query the information needed. We are currently in progress on PR #11540 that will expose the image ids for Gallery which would likely be a blocker to importer adjusting. I'll leave this open until that work is finished out.

@mtias mtias modified the milestones: WordPress 5.0 RC, WordPress 5.0 Nov 16, 2018
@pbiron
Copy link

pbiron commented Nov 16, 2018

I've just been looking into what changes would be necessary to the importer to handle this.

I've got a working proof-of-concept mod to the importer that handles remapping the attachment ID in the Image block attributes (at least as implemented in GB 4.4.0) and was just coming here to ask if there were any other Core blocks that store IDs in block attributes that might change during an import...so that I can work on generalizing that mod to handle cases other than the Image block.

I see @antpb comment about #11540. It's hard for me to tell from that PR...does it implement exactly what is proposed in #8193?

The File, Audio, Video blocks also seems to store the attachment ID in the block's attributes. Are there any others? In particular, are there any that are not media-related?

@antpb
Copy link
Contributor

antpb commented Nov 19, 2018

I cannot think of any others that would need to store ids. I verified that the file block is storing the id as expected. That was the only one that had me worried. Categories and Latest Post will always be dynamic so we don't have to account for ids there either.

FYI #11540 has been merged so Gallery ids are now available.

@pbiron With that merged, is it safe to close this issue now that we have a way to map each block?

@pbiron
Copy link

pbiron commented Nov 19, 2018

@pbiron With that merged, is it safe to close this issue now that we have a way to map each block?

I will open a trac ticket on the mods necessary to the importer to support remapping of attachment IDs in block attributes (and reference this issue in that ticket).

Before closing this, let me ask one more question (the answer to which might be better handled in the trac ticket, but I'll ask it here first).

The proof-of-concept importer 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 this issue is closed.

@antpb
Copy link
Contributor

antpb commented Nov 20, 2018

Thanks @pbiron! I'm going to close this issue to keep our open issues number focused.

If anyone wants to add to the conversation, the trac ticket can be found here: https://core.trac.wordpress.org/ticket/45381

@antpb antpb closed this as completed Nov 20, 2018
@pbiron
Copy link

pbiron commented Nov 20, 2018

I had meant to add a link to the trac ticket I opened, but forgot. thanx for doing that.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
[Feature] Media Anything that impacts the experience of managing media [Type] Bug An existing feature does not function as intended [Type] Plugin Interoperability Incompatibilities between a specific plugin and the block editor. Close with workaround notes.
Projects
None yet
Development

No branches or pull requests

5 participants