n_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; } } }