Automattic / newspack-custom-content-migrator

Custom migration tasks for launching and migrating Newspack sites on Atomic
5 stars 5 forks source link

Add a fixer for image blocks that are "unattached" to the image #490

Closed naxoc closed 5 months ago

naxoc commented 6 months ago

This is a generic fixer that fixes image blocks that are not pointing to an attachment ID. Those blocks become really hard to work with the for publisher, because it's not pointing to the media library. This finds those blocks and fixes them.

The wp newspack-content-migrator attachments-repair-img-blocks-w-no-id command is added. It currently only takes "num items" as an arg, but we can add to that when we need it.

How to test

You need a broken block. Something like this:

<!-- wp:image {"linkDestination":"custom","height":295,"width":400} -->
<figure class="wp-block-image is-resized"><img src="https://some-site.local/wp-content/uploads/2021/08/1Scv2cG3bvsYJC5ZBVRQcKA.jpeg?ssl=1" alt="" height="295" width="400"/><figcaption class="wp-element-caption">Some capation</figcaption></figure>
<!-- /wp:image -->

The image should be in the media library already. If it's not the code will try to import it. Now run the command above.

naxoc commented 5 months ago

I'll merge this one now. @jorostoyanov let's keep the other use cases in mind an maybe create fixers for them :)