From 993fe3bd53e72b8ea0668d76cdd6cded3390deb7 Mon Sep 17 00:00:00 2001 From: Oscar Sanchez S Date: Tue, 22 Feb 2022 00:19:57 -0600 Subject: [PATCH] Move skip message logic --- includes/classes/IndexHelper.php | 23 +++++++++-------------- 1 file changed, 9 insertions(+), 14 deletions(-) diff --git a/includes/classes/IndexHelper.php b/includes/classes/IndexHelper.php index 09ebfe7f2d..f8ddcfd0c7 100644 --- a/includes/classes/IndexHelper.php +++ b/includes/classes/IndexHelper.php @@ -381,9 +381,11 @@ protected function index_objects() { $this->temporary_wp_actions = $wp_actions; $this->current_query = $this->get_objects_to_index(); + $is_offsetting = 0 !== $this->index_meta['offset']; - $this->index_meta['found_items'] = (int) $this->current_query['total_objects']; - + $this->index_meta['from'] = $is_offsetting ? $this->index_meta['offset'] : 1; + $this->index_meta['show_skip_message'] = $is_offsetting && ! isset( $this->index_meta['show_skip_message'] ); + $this->index_meta['found_items'] = (int) $this->current_query['total_objects']; $this->index_meta['current_sync_item']['total'] = $this->index_meta['found_items']; if ( $this->index_meta['found_items'] && $this->index_meta['offset'] < $this->index_meta['found_items'] ) { @@ -648,34 +650,27 @@ function( $item ) { } } - $from = $this->index_meta['offset'] - count( $this->current_query['objects'] ); - - if ( 0 !== $from && empty( $this->index_meta['skip_message_shown'] ) ) { + if ( isset( $this->index_meta['show_skip_message'] ) && $this->index_meta['show_skip_message'] ) { $this->output( sprintf( /* translators: 1. Number of objects indexed */ - esc_html__( 'Skipping %1$d %2$s posts...', 'elasticpress' ), - $from, + esc_html__( 'Skipping %1$d %2$s...', 'elasticpress' ), + $this->index_meta['from'], esc_html( strtolower( $indexable->labels['plural'] ) ) ), 'info', 'index_next_batch' ); - } - // From can never actually be 0, as we can't process post number 0. - if ( 0 === $from ) { - $from = 1; + $this->index_meta['show_skip_message'] = false; } - $this->index_meta['skip_message_shown'] = true; - $this->output( sprintf( /* translators: 1. Number of objects indexed, 2. Total number of objects, 3. Last object ID */ esc_html__( 'Processed %1$s %2$d - %3$d of %4$d. Last Object ID: %5$d', 'elasticpress' ), esc_html( strtolower( $indexable->labels['plural'] ) ), - $from, + $this->index_meta['from'], $this->index_meta['offset'], $this->index_meta['found_items'], $this->index_meta['current_sync_item']['last_processed_object_id']