Robotstxt_Mlp2_Mlp5_Reader_Content_Relations::count_groups( 'post' ), 'term_total' => Robotstxt_Mlp2_Mlp5_Reader_Content_Relations::count_groups( 'term' ), 'post_offset' => 0, 'term_offset' => 0, 'post_done' => false, 'term_done' => false, ); } // Process posts first, then terms. if ( ! $state['post_done'] ) { $groups = Robotstxt_Mlp2_Mlp5_Reader_Content_Relations::get_groups_batch( 'post', (int) $state['post_offset'], self::BATCH_SIZE ); $state['post_offset'] += count( $groups ); self::process_groups( $groups ); if ( empty( $groups ) || (int) $state['post_offset'] >= (int) $state['post_total'] ) { $state['post_done'] = true; } } elseif ( ! $state['term_done'] ) { $groups = Robotstxt_Mlp2_Mlp5_Reader_Content_Relations::get_groups_batch( 'term', (int) $state['term_offset'], self::BATCH_SIZE ); $state['term_offset'] += count( $groups ); self::process_groups( $groups ); if ( empty( $groups ) || (int) $state['term_offset'] >= (int) $state['term_total'] ) { $state['term_done'] = true; } } Robotstxt_Mlp2_Mlp5_Wizard_State::set_step_data( 4, $state ); return self::build_progress( $state ); } /** * Return the current progress snapshot without running any work. * * @return array { * @type int $total Total groups to process. * @type int $processed Groups processed so far. * @type int $migrated Successfully written to MLP5. * @type int $skipped Skipped (orphaned, already exists, etc.). * @type int $errors Failed writes. * @type bool $done True when all groups (post + term) have been processed. * } */ public static function get_progress(): array { $state = Robotstxt_Mlp2_Mlp5_Wizard_State::get_step_data( 4 ); if ( empty( $state ) ) { return array( 'total' => 0, 'processed' => 0, 'migrated' => 0, 'skipped' => 0, 'errors' => 0, 'done' => false, ); } return self::build_progress( $state ); } /** * Render the Step 4 UI. */ public static function render(): void { $progress = self::get_progress(); $done = $progress['done']; $nonce = wp_create_nonce( Robotstxt_Mlp2_Mlp5_Ajax::NONCE_ACTION ); ?>
' . esc_html( number_format_i18n( $progress['processed'] ) ) . '', '' . esc_html( number_format_i18n( $progress['total'] ) ) . '' ); ?>
'success' ) ); $skipped = Robotstxt_Mlp2_Mlp5_Logger::count( array( 'type' => 'skipped' ) ); $errors = Robotstxt_Mlp2_Mlp5_Logger::count( array( 'type' => 'error' ) ); // Subtract site_relation log entries (those belong to step 3). $migrated -= Robotstxt_Mlp2_Mlp5_Logger::count( array( 'type' => 'success', 'context' => 'site_relation', ) ); $skipped -= Robotstxt_Mlp2_Mlp5_Logger::count( array( 'type' => 'skipped', 'context' => 'site_relation', ) ); $errors -= Robotstxt_Mlp2_Mlp5_Logger::count( array( 'type' => 'error', 'context' => 'site_relation', ) ); return array( 'total' => $post_total + $term_total, 'processed' => $post_offset + $term_offset, 'migrated' => max( 0, $migrated ), 'skipped' => max( 0, $skipped ), 'errors' => max( 0, $errors ), 'done' => $post_done && $term_done, ); } }