= null ) {
if ( ! self::sync_allowed() ) {
return false;
}
$full_sync_module = Modules::get_module( 'full-sync' );
'@phan-var Modules\Full_Sync_Immediately|Modules\Full_Sync $full_sync_module';
if ( ! $full_sync_module ) {
return false;
}
self::initialize_listener();
$full_sync_module->start( $modules, $context );
return true;
}
/**
* Adds a cron schedule for regular syncing via cron, unless the schedule already exists.
*
* @access public
* @static
*
* @param array $schedules The list of WordPress cron schedules prior to this filter.
* @return array A list of WordPress cron schedules with the Jetpack sync interval added.
*/
public static function jetpack_cron_schedule( $schedules ) {
if ( ! isset( $schedules[ self::DEFAULT_SYNC_CRON_INTERVAL_NAME ] ) ) {
$minutes = (int) ( self::DEFAULT_SYNC_CRON_INTERVAL_VALUE / 60 );
$display = ( 1 === $minutes ) ?
__( 'Every minute', 'jetpack-sync' ) :
/* translators: %d is an integer indicating the number of minutes. */
sprintf( __( 'Every %d minutes', 'jetpack-sync' ), $minutes );
$schedules[ self::DEFAULT_SYNC_CRON_INTERVAL_NAME ] = array(
'interval' => self::DEFAULT_SYNC_CRON_INTERVAL_VALUE,
'display' => $display,
);
}
return $schedules;
}
/**
* Starts an incremental sync via cron.
*
* @access public
* @static
*/
public static function do_cron_sync() {
self::do_cron_sync_by_type( 'sync' );
}
/**
* Starts a full sync via cron.
*
* @access public
* @static
*/
public static function do_cron_full_sync() {
self::do_cron_sync_by_type( 'full_sync' );
}
/**
* Try to send actions until we run out of things to send,
* or have to wait more than 15s before sending again,
* or we hit a lock or some other sending issue
*
* @access public
* @static
*
* @param string $type Sync type. Can be `sync` or `full_sync`.
*/
public static function do_cron_sync_by_type( $type ) {
if ( ! self::sync_allowed() || ( 'sync' !== $type && 'full_sync' !== $type ) ) {
return;
}
self::initialize_sender();
$time_limit = Settings::get_setting( 'cron_sync_time_limit' );
$start_time = time();
$executions = 0;
do {
$next_sync_time = self::$sender->get_next_sync_time( $type );
if ( $next_sync_time ) {
$delay = $next_sync_time - time() + 1;
if ( $delay > 15 ) {
break;
} elseif ( $delay > 0 ) {
sleep( $delay );
}
}
// Explicitly only allow 1 do_full_sync call until issue with Immediate Full Sync is resolved.
// For more context see p1HpG7-9pe-p2.
if ( 'full_sync' === $type && $executions >= 1 ) {
break;
}
/**
* Only try to sync once if Dedicated Sync is enabled. Dedicated Sync has its own requeueing mechanism
* that will re-run it if there are items in the queue at the end.
*/
if ( 'sync' === $type && $executions >= 1 && Settings::is_dedicated_sync_enabled() ) {
break;
}
$result = 'full_sync' === $type ? self::$sender->do_full_sync() : self::$sender->do_sync();
// # of send actions performed.
++$executions;
} while ( $result && ! is_wp_error( $result ) && ( $start_time + $time_limit ) > time() );
return $executions;
}
/**
* Initialize the sync listener.
*
* @access public
* @static
*/
public static function initialize_listener() {
self::$listener = Listener::get_instance();
}
/**
* Initializes the sync sender.
*
* @access public
* @static
*/
public static function initialize_sender() {
self::$sender = Sender::get_instance();
add_filter( 'jetpack_sync_send_data', array( __CLASS__, 'send_data' ), 10, 8 );
}
/**
* Initializes sync for WooCommerce.
*
* @access public
* @static
*/
public static function initialize_woocommerce() {
if ( false === class_exists( 'WooCommerce' ) ) {
return;
}
add_filter( 'jetpack_sync_modules', array( __CLASS__, 'add_woocommerce_sync_module' ) );
if ( ! class_exists( CustomOrdersTableController::class ) ) {
return;
}
$cot_controller = wc_get_container()->get( CustomOrdersTableController::class );
if ( $cot_controller->custom_orders_table_usage_is_enabled() ) {
add_filter( 'jetpack_sync_modules', array( __CLASS__, 'add_woocommerce_hpos_order_sync_module' ) );
}
}
/**
* Initializes sync for Instant Search.
*
* @access public
* @static
*/
public static function initialize_search() {
if ( false === class_exists( 'Automattic\\Jetpack\\Search\\Module_Control' ) ) {
return;
}
$search_module = new \Automattic\Jetpack\Search\Module_Control();
if ( $search_module->is_instant_search_enabled() ) {
add_filter( 'jetpack_sync_modules', array( __CLASS__, 'add_search_sync_module' ) );
}
}
/**
* Add Search updates to Sync Filters.
*
* @access public
* @static
*
* @param array $sync_modules The list of sync modules declared prior to this filter.
* @return array A list of sync modules that now includes Search's modules.
*/
public static function add_search_sync_module( $sync_modules ) {
$sync_modules[] = 'Automattic\\Jetpack\\Sync\\Modules\\Search';
return $sync_modules;
}
/**
* Adds Woo's sync modules to existing modules for sending.
*
* @access public
* @static
*
* @param array $sync_modules The list of sync modules declared prior to this filter.
* @return array A list of sync modules that now includes Woo's modules.
*/
public static function add_woocommerce_sync_module( $sync_modules ) {
$sync_modules[] = 'Automattic\\Jetpack\\Sync\\Modules\\WooCommerce';
return $sync_modules;
}
/**
* Adds Woo's HPOS sync modules to existing modules for sending.
*
* @param array $sync_modules The list of sync modules declared prior to this filter.
*
* @access public
* @static
*
* @return array A list of sync modules that now includes Woo's HPOS modules.
*/
public static function add_woocommerce_hpos_order_sync_module( $sync_modules ) {
$sync_modules[] = WooCommerce_HPOS_Orders::class;
return $sync_modules;
}
/**
* Initializes sync for WP Super Cache.
*
* @access public
* @static
*/
public static function initialize_wp_super_cache() {
if ( false === function_exists( 'wp_cache_is_enabled' ) ) {
return;
}
add_filter( 'jetpack_sync_modules', array( __CLASS__, 'add_wp_super_cache_sync_module' ) );
}
/**
* Adds WP Super Cache's sync modules to existing modules for sending.
*
* @access public
* @static
*
* @param array $sync_modules The list of sync modules declared prior to this filer.
* @return array A list of sync modules that now includes WP Super Cache's modules.
*/
public static function add_wp_super_cache_sync_module( $sync_modules ) {
$sync_modules[] = 'Automattic\\Jetpack\\Sync\\Modules\\WP_Super_Cache';
return $sync_modules;
}
/**
* Sanitizes the name of sync's cron schedule.
*
* @access public
* @static
*
* @param string $schedule The name of a WordPress cron schedule.
* @return string The sanitized name of sync's cron schedule.
*/
public static function sanitize_filtered_sync_cron_schedule( $schedule ) {
$schedule = sanitize_key( $schedule );
$schedules = wp_get_schedules();
// Make sure that the schedule has actually been registered using the `cron_intervals` filter.
if ( isset( $schedules[ $schedule ] ) ) {
return $schedule;
}
return self::DEFAULT_SYNC_CRON_INTERVAL_NAME;
}
/**
* Allows offsetting of start times for sync cron jobs.
*
* @access public
* @static
*
* @param string $schedule The name of a cron schedule.
* @param string $hook The hook that this method is responding to.
* @return int The offset for the sync cron schedule.
*/
public static function get_start_time_offset( $schedule = '', $hook = '' ) {
$start_time_offset = is_multisite()
? wp_rand( 0, ( 2 * self::DEFAULT_SYNC_CRON_INTERVAL_VALUE ) )
: 0;
/**
* Allows overriding the offset that the sync cron jobs will first run. This can be useful when scheduling
* cron jobs across multiple sites in a network.
*
* @since 1.6.3
* @since-jetpack 4.5.0
*
* @param int $start_time_offset
* @param string $hook
* @param string $schedule
*/
return (int) apply_filters(
'jetpack_sync_cron_start_time_offset',
$start_time_offset,
$hook,
$schedule
);
}
/**
* Decides if a sync cron should be scheduled.
*
* @access public
* @static
*
* @param string $schedule The name of a cron schedule.
* @param string $hook The hook that this method is responding to.
*/
public static function maybe_schedule_sync_cron( $schedule, $hook ) {
if ( ! $hook ) {
return;
}
$schedule = self::sanitize_filtered_sync_cron_schedule( $schedule );
$start_time = time() + self::get_start_time_offset( $schedule, $hook );
if ( ! wp_next_scheduled( $hook ) ) {
// Schedule a job to send pending queue items once a minute.
wp_schedule_event( $start_time, $schedule, $hook );
} elseif ( wp_get_schedule( $hook ) !== $schedule ) {
// If the schedule has changed, update the schedule.
wp_clear_scheduled_hook( $hook );
wp_schedule_event( $start_time, $schedule, $hook );
}
}
/**
* Clears Jetpack sync cron jobs.
*
* @access public
* @static
*/
public static function clear_sync_cron_jobs() {
wp_clear_scheduled_hook( 'jetpack_sync_cron' );
wp_clear_scheduled_hook( 'jetpack_sync_full_cron' );
}
/**
* Initializes Jetpack sync cron jobs.
*
* @access public
* @static
*/
public static function init_sync_cron_jobs() {
add_filter( 'cron_schedules', array( __CLASS__, 'jetpack_cron_schedule' ) ); // phpcs:ignore WordPress.WP.CronInterval.ChangeDetected
add_action( 'jetpack_sync_cron', array( __CLASS__, 'do_cron_sync' ) );
add_action( 'jetpack_sync_full_cron', array( __CLASS__, 'do_cron_full_sync' ) );
/**
* Allows overriding of the default incremental sync cron schedule which defaults to once every 5 minutes.
*
* @since 1.6.3
* @since-jetpack 4.3.2
*
* @param string self::DEFAULT_SYNC_CRON_INTERVAL_NAME
*/
$incremental_sync_cron_schedule = apply_filters( 'jetpack_sync_incremental_sync_interval', self::DEFAULT_SYNC_CRON_INTERVAL_NAME );
self::maybe_schedule_sync_cron( $incremental_sync_cron_schedule, 'jetpack_sync_cron' );
/**
* Allows overriding of the full sync cron schedule which defaults to once every 5 minutes.
*
* @since 1.6.3
* @since-jetpack 4.3.2
*
* @param string self::DEFAULT_SYNC_CRON_INTERVAL_NAME
*/
$full_sync_cron_schedule = apply_filters( 'jetpack_sync_full_sync_interval', self::DEFAULT_SYNC_CRON_INTERVAL_NAME );
self::maybe_schedule_sync_cron( $full_sync_cron_schedule, 'jetpack_sync_full_cron' );
}
/**
* Perform maintenance when a plugin upgrade occurs.
*
* @access public
* @static
*
* @param string $new_version New version of the plugin.
* @param string $old_version Old version of the plugin.
*/
public static function cleanup_on_upgrade( $new_version = '', $old_version = '' ) {
if ( wp_next_scheduled( 'jetpack_sync_send_db_checksum' ) ) {
wp_clear_scheduled_hook( 'jetpack_sync_send_db_checksum' );
}
$is_new_sync_upgrade = version_compare( $old_version, '4.2', '>=' );
if ( ! empty( $old_version ) && $is_new_sync_upgrade && version_compare( $old_version, '4.5', '<' ) ) {
self::clear_sync_cron_jobs();
Settings::update_settings(
array(
'render_filtered_content' => Defaults::$default_render_filtered_content,
)
);
}
Health::on_jetpack_upgraded();
}
/**
* Get syncing status for the given fields.
*
* @access public
* @static
*
* @param string|null $fields A comma-separated string of the fields to include in the array from the JSON response.
* @return array An associative array with the status report.
*/
public static function get_sync_status( $fields = null ) {
self::initialize_sender();
$sync_module = Modules::get_module( 'full-sync' );
'@phan-var Modules\Full_Sync_Immediately|Modules\Full_Sync $sync_module';
$queue = self::$sender->get_sync_queue();
// _get_cron_array can be false
$cron_timestamps = ( _get_cron_array() ) ? array_keys( _get_cron_array() ) : array();
$next_cron = ( ! empty( $cron_timestamps ) ) ? $cron_timestamps[0] - time() : '';
$checksums = array();
$debug = array();
if ( ! empty( $fields ) ) {
$store = new Replicastore();
$fields_params = array_map( 'trim', explode( ',', $fields ) );
if ( in_array( 'posts_checksum', $fields_params, true ) ) {
$checksums['posts_checksum'] = $store->posts_checksum();
}
if ( in_array( 'comments_checksum', $fields_params, true ) ) {
$checksums['comments_checksum'] = $store->comments_checksum();
}
if ( in_array( 'post_meta_checksum', $fields_params, true ) ) {
$checksums['post_meta_checksum'] = $store->post_meta_checksum();
}
if ( in_array( 'comment_meta_checksum', $fields_params, true ) ) {
$checksums['comment_meta_checksum'] = $store->comment_meta_checksum();
}
if ( in_array( 'debug_details', $fields_params, true ) ) {
$debug = self::get_debug_details();
}
}
$full_sync_status = ( $sync_module ) ? $sync_module->get_status() : array();
$full_queue = self::$sender->get_full_sync_queue();
$result = array_merge(
$full_sync_status,
$checksums,
$debug,
array(
'cron_size' => count( $cron_timestamps ),
'next_cron' => $next_cron,
'queue_size' => $queue->size(),
'queue_lag' => $queue->lag(),
'queue_next_sync' => ( self::$sender->get_next_sync_time( 'sync' ) - microtime( true ) ),
'full_queue_next_sync' => ( self::$sender->get_next_sync_time( 'full_sync' ) - microtime( true ) ),
)
);
// Verify $sync_module is not false.
if ( $sync_module && ! $sync_module instanceof Modules\Full_Sync_Immediately ) {
$result['full_queue_size'] = $full_queue->size();
$result['full_queue_lag'] = $full_queue->lag();
}
return $result;
}
/**
* Reset Sync locks.
*
* @access public
* @static
* @since 1.43.0
*
* @param bool $unlock_queues Whether to unlock Sync queues. Defaults to true.
*/
public static function reset_sync_locks( $unlock_queues = true ) {
// Next sync locks.
delete_option( Sender::NEXT_SYNC_TIME_OPTION_NAME . '_sync' );
delete_option( Sender::NEXT_SYNC_TIME_OPTION_NAME . '_full_sync' );
delete_option( Sender::NEXT_SYNC_TIME_OPTION_NAME . '_full-sync-enqueue' );
// Retry after locks.
delete_option( self::RETRY_AFTER_PREFIX . 'sync' );
delete_option( self::RETRY_AFTER_PREFIX . 'full_sync' );
// Dedicated sync locks.
\Jetpack_Options::delete_raw_option( Dedicated_Sender::DEDICATED_SYNC_REQUEST_LOCK_OPTION_NAME );
delete_transient( Dedicated_Sender::DEDICATED_SYNC_TEMPORARY_DISABLE_FLAG );
// Lock for disabling Sync sending temporarily.
delete_transient( Sender::TEMP_SYNC_DISABLE_TRANSIENT_NAME );
// Queue locks.
// Note that we are just unlocking the queues here, not reseting them.
if ( $unlock_queues ) {
$sync_queue = new Queue( 'sync' );
$sync_queue->unlock();
$full_sync_queue = new Queue( 'full_sync' );
$full_sync_queue->unlock();
}
}
/**
* Prepare JSONL data.
*
* @param mixed $data The data to be prepared.
*
* @return string The prepared JSONL data.
*/
private static function prepare_jsonl_data( $data ) {
$jsonl_data = implode(
"\n",
array_map(
function ( $key, $value ) {
return wp_json_encode( array( $key => $value ) );
},
array_keys( (array) $data ),
array_values( (array) $data )
)
);
return $jsonl_data;
}
/**
* Helper method to process the API response.
*
* @param mixed $response The response from the API.
* @return array|Wp_Error Array for successful response or a WP_Error object.
*/
private static function process_rest_api_response( $response ) {
$response_code = wp_remote_retrieve_response_code( $response );
$response_body = wp_remote_retrieve_body( $response );
if ( is_wp_error( $response ) ) {
return $response;
}
$decoded_response = json_decode( $response_body, true );
if ( false === is_array( $decoded_response ) ) {
return new WP_Error( 'sync_rest_api_response_decoding_failed', 'Sync REST API response decoding failed', $response_body );
}
if ( $response_code !== 200 || false === isset( $decoded_response['processed_items'] ) ) {
if ( is_array( $decoded_response ) && isset( $decoded_response['code'] ) && isset( $decoded_response['message'] ) ) {
return new WP_Error(
'jetpack_sync_send_error_' . $decoded_response['code'],
$decoded_response['message'],
$decoded_response['data'] ?? null
);
} else {
return new WP_Error( $response_code, 'Sync REST API request failed', $response_body );
}
} else {
return $decoded_response;
}
}
}
Fatal error: Uncaught Error: Class 'Automattic\Jetpack\Sync\Actions' not found in /var/www/html/dportilho.com.br/web/wp-content/plugins/jetpack/jetpack_vendor/automattic/jetpack-sync/src/class-main.php:24
Stack trace:
#0 /var/www/html/dportilho.com.br/web/wp-content/plugins/jetpack/jetpack_vendor/automattic/jetpack-config/src/class-config.php(257): Automattic\Jetpack\Sync\Main::configure()
#1 /var/www/html/dportilho.com.br/web/wp-content/plugins/jetpack/jetpack_vendor/automattic/jetpack-config/src/class-config.php(217): Automattic\Jetpack\Config->enable_sync()
#2 /var/www/html/dportilho.com.br/web/wp-content/plugins/jetpack/jetpack_vendor/automattic/jetpack-config/src/class-config.php(112): Automattic\Jetpack\Config->ensure_feature('sync')
#3 /var/www/html/dportilho.com.br/web/wp-includes/class-wp-hook.php(324): Automattic\Jetpack\Config->on_plugins_loaded('')
#4 /var/www/html/dportilho.com.br/web/wp-includes/class-wp-hook.php(348): WP_Hook->apply_filters(NULL, Array)
#5 /var/www/html/dportilho.com.br/web/wp-includes/plug in /var/www/html/dportilho.com.br/web/wp-content/plugins/jetpack/jetpack_vendor/automattic/jetpack-sync/src/class-main.php on line 24