false ); } wp_cache_delete( 'sem_object_counts', 'aieo_dmm' ); $counts = AIEO_Semantic_Index_Store::object_counts(); $sync = class_exists( 'AIEO_Semantic_Transport' ) && AIEO_Semantic_Transport::sync_enabled(); return array( 'ready' => true, 'total' => (int) ( $counts['total'] ?? 0 ), 'dirty' => (int) ( $counts['dirty'] ?? 0 ), 'indexed' => (int) ( $counts['indexed'] ?? 0 ), 'sync' => (bool) $sync, 'est_push_batches' => (int) ceil( max( 0, (int) ( $counts['total'] ?? 0 ) ) / 500 ), ); } public static function start_onboarding( $seed_all = false, $driver = 'ajax' ) { $enqueue = ( 'as' === $driver ); if ( ! self::engine_ready() ) { return array( 'started' => false, 'reason' => 'engine_absent' ); } if ( method_exists( 'AIEO_Semantic_Index', 'enabled' ) && ! AIEO_Semantic_Index::enabled() ) { return array( 'started' => false, 'reason' => 'indexing_disabled' ); } if ( ! empty( static::runner_status()['running'] ) ) { $res = static::start_streams( array( array( 'onboard' ) ), $enqueue ); return array( 'started' => $res['started'], 'reason' => $res['started'] ? 'stale_run_taken_over' : $res['reason'], ); } if ( $seed_all && method_exists( 'AIEO_Semantic_Index_Store', 'seed_all_dirty' ) ) { AIEO_Semantic_Index_Store::seed_all_dirty(); } $res = static::start_streams( array( array( 'onboard' ) ), $enqueue ); return array( 'started' => $res['started'], 'reason' => $res['reason'] ); } protected static function do_batch( array $args ) { if ( ! self::engine_ready() ) { return array( 'success' => false, 'remaining' => 0, 'total' => 0, 'extra' => array( 'phase' => 'error', 'note' => 'engine_absent' ), ); } wp_cache_delete( 'sem_object_counts', 'aieo_dmm' ); $counts = AIEO_Semantic_Index_Store::object_counts(); $total = (int) ( $counts['total'] ?? 0 ); if ( (int) ( $counts['dirty'] ?? 0 ) > 0 ) { $r = AIEO_Semantic_Index::process_batch( self::INDEX_BATCH ); if ( (int) ( $r['processed'] ?? 0 ) === 0 ) { return array( 'success' => false, 'remaining' => 0, 'total' => $total, 'extra' => array( 'phase' => 'index', 'note' => 'indexer_made_no_progress' ), ); } $index_remaining = (int) ( $r['remaining'] ?? 0 ); if ( 0 === $index_remaining && method_exists( 'AIEO_Semantic_Index_Store', 'refresh_doc_counts' ) ) { AIEO_Semantic_Index_Store::refresh_doc_counts(); } return array( 'success' => true, 'remaining' => $index_remaining + 1, 'total' => $total, 'extra' => array( 'phase' => 'index', 'index_remaining' => $index_remaining ), ); } if ( ! class_exists( 'AIEO_Semantic_Transport' ) || ! is_callable( array( 'AIEO_Semantic_Transport', 'sync_step' ) ) || ! AIEO_Semantic_Transport::sync_enabled() ) { return array( 'success' => true, 'remaining' => 0, 'total' => $total, 'extra' => array( 'phase' => 'done', 'note' => 'sync_disabled_index_only' ), ); } $res = AIEO_Semantic_Transport::sync_step( self::PUSH_BATCHES_PER_TICK ); if ( is_wp_error( $res ) ) { $code = $res->get_error_code(); $permanent = in_array( $code, array( 'no_api_key', 'sem_terminal', 'sem_resync_loop', 'no_data_plane', 'handshake_failed' ), true ); if ( $permanent ) { return array( 'success' => false, 'remaining' => 0, 'total' => $total, 'extra' => array( 'phase' => 'push', 'error' => $code ), ); } return array( 'success' => false, 'remaining' => 1, 'total' => $total, 'retry_in' => self::PUSH_RETRY_IN, 'extra' => array( 'phase' => 'push', 'error' => $code ), ); } if ( ! empty( $res['more'] ) ) { return array( 'success' => true, 'remaining' => max( 1, (int) ( $res['remaining_keys'] ?? 1 ) ), 'total' => $total, 'extra' => array( 'phase' => 'push', 'push_planned' => (int) ( $res['planned_total'] ?? 0 ), 'push_remaining' => (int) ( $res['remaining_keys'] ?? 0 ), 'push_accepted' => (int) ( $res['accepted'] ?? 0 ), ), ); } return array( 'success' => true, 'remaining' => 0, 'total' => $total, 'extra' => array( 'phase' => 'done', 'synced' => ! empty( $res['synced'] ) ), ); } }