Skip to content

Commit 7127225

Browse files
authored
Add reason for skipping regeneration in wp media regenerate (#248)
1 parent 5160da9 commit 7127225

2 files changed

Lines changed: 26 additions & 19 deletions

File tree

features/media-regenerate.feature

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1146,7 +1146,7 @@ Feature: Regenerate WordPress attachments
11461146
"""
11471147
And STDOUT should contain:
11481148
"""
1149-
1/1 Skipped thumbnail regeneration for "My imported SVG attachment" (ID {ATTACHMENT_ID})
1149+
1/1 Skipped thumbnail regeneration for "My imported SVG attachment" (ID {ATTACHMENT_ID}): no editor available for image/svg+xml.
11501150
"""
11511151
And STDOUT should not contain:
11521152
"""
@@ -1166,7 +1166,7 @@ Feature: Regenerate WordPress attachments
11661166
"""
11671167
And STDOUT should contain:
11681168
"""
1169-
1/1 Skipped thumbnail regeneration for "My imported SVG attachment" (ID {ATTACHMENT_ID})
1169+
1/1 Skipped thumbnail regeneration for "My imported SVG attachment" (ID {ATTACHMENT_ID}): no editor available for image/svg+xml.
11701170
"""
11711171
And STDOUT should not contain:
11721172
"""
@@ -1213,7 +1213,7 @@ Feature: Regenerate WordPress attachments
12131213
"""
12141214
And STDOUT should contain:
12151215
"""
1216-
/2 Skipped thumbnail regeneration for "My imported PDF attachment" (ID {PDF_ATTACHMENT_ID})
1216+
/2 Skipped thumbnail regeneration for "My imported PDF attachment" (ID {PDF_ATTACHMENT_ID}): no editor available for application/pdf.
12171217
"""
12181218
And STDOUT should contain:
12191219
"""
@@ -1237,7 +1237,7 @@ Feature: Regenerate WordPress attachments
12371237
"""
12381238
And STDOUT should contain:
12391239
"""
1240-
/2 Skipped thumbnail regeneration for "My imported PDF attachment" (ID {PDF_ATTACHMENT_ID})
1240+
/2 Skipped thumbnail regeneration for "My imported PDF attachment" (ID {PDF_ATTACHMENT_ID}): no editor available for application/pdf.
12411241
"""
12421242
And STDOUT should contain:
12431243
"""
@@ -1286,7 +1286,7 @@ Feature: Regenerate WordPress attachments
12861286
"""
12871287
And STDOUT should contain:
12881288
"""
1289-
/1 Skipped thumbnail regeneration for "My imported PDF attachment" (ID {PDF_ATTACHMENT_ID})
1289+
/1 Skipped thumbnail regeneration for "My imported PDF attachment" (ID {PDF_ATTACHMENT_ID}): no editor available for application/pdf.
12901290
"""
12911291
And STDOUT should not contain:
12921292
"""
@@ -1371,7 +1371,7 @@ Feature: Regenerate WordPress attachments
13711371
"""
13721372
And STDOUT should contain:
13731373
"""
1374-
/1 Skipped thumbnail regeneration for "My imported PDF attachment" (ID {PDF_ATTACHMENT_ID})
1374+
/1 Skipped thumbnail regeneration for "My imported PDF attachment" (ID {PDF_ATTACHMENT_ID}): no editor available for application/pdf.
13751375
"""
13761376
And STDOUT should not contain:
13771377
"""
@@ -1470,7 +1470,7 @@ Feature: Regenerate WordPress attachments
14701470
"""
14711471
And STDOUT should contain:
14721472
"""
1473-
1/1 Skipped thumbnail regeneration for "My imported BMP attachment" (ID {BMP_ATTACHMENT_ID}).
1473+
1/1 Skipped thumbnail regeneration for "My imported BMP attachment" (ID {BMP_ATTACHMENT_ID}): no editor available for image/bmp.
14741474
"""
14751475
And STDOUT should contain:
14761476
"""
@@ -1529,7 +1529,7 @@ Feature: Regenerate WordPress attachments
15291529
"""
15301530
And STDOUT should contain:
15311531
"""
1532-
1/1 Skipped thumbnail regeneration for "My imported BMP attachment" (ID {BMP_ATTACHMENT_ID}).
1532+
1/1 Skipped thumbnail regeneration for "My imported BMP attachment" (ID {BMP_ATTACHMENT_ID}): no editor available for image/bmp.
15331533
"""
15341534
And STDOUT should contain:
15351535
"""
@@ -1621,7 +1621,7 @@ Feature: Regenerate WordPress attachments
16211621
"""
16221622
And STDOUT should contain:
16231623
"""
1624-
/4 Skipped thumbnail regeneration for "My imported SVG attachment" (ID {SVG_ATTACHMENT_ID}).
1624+
/4 Skipped thumbnail regeneration for "My imported SVG attachment" (ID {SVG_ATTACHMENT_ID}): no editor available for image/svg+xml.
16251625
"""
16261626
And STDOUT should contain:
16271627
"""
@@ -1653,11 +1653,11 @@ Feature: Regenerate WordPress attachments
16531653
"""
16541654
And STDOUT should contain:
16551655
"""
1656-
/4 Skipped thumbnail regeneration for "My imported SVG attachment" (ID {SVG_ATTACHMENT_ID}).
1656+
/4 Skipped thumbnail regeneration for "My imported SVG attachment" (ID {SVG_ATTACHMENT_ID}): no editor available for image/svg+xml.
16571657
"""
16581658
And STDOUT should contain:
16591659
"""
1660-
/4 Skipped thumbnail regeneration for "My imported PDF attachment" (ID {PDF_ATTACHMENT_ID}).
1660+
/4 Skipped thumbnail regeneration for "My imported PDF attachment" (ID {PDF_ATTACHMENT_ID}): no editor available for application/pdf.
16611661
"""
16621662
And STDOUT should contain:
16631663
"""
@@ -1683,11 +1683,11 @@ Feature: Regenerate WordPress attachments
16831683
"""
16841684
And STDOUT should contain:
16851685
"""
1686-
/4 Skipped thumbnail regeneration for "My imported SVG attachment" (ID {SVG_ATTACHMENT_ID}).
1686+
/4 Skipped thumbnail regeneration for "My imported SVG attachment" (ID {SVG_ATTACHMENT_ID}): no editor available for image/svg+xml.
16871687
"""
16881688
And STDOUT should contain:
16891689
"""
1690-
/4 Skipped thumbnail regeneration for "My imported PDF attachment" (ID {PDF_ATTACHMENT_ID}).
1690+
/4 Skipped thumbnail regeneration for "My imported PDF attachment" (ID {PDF_ATTACHMENT_ID}): no editor available for application/pdf.
16911691
"""
16921692
And STDOUT should contain:
16931693
"""
@@ -1716,7 +1716,7 @@ Feature: Regenerate WordPress attachments
17161716
"""
17171717
And STDOUT should contain:
17181718
"""
1719-
/4 Skipped thumbnail regeneration for "My imported SVG attachment" (ID {SVG_ATTACHMENT_ID}).
1719+
/4 Skipped thumbnail regeneration for "My imported SVG attachment" (ID {SVG_ATTACHMENT_ID}): no editor available for image/svg+xml.
17201720
"""
17211721
And STDOUT should contain:
17221722
"""
@@ -1765,7 +1765,7 @@ Feature: Regenerate WordPress attachments
17651765
"""
17661766
And STDOUT should contain:
17671767
"""
1768-
/4 Skipped thumbnail regeneration for "My imported SVG attachment" (ID {SVG_ATTACHMENT_ID}).
1768+
/4 Skipped thumbnail regeneration for "My imported SVG attachment" (ID {SVG_ATTACHMENT_ID}): no editor available for image/svg+xml.
17691769
"""
17701770
And STDOUT should contain:
17711771
"""

src/Media_Command.php

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1167,7 +1167,7 @@ private function process_regeneration( $id, $skip_delete, $only_missing, $delete
11671167
$needs_regeneration = $this->needs_regeneration( $id, $fullsizepath, $is_pdf, $image_sizes, $skip_delete, $skip_it );
11681168

11691169
if ( $skip_it ) {
1170-
WP_CLI::log( "$progress Skipped $thumbnail_desc regeneration for $att_desc." );
1170+
WP_CLI::log( "$progress Skipped $thumbnail_desc regeneration for $att_desc: $skip_it" );
11711171
++$skips;
11721172
return;
11731173
}
@@ -1429,8 +1429,8 @@ private function remove_old_images( $metadata, $fullsizepath, $image_sizes ) {
14291429
* @param bool $is_pdf
14301430
* @param string[] $image_sizes
14311431
* @param bool $skip_delete
1432-
* @param bool $skip_it
1433-
* @param-out bool $skip_it
1432+
* @param string|false $skip_it Reason string if skipping, false otherwise.
1433+
* @param-out string|false $skip_it
14341434
* @return bool
14351435
*/
14361436
private function needs_regeneration( $att_id, $fullsizepath, $is_pdf, $image_sizes, $skip_delete, &$skip_it ) {
@@ -1449,7 +1449,9 @@ private function needs_regeneration( $att_id, $fullsizepath, $is_pdf, $image_siz
14491449
if ( ! $is_pdf && is_array( $metadata ) && ! empty( $metadata['sizes'] ) ) {
14501450
WP_CLI::warning( sprintf( '%s (ID %d)', $attachment_sizes->get_error_message(), $att_id ) );
14511451
}
1452-
$skip_it = true;
1452+
$mime_type = get_post_mime_type( $att_id );
1453+
$skip_it = sprintf( 'no editor available for %s.', $mime_type ? $mime_type : 'this file type' );
1454+
WP_CLI::debug( sprintf( 'Skipping attachment %d: %s.', $att_id, $skip_it ), 'media' );
14531455
return false;
14541456
}
14551457

@@ -1481,6 +1483,7 @@ private function needs_regeneration( $att_id, $fullsizepath, $is_pdf, $image_siz
14811483
$filtered_sizes = array_intersect_key( $attachment_sizes, array_flip( $image_sizes ) );
14821484

14831485
if ( empty( $filtered_sizes ) ) {
1486+
WP_CLI::debug( sprintf( 'Not regenerating attachment %d: no requested sizes apply to this attachment.', $att_id ), 'media' );
14841487
return false;
14851488
}
14861489

@@ -1501,6 +1504,7 @@ private function needs_regeneration( $att_id, $fullsizepath, $is_pdf, $image_siz
15011504
}
15021505

15031506
if ( $this->image_sizes_differ( $attachment_sizes, $metadata['sizes'] ) ) {
1507+
WP_CLI::debug( sprintf( 'Regenerating attachment %d: image sizes have changed.', $att_id ), 'media' );
15041508
return true;
15051509
}
15061510

@@ -1519,9 +1523,12 @@ private function needs_regeneration( $att_id, $fullsizepath, $is_pdf, $image_siz
15191523
}
15201524

15211525
if ( ! file_exists( $intermediate_path ) ) {
1526+
WP_CLI::debug( sprintf( 'Regenerating attachment %d: missing thumbnail file "%s".', $att_id, $size_info['file'] ), 'media' );
15221527
return true;
15231528
}
15241529
}
1530+
1531+
WP_CLI::debug( sprintf( 'Attachment %d: all thumbnails up to date.', $att_id ), 'media' );
15251532
return false;
15261533
}
15271534

0 commit comments

Comments
 (0)