Skip to content

Commit

Permalink
Merge pull request #162 from wp-cli/fix/read-error-in-exif-discovery
Browse files Browse the repository at this point in the history
Fix read error detection in EXIF discovery
  • Loading branch information
schlessera authored Sep 2, 2022
2 parents 0d5fa2a + 56f2c03 commit 7e35526
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 0 deletions.
1 change: 1 addition & 0 deletions features/media-regenerate.feature
Original file line number Diff line number Diff line change
Expand Up @@ -1561,6 +1561,7 @@ Feature: Regenerate WordPress attachments
# Make canola.jpg fail.
Given a wp-content/uploads/canola.jpg file:
"""
We need to have some bytes at least to avoid a PHP notice in exif_imagetype().
"""

When I try `WP_CLI_TEST_MEDIA_REGENERATE_PDF=1 wp media regenerate --yes`
Expand Down
8 changes: 8 additions & 0 deletions src/Media_Command.php
Original file line number Diff line number Diff line change
Expand Up @@ -605,6 +605,14 @@ private function process_regeneration( $id, $skip_delete, $only_missing, $image_
return;
}

// On read error, we might only get the filesize returned and nothing else.
if ( 1 === count( $metadata ) && array_key_exists( 'filesize', $metadata ) && ! ( $is_pdf && $image_size ) ) {
WP_CLI::warning( sprintf( 'Read error while retrieving metadata. (ID %d)', $id ) );
WP_CLI::log( "$progress Couldn't regenerate thumbnails for $att_desc." );
$errors++;
return;
}

if ( $image_size ) {
if ( $this->update_attachment_metadata_for_image_size( $id, $metadata, $image_size ) ) {
WP_CLI::log( "$progress Regenerated $thumbnail_desc for $att_desc." );
Expand Down

0 comments on commit 7e35526

Please sign in to comment.