@@ -1723,6 +1723,67 @@ Feature: Regenerate WordPress attachments
17231723 """
17241724 And the return code should be 1
17251725
1726+ @require-wp-5.3
1727+ Scenario : Regenerate a large image that was edited by the user preserves the edits
1728+ Given download:
1729+ | path | url |
1730+ | {CACHE_DIR }/large -image .jpg | http ://wp -cli .org /behat -data /large -image .jpg |
1731+ And I run `wp option update uploads_use_yearmonth_folders 0`
1732+
1733+ When I run `wp media import {CACHE_DIR}/large-image.jpg --title="My imported large attachment" --porcelain`
1734+ Then save STDOUT as {ATTACHMENT_ID}
1735+ And the wp-content/uploads/large-image.jpg file should exist
1736+ And the wp-content/uploads/large-image-scaled.jpg file should exist
1737+
1738+ # Simulate a user edit by copying the scaled file as an "edited" version,
1739+ # updating the attached file metadata, and setting backup sizes.
1740+ Given a simulate-edit.php file:
1741+ """
1742+ <?php
1743+ $id = (int) $args[0];
1744+ $meta = wp_get_attachment_metadata( $id );
1745+ $old_file = get_attached_file( $id );
1746+ $edited_file = preg_replace( "/(\.[^.]+)$/", "-e0000000000000$1", $old_file );
1747+ copy( $old_file, $edited_file );
1748+ $edited_relative = _wp_relative_upload_path( $edited_file );
1749+ update_post_meta( $id, '_wp_attached_file', $edited_relative );
1750+ $backup = array();
1751+ if ( ! empty( $meta['sizes'] ) ) {
1752+ foreach ( $meta['sizes'] as $size => $size_data ) {
1753+ $backup[ $size . '-orig' ] = $size_data;
1754+ }
1755+ }
1756+ if ( empty( $backup ) ) {
1757+ $backup['full-orig'] = array(
1758+ 'file' => wp_basename( $old_file ),
1759+ 'width' => isset( $meta['width'] ) ? $meta['width'] : 0,
1760+ 'height' => isset( $meta['height'] ) ? $meta['height'] : 0,
1761+ 'mime-type' => get_post_mime_type( $id ),
1762+ );
1763+ }
1764+ update_post_meta( $id, '_wp_attachment_backup_sizes', $backup );
1765+ """
1766+ When I run `wp eval-file simulate-edit.php {ATTACHMENT_ID}`
1767+ Then the wp-content/uploads/large-image-scaled-e0000000000000.jpg file should exist
1768+
1769+ When I run `wp post meta get {ATTACHMENT_ID} _wp_attached_file`
1770+ Then STDOUT should contain:
1771+ """
1772+ large-image-scaled-e0000000000000.jpg
1773+ """
1774+
1775+ When I run `wp media regenerate {ATTACHMENT_ID} --yes`
1776+ Then STDOUT should contain:
1777+ """
1778+ Regenerated thumbnails for "My imported large attachment"
1779+ """
1780+
1781+ When I run `wp post meta get {ATTACHMENT_ID} _wp_attached_file`
1782+ Then STDOUT should contain:
1783+ """
1784+ large-image-scaled-e0000000000000.jpg
1785+ """
1786+
17261787 Scenario : Only delete missing image sizes
17271788 Given download:
17281789 | path | url |
0 commit comments