Skip to content
Open
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
26 changes: 10 additions & 16 deletions src/features/class-block-audit-command.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@

use Alley\WP\Types\Feature;
use Alley\WP_Bulk_Task\Bulk_Task;
use Alley\WP_Bulk_Task\Cursor\Memory_Cursor;
use Alley\WP_Bulk_Task\Progress\Null_Progress_Bar;
use Alley\WP_Bulk_Task\Progress\PHP_CLI_Progress_Bar;
use WP_CLI;
Expand Down Expand Up @@ -58,9 +59,6 @@ public function boot(): void {
* [--verbose]
* : Turn on verbose mode.
*
* [--rewind]
* : Resets the cursor so the next time the command is run it will start from the beginning.
*
* ## EXAMPLES
*
* $ wp block-audit run --post_type=post,page
Expand Down Expand Up @@ -97,23 +95,17 @@ public function boot(): void {
public function run( array $args, array $assoc_args = [] ): void {
global $wpdb;

$out = [];

$user_query_args = array_diff_key( $assoc_args, array_flip( [ 'format', 'verbose', 'rewind' ] ) );
$user_query_args = array_diff_key( $assoc_args, array_flip( [ 'format', 'verbose' ] ) );
$task_name = get_flag_value( $assoc_args, 'verbose', false )
? new PHP_CLI_Progress_Bar( 'Bulk Task: audit-blocks' )
: new Null_Progress_Bar();

$bulk_task = new Bulk_Task(
'audit-blocks-' . md5( (string) wp_json_encode( $user_query_args ) ),
get_flag_value( $assoc_args, 'verbose', false )
? new PHP_CLI_Progress_Bar( 'Bulk Task: audit-blocks' )
: new Null_Progress_Bar(),
$task_name,
new Memory_Cursor()
);

if ( get_flag_value( $assoc_args, 'rewind', false ) ) {
$bulk_task->cursor->reset();
\WP_CLI::log( 'Rewound the cursor. Run again without the --rewind flag to process posts.' );
return;
}

add_filter( 'ep_skip_query_integration', '__return_true' );

$query_args = array_merge(
Expand All @@ -133,6 +125,8 @@ public function run( array $args, array $assoc_args = [] ): void {
$query_args['post_type'] = explode( ',', $query_args['post_type'] );
}

$out = [];

$bulk_task->run(
$query_args,
function ( \WP_Post $post ) use ( &$out ) {
Expand Down Expand Up @@ -197,7 +191,7 @@ function ( \WP_Post $post ) use ( &$out ) {
);

if ( count( $out ) === 0 ) {
\WP_CLI::warning( 'No results. Run again with the --rewind flag to reset the cursor.' );
\WP_CLI::warning( 'No results found.' );
return;
}

Expand Down