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

Images skipped due to "no regeneration needed" have outdated meta data #208

Open
2 tasks done
jamieburchell opened this issue Nov 5, 2024 · 1 comment
Open
2 tasks done

Comments

@jamieburchell
Copy link

jamieburchell commented Nov 5, 2024

Bug Report

Describe the current, buggy behavior

I changed the "medium" image size in the WordPress media settings from 360x360px to 400x400px and ran the following command:

wp media regenerate --missing-only

The images were regenerated, but some were skipped as "No thumbnail regeneration needed". I later discovered that the meta data in the image attachments for those that were skipped still referenced the 360px version of the "medium" sized image. I identified all affected image attachments and then ran:

wp media regenerate [attachment-ids]

This successfully updated the attachment meta and removed the reference to the 360px version of the image. I believe this occurred on images that were <= 400px.

It appears that if the command sees that the original image is the same size or less than the target, it is skipped but in doing so the meta is not updated to reference the original image.

Describe how other contributors can replicate this bug

  • Set medium size images to 360 x 360 in WordPress settings
  • Upload an image of size 400 x 400
  • Change medium size images to 400 x 400 in WordPress settings
  • Run wp media regenerate --missing-only
  • Image is skipped, meta for medium refers to the 360x360 version of the image

Example meta (note 360px image still referenced as "medium" size):

a:6:{s:5:"width";i:400;s:6:"height";i:400;s:4:"file";s:13:"2024/11/a.jpg";s:8:"filesize";i:222592;s:5:"sizes";a:3:{s:6:"medium";a:5:{s:4:"file";s:13:"a-360x360.jpg";s:5:"width";i:360;s:6:"height";i:360;s:9:"mime-type";s:10:"image/jpeg";s:8:"filesize";i:49522;}s:9:"thumbnail";a:5:{s:4:"file";s:13:"a-150x150.jpg";s:5:"width";i:150;s:6:"height";i:150;s:9:"mime-type";s:10:"image/jpeg";s:8:"filesize";i:9796;}s:5:"Small";a:5:{s:4:"file";s:13:"a-250x250.jpg";s:5:"width";i:250;s:6:"height";i:250;s:9:"mime-type";s:10:"image/jpeg";s:8:"filesize";i:25537;}}s:10:"image_meta";a:12:{s:8:"aperture";s:1:"0";s:6:"credit";s:0:"";s:6:"camera";s:0:"";s:7:"caption";s:0:"";s:17:"created_timestamp";s:1:"0";s:9:"copyright";s:0:"";s:12:"focal_length";s:1:"0";s:3:"iso";s:1:"0";s:13:"shutter_speed";s:1:"0";s:5:"title";s:0:"";s:11:"orientation";s:1:"0";s:8:"keywords";a:0:{}}}

Additionally, the old 360px medium size image file is not deleted from the filesystem.

Example meta after running wp media regenerate [attachment-id] on affected image (note 360px version removed from meta and filesystem):

a:6:{s:5:"width";i:400;s:6:"height";i:400;s:4:"file";s:13:"2024/11/a.jpg";s:8:"filesize";i:222592;s:5:"sizes";a:2:{s:9:"thumbnail";a:5:{s:4:"file";s:13:"a-150x150.jpg";s:5:"width";i:150;s:6:"height";i:150;s:9:"mime-type";s:10:"image/jpeg";s:8:"filesize";i:9796;}s:5:"Small";a:5:{s:4:"file";s:13:"a-250x250.jpg";s:5:"width";i:250;s:6:"height";i:250;s:9:"mime-type";s:10:"image/jpeg";s:8:"filesize";i:25537;}}s:10:"image_meta";a:12:{s:8:"aperture";s:1:"0";s:6:"credit";s:0:"";s:6:"camera";s:0:"";s:7:"caption";s:0:"";s:17:"created_timestamp";s:1:"0";s:9:"copyright";s:0:"";s:12:"focal_length";s:1:"0";s:3:"iso";s:1:"0";s:13:"shutter_speed";s:1:"0";s:5:"title";s:0:"";s:11:"orientation";s:1:"0";s:8:"keywords";a:0:{}}}

Describe what you would expect as the correct outcome

Image meta should be updated.

Let us know what environment you are running this on

OS:     Linux 5.14.0-427.40.1.el9_4.x86_64 #1 SMP PREEMPT_DYNAMIC Wed Oct 16 14:57:47 UTC 2024 x86_64
Shell:  /sbin/nologin
PHP binary:     /usr/bin/php
PHP version:    8.2.25
php.ini used:   /etc/php.ini
MySQL binary:   /bin/mysql
MySQL version:  mysql  Ver 15.1 Distrib 10.5.22-MariaDB, for Linux (x86_64) using  EditLine wrapper
SQL modes:
WP-CLI root dir:        phar://wp-cli.phar/vendor/wp-cli/wp-cli
WP-CLI vendor dir:      phar://wp-cli.phar/vendor
WP_CLI phar path:       /var/www/vhosts/X/releases/194
WP-CLI packages dir:
WP-CLI cache dir:       /usr/share/httpd/.wp-cli/cache
WP-CLI global config:
WP-CLI project config:  /var/www/vhosts/X/releases/194/wp-cli.yml
WP-CLI version: 2.11.0```
@jamieburchell jamieburchell changed the title Images skipped due to "no regeneration necessary" have outdated meta data Images skipped due to "no regeneration needed" have outdated meta data Nov 5, 2024
@dilipom13
Copy link

The above command is working for me again I will review it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants