Skip to content

Set sizes metadata to empty array if doesn't exist.#61

Merged
schlessera merged 2 commits intomasterfrom
issue-60-no-metadata-sizes
Jan 7, 2018
Merged

Set sizes metadata to empty array if doesn't exist.#61
schlessera merged 2 commits intomasterfrom
issue-60-no-metadata-sizes

Conversation

@gitlost
Copy link
Contributor

@gitlost gitlost commented Jan 5, 2018

Closes #60

In needs_regeneration():

  • skips if no image editor available for an image (previously only skipped if PDF) and warns (unless it's a PDF).
  • sets the sizes metadata for an image to an empty array if it doesn't exist before checking it.

Reproduces the issue by uploading a BMP with Imagick disabled so no sizes metadata generated.

Also adds attachment ID to some warnings for better feedback, separates out warnings from progress log on metadata error, and adjusts tests.

@gitlost gitlost added bug command:media-regenerate Related to 'media regenerate' command labels Jan 5, 2018
@gitlost gitlost added this to the 1.1.4 milestone Jan 5, 2018
@gitlost gitlost requested a review from a team January 5, 2018 15:52

# Regenerate with Imagick disabled.
When I try `WP_CLI_TEST_MEDIA_REGENERATE_IMAGICK=0 wp media regenerate --yes`
Then the return code should be 0
Copy link
Member

Choose a reason for hiding this comment

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

Problem with indentation here.

$metadata['sizes'] = array();
}

if ( $this->image_sizes_differ( $image_sizes, $metadata['sizes'] ) ) {
Copy link
Member

Choose a reason for hiding this comment

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

Do you think the above logical construction (the check to make sure $metadata['sizes'] is an array) is useful for documentation purposes?

Otherwise, the code would be cleaner with a simple cast to array in the line where it is used...

if ( $this->image_sizes_differ( $image_sizes, (array) $metadata['sizes'] ) ) {

@schlessera
Copy link
Member

Nice, a creative way to force the problem in tests, @gitlost !

@schlessera schlessera merged commit cff1041 into master Jan 7, 2018
@schlessera schlessera deleted the issue-60-no-metadata-sizes branch January 7, 2018 12:05
danielbachhuber pushed a commit that referenced this pull request Nov 18, 2022
Set sizes metadata to empty array if doesn't exist.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug command:media-regenerate Related to 'media regenerate' command

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants