Skip to content

Restore and backup Image sizes with sources when an image is edited #228

Closed

Description

@mitogh

Description

  • When an image is edited make sure that existing images are stored in the _wp_attachment_backup_sizes meta before applying the changes into the image.
  • If the image is restored update _wp_attachment_backup_sizes array 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_OVERWRITE is 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_sizes should accurately reflect the file locations and properties of each edited image.
  • Image edits should include the suffix e-$id where $id is a 13 digit number specifically time() . 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 of IMAGE_EDIT_OVERWRITE This suffix is also included as part of the image size name.
  • Last update or the restore point in _wp_attachment_backup_sizes uses the suffix -orig on 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

  1. self-assigned this
    on Mar 14, 2022
  2. changed the title [-]Restore and backup Image sizes with sources when an image is edited.[/-] [+]Restore and backup Image sizes with sources when an image is edited[/+] on Mar 14, 2022
  3. felixarntz commented on Mar 16, 2022

    @felixarntz
    Member

    @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.

  4. mitogh commented on Mar 16, 2022

    @mitogh
    MemberAuthor

    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.

  5. added this to the 1.0.0-beta.3 milestone on Mar 19, 2022
  6. mitogh commented on Mar 19, 2022

    @mitogh
    MemberAuthor

    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.

  7. felixarntz commented on Mar 31, 2022

    @felixarntz
    Member

    Fixed via #242

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

Type

No type

Projects

No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions