if ( defined( 'WP_CLI' ) && WP_CLI ) { WP_CLI::add_command( 'imlss sched_probe', function() { $state = get_option( IMLSS_Login_Scrape_Test::SCHED_STATE_KEY, [] ); if ( empty( $state['active'] ) || !empty( $state['finished'] ) ) { WP_CLI::success( 'Scheduler is not active or already finished.' ); return; } $cats = $state['cats'] ?? []; $ci = (int) ( $state['cat_idx'] ?? 0 ); if ( $ci >= count( $cats ) ) { WP_CLI::success( 'All categories complete.' ); return; } $cat = $cats[ $ci ]; $cat_name = $cat['name'] ?? $cat['id'] ?? 'Unknown'; $max_steps = 100; $steps = 0; while ( empty( $state['probe_locked'] ) && $steps < $max_steps ) { IMLSS_Login_Scrape_Test::run_sched_batch( $state ); $state = get_option( IMLSS_Login_Scrape_Test::SCHED_STATE_KEY, [] ); $steps++; if ( !empty( $state['probe_locked'] ) ) { WP_CLI::success( "Tail found for {$cat_name} at page " . ( $state['tail_last_page'] ?? '?' ) . "." ); return; } } if ( empty( $state['probe_locked'] ) ) { WP_CLI::warning( "Probe did not lock tail after {$steps} steps for {$cat_name}." ); } } ); }