-
Notifications
You must be signed in to change notification settings - Fork 101
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
Restore and backup image sizes alongside the sources properties #242
Restore and backup image sizes alongside the sources properties #242
Conversation
The class is in charge of performing operations to an image as if a user is performing those actions from the image editor but from the BE. This class is a utility class to be used from within the test context to mimic the user behavior of performing edits into an image.
When an image is edited the `sources` properties is going to be backup with the rest of the sizes properties, however that's not the case for the `full` size which is a virtual type and the top level `sources` would be moved into the backup metadata. When the image is restored any edited image available in the sources array would be removed before the restore takes place. The `sources` property for the `full-orig` would be placed at the top level `sources` with the rest of the metadata.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@mitogh Left a few comments. High-level summary:
- We can simplify this implementation by introducing our own
_wp_attachment_backup_sources
meta key. - This meta key will be used to store the
sources
only for the original image (since WP core otherwise wouldn't store it). - The other
sources
are automatically backed up by WP core, since it just copies everything over for the sub-sizes. That actually already works today, which is nice to see. - When restoring, we then only need to include logic to restore the original image
sources
. - We don't need to delete any image files because edited images will not have any
sources
added (that'll be part of Perform updates on secondary image mime types when original image is edited #158). In other words, there will not be anything to delete other than what WP core already handles.
This would be handled once #158 is merged so the current approach can be adjusted accordingly.
When an image is edited using a target other than the all and the thumbnail make sure the `success` method returns the correct value.
Due to the only value that is not correctly stored is the top level sources attributes this now is stored in a separate meta value. Stored in `_wp_attachment_backup_sources` Logic was added to handle scenarios where only the thumbnail or all images except the thumbnail are modified.
Thanks for this review @felixarntz just updated this PR based on your feedback, let me know in case you have any additional comments or feedback. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@mitogh Left a few follow-up comments, I still have some open questions, and a few small nit-picks.
Co-authored-by: Felix Arntz <felixarntz@users.noreply.github.com>
Co-authored-by: Felix Arntz <felixarntz@users.noreply.github.com>
Co-authored-by: Felix Arntz <felixarntz@users.noreply.github.com>
Co-authored-by: Felix Arntz <felixarntz@users.noreply.github.com>
Move the hooks for the update right into the place where they are actually used.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@mitogh This looks great now from a functionality perspective! I left a few comments on cleaning up a few things, we can simplify some code and reuse the function instead of rewriting it twice.
The main point of feedback here is that we also should do an extra security check to ensure we're updating the correct attachment.
Co-authored-by: Felix Arntz <felixarntz@users.noreply.github.com>
Co-authored-by: Felix Arntz <felixarntz@users.noreply.github.com>
The `backup_sizes` parameter was not used so it can be safely removed from the code execution.
Reuse the hook as now is stored in a variable, so it can be reused in both hooks.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@mitogh Awesome work!
cc @adamsilverstein for incorporating this into the core patch (in there we can do it without that hook weirdness present here)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice work, @mitogh! Added some comments with minor improvements. Please, let me know whether it makes sense to you.
Co-authored-by: Eugene Manuilov <manuilov@google.com>
Co-authored-by: Eugene Manuilov <manuilov@google.com>
Co-authored-by: Eugene Manuilov <manuilov@google.com>
Co-authored-by: Eugene Manuilov <manuilov@google.com>
Make sure the code performns in a more structured way
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM! Thanks, @mitogh.
Summary
Fixes #228
Relevant technical choices
Usage of
_sources
metadata keyA
_sources
property is stored to hold the top-levelsources
for the full image size when an image is edited, after the backup is updated the_sources
property would be moved into the appropriatefull
size inside of the backup metadata and the temporarily_sources
property would be removed from the attachment image.This key is used so when the metadata is updated we still have a reference to the previous sources values to the full size image when the image is edited. This is not the case for the rest of real sizes, this is only the case for full sizes.
When the image is restored the
sources
property is populated again from the backup metadata if thefull-orig
has thesources
property.Removal of edited images
When an image is edited and restored any edited version of the images are removed if
IMAGE_EDIT_OVERWRITE
is defined as atruthy
value.Checklist
[Focus]
orInfrastructure
label.[Type]
label.no milestone
label.