'ids', 'number' => 0 ) ) as $blog_id ) { switch_to_blog( (int) $blog_id ); try { self::deactivate_current_site(); } finally { restore_current_blog(); } } return; } self::deactivate_current_site(); } /** * @return void */ private static function deactivate_current_site() { foreach ( array_merge( CronRegistry::hooks(), CronRegistry::legacy_hooks() ) as $hook ) { try { if ( false === wp_unschedule_hook( $hook ) ) { Logger::error( 'lifecycle', 'Cron hook could not be unscheduled', array( 'hook' => $hook ) ); } } catch ( \Throwable $throwable ) { Logger::error( 'lifecycle', 'Cron hook could not be unscheduled', array( 'hook' => $hook, 'error' => $throwable->getMessage() ) ); } } try { if ( false === wp_clear_scheduled_hook( 'aipt_entitlement_background_refresh' ) ) { Logger::error( 'lifecycle', 'Cron hook could not be unscheduled', array( 'hook' => 'aipt_entitlement_background_refresh' ) ); } } catch ( \Throwable $throwable ) { Logger::error( 'lifecycle', 'Cron hook could not be unscheduled', array( 'hook' => 'aipt_entitlement_background_refresh', 'error' => $throwable->getMessage() ) ); } delete_option( 'aipt_entitlement_refresh_state' ); self::unschedule_automation_jobs_crons(); self::unschedule_store_index_jobs(); if (function_exists('as_unschedule_all_actions')) { try { as_unschedule_all_actions('', [], 'aipt-catalog-watch'); } catch (\Throwable $throwable) { Logger::error('lifecycle', 'Catalog watch actions could not be unscheduled', array('error' => $throwable->getMessage())); } } } /** * Stops the cron tasks related to automation jobs * * @return void */ private static function unschedule_automation_jobs_crons() { try { \AIPT\Api\AutomationJobs\JobScheduler::clearCronSchedules(); } catch (\Exception $e) { } } /** * Stops the Action Scheduler jobs related to the AI Store Index * * @return void */ private static function unschedule_store_index_jobs() { if (!function_exists('as_unschedule_all_actions')) { return; } try { $group = 'aipt-store-index'; as_unschedule_all_actions('aipt_build_store_index', [], $group); as_unschedule_all_actions('aipt_scheduled_index_rebuild', [], $group); update_option('aipt_store_index_status', 'idle', false); update_option('aipt_store_index_build_progress', 0, false); update_option('aipt_store_index_build_job_id', 0, false); delete_transient('aipt_index_build_data'); } catch (\Exception $e) { Logger::error('lifecycle', 'Store index jobs could not be unscheduled', array('error' => $e->getMessage())); } } }