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

Add image replacement feature #230

Open
wants to merge 13 commits into
base: develop
Choose a base branch
from

Conversation

hugosolar
Copy link

@hugosolar hugosolar commented May 27, 2024

Description of the Change

Extending our previous feature to replace PDFs in #220
Now I'm adding the feature to replace images.
The criteria to replace images is based on the source image, we're using it as a reference to handle metadata
The process is to loop over the registered sizes for the image and find the image with the nearest size from the replacement and replace the correspondent image size.
This approach seems to be the one used by known plugins like Enable Media replace

The workflow we're following is

  • Selecting an image to be replaced
  • Click "Replace this media"
  • Select an image to replace
  • The new image is going to be uploaded to Azure
  • After that if "Replace media" is clicked:
    • Replacing the main image
    • Loop through the source sizes in _wp_attached_file and copy those over to replace the location finding the closest size possible
    • Then we delete the newest attachment

https://drive.google.com/file/d/1vPuk_cYUdWrlGBY3bUkjxWTpZeYr-BTG/view

This plugin also fixes #184 ensuring we're processing an array with array_flip otherwise returning a WP_Error object
closes #182 #130

How to test the Change

Changelog Entry

Added - New feature
Feature to replace images at the blob storage level

Fixed - Bug fix
Fixed bug relate to the use of array_flip and not ensuring it was an actual arrat

Credits

Props @hugosolar

Checklist:

  • I agree to follow this project's Code of Conduct.
  • I have updated the documentation accordingly.
  • I have added tests to cover my change.
  • All new and existing tests pass.

@hugosolar hugosolar self-assigned this May 27, 2024
@vikrampm1 vikrampm1 modified the milestones: Future Release, 4.5.0 May 28, 2024
@jeffpaul jeffpaul removed their request for review May 28, 2024 20:08
@jeffpaul
Copy link
Member

jeffpaul commented Jun 3, 2024

@rickalee looking to you / your team for review / approval here

rickalee
rickalee previously approved these changes Jun 16, 2024
@rickalee
Copy link
Collaborator

@hugosolar Approved. Looks great. Any considerations with Cache and configuration we need to document for other users of public plugin?

@hugosolar
Copy link
Author

@rickalee I've addressed cache issue by setting the blob properties cache to 30 segs
Screenshot 2024-06-17 at 14 42 01

rickalee
rickalee previously approved these changes Jun 17, 2024
@hugosolar
Copy link
Author

@jeffpaul the e2e error seems to come directly from wp-env

ERROR: for f505fb82f2963a5299b2972f47ad8834_mysql_1  'ContainerConfig'
Creating f505fb82f2963a5299b2972f47ad8834_tests-wordpress_1 ... done
Creating f505fb82f2963a5299b2972f47ad8834_tests-cli_1       ... 
Creating f505fb82f2963a5299b2972f47ad8834_tests-cli_1       ... done
[2378] Failed to execute script docker-compose

ERROR: for mysql  'ContainerConfig'

have you seen this before?
actually, we're using @wordpress/env 8.7.0 in the plugin and it's currently at 2.0.0 I can try to update that library and see how it goes

@dkotter
Copy link
Collaborator

dkotter commented Jun 18, 2024

@hugosolar Yes, updating @wordpress/env to the latest should fix that particular issue, as we've ran across this on a few other plugins. Seems GitHub updated the ubuntu-latest image and this causes issues with wp-env if it's not running the latest

@hugosolar
Copy link
Author

@dkotter @jeffpaul I've updated wp-env and I can see the build is passing now
now it's failing on cypress tests since I'm pushing from a forked repository and secrets aren't available to accomplish those tests.
This has been fixed on my other PRs
let me know how can I help with this

includes/class-windows-azure-helper.php Show resolved Hide resolved
includes/class-windows-azure-replace-media.php Outdated Show resolved Hide resolved
Comment on lines +368 to +371
$filename_path = $source_sizes['meta_data']['file'];
$file_path = dirname( $filename_path );

$target_filename = $target_sizes['meta_data']['file'];
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Wondering if we need to be more defensive here? For both $source_sizes and $target_sizes, will these always be arrays and will the keys we want always exist? Or do we need to check for those before proceeding?

Copy link
Author

@hugosolar hugosolar Jun 24, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@dkotter since this array is made above, it stores WordPress default _wp_attachment_metadata so it's always expected to exist if it's a valid attachment. Although I agree with the extra check because we never knows if we're about to handle an invalid attachment or a similar situation.
I've added some extra checks to bail early

includes/class-windows-azure-replace-media.php Outdated Show resolved Hide resolved
@jeffpaul
Copy link
Member

Note I'm holding for @rickalee's review before merging here

@jeffpaul jeffpaul linked an issue Jul 3, 2024 that may be closed by this pull request
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

Successfully merging this pull request may close these issues.

WP 6.2.2 error Add a 'Replace Media File' option Feature: Replace File option in Media Library
5 participants