run_sync(); if ( isset( $result['success'] ) && $result['success'] ) { WBC_Logger::info( 'Cron', 'Scheduled product sync completed', $result ); } else { WBC_Logger::error( 'Cron', 'Scheduled product sync failed', $result ); } } /** * Run log cleanup */ public function run_log_cleanup() { $deleted = WBC_Logger::cleanup_old_logs( 30 ); WBC_Logger::info( 'Cron', 'Log cleanup completed', array( 'deleted_count' => $deleted ) ); } /** * Reschedule the sync event with a new frequency * * @param string $frequency New frequency (hourly, twice_daily, daily). */ public static function reschedule_sync( $frequency ) { // Clear existing schedule $timestamp = wp_next_scheduled( self::SYNC_EVENT ); if ( $timestamp ) { wp_unschedule_event( $timestamp, self::SYNC_EVENT ); } // Schedule with new frequency wp_schedule_event( time(), $frequency, self::SYNC_EVENT ); WBC_Logger::info( 'Cron', 'Sync schedule updated', array( 'frequency' => $frequency ) ); } /** * Get next scheduled sync time * * @return int|false Timestamp of next scheduled sync or false if not scheduled. */ public static function get_next_sync_time() { return wp_next_scheduled( self::SYNC_EVENT ); } /** * Get next scheduled sync time formatted * * @return string Formatted date/time string or 'Not scheduled'. */ public static function get_next_sync_formatted() { $next = self::get_next_sync_time(); if ( ! $next ) { return __( 'Not scheduled', 'woo-business-central' ); } return wp_date( get_option( 'date_format' ) . ' ' . get_option( 'time_format' ), $next ); } /** * Get last sync time * * @return string|false Last sync time or false if never synced. */ public static function get_last_sync_time() { return get_option( 'wbc_last_sync_time', false ); } /** * Get last sync time formatted * * @return string Formatted date/time string or 'Never'. */ public static function get_last_sync_formatted() { $last = self::get_last_sync_time(); if ( ! $last ) { return __( 'Never', 'woo-business-central' ); } return wp_date( get_option( 'date_format' ) . ' ' . get_option( 'time_format' ), strtotime( $last ) ); } /** * Update last sync time */ public static function update_last_sync_time() { update_option( 'wbc_last_sync_time', current_time( 'mysql' ) ); } /** * Run sync now (manual trigger) * * @return array Sync result. */ public static function run_sync_now() { WBC_Logger::info( 'Cron', 'Manual sync triggered' ); $product_sync = new WBC_Product_Sync(); $result = $product_sync->run_sync(); // Update last sync time self::update_last_sync_time(); return $result; } /** * Clear all scheduled events */ public static function clear_all_schedules() { // Clear sync event $sync_timestamp = wp_next_scheduled( self::SYNC_EVENT ); if ( $sync_timestamp ) { wp_unschedule_event( $sync_timestamp, self::SYNC_EVENT ); } // Clear cleanup event $cleanup_timestamp = wp_next_scheduled( self::CLEANUP_EVENT ); if ( $cleanup_timestamp ) { wp_unschedule_event( $cleanup_timestamp, self::CLEANUP_EVENT ); } } }