Automattic / newspack-custom-content-migrator

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

Rename attachment images to be supported by Subsizes #426

Open iuravic opened 8 months ago

iuravic commented 8 months ago

This PR

Subsizes does not allow attachment filenames to end in -\d+x\d+, e.g. image-100x200.jpg. If you upload a file like that to Atomic, it will be accepted, but a -1 will be appended to its filename and attachment post object's post_name, e.g. you will get image-100x200-1.jpg uploaded to your media library. If we're cloning historic WP sites to Atomic, such images won't work once Subsizes starts appending its size suffixes.

This PR fixes those attachments by:

Caveat!

This needs to be run before conversion to blocks. Because conversion to blocks might append an additional -\d+x\d+ on top of the existing old -\d+x\d+. E.g. invalid image in HTML Dorothy-336x225.jpg might be updated to Dorothy-336x225-336x225.jpg by Gutenberg. So it's important to run this before converting to blocks.

How to test


iuravic commented 8 months ago

Generally I think we should use PHP 8 return declarations on functions now that we have left PHP 7 behind, so I'd love to also see them. (feel free to also ignore that one).

Agreed, I think we're ready to add this to our PHPCS standard. Feel free to if you'd like.