Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
48 changes: 48 additions & 0 deletions features/media-regenerate.feature
Original file line number Diff line number Diff line change
Expand Up @@ -144,3 +144,51 @@ Feature: Regenerate WordPress attachments
"""
Success: Finished regenerating all images.
"""

Scenario: Regenerate images which are missing globally-defined image sizes
Given download:
| path | url |
| {CACHE_DIR}/large-image.jpg | http://wp-cli.org/behat-data/large-image.jpg |
And I run `wp option update uploads_use_yearmonth_folders 0`

When I run `wp media import {CACHE_DIR}/large-image.jpg --title="My imported attachment" --porcelain`
Then save STDOUT as {ATTACHMENT_ID}
And the wp-content/uploads/large-image-100x100.jpg file should not exist

Given a wp-content/mu-plugins/media-settings.php file:
"""
<?php
add_action( 'after_setup_theme', function(){
add_image_size( 'test1', 100, 100, true );
});
"""

When I run `wp media regenerate --only-missing --yes`
Then STDOUT should contain:
"""
Found 1 image to regenerate.
"""
And STDOUT should contain:
"""
Regenerated thumbnails for "My imported attachment"
"""
And STDOUT should contain:
"""
Success: Finished regenerating the image.
"""
And the wp-content/uploads/large-image-100x100.jpg file should exist

When I run `wp media regenerate --only-missing --yes`
Then STDOUT should contain:
"""
Found 1 image to regenerate
"""
And STDOUT should contain:
"""
No thumbnail regeneration needed for "My imported attachment"
"""
And STDOUT should contain:
"""
Success: Finished regenerating the image.
"""
And the wp-content/uploads/large-image-100x100.jpg file should exist
6 changes: 5 additions & 1 deletion php/commands/media.php
Original file line number Diff line number Diff line change
Expand Up @@ -315,7 +315,11 @@ private function needs_regeneration( $att_id ) {
$original_path = $dir_path . basename( $metadata['file'] );

if ( empty( $metadata['sizes'] ) ) {
return false;
return true;
}

if ( array_diff( get_intermediate_image_sizes(), array_keys( $metadata['sizes'] ) ) ) {
return true;
}

foreach( $metadata['sizes'] as $size_info ) {
Expand Down