From c84bf18ad20e832fe364e8155cfb5b4c8cea4e3a Mon Sep 17 00:00:00 2001 From: Nikolay Yordanov Date: Fri, 16 Sep 2016 10:16:49 +0100 Subject: [PATCH 1/3] Add a simple progress indicator to `wp media regenerate` --- php/commands/media.php | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/php/commands/media.php b/php/commands/media.php index 910658d37f..051e371392 100644 --- a/php/commands/media.php +++ b/php/commands/media.php @@ -90,8 +90,8 @@ function regenerate( $args, $assoc_args = array() ) { _n( 'image', 'images', $count ) ) ); $errored = false; - foreach ( $images->posts as $id ) { - if ( ! $this->_process_regeneration( $id, $skip_delete, $only_missing ) ) { + foreach ( $images->posts as $number => $id ) { + if ( ! $this->_process_regeneration( $id, $skip_delete, $only_missing, ( $number + 1 ) . '/' . $count ) ) { $errored = true; } } @@ -275,7 +275,7 @@ private function _make_copy( $path ) { return $filename; } - private function _process_regeneration( $id, $skip_delete = false, $only_missing = false ) { + private function _process_regeneration( $id, $skip_delete = false, $only_missing = false, $progress = '' ) { $fullsizepath = get_attached_file( $id ); @@ -299,16 +299,16 @@ private function _process_regeneration( $id, $skip_delete = false, $only_missing } if ( empty( $metadata ) ) { - WP_CLI::warning( "Couldn't regenerate thumbnails for $att_desc." ); + WP_CLI::warning( "$progress Couldn't regenerate thumbnails for $att_desc." ); return false; } wp_update_attachment_metadata( $id, $metadata ); - WP_CLI::log( "Regenerated thumbnails for $att_desc." ); + WP_CLI::log( "$progress Regenerated thumbnails for $att_desc." ); return true; } else { - WP_CLI::log( "No thumbnail regeneration needed for $att_desc." ); + WP_CLI::log( "$progress No thumbnail regeneration needed for $att_desc." ); return true; } } From a6cea71f68e1871ededf059337e48bee7d536407 Mon Sep 17 00:00:00 2001 From: Nikolay Yordanov Date: Fri, 16 Sep 2016 11:43:39 +0100 Subject: [PATCH 2/3] `wp media regenerate`: update tests to reflect changes in output --- features/media-regenerate.feature | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/features/media-regenerate.feature b/features/media-regenerate.feature index 0981e41c87..ae81bf092a 100644 --- a/features/media-regenerate.feature +++ b/features/media-regenerate.feature @@ -134,11 +134,11 @@ Feature: Regenerate WordPress attachments """ And STDOUT should contain: """ - No thumbnail regeneration needed for "My second imported attachment" + 1/2 No thumbnail regeneration needed for "My second imported attachment" """ And STDOUT should contain: """ - Regenerated thumbnails for "My imported attachment" + 2/2 Regenerated thumbnails for "My imported attachment" """ And STDOUT should contain: """ @@ -170,7 +170,7 @@ Feature: Regenerate WordPress attachments """ And STDOUT should contain: """ - Regenerated thumbnails for "My imported attachment" + 1/1 Regenerated thumbnails for "My imported attachment" """ And STDOUT should contain: """ @@ -185,7 +185,7 @@ Feature: Regenerate WordPress attachments """ And STDOUT should contain: """ - No thumbnail regeneration needed for "My imported attachment" + 1/1 No thumbnail regeneration needed for "My imported attachment" """ And STDOUT should contain: """ From 01bebd9c9589721f7e96df9a0713fda647bc79e2 Mon Sep 17 00:00:00 2001 From: Nikolay Yordanov Date: Fri, 23 Sep 2016 10:42:16 +0100 Subject: [PATCH 3/3] Make Media_Command::_process_regeneration() $progress argument required --- php/commands/media.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/php/commands/media.php b/php/commands/media.php index 051e371392..c3bf4b3342 100644 --- a/php/commands/media.php +++ b/php/commands/media.php @@ -275,7 +275,7 @@ private function _make_copy( $path ) { return $filename; } - private function _process_regeneration( $id, $skip_delete = false, $only_missing = false, $progress = '' ) { + private function _process_regeneration( $id, $skip_delete = false, $only_missing = false, $progress ) { $fullsizepath = get_attached_file( $id );