deliciousbrains / wp-amazon-s3-and-cloudfront

Automatically copies media uploads to Amazon S3 for delivery. Optionally configure Amazon CloudFront for even faster delivery.
https://wordpress.org/plugins/amazon-s3-and-cloudfront/
304 stars 148 forks source link

Bug: Local urls and missing wp_as3cf_items data #615

Closed cvn closed 1 year ago

cvn commented 1 year ago

In August, we noticed several newly broken img tags on our site. The broken img src's all had local paths and were pointing to images that were uploaded several years ago. We've used WP Offload Media Lite since 1.4.3, and are currently on 3.0.2. Our site is deployed as a docker image.

I discovered that all the broken images did not have entries in the wp_as3cf_items table. I found that if I created a row manually, and then used wp-cli to regenerate thumbnails, i could fix a broken image. Then, I found a better way to add items to the table in upgrade-items-table.php. I made a script based on that, and successfully fixed my images.

https://gist.github.com/cvn/e2dad31c38be34cee59f3be25ca191d2

In my case, none of the legacy images were in wp_as3cf_items before I ran the script.

I think I'm set now, but I wanted to share this in case I'm not the only one.

Thank you

ianmjones commented 1 year ago

Thanks for sharing @cvn, much appreciated.

It sounds like there was a problem during one of the plugin upgrades and the Upgrade Items Table update didn't complete.

Your script is a little risky as it's not guaranteed that the process it utilizes is always going to be available. It also doesn't cater for all the upgrade routines that follow the one that created the as3cf_items table. We'd strongly recommend allowing WP Offload Media to run through its upgrade routines in their numeric order to ensure data is properly migrated.

Currently, we'd recommend that customers update the post_meta_version element of the tantan_wordpress_s3 options table record to the numeric ID of the upgrade just before the one they had issues with.

So in this case, as the Upgrade Items Table routine has ID 8, we'd recommend using 7.

It's a little tricky updating the tantan_wordpress_s3 record as it is a serialized value that includes key and value length indicators, and if they get out of sync the record will be "broken" and will not load, and therefore WP Offload Media's settings will not load.

So we'd recommend using https://serializededitor.com/ to ensure the record is correct before updating, or https://wordpress.org/plugins/wp-table-pixie/, which corrects lengths on save.

cvn commented 1 year ago

Thank you, @ianmjones! This is gold.