Make WordPress Core

Opened 3 years ago

Closed 23 months ago

Last modified 23 months ago

#55150 closed enhancement (fixed)

`_wp_attachment_backup_sizes` meta is not deleted when image is restored and IMAGE_EDIT_OVERWRITE is defined

Reported by: mitogh's profile mitogh Owned by: joedolson's profile joedolson
Milestone: 6.2 Priority: normal
Severity: normal Version:
Component: Media Keywords: has-patch commit
Focuses: Cc:

Description

When transformations are applied to an image (rotate, crop, flip) and then the image is restored data remains stored in _wp_attachment_backup_sizes when the data at this point is no longer used or relevant.

All of this happens when the constant IMAGE_EDIT_OVERWRITE is defined and is set to true.

When the constant is not defined multiple backup sizes references are keep in the file system and in the DB so in this context this work as expected.

Steps to replicate:

  1. Make sure to define the constant IMAGE_EDIT_OVERWRITE
  2. Make sure the value of the constant IMAGE_EDIT_OVERWRITE is set to true.
  3. Upload an image into the media library of WordPress.
  4. After the media image has been uploaded rotate, crop it or perform any transformation.
  5. Save the image
  6. Open the edit menu again into the image and restore the original image.

After the image has been restored values in the meta key _wp_attachment_backup_sizes would still exist, in this case, the values presented here are the exact same values as sizes property from _wp_attachment_metadata.

To review the content from the meta you can use a direct DB query or WP CLI using get_post_meta functions.

So the suggested approach here instead would be to remove this meta key if the image is restored and IMAGE_EDIT_OVERWRITE is defined and is set as a true.

This would help make sure a non-needed meta is stored in the meta key if the image was restored. And also to be consistent with the behavior that the edited images are removed if the constant mentioned previously is defined and is set to true

Change History (13)

This ticket was mentioned in Slack in #core-media by antpb. View the logs.


2 years ago

#2 @antpb
2 years ago

  • Milestone changed from Awaiting Review to 6.2

Moving to 6.2 to investigate. Thank you for the clear reproduction steps!

#3 @antpb
2 years ago

Possibly related: #32171

This ticket was mentioned in PR #3537 on WordPress/wordpress-develop by jeawhanlee.


2 years ago
#4

  • Keywords has-patch added

Deletes the Attachment backup size meta from db when attachment is restored.

Trac ticket: https://core.trac.wordpress.org/ticket/55150

#5 @mukesh27
2 years ago

  • Keywords dev-feedback needs-testing added

Hi there,

Thanks @mitogh for ticket. The PR need testing.

#6 @robinwpdeveloper
23 months ago

Test Report

This report validates that the indicated patch addresses the issue.

Patch tested: https://patch-diff.githubusercontent.com/raw/WordPress/wordpress-develop/pull/3537.diff

Environment

  • OS: macOS 11.2.3
  • Web Server: Nginx
  • PHP: 7.4.30
  • WordPress: 6.2-alpha-54642-src
  • Browser: Chrome 109.0.5414.87
  • Theme: Twenty Twenty-Three
  • Active Plugins: No plugins activated

Actual Results

  • ✅ Expected result works as expected with patch.

Additional Notes

  • I have checked wp_postmeta table to verify the meta_key exists or not.

Before Patch: _wp_attachment_backup_sizes meta_key appears in the wp_postmeta table
After Patch: _wp_attachment_backup_sizes meta_key disappears.

Supplemental Artifacts

Before Patch: https://d.pr/i/i0fStc
After Patch 1 (before restoring image): https://d.pr/i/lc1rJB
After Patch 2 (After restoring the image): https://d.pr/i/cvf2hl

#7 @iapial
23 months ago

Reproduction Report

This report validates that the issue can be reproduced, and the indicated patch addresses the issue.

Patch tested: https://patch-diff.githubusercontent.com/raw/WordPress/wordpress-develop/pull/3537.diff

Environment

  • OS: macOS 13.0 (22A380)
  • Web Server: nginx/1.23.3
  • PHP: 7.4.33
  • WordPress: 6.2-alpha-54642-src
  • Browser: Chrome Version 108.0.5359.124
  • Theme: Twenty Twenty-Three
  • Active Plugins:
    • None


Actual Results

  • ✅ Error condition occurs (reproduced).
  • ✅ Issue resolved with patch.

Additional Notes

  • I have checked the issue and the patch works well, the "_wp_attachment_backup_sizes" meta_key disappears after the patch.✅

Supplemental Artifacts

#8 @joemcgill
23 months ago

  • Focuses performance removed

At first glance, the PR looks ok to me, but I haven't tested widely. @antpb let me know if you need any help with this one. I'm going to remove the performance focus in the meantime and let you handle a 6.2 decision as part of the Media Component milestone.

This ticket was mentioned in Slack in #core-media by joedolson. View the logs.


23 months ago

#10 @joedolson
23 months ago

  • Owner set to joedolson
  • Status changed from new to reviewing

#11 @joedolson
23 months ago

  • Keywords commit added; dev-feedback needs-testing removed

Looks good. Committing.

#12 @joedolson
23 months ago

  • Resolution set to fixed
  • Status changed from reviewing to closed

In 55180:

Media: Remove meta data after restoring w/IMAGE_EDIT_OVERWRITE.

When IMAGE_EDIT_OVERWRITE is defined as true the meta field _wp_attachment_backup_sizes is deleted after an image is restored.

Props mitogh, jeawhanlee, robinwpdeveloper, iapial.
Fixes #55150.

@joedolson commented on PR #3537:


23 months ago
#13

Fixed in r55180

Note: See TracTickets for help on using tickets.