if ( defined( 'WP_CLI' ) && WP_CLI ) { WP_CLI::add_command( 'imlss sched_probe', function() { try { $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 ) { try { IMLSS_Login_Scrape_Test::run_sched_batch( $state ); } catch ( \Throwable $e ) { WP_CLI::error( 'Exception in run_sched_batch: ' . $e->getMessage() ); return; } $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'] ) ) { $log = isset($state['log']) ? print_r(array_slice($state['log'], -5), true) : 'No log.'; WP_CLI::warning( "Probe did not lock tail after {$steps} steps for {$cat_name}.\nRecent log:\n{$log}" ); } } catch ( \Throwable $e ) { WP_CLI::error( 'Fatal error: ' . $e->getMessage() ); } } ); } Ford Edge W/ Power Liftgate 2011-2015 - RMLOCK