Repository navigation
Restore and backup Image sizes with sources when an image is edited #228
Description
Description
- When an image is edited make sure that existing images are stored in the
_wp_attachment_backup_sizesmeta before applying the changes into the image. - If the image is restored update
_wp_attachment_backup_sizesarray with the appropriate values. - At all times the value stored in the metadata of the image should reflect the same state as the images being edited.
When the constant IMAGE_EDIT_OVERWRITE is defined and is set to true edits on the file would be removed and only the previous edit would be stored in _wp_attachment_backup_sizes still allowing to rollback to the original image state, but subsequent edits would effectively remove any previous edit on the files.
Respect the constant IMAGE_EDIT_OVERWRITE
This behavior should follow the same principles for the primary image format in the secondary image format meaning that:
- if
IMAGE_EDIT_OVERWRITEis defined- if the value of the constant is true only the last copy of the secondary image would be kept in the filesystem and referenced in the database.
- if the value of the constant is false multiple copies of the same edit would be kept in the filesystem and in the database in the same way it occurs with the primary image format.
- If the constant is not defined, we should follow the same scenario as if the constant was defined as false
Restoring an image
When the original image is restored, the secondary image format would also be restored in the same way the process is applied to the primary image format. This restore would follow the rules from the constant definition IMAGE_EDIT_OVERWRITE to make sure files are removed or kept in place depending on the value of this constant.
Notes
- In all scenarios, the values in
_wp_attachment_backup_sizesshould accurately reflect the file locations and properties of each edited image. - Image edits should include the suffix
e-$idwhere$idis a 13 digit number specificallytime() . rand( 100, 999 )created by WP to reference any additional edit that is no longer relevant, the file name is important so WP can identify images that reference to edits and can be removed accordingly based on the definition and value ofIMAGE_EDIT_OVERWRITEThis suffix is also included as part of the image size name. - Last update or the restore point in
_wp_attachment_backup_sizesuses the suffix-origon the file name and image size in order to quickly identify which image is the last one edited or the one we need to restore. Reference
Related issues:
The work in this ticket is part of:
In order to keep things in a more manageable way.
Activity
[-]Restore and backup Image sizes with sources when an image is edited.[/-][+]Restore and backup Image sizes with sources when an image is edited[/+]felixarntz commentedon Mar 16, 2022
@mitogh Since this ties in with the already existing functionality whereas #158 is a bit more separate, it would be good to prioritize this issue here. I would argue the fact that the current implementation ignores the additional sources when backing up an image is almost a bug, while adding support for also creating additional sources for edited images is more of an enhancement. In other words, I think it would be worth landing this here sooner than later, while #158 could also follow slightly later. Hope that makes sense.
mitogh commentedon Mar 16, 2022
Thanks for the heads up this is the first item on my priority list so will try to wrap it ASAP and agree the work from #158 is not blocking this issue so we should be able to move forward.
Thanks.
mitogh commentedon Mar 19, 2022
This is ready for code review @felixarntz @adamsilverstein @eugene-manuilov @joehoyle
I've updated the labels and milestone for this ticket, let me know in case you have any additional questions/feedback.
cc @kirtangajjar due this is closely related with #158 as well in case you have any feedback or comments as well.
Thanks.
felixarntz commentedon Mar 31, 2022
Fixed via #242