diff options
author | Anthony G. Basile <blueness@gentoo.org> | 2020-02-17 11:55:41 -0500 |
---|---|---|
committer | Anthony G. Basile <blueness@gentoo.org> | 2020-02-17 11:55:41 -0500 |
commit | dd791649a46b33fd7d5ea388fa42f1cf99c82884 (patch) | |
tree | ddc745e49425b01732343da42a19018b7dd737c4 /plugins/jetpack/vendor/automattic | |
parent | Remove extraneous .zip (diff) | |
download | blogs-gentoo-dd791649a46b33fd7d5ea388fa42f1cf99c82884.tar.gz blogs-gentoo-dd791649a46b33fd7d5ea388fa42f1cf99c82884.tar.bz2 blogs-gentoo-dd791649a46b33fd7d5ea388fa42f1cf99c82884.zip |
update jetpack 8.2.1
Signed-off-by: Anthony G. Basile <blueness@gentoo.org>
Diffstat (limited to 'plugins/jetpack/vendor/automattic')
30 files changed, 1574 insertions, 197 deletions
diff --git a/plugins/jetpack/vendor/automattic/jetpack-assets/src/class-assets.php b/plugins/jetpack/vendor/automattic/jetpack-assets/src/class-assets.php index 7713aadf..b071ab1f 100644 --- a/plugins/jetpack/vendor/automattic/jetpack-assets/src/class-assets.php +++ b/plugins/jetpack/vendor/automattic/jetpack-assets/src/class-assets.php @@ -37,6 +37,20 @@ class Assets { $path = ( Jetpack_Constants::is_defined( 'SCRIPT_DEBUG' ) && Jetpack_Constants::get_constant( 'SCRIPT_DEBUG' ) ) ? $non_min_path : $min_path; - return plugins_url( $path, Jetpack_Constants::get_constant( 'JETPACK__PLUGIN_FILE' ) ); + + $url = plugins_url( $path, Jetpack_Constants::get_constant( 'JETPACK__PLUGIN_FILE' ) ); + + /** + * Filters the URL for a file passed through the get_file_url_for_environment function. + * + * @since 8.1.0 + * + * @package assets + * + * @param string $url The URL to the file. + * @param string $min_path The minified path. + * @param string $non_min_path The non-minified path. + */ + return apply_filters( 'jetpack_get_file_for_environment', $url, $min_path, $non_min_path ); } } diff --git a/plugins/jetpack/vendor/automattic/jetpack-config/src/class-config.php b/plugins/jetpack/vendor/automattic/jetpack-config/src/class-config.php new file mode 100644 index 00000000..6f16373a --- /dev/null +++ b/plugins/jetpack/vendor/automattic/jetpack-config/src/class-config.php @@ -0,0 +1,200 @@ +<?php +/** + * The base Jetpack configuration class file. + * + * @package automattic/jetpack-config + */ + +namespace Automattic\Jetpack; + +use Automattic\Jetpack\Connection\Manager; +use Automattic\Jetpack\JITM; +use Automattic\Jetpack\Plugin\Tracking as Plugin_Tracking; +use Automattic\Jetpack\Sync\Main as Sync_Main; +use Automattic\Jetpack\Terms_Of_Service; + +/** + * The configuration class. + */ +class Config { + + const FEATURE_ENSURED = 1; + const FEATURE_NOT_AVAILABLE = 0; + const FEATURE_ALREADY_ENSURED = -1; + + /** + * The initial setting values. + * + * @var Array + */ + protected $config = array( + 'jitm' => false, + 'connection' => false, + 'sync' => false, + 'tracking' => false, + 'tos' => false, + ); + + /** + * Creates the configuration class instance. + */ + public function __construct() { + + /** + * Adding the config handler to run on priority 2 because the class itself is + * being constructed on priority 1. + */ + add_action( 'plugins_loaded', array( $this, 'on_plugins_loaded' ), 2 ); + } + + /** + * Require a feature to be initialized. It's up to the package consumer to actually add + * the package to their composer project. Declaring a requirement using this method + * instructs the class to initalize it. + * + * @param String $feature the feature slug. + */ + public function ensure( $feature ) { + $this->config[ $feature ] = true; + } + + /** + * Runs on plugins_loaded hook priority with priority 2. + * + * @action plugins_loaded + */ + public function on_plugins_loaded() { + if ( $this->config['connection'] ) { + $this->ensure_class( 'Automattic\Jetpack\Connection\Manager' ) + && $this->ensure_feature( 'connection' ); + } + + if ( $this->config['tracking'] ) { + $this->ensure_class( 'Automattic\Jetpack\Terms_Of_Service' ) + && $this->ensure_class( 'Automattic\Jetpack\Tracking' ) + && $this->ensure_feature( 'tracking' ); + } + + if ( $this->config['sync'] ) { + $this->ensure_class( 'Automattic\Jetpack\Sync\Main' ) + && $this->ensure_feature( 'sync' ); + } + + if ( $this->config['jitm'] ) { + $this->ensure_class( 'Automattic\Jetpack\JITM' ) + && $this->ensure_feature( 'jitm' ); + } + } + + /** + * Returns true if the required class is available and alerts the user if it's not available + * in case the site is in debug mode. + * + * @param String $classname a fully qualified class name. + * @return Boolean whether the class is available. + */ + protected function ensure_class( $classname ) { + $available = class_exists( $classname ); + + if ( ! $available && defined( 'WP_DEBUG' ) && WP_DEBUG ) { + trigger_error( // phpcs:ignore WordPress.PHP.DevelopmentFunctions.error_log_trigger_error + sprintf( + /* translators: %1$s is a PHP class name. */ + esc_html__( + 'Unable to load class %1$s. Please add the package that contains it using composer and make sure you are requiring the Jetpack autoloader', + 'jetpack' + ), + esc_html( $classname ) + ), + E_USER_NOTICE + ); + } + + return $available; + } + + /** + * Ensures a feature is enabled, sets it up if it hasn't already been set up. + * + * @param String $feature slug of the feature. + * @return Integer either FEATURE_ENSURED, FEATURE_ALREADY_ENSURED or FEATURE_NOT_AVAILABLE constants. + */ + protected function ensure_feature( $feature ) { + $method = 'enable_' . $feature; + if ( ! method_exists( $this, $method ) ) { + return self::FEATURE_NOT_AVAILABLE; + } + + if ( did_action( 'jetpack_feature_' . $feature . '_enabled' ) ) { + return self::FEATURE_ALREADY_ENSURED; + } + + $this->{ $method }(); + + /** + * Fires when a specific Jetpack package feature is initalized using the Config package. + * + * @since 8.2.0 + */ + do_action( 'jetpack_feature_' . $feature . '_enabled' ); + + return self::FEATURE_ENSURED; + } + + /** + * Dummy method to enable Terms of Service. + */ + protected function enable_tos() { + return true; + } + + /** + * Enables the tracking feature. Depends on the Terms of Service package, so enables it too. + */ + protected function enable_tracking() { + + // Enabling dependencies. + $this->ensure_feature( 'tos' ); + + $terms_of_service = new Terms_Of_Service(); + $tracking = new Plugin_Tracking(); + if ( $terms_of_service->has_agreed() ) { + add_action( 'init', array( $tracking, 'init' ) ); + } else { + /** + * Initialize tracking right after the user agrees to the terms of service. + */ + add_action( 'jetpack_agreed_to_terms_of_service', array( $tracking, 'init' ) ); + } + + return true; + } + + /** + * Enables the JITM feature. + */ + protected function enable_jitm() { + JITM::configure(); + + return true; + } + + /** + * Enables the Sync feature. + */ + protected function enable_sync() { + Sync_Main::configure(); + + return true; + } + + /** + * Enables the Connection feature. + */ + protected function enable_connection() { + Manager::configure(); + + return true; + } + +} diff --git a/plugins/jetpack/vendor/automattic/jetpack-connection/src/class-client.php b/plugins/jetpack/vendor/automattic/jetpack-connection/src/class-client.php index 0070f294..e8f16b6e 100644 --- a/plugins/jetpack/vendor/automattic/jetpack-connection/src/class-client.php +++ b/plugins/jetpack/vendor/automattic/jetpack-connection/src/class-client.php @@ -70,7 +70,7 @@ class Client { $token_key = sprintf( '%s:%d:%d', $token_key, - Constants::get_constant( 'JETPACK__API_VERSION' ), + Utils::get_jetpack_api_version(), $token->external_user_id ); diff --git a/plugins/jetpack/vendor/automattic/jetpack-connection/src/class-manager.php b/plugins/jetpack/vendor/automattic/jetpack-connection/src/class-manager.php index f37dbf88..d97cf077 100644 --- a/plugins/jetpack/vendor/automattic/jetpack-connection/src/class-manager.php +++ b/plugins/jetpack/vendor/automattic/jetpack-connection/src/class-manager.php @@ -50,20 +50,22 @@ class Manager { * * @todo Implement a proper nonce verification. */ - public function init() { - $this->setup_xmlrpc_handlers( + public static function configure() { + $manager = new self(); + + $manager->setup_xmlrpc_handlers( $_GET, // phpcs:ignore WordPress.Security.NonceVerification.Recommended - $this->is_active(), - $this->verify_xml_rpc_signature() + $manager->is_active(), + $manager->verify_xml_rpc_signature() ); - if ( $this->is_active() ) { - add_filter( 'xmlrpc_methods', array( $this, 'public_xmlrpc_methods' ) ); + if ( $manager->is_active() ) { + add_filter( 'xmlrpc_methods', array( $manager, 'public_xmlrpc_methods' ) ); } else { - add_action( 'rest_api_init', array( $this, 'initialize_rest_api_registration_connector' ) ); + add_action( 'rest_api_init', array( $manager, 'initialize_rest_api_registration_connector' ) ); } - add_action( 'jetpack_clean_nonces', array( $this, 'clean_nonces' ) ); + add_action( 'jetpack_clean_nonces', array( $manager, 'clean_nonces' ) ); if ( ! wp_next_scheduled( 'jetpack_clean_nonces' ) ) { wp_schedule_event( time(), 'hourly', 'jetpack_clean_nonces' ); } @@ -335,7 +337,7 @@ class Manager { if ( empty( $token_key ) || - empty( $version ) || strval( JETPACK__API_VERSION ) !== $version + empty( $version ) || strval( Utils::get_jetpack_api_version() ) !== $version ) { return new \WP_Error( 'malformed_token', 'Malformed token in request', compact( 'signature_details' ) ); } @@ -526,7 +528,7 @@ class Manager { * @return string|int Returns the ID of the connection owner or False if no connection owner found. */ public function get_connection_owner_id() { - $user_token = $this->get_access_token( JETPACK_MASTER_USER ); + $user_token = $this->get_access_token( self::JETPACK_MASTER_USER ); $connection_owner = false; if ( $user_token && is_object( $user_token ) && isset( $user_token->external_user_id ) ) { $connection_owner = $user_token->external_user_id; @@ -601,7 +603,7 @@ class Manager { * @return object|false False if no connection owner found. */ public function get_connection_owner() { - $user_token = $this->get_access_token( JETPACK_MASTER_USER ); + $user_token = $this->get_access_token( self::JETPACK_MASTER_USER ); $connection_owner = false; if ( $user_token && is_object( $user_token ) && isset( $user_token->external_user_id ) ) { @@ -623,7 +625,7 @@ class Manager { $user_id = get_current_user_id(); } - $user_token = $this->get_access_token( JETPACK_MASTER_USER ); + $user_token = $this->get_access_token( self::JETPACK_MASTER_USER ); return $user_token && is_object( $user_token ) && isset( $user_token->external_user_id ) && $user_id === $user_token->external_user_id; } @@ -714,10 +716,8 @@ class Manager { */ public function api_url( $relative_url ) { $api_base = Constants::get_constant( 'JETPACK__API_BASE' ); - $version = Constants::get_constant( 'JETPACK__API_VERSION' ); - $api_base = $api_base ? $api_base : 'https://jetpack.wordpress.com/jetpack.'; - $version = $version ? '/' . $version . '/' : '/1/'; + $version = '/' . Utils::get_jetpack_api_version() . '/'; /** * Filters the API URL that Jetpack uses for server communication. @@ -1556,6 +1556,7 @@ class Manager { return new \WP_Error( 'unknown', '', $code ); } + /* translators: Error description string. */ $error_description = isset( $json->error_description ) ? sprintf( __( 'Error Details: %s', 'jetpack' ), (string) $json->error_description ) : ''; return new \WP_Error( (string) $json->error, $error_description, $code ); diff --git a/plugins/jetpack/vendor/automattic/jetpack-connection/src/class-utils.php b/plugins/jetpack/vendor/automattic/jetpack-connection/src/class-utils.php index 1c280262..652fd250 100644 --- a/plugins/jetpack/vendor/automattic/jetpack-connection/src/class-utils.php +++ b/plugins/jetpack/vendor/automattic/jetpack-connection/src/class-utils.php @@ -14,6 +14,8 @@ use Automattic\Jetpack\Constants; */ class Utils { + const DEFAULT_JETPACK_API_VERSION = 1; + /** * Some hosts disable the OpenSSL extension and so cannot make outgoing HTTPS requests. * This method sets the URL scheme to HTTP when HTTPS requests can't be made. @@ -59,4 +61,16 @@ class Utils { } return \Jetpack_Options::update_options( $options ); } + + /** + * Returns the Jetpack__API_VERSION constant if it exists, else returns a + * default value of 1. + * + * @return integer + */ + public static function get_jetpack_api_version() { + $api_version = Constants::get_constant( 'JETPACK__API_VERSION' ); + $api_version = $api_version ? $api_version : self::DEFAULT_JETPACK_API_VERSION; + return $api_version; + } } diff --git a/plugins/jetpack/vendor/automattic/jetpack-jitm/src/class-jitm.php b/plugins/jetpack/vendor/automattic/jetpack-jitm/src/class-jitm.php index ccdd1d72..79a2947f 100644 --- a/plugins/jetpack/vendor/automattic/jetpack-jitm/src/class-jitm.php +++ b/plugins/jetpack/vendor/automattic/jetpack-jitm/src/class-jitm.php @@ -11,6 +11,7 @@ use Automattic\Jetpack\Assets; use Automattic\Jetpack\Connection\Manager as Jetpack_Connection; use Automattic\Jetpack\Connection\Client; use Automattic\Jetpack\Assets\Logo as Jetpack_Logo; +use Automattic\Jetpack\Partner; use Automattic\Jetpack\Tracking; use Automattic\Jetpack\Connection\Manager; @@ -33,6 +34,14 @@ class JITM { private $tracking; /** + * The configuration method that is called from the jetpack-config package. + */ + public static function configure() { + $jitm = new self(); + $jitm->register(); + } + + /** * JITM constructor. */ public function __construct() { @@ -564,11 +573,8 @@ class JITM { 'u' => $user->ID, ); - if ( ! class_exists( 'Jetpack_Affiliate' ) ) { - require_once JETPACK__PLUGIN_DIR . 'class.jetpack-affiliate.php'; - } // Get affiliate code and add it to the array of URL parameters. - $aff = \Jetpack_Affiliate::init()->get_affiliate_code(); + $aff = Partner::init()->get_partner_code( Partner::AFFILIATE_CODE ); if ( '' !== $aff ) { $url_params['aff'] = $aff; } diff --git a/plugins/jetpack/vendor/automattic/jetpack-partner/src/class-partner.php b/plugins/jetpack/vendor/automattic/jetpack-partner/src/class-partner.php new file mode 100644 index 00000000..62d984e8 --- /dev/null +++ b/plugins/jetpack/vendor/automattic/jetpack-partner/src/class-partner.php @@ -0,0 +1,152 @@ +<?php +/** + * Jetpack Partner package. + * + * @package automattic/jetpack-partner + */ + +namespace Automattic\Jetpack; + +/** + * This class introduces functionality used by Jetpack hosting partners. + * + * @since 8.1.0 + */ +class Partner { + + /** + * Affiliate code. + */ + const AFFILIATE_CODE = 'affiliate'; + + /** + * Subsidiary id code. + */ + const SUBSIDIARY_CODE = 'subsidiary'; + + /** + * Singleton instance. + * + * @since 8.1.0 + * + * @var Partner This class instance. + */ + private static $instance = null; + + /** + * Partner constructor. + */ + private function __construct() { + } + + /** + * Initializes the class or returns the singleton. + * + * @return Partner | false + * @since 8.1.0 + */ + public static function init() { + if ( is_null( self::$instance ) ) { + self::$instance = new Partner(); + add_filter( 'jetpack_build_connection_url', array( self::$instance, 'add_subsidiary_id_as_query_arg' ) ); + add_filter( 'jetpack_build_connection_url', array( self::$instance, 'add_affiliate_code_as_query_arg' ) ); + } + + return self::$instance; + } + + /** + * Adds the partner subsidiary code to the passed URL. + * + * @param string $url The URL. + * + * @return string + */ + public function add_subsidiary_id_as_query_arg( $url ) { + return $this->add_code_as_query_arg( self::SUBSIDIARY_CODE, $url ); + } + + /** + * Adds the affiliate code to the passed URL. + * + * @param string $url The URL. + * + * @return string + */ + public function add_affiliate_code_as_query_arg( $url ) { + return $this->add_code_as_query_arg( self::AFFILIATE_CODE, $url ); + } + + /** + * Returns the passed URL with the partner code added as a URL query arg. + * + * @param string $type The partner code. + * @param string $url The URL where the partner subsidiary id will be added. + * + * @return string The passed URL with the partner code added. + * @since 8.1.0 + */ + public function add_code_as_query_arg( $type, $url ) { + switch ( $type ) { + case self::AFFILIATE_CODE: + $query_arg_name = 'aff'; + break; + case self::SUBSIDIARY_CODE: + $query_arg_name = 'subsidiaryId'; + break; + default: + return $url; + } + + $code = $this->get_partner_code( $type ); + + if ( '' === $code ) { + return $url; + } + + return add_query_arg( $query_arg_name, $code, $url ); + } + + /** + * Returns a partner code. + * + * @param string $type This can be either 'affiliate' or 'subsidiary'. Returns empty string when code is unknown. + * + * @return string The partner code. + * @since 8.1.0 + */ + public function get_partner_code( $type ) { + switch ( $type ) { + case self::AFFILIATE_CODE: + /** + * Allow to filter the affiliate code. + * + * @param string $affiliate_code The affiliate code, blank by default. + * + * @since 6.9.0 + */ + return apply_filters( 'jetpack_affiliate_code', get_option( 'jetpack_affiliate_code', '' ) ); + case self::SUBSIDIARY_CODE: + /** + * Allow to filter the partner subsidiary id. + * + * @param string $subsidiary_id The partner subsidiary id, blank by default. + * + * @since 8.1.0 + */ + return apply_filters( + 'jetpack_partner_subsidiary_id', + get_option( 'jetpack_partner_subsidiary_id', '' ) + ); + default: + return ''; + } + } + + /** + * Resets the singleton for testing purposes. + */ + public static function reset() { + self::$instance = null; + } +} diff --git a/plugins/jetpack/vendor/automattic/jetpack-status/src/class-status.php b/plugins/jetpack/vendor/automattic/jetpack-status/src/class-status.php index f87ca9af..5a299056 100644 --- a/plugins/jetpack/vendor/automattic/jetpack-status/src/class-status.php +++ b/plugins/jetpack/vendor/automattic/jetpack-status/src/class-status.php @@ -80,4 +80,72 @@ class Status { } return 1 === (int) $some_users; } + + /** + * If is a staging site. + * + * @todo Add IDC detection to a package. + * + * @return bool + */ + public function is_staging_site() { + $is_staging = false; + + $known_staging = array( + 'urls' => array( + '#\.staging\.wpengine\.com$#i', // WP Engine. + '#\.staging\.kinsta\.com$#i', // Kinsta.com. + '#\.stage\.site$#i', // DreamPress. + ), + 'constants' => array( + 'IS_WPE_SNAPSHOT', // WP Engine. + 'KINSTA_DEV_ENV', // Kinsta.com. + 'WPSTAGECOACH_STAGING', // WP Stagecoach. + 'JETPACK_STAGING_MODE', // Generic. + ), + ); + /** + * Filters the flags of known staging sites. + * + * @since 3.9.0 + * + * @param array $known_staging { + * An array of arrays that each are used to check if the current site is staging. + * @type array $urls URLs of staging sites in regex to check against site_url. + * @type array $constants PHP constants of known staging/developement environments. + * } + */ + $known_staging = apply_filters( 'jetpack_known_staging', $known_staging ); + + if ( isset( $known_staging['urls'] ) ) { + foreach ( $known_staging['urls'] as $url ) { + if ( preg_match( $url, site_url() ) ) { + $is_staging = true; + break; + } + } + } + + if ( isset( $known_staging['constants'] ) ) { + foreach ( $known_staging['constants'] as $constant ) { + if ( defined( $constant ) && constant( $constant ) ) { + $is_staging = true; + } + } + } + + // Last, let's check if sync is erroring due to an IDC. If so, set the site to staging mode. + if ( ! $is_staging && method_exists( 'Jetpack', 'validate_sync_error_idc_option' ) && \Jetpack::validate_sync_error_idc_option() ) { + $is_staging = true; + } + + /** + * Filters is_staging_site check. + * + * @since 3.9.0 + * + * @param bool $is_staging If the current site is a staging site. + */ + return apply_filters( 'jetpack_is_staging_site', $is_staging ); + } } diff --git a/plugins/jetpack/vendor/automattic/jetpack-sync/src/class-actions.php b/plugins/jetpack/vendor/automattic/jetpack-sync/src/class-actions.php index 2c31b914..3cd482e6 100644 --- a/plugins/jetpack/vendor/automattic/jetpack-sync/src/class-actions.php +++ b/plugins/jetpack/vendor/automattic/jetpack-sync/src/class-actions.php @@ -128,7 +128,7 @@ class Actions { ) ) { self::initialize_sender(); add_action( 'shutdown', array( self::$sender, 'do_sync' ) ); - add_action( 'shutdown', array( self::$sender, 'do_full_sync' ) ); + add_action( 'shutdown', array( self::$sender, 'do_full_sync' ), 9999 ); } } @@ -177,6 +177,10 @@ class Actions { * @return bool */ public static function sync_allowed() { + if ( defined( 'IS_WPCOM' ) && IS_WPCOM ) { + return false; + } + if ( defined( 'PHPUNIT_JETPACK_TESTSUITE' ) ) { return true; } @@ -189,7 +193,7 @@ class Actions { return false; } - if ( \Jetpack::is_staging_site() ) { + if ( ( new Status() )->is_staging_site() ) { return false; } @@ -723,9 +727,10 @@ class Actions { $sync_module = Modules::get_module( 'full-sync' ); $queue = self::$sender->get_sync_queue(); - $full_queue = self::$sender->get_full_sync_queue(); - $cron_timestamps = array_keys( _get_cron_array() ); - $next_cron = $cron_timestamps[0] - time(); + + // _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(); @@ -749,7 +754,9 @@ class Actions { $full_sync_status = ( $sync_module ) ? $sync_module->get_status() : array(); - return array_merge( + $full_queue = self::$sender->get_full_sync_queue(); + + $result = array_merge( $full_sync_status, $checksums, array( @@ -758,10 +765,15 @@ class Actions { 'queue_size' => $queue->size(), 'queue_lag' => $queue->lag(), 'queue_next_sync' => ( self::$sender->get_next_sync_time( 'sync' ) - microtime( true ) ), - 'full_queue_size' => $full_queue->size(), - 'full_queue_lag' => $full_queue->lag(), 'full_queue_next_sync' => ( self::$sender->get_next_sync_time( 'full_sync' ) - microtime( true ) ), ) ); + + // Verify $sync_module is not false + if ( ( $sync_module ) && false === strpos( get_class( $sync_module ), 'Full_Sync_Immediately' ) ) { + $result['full_queue_size'] = $full_queue->size(); + $result['full_queue_lag'] = $full_queue->lag(); + } + return $result; } } diff --git a/plugins/jetpack/vendor/automattic/jetpack-sync/src/class-defaults.php b/plugins/jetpack/vendor/automattic/jetpack-sync/src/class-defaults.php index 69b7c7a8..c6ff4632 100644 --- a/plugins/jetpack/vendor/automattic/jetpack-sync/src/class-defaults.php +++ b/plugins/jetpack/vendor/automattic/jetpack-sync/src/class-defaults.php @@ -7,10 +7,7 @@ namespace Automattic\Jetpack\Sync; -require_once JETPACK__PLUGIN_DIR . 'modules/sso/class.jetpack-sso-helpers.php'; - use Automattic\Jetpack\Status; -use Automattic\Jetpack\Sync\Functions; /** * Just some defaults that we share with the server. @@ -283,11 +280,6 @@ class Defaults { 'shortcodes' => array( 'Automattic\\Jetpack\\Sync\\Functions', 'get_shortcodes' ), 'rest_api_allowed_post_types' => array( 'Automattic\\Jetpack\\Sync\\Functions', 'rest_api_allowed_post_types' ), 'rest_api_allowed_public_metadata' => array( 'Automattic\\Jetpack\\Sync\\Functions', 'rest_api_allowed_public_metadata' ), - 'sso_is_two_step_required' => array( 'Jetpack_SSO_Helpers', 'is_two_step_required' ), - 'sso_should_hide_login_form' => array( 'Jetpack_SSO_Helpers', 'should_hide_login_form' ), - 'sso_match_by_email' => array( 'Jetpack_SSO_Helpers', 'match_by_email' ), - 'sso_new_user_override' => array( 'Jetpack_SSO_Helpers', 'new_user_override' ), - 'sso_bypass_default_login_form' => array( 'Jetpack_SSO_Helpers', 'bypass_login_forward_wpcom' ), 'wp_version' => array( 'Automattic\\Jetpack\\Sync\\Functions', 'wp_version' ), 'get_plugins' => array( 'Automattic\\Jetpack\\Sync\\Functions', 'get_plugins' ), 'get_plugins_action_links' => array( 'Automattic\\Jetpack\\Sync\\Functions', 'get_plugins_action_links' ), @@ -346,6 +338,19 @@ class Defaults { * @return array Whitelist of callables allowed to be managed via the JSON API. */ public static function get_callable_whitelist() { + $default = self::$default_callable_whitelist; + + if ( defined( 'JETPACK__PLUGIN_DIR' ) && include_once JETPACK__PLUGIN_DIR . 'modules/sso/class.jetpack-sso-helpers.php' ) { + $sso_helpers = array( + 'sso_is_two_step_required' => array( 'Jetpack_SSO_Helpers', 'is_two_step_required' ), + 'sso_should_hide_login_form' => array( 'Jetpack_SSO_Helpers', 'should_hide_login_form' ), + 'sso_match_by_email' => array( 'Jetpack_SSO_Helpers', 'match_by_email' ), + 'sso_new_user_override' => array( 'Jetpack_SSO_Helpers', 'new_user_override' ), + 'sso_bypass_default_login_form' => array( 'Jetpack_SSO_Helpers', 'bypass_login_forward_wpcom' ), + ); + $default = array_merge( $default, $sso_helpers ); + } + /** * Filter the list of callables that are manageable via the JSON API. * @@ -355,7 +360,7 @@ class Defaults { * * @param array The default list of callables. */ - return apply_filters( 'jetpack_sync_callable_whitelist', self::$default_callable_whitelist ); + return apply_filters( 'jetpack_sync_callable_whitelist', $default ); } /** @@ -1018,14 +1023,14 @@ class Defaults { * * @var int Number of seconds. */ - public static $default_sync_wait_threshold = 5; + public static $default_sync_wait_threshold = 10; /** * Default wait between attempting to continue a full sync via requests. * * @var int Number of seconds. */ - public static $default_enqueue_wait_time = 10; + public static $default_enqueue_wait_time = 1; /** * Maximum queue size. @@ -1130,6 +1135,13 @@ class Defaults { public static $default_max_queue_size_full_sync = 1000; // max number of total items in the full sync queue. /** + * Default max time for sending in immediate mode. + * + * @var float Number of Seconds + */ + public static $default_full_sync_send_duration = 9; + + /** * Defaul for time between syncing callables. * * @var int Number of seconds. @@ -1154,7 +1166,7 @@ class Defaults { * * @var int Number of seconds. */ - public static $default_cron_sync_time_limit = 30; // 30 seconds. + public static $default_cron_sync_time_limit = 4 * MINUTE_IN_SECONDS; /** * Default for number of term relationship items sent in an full sync item. @@ -1176,4 +1188,51 @@ class Defaults { * @var int 1 for true. */ public static $default_full_sync_sender_enabled = 1; // Should send full sync items. + + /** + * Default Full Sync config + * + * @var array list of module names. + */ + public static $default_full_sync_config = array( + 'constants' => 1, + 'functions' => 1, + 'options' => 1, + 'updates' => 1, + 'themes' => 1, + 'users' => 1, + 'terms' => 1, + 'posts' => 1, + 'comments' => 1, + 'term_relationships' => 1, + ); + + /** + * Default Full Sync max objects to send on a single request. + * + * @var array list of module => max. + */ + public static $default_full_sync_limits = array( + 'users' => array( + 'chunk_size' => 100, + 'max_chunks' => 10, + ), + 'terms' => array( + 'chunk_size' => 1000, + 'max_chunks' => 10, + ), + 'posts' => array( + 'chunk_size' => 100, + 'max_chunks' => 1, + ), + 'comments' => array( + 'chunk_size' => 100, + 'max_chunks' => 10, + ), + 'term_relationships' => array( + 'chunk_size' => 1000, + 'max_chunks' => 10, + ), + ); + } diff --git a/plugins/jetpack/vendor/automattic/jetpack-sync/src/class-functions.php b/plugins/jetpack/vendor/automattic/jetpack-sync/src/class-functions.php index dc45c5c8..cfdc2bd8 100644 --- a/plugins/jetpack/vendor/automattic/jetpack-sync/src/class-functions.php +++ b/plugins/jetpack/vendor/automattic/jetpack-sync/src/class-functions.php @@ -161,22 +161,83 @@ class Functions { * @return string Hosting provider. */ public static function get_hosting_provider() { - if ( defined( 'GD_SYSTEM_PLUGIN_DIR' ) || class_exists( '\\WPaaS\\Plugin' ) ) { - return 'gd-managed-wp'; - } - if ( defined( 'MM_BASE_DIR' ) ) { - return 'bh'; + $hosting_provider_detection_methods = array( + 'get_hosting_provider_by_known_constant', + 'get_hosting_provider_by_known_class', + 'get_hosting_provider_by_known_function', + ); + + $functions = new Functions(); + foreach ( $hosting_provider_detection_methods as $method ) { + $hosting_provider = call_user_func( array( $functions, $method ) ); + if ( false !== $hosting_provider ) { + return $hosting_provider; + } } - if ( defined( 'IS_PRESSABLE' ) ) { - return 'pressable'; + + return 'unknown'; + } + + /** + * Return a hosting provider using a set of known constants. + * + * @return mixed A host identifier string or false. + */ + public function get_hosting_provider_by_known_constant() { + $hosting_provider_constants = array( + 'GD_SYSTEM_PLUGIN_DIR' => 'gd-managed-wp', + 'MM_BASE_DIR' => 'bh', + 'PAGELYBIN' => 'pagely', + 'KINSTAMU_VERSION' => 'kinsta', + 'FLYWHEEL_CONFIG_DIR' => 'flywheel', + 'IS_PRESSABLE' => 'pressable', + 'VIP_GO_ENV' => 'vip-go', + ); + + foreach ( $hosting_provider_constants as $constant => $constant_value ) { + if ( Constants::is_defined( $constant ) ) { + if ( 'VIP_GO_ENV' === $constant && false === Constants::get_constant( 'VIP_GO_ENV' ) ) { + continue; + } + return $constant_value; + } } - if ( function_exists( 'is_wpe' ) || function_exists( 'is_wpe_snapshot' ) ) { - return 'wpe'; + + return false; + } + + /** + * Return a hosting provider using a set of known classes. + * + * @return mixed A host identifier string or false. + */ + public function get_hosting_provider_by_known_class() { + $hosting_provider = false; + + switch ( true ) { + case ( class_exists( '\\WPaaS\\Plugin' ) ): + $hosting_provider = 'gd-managed-wp'; + break; } - if ( defined( 'VIP_GO_ENV' ) && false !== VIP_GO_ENV ) { - return 'vip-go'; + + return $hosting_provider; + } + + /** + * Return a hosting provider using a set of known functions. + * + * @return mixed A host identifier string or false. + */ + public function get_hosting_provider_by_known_function() { + $hosting_provider = false; + + switch ( true ) { + case ( function_exists( 'is_wpe' ) || function_exists( 'is_wpe_snapshot' ) ): + $hosting_provider = 'wpe'; + break; } - return 'unknown'; + + return $hosting_provider; } /** diff --git a/plugins/jetpack/vendor/automattic/jetpack-sync/src/class-listener.php b/plugins/jetpack/vendor/automattic/jetpack-sync/src/class-listener.php index 8073e11b..db5f377e 100644 --- a/plugins/jetpack/vendor/automattic/jetpack-sync/src/class-listener.php +++ b/plugins/jetpack/vendor/automattic/jetpack-sync/src/class-listener.php @@ -70,7 +70,6 @@ class Listener { * This is necessary because you can't use "new" when you declare instance properties >:( */ protected function __construct() { - Main::init(); $this->set_defaults(); $this->init(); } diff --git a/plugins/jetpack/vendor/automattic/jetpack-sync/src/class-main.php b/plugins/jetpack/vendor/automattic/jetpack-sync/src/class-main.php index 2e1c3cbd..ac552008 100644 --- a/plugins/jetpack/vendor/automattic/jetpack-sync/src/class-main.php +++ b/plugins/jetpack/vendor/automattic/jetpack-sync/src/class-main.php @@ -7,28 +7,59 @@ namespace Automattic\Jetpack\Sync; +use Automattic\Jetpack\Sync\Actions as Sync_Actions; + /** * Jetpack Sync main class. */ class Main { + + /** + * Sets up event handlers for the Sync package. Is used from the Config package. + * + * @action plugins_loaded + */ + public static function configure() { + if ( Actions::sync_allowed() ) { + add_action( 'plugins_loaded', array( __CLASS__, 'on_plugins_loaded_early' ), 5 ); + add_action( 'plugins_loaded', array( __CLASS__, 'on_plugins_loaded_late' ), 90 ); + } + // Any hooks below are special cases that need to be declared even if Sync is not allowed. + add_action( 'jetpack_user_authorized', array( 'Automattic\\Jetpack\\Sync\\Actions', 'do_initial_sync' ), 10, 0 ); + } + /** * Initialize the main sync actions. + * + * @action plugins_loaded */ - public static function init() { - // Check for WooCommerce support. - add_action( 'plugins_loaded', array( 'Automattic\\Jetpack\\Sync\\Actions', 'initialize_woocommerce' ), 5 ); + public static function on_plugins_loaded_early() { + /** + * Additional Sync modules can be carried out into their own packages and they + * will get their own config settings. + * + * For now additional modules are enabled based on whether the third party plugin + * class exists or not. + */ + Sync_Actions::initialize_woocommerce(); + Sync_Actions::initialize_wp_super_cache(); - // Check for WP Super Cache. - add_action( 'plugins_loaded', array( 'Automattic\\Jetpack\\Sync\\Actions', 'initialize_wp_super_cache' ), 5 ); + // We need to define this here so that it's hooked before `updating_jetpack_version` is called. + add_action( 'updating_jetpack_version', array( 'Automattic\\Jetpack\\Sync\\Actions', 'cleanup_on_upgrade' ), 10, 2 ); + } + /** + * Runs after most of plugins_loaded hook functions have been run. + * + * @action plugins_loaded + */ + public static function on_plugins_loaded_late() { /* * Init after plugins loaded and before the `init` action. This helps with issues where plugins init * with a high priority or sites that use alternate cron. */ - add_action( 'plugins_loaded', array( 'Automattic\\Jetpack\\Sync\\Actions', 'init' ), 90 ); - - // We need to define this here so that it's hooked before `updating_jetpack_version` is called. - add_action( 'updating_jetpack_version', array( 'Automattic\\Jetpack\\Sync\\Actions', 'cleanup_on_upgrade' ), 10, 2 ); - add_action( 'jetpack_user_authorized', array( 'Automattic\\Jetpack\\Sync\\Actions', 'do_initial_sync' ), 10, 0 ); + Sync_Actions::init(); } + + } diff --git a/plugins/jetpack/vendor/automattic/jetpack-sync/src/class-modules.php b/plugins/jetpack/vendor/automattic/jetpack-sync/src/class-modules.php index 1aaddb9a..09e95e5d 100644 --- a/plugins/jetpack/vendor/automattic/jetpack-sync/src/class-modules.php +++ b/plugins/jetpack/vendor/automattic/jetpack-sync/src/class-modules.php @@ -8,6 +8,8 @@ namespace Automattic\Jetpack\Sync; +use Automattic\Jetpack\Sync\Modules\Module; + /** * A class to handle loading of sync modules. */ @@ -21,56 +23,28 @@ class Modules { * @var array */ const DEFAULT_SYNC_MODULES = array( - 'Jetpack_Sync_Modules_Constants', - 'Jetpack_Sync_Modules_Callables', - 'Jetpack_Sync_Modules_Network_Options', - 'Jetpack_Sync_Modules_Options', - 'Jetpack_Sync_Modules_Terms', - 'Jetpack_Sync_Modules_Menus', - 'Jetpack_Sync_Modules_Themes', - 'Jetpack_Sync_Modules_Users', - 'Jetpack_Sync_Modules_Import', - 'Jetpack_Sync_Modules_Posts', - 'Jetpack_Sync_Modules_Protect', - 'Jetpack_Sync_Modules_Comments', - 'Jetpack_Sync_Modules_Updates', - 'Jetpack_Sync_Modules_Attachments', - 'Jetpack_Sync_Modules_Meta', - 'Jetpack_Sync_Modules_Plugins', - 'Jetpack_Sync_Modules_Stats', - 'Jetpack_Sync_Modules_Full_Sync', + 'Automattic\\Jetpack\\Sync\\Modules\\Constants', + 'Automattic\\Jetpack\\Sync\\Modules\\Callables', + 'Automattic\\Jetpack\\Sync\\Modules\\Network_Options', + 'Automattic\\Jetpack\\Sync\\Modules\\Options', + 'Automattic\\Jetpack\\Sync\\Modules\\Terms', + 'Automattic\\Jetpack\\Sync\\Modules\\Menus', + 'Automattic\\Jetpack\\Sync\\Modules\\Themes', + 'Automattic\\Jetpack\\Sync\\Modules\\Users', + 'Automattic\\Jetpack\\Sync\\Modules\\Import', + 'Automattic\\Jetpack\\Sync\\Modules\\Posts', + 'Automattic\\Jetpack\\Sync\\Modules\\Protect', + 'Automattic\\Jetpack\\Sync\\Modules\\Comments', + 'Automattic\\Jetpack\\Sync\\Modules\\Updates', + 'Automattic\\Jetpack\\Sync\\Modules\\Attachments', + 'Automattic\\Jetpack\\Sync\\Modules\\Meta', + 'Automattic\\Jetpack\\Sync\\Modules\\Plugins', + 'Automattic\\Jetpack\\Sync\\Modules\\Stats', + 'Automattic\\Jetpack\\Sync\\Modules\\Full_Sync_Immediately', 'Automattic\\Jetpack\\Sync\\Modules\\Term_Relationships', ); /** - * Maps classnames of sync modules before to v7.5 to classnames of sync modules after v7.5. - * - * @access public - * - * @var array - */ - const LEGACY_SYNC_MODULES_MAP = array( - 'Jetpack_Sync_Modules_Constants' => 'Automattic\\Jetpack\\Sync\\Modules\\Constants', - 'Jetpack_Sync_Modules_Callables' => 'Automattic\\Jetpack\\Sync\\Modules\\Callables', - 'Jetpack_Sync_Modules_Network_Options' => 'Automattic\\Jetpack\\Sync\\Modules\\Network_Options', - 'Jetpack_Sync_Modules_Options' => 'Automattic\\Jetpack\\Sync\\Modules\\Options', - 'Jetpack_Sync_Modules_Terms' => 'Automattic\\Jetpack\\Sync\\Modules\\Terms', - 'Jetpack_Sync_Modules_Menus' => 'Automattic\\Jetpack\\Sync\\Modules\\Menus', - 'Jetpack_Sync_Modules_Themes' => 'Automattic\\Jetpack\\Sync\\Modules\\Themes', - 'Jetpack_Sync_Modules_Users' => 'Automattic\\Jetpack\\Sync\\Modules\\Users', - 'Jetpack_Sync_Modules_Import' => 'Automattic\\Jetpack\\Sync\\Modules\\Import', - 'Jetpack_Sync_Modules_Posts' => 'Automattic\\Jetpack\\Sync\\Modules\\Posts', - 'Jetpack_Sync_Modules_Protect' => 'Automattic\\Jetpack\\Sync\\Modules\\Protect', - 'Jetpack_Sync_Modules_Comments' => 'Automattic\\Jetpack\\Sync\\Modules\\Comments', - 'Jetpack_Sync_Modules_Updates' => 'Automattic\\Jetpack\\Sync\\Modules\\Updates', - 'Jetpack_Sync_Modules_Attachments' => 'Automattic\\Jetpack\\Sync\\Modules\\Attachments', - 'Jetpack_Sync_Modules_Meta' => 'Automattic\\Jetpack\\Sync\\Modules\\Meta', - 'Jetpack_Sync_Modules_Plugins' => 'Automattic\\Jetpack\\Sync\\Modules\\Plugins', - 'Jetpack_Sync_Modules_Stats' => 'Automattic\\Jetpack\\Sync\\Modules\\Stats', - 'Jetpack_Sync_Modules_Full_Sync' => 'Automattic\\Jetpack\\Sync\\Modules\\Full_Sync', - ); - - /** * Keeps track of initialized sync modules. * * @access private @@ -86,7 +60,7 @@ class Modules { * @access public * @static * - * @return array|null + * @return Module[] */ public static function get_modules() { if ( null === self::$initialized_modules ) { @@ -146,11 +120,9 @@ class Modules { */ $modules = apply_filters( 'jetpack_sync_modules', self::DEFAULT_SYNC_MODULES ); - $modules = array_map( array( 'Automattic\\Jetpack\\Sync\\Modules', 'map_legacy_modules' ), $modules ); + $modules = array_map( array( __CLASS__, 'load_module' ), $modules ); - $modules = array_map( array( 'Automattic\\Jetpack\\Sync\\Modules', 'load_module' ), $modules ); - - return array_map( array( 'Automattic\\Jetpack\\Sync\\Modules', 'set_module_defaults' ), $modules ); + return array_map( array( __CLASS__, 'set_module_defaults' ), $modules ); } /** @@ -168,25 +140,6 @@ class Modules { } /** - * For backwards compat, takes the classname of a given module pre Jetpack 7.5, - * and returns the new namespaced classname. - * - * @access public - * @static - * - * @param string $module_class The classname of a Jetpack sync module. - * - * @return string - */ - public static function map_legacy_modules( $module_class ) { - $legacy_map = self::LEGACY_SYNC_MODULES_MAP; - if ( isset( $legacy_map[ $module_class ] ) ) { - return $legacy_map[ $module_class ]; - } - return $module_class; - } - - /** * Sets defaults for the given instance of a Jetpack sync module. * * @access public @@ -203,5 +156,4 @@ class Modules { } return $module; } - } diff --git a/plugins/jetpack/vendor/automattic/jetpack-sync/src/class-sender.php b/plugins/jetpack/vendor/automattic/jetpack-sync/src/class-sender.php index 4bed9181..641110e0 100644 --- a/plugins/jetpack/vendor/automattic/jetpack-sync/src/class-sender.php +++ b/plugins/jetpack/vendor/automattic/jetpack-sync/src/class-sender.php @@ -7,6 +7,7 @@ namespace Automattic\Jetpack\Sync; +use Automattic\Jetpack\Connection\Manager; use Automattic\Jetpack\Constants; /** @@ -155,7 +156,7 @@ class Sender { * @access public * @static * - * @return Automattic\Jetpack\Sync\Sender + * @return Sender */ public static function get_instance() { if ( null === self::$instance ) { @@ -199,7 +200,8 @@ class Sender { * @access public */ public function maybe_set_user_from_token() { - $verified_user = \Jetpack::connection()->verify_xml_rpc_signature(); + $connection = new Manager(); + $verified_user = $connection->verify_xml_rpc_signature(); if ( Constants::is_true( 'XMLRPC_REQUEST' ) && ! is_wp_error( $verified_user ) && $verified_user @@ -257,6 +259,9 @@ class Sender { if ( ! Modules::get_module( 'full-sync' ) ) { return; } + if ( ! Settings::get_setting( 'full_sync_sender_enabled' ) ) { + return; + } $this->continue_full_sync_enqueue(); return $this->do_sync_and_set_delays( $this->full_sync_queue ); } @@ -349,16 +354,16 @@ class Sender { * * @access public * - * @param Automattic\Jetpack\Sync\Queue_Buffer $buffer Queue buffer object. - * @param boolean $encode Whether to encode the items. + * @param (array|Automattic\Jetpack\Sync\Queue_Buffer) $buffer_or_items Queue buffer or array of objects. + * @param boolean $encode Whether to encode the items. * @return array Sync items to send. */ - public function get_items_to_send( $buffer, $encode = true ) { + public function get_items_to_send( $buffer_or_items, $encode = true ) { // Track how long we've been processing so we can avoid request timeouts. $start_time = microtime( true ); $upload_size = 0; $items_to_send = array(); - $items = $buffer->get_items(); + $items = is_array( $buffer_or_items ) ? $buffer_or_items : $buffer_or_items->get_items(); // Set up current screen to avoid errors rendering content. require_once ABSPATH . 'wp-admin/includes/class-wp-screen.php'; require_once ABSPATH . 'wp-admin/includes/screen.php'; @@ -518,6 +523,61 @@ class Sender { } /** + * Immediately sends a single item without firing or enqueuing it + * + * @param string $action_name The action. + * @param array $data The data associated with the action. + * + * @return Items processed. TODO: this doesn't make much sense anymore, it should probably be just a bool. + */ + public function send_action( $action_name, $data = null ) { + if ( ! Settings::is_sender_enabled( 'full_sync' ) ) { + return array(); + } + + // Compose the data to be sent. + $action_to_send = $this->create_action_to_send( $action_name, $data ); + + list( $items_to_send, $skipped_items_ids, $items, $preprocess_duration ) = $this->get_items_to_send( $action_to_send, true ); // phpcs:ignore VariableAnalysis.CodeAnalysis.VariableAnalysis.UnusedVariable + Settings::set_is_sending( true ); + $processed_item_ids = apply_filters( 'jetpack_sync_send_data', $items_to_send, $this->get_codec()->name(), microtime( true ), 'immediate-send', 0, $preprocess_duration ); + Settings::set_is_sending( false ); + + /** + * Allows us to keep track of all the actions that have been sent. + * Allows us to calculate the progress of specific actions. + * + * @param array $processed_actions The actions that we send successfully. + * + * @since 4.2.0 + */ + do_action( 'jetpack_sync_processed_actions', $action_to_send ); + + return $processed_item_ids; + } + + /** + * Create an synthetic action for direct sending to WPCOM during full sync (for example) + * + * @access private + * + * @param string $action_name The action. + * @param array $data The data associated with the action. + * @return array An array of synthetic sync actions keyed by current microtime(true) + */ + private function create_action_to_send( $action_name, $data ) { + return array( + (string) microtime( true ) => array( + $action_name, + $data, + get_current_user_id(), + microtime( true ), + Settings::is_importing(), + ), + ); + } + + /** * Returns any object that is able to be synced. * * @access public diff --git a/plugins/jetpack/vendor/automattic/jetpack-sync/src/class-settings.php b/plugins/jetpack/vendor/automattic/jetpack-sync/src/class-settings.php index 834d3670..8ab6b6fa 100644 --- a/plugins/jetpack/vendor/automattic/jetpack-sync/src/class-settings.php +++ b/plugins/jetpack/vendor/automattic/jetpack-sync/src/class-settings.php @@ -53,6 +53,8 @@ class Settings { 'term_relationships_full_sync_item_size' => true, 'sync_sender_enabled' => true, 'full_sync_sender_enabled' => true, + 'full_sync_send_duration' => true, + 'full_sync_limits' => true, ); /** @@ -246,7 +248,7 @@ class Settings { * @return string SQL WHERE clause. */ public static function get_blacklisted_taxonomies_sql() { - return 'taxonomy NOT IN (\'' . join( '\', \'', array_map( 'esc_sql', self::get_setting( 'taxonomies_blacklist' ) ) ) . '\')'; + return "taxonomy NOT IN ('" . join( "', '", array_map( 'esc_sql', self::get_setting( 'taxonomies_blacklist' ) ) ) . "')"; } /** diff --git a/plugins/jetpack/vendor/automattic/jetpack-sync/src/class-users.php b/plugins/jetpack/vendor/automattic/jetpack-sync/src/class-users.php index efb43a28..f37492f6 100644 --- a/plugins/jetpack/vendor/automattic/jetpack-sync/src/class-users.php +++ b/plugins/jetpack/vendor/automattic/jetpack-sync/src/class-users.php @@ -27,16 +27,6 @@ class Users { public static $user_roles = array(); /** - * Jetpack connection manager instance. - * - * @access public - * @static - * - * @var null|Automattic\Jetpack\Connection\Manager - */ - public static $connection = null; - - /** * Initialize sync for user data changes. * * @access public @@ -44,8 +34,8 @@ class Users { * @todo Eventually, connection needs to be instantiated at the top level in the sync package. */ public static function init() { - self::$connection = new Jetpack_Connection(); - if ( self::$connection->is_active() ) { + $connection = new Jetpack_Connection(); + if ( $connection->is_active() ) { // Kick off synchronization of user role when it changes. add_action( 'set_user_role', array( __CLASS__, 'user_role_change' ) ); } @@ -60,7 +50,8 @@ class Users { * @param int $user_id ID of the user. */ public static function user_role_change( $user_id ) { - if ( self::$connection->is_user_connected( $user_id ) ) { + $connection = new Jetpack_Connection(); + if ( $connection->is_user_connected( $user_id ) ) { self::update_role_on_com( $user_id ); // Try to choose a new master if we're demoting the current one. self::maybe_demote_master_user( $user_id ); @@ -101,7 +92,8 @@ class Users { * @return string Signed role of the user. */ public static function get_signed_role( $user_id ) { - return \Jetpack::connection()->sign_role( self::get_role( $user_id ), $user_id ); + $connection = new Jetpack_Connection(); + return $connection->sign_role( self::get_role( $user_id ), $user_id ); } /** @@ -140,9 +132,10 @@ class Users { ) ); $new_master = false; + $connection = new Jetpack_Connection(); foreach ( $query->results as $result ) { $found_user_id = absint( $result->id ); - if ( $found_user_id && self::$connection->is_user_connected( $found_user_id ) ) { + if ( $found_user_id && $connection->is_user_connected( $found_user_id ) ) { $new_master = $found_user_id; break; } diff --git a/plugins/jetpack/vendor/automattic/jetpack-sync/src/modules/class-callables.php b/plugins/jetpack/vendor/automattic/jetpack-sync/src/modules/class-callables.php index d8ac3e9e..83d8e398 100644 --- a/plugins/jetpack/vendor/automattic/jetpack-sync/src/modules/class-callables.php +++ b/plugins/jetpack/vendor/automattic/jetpack-sync/src/modules/class-callables.php @@ -238,6 +238,25 @@ class Callables extends Module { } /** + * Send the callable actions for full sync. + * + * @access public + * + * @param array $config Full sync configuration for this sync module. + * @param int $send_until The timestamp until the current request can send. + * @param array $status This Module Full Sync Status. + * + * @return array This Module Full Sync Status. + */ + public function send_full_sync_actions( $config, $send_until, $status ) { // phpcs:ignore VariableAnalysis.CodeAnalysis.VariableAnalysis.UnusedVariable + // we call this instead of do_action when sending immediately. + $this->send_action( 'jetpack_full_sync_callables', array( true ) ); + + // The number of actions enqueued, and next module state (true == done). + return array( 'finished' => true ); + } + + /** * Retrieve an estimated number of actions that will be enqueued. * * @access public @@ -488,4 +507,16 @@ class Callables extends Module { return $args; } + + /** + * Return Total number of objects. + * + * @param array $config Full Sync config. + * + * @return int total + */ + public function total( $config ) { + return count( $this->get_callable_whitelist() ); + } + } diff --git a/plugins/jetpack/vendor/automattic/jetpack-sync/src/modules/class-comments.php b/plugins/jetpack/vendor/automattic/jetpack-sync/src/modules/class-comments.php index e956748c..ac3ca1c6 100644 --- a/plugins/jetpack/vendor/automattic/jetpack-sync/src/modules/class-comments.php +++ b/plugins/jetpack/vendor/automattic/jetpack-sync/src/modules/class-comments.php @@ -273,7 +273,7 @@ class Comments extends Module { return 'comment_ID IN (' . implode( ',', array_map( 'intval', $config ) ) . ')'; } - return null; + return '1=1'; } /** diff --git a/plugins/jetpack/vendor/automattic/jetpack-sync/src/modules/class-constants.php b/plugins/jetpack/vendor/automattic/jetpack-sync/src/modules/class-constants.php index d4fecb3b..b95c3bc0 100644 --- a/plugins/jetpack/vendor/automattic/jetpack-sync/src/modules/class-constants.php +++ b/plugins/jetpack/vendor/automattic/jetpack-sync/src/modules/class-constants.php @@ -112,18 +112,19 @@ class Constants extends Module { * * @access public * - * @param array $config Full sync configuration for this sync module. + * @param array $config Full sync configuration for this sync module. * @param int $max_items_to_enqueue Maximum number of items to enqueue. - * @param boolean $state True if full sync has finished enqueueing this module, false otherwise. + * @param boolean $state True if full sync has finished enqueueing this module, false otherwise. + * * @return array Number of actions enqueued, and next module state. */ public function enqueue_full_sync_actions( $config, $max_items_to_enqueue, $state ) { // phpcs:ignore VariableAnalysis.CodeAnalysis.VariableAnalysis.UnusedVariable /** * Tells the client to sync all constants to the server * - * @since 4.2.0 - * * @param boolean Whether to expand constants (should always be true) + * + * @since 4.2.0 */ do_action( 'jetpack_full_sync_constants', true ); @@ -132,11 +133,31 @@ class Constants extends Module { } /** + * Send the constants actions for full sync. + * + * @access public + * + * @param array $config Full sync configuration for this sync module. + * @param int $send_until The timestamp until the current request can send. + * @param array $state This module Full Sync status. + * + * @return array This module Full Sync status. + */ + public function send_full_sync_actions( $config, $send_until, $state ) { // phpcs:ignore VariableAnalysis.CodeAnalysis.VariableAnalysis.UnusedVariable + // we call this instead of do_action when sending immediately. + $this->send_action( 'jetpack_full_sync_constants', array( true ) ); + + // The number of actions enqueued, and next module state (true == done). + return array( 'finished' => true ); + } + + /** * Retrieve an estimated number of actions that will be enqueued. * * @access public * * @param array $config Full sync configuration for this sync module. + * * @return array Number of items yet to be enqueued. */ public function estimate_full_sync_actions( $config ) { // phpcs:ignore VariableAnalysis.CodeAnalysis.VariableAnalysis.UnusedVariable @@ -180,10 +201,10 @@ class Constants extends Module { /** * Tells the client to sync a constant to the server * - * @since 4.2.0 - * * @param string The name of the constant * @param mixed The value of the constant + * + * @since 4.2.0 */ do_action( 'jetpack_sync_constant', $name, $value ); $constants_checksums[ $name ] = $checksum; @@ -204,6 +225,7 @@ class Constants extends Module { */ public function get_all_constants() { $constants_whitelist = $this->get_constants_whitelist(); + return array_combine( $constants_whitelist, array_map( array( $this, 'get_constant' ), $constants_whitelist ) @@ -217,6 +239,7 @@ class Constants extends Module { * @access private * * @param string $constant Constant name. + * * @return mixed Return value of the constant. */ private function get_constant( $constant ) { @@ -231,6 +254,7 @@ class Constants extends Module { * @access public * * @param array $args The hook parameters. + * * @return array $args The hook parameters. */ public function expand_constants( $args ) { @@ -241,8 +265,21 @@ class Constants extends Module { $constants_checksums[ $name ] = $this->get_check_sum( $value ); } update_option( self::CONSTANTS_CHECKSUM_OPTION_NAME, $constants_checksums ); + return $constants; } + return $args; } + + /** + * Return Total number of objects. + * + * @param array $config Full Sync config. + * + * @return int total + */ + public function total( $config ) { + return count( $this->get_constants_whitelist() ); + } } diff --git a/plugins/jetpack/vendor/automattic/jetpack-sync/src/modules/class-full-sync-immediately.php b/plugins/jetpack/vendor/automattic/jetpack-sync/src/modules/class-full-sync-immediately.php new file mode 100644 index 00000000..55ddc494 --- /dev/null +++ b/plugins/jetpack/vendor/automattic/jetpack-sync/src/modules/class-full-sync-immediately.php @@ -0,0 +1,404 @@ +<?php +/** + * Full sync module. + * + * @package automattic/jetpack-sync + */ + +namespace Automattic\Jetpack\Sync\Modules; + +use Automattic\Jetpack\Sync\Defaults; +use Automattic\Jetpack\Sync\Lock; +use Automattic\Jetpack\Sync\Modules; +use Automattic\Jetpack\Sync\Settings; + +/** + * This class does a full resync of the database by + * sending an outbound action for every single object + * that we care about. + */ +class Full_Sync_Immediately extends Module { + /** + * Prefix of the full sync status option name. + * + * @var string + */ + const STATUS_OPTION = 'jetpack_sync_full_status'; + + /** + * Sync Lock name. + * + * @var string + */ + const LOCK_NAME = 'full_sync'; + + /** + * Sync module name. + * + * @access public + * + * @return string + */ + public function name() { + return 'full-sync'; + } + + /** + * Initialize action listeners for full sync. + * + * @access public + * + * @param callable $callable Action handler callable. + */ + public function init_full_sync_listeners( $callable ) { + } + + /** + * Start a full sync. + * + * @access public + * + * @param array $full_sync_config Full sync configuration. + * + * @return bool Always returns true at success. + */ + public function start( $full_sync_config = null ) { + // There was a full sync in progress. + if ( $this->is_started() && ! $this->is_finished() ) { + /** + * Fires when a full sync is cancelled. + * + * @since 4.2.0 + */ + do_action( 'jetpack_full_sync_cancelled' ); + $this->send_action( 'jetpack_full_sync_cancelled' ); + } + + // Remove all evidence of previous full sync items and status. + $this->reset_data(); + + if ( ! is_array( $full_sync_config ) ) { + $full_sync_config = Defaults::$default_full_sync_config; + if ( is_multisite() ) { + $full_sync_config['network_options'] = 1; + } + } + + if ( isset( $full_sync_config['users'] ) && 'initial' === $full_sync_config['users'] ) { + $full_sync_config['users'] = Modules::get_module( 'users' )->get_initial_sync_user_config(); + } + + $this->update_status( + array( + 'started' => time(), + 'config' => $full_sync_config, + 'progress' => $this->get_initial_progress( $full_sync_config ), + ) + ); + + $range = $this->get_content_range( $full_sync_config ); + /** + * Fires when a full sync begins. This action is serialized + * and sent to the server so that it knows a full sync is coming. + * + * @param array $full_sync_config Sync configuration for all sync modules. + * @param array $range Range of the sync items, containing min and max IDs for some item types. + * @param array $empty The modules with no items to sync during a full sync. + * + * @since 4.2.0 + * @since 7.3.0 Added $range arg. + * @since 7.4.0 Added $empty arg. + */ + do_action( 'jetpack_full_sync_start', $full_sync_config, $range ); + $this->send_action( 'jetpack_full_sync_start', array( $full_sync_config, $range ) ); + + return true; + } + + /** + * Whether full sync has started. + * + * @access public + * + * @return boolean + */ + public function is_started() { + return ! ! $this->get_status()['started']; + } + + /** + * Retrieve the status of the current full sync. + * + * @access public + * + * @return array Full sync status. + */ + public function get_status() { + $default = array( + 'started' => false, + 'finished' => false, + 'progress' => array(), + 'config' => array(), + ); + + return wp_parse_args( \Jetpack_Options::get_raw_option( self::STATUS_OPTION ), $default ); + } + + /** + * Whether full sync has finished. + * + * @access public + * + * @return boolean + */ + public function is_finished() { + return ! ! $this->get_status()['finished']; + } + + /** + * Clear all the full sync data. + * + * @access public + */ + public function reset_data() { + $this->clear_status(); + ( new Lock() )->remove( self::LOCK_NAME ); + } + + /** + * Clear all the full sync status options. + * + * @access public + */ + public function clear_status() { + \Jetpack_Options::delete_raw_option( self::STATUS_OPTION ); + } + + /** + * Updates the status of the current full sync. + * + * @access public + * + * @param array $values New values to set. + * + * @return bool True if success. + */ + public function update_status( $values ) { + return $this->set_status( wp_parse_args( $values, $this->get_status() ) ); + } + + /** + * Retrieve the status of the current full sync. + * + * @param array $values New values to set. + * + * @access public + * + * @return boolean Full sync status. + */ + public function set_status( $values ) { + return \Jetpack_Options::update_raw_option( self::STATUS_OPTION, $values ); + } + + /** + * Given an initial Full Sync configuration get the initial status. + * + * @param array $full_sync_config Full sync configuration. + * + * @return array Initial Sent status. + */ + public function get_initial_progress( $full_sync_config ) { + // Set default configuration, calculate totals, and save configuration if totals > 0. + $status = array(); + foreach ( $full_sync_config as $name => $config ) { + $module = Modules::get_module( $name ); + $status[ $name ] = array( + 'total' => $module->total( $config ), + 'sent' => 0, + 'finished' => false, + ); + } + + return $status; + } + + /** + * Get the range for content (posts and comments) to sync. + * + * @access private + * + * @return array Array of range (min ID, max ID, total items) for all content types. + */ + private function get_content_range() { + $range = array(); + $config = $this->get_status()['config']; + // Add range only when syncing all objects. + if ( true === isset( $config['posts'] ) && $config['posts'] ) { + $range['posts'] = $this->get_range( 'posts' ); + } + + if ( true === isset( $config['comments'] ) && $config['comments'] ) { + $range['comments'] = $this->get_range( 'comments' ); + } + + return $range; + } + + /** + * Get the range (min ID, max ID and total items) of items to sync. + * + * @access public + * + * @param string $type Type of sync item to get the range for. + * + * @return array Array of min ID, max ID and total items in the range. + */ + public function get_range( $type ) { + global $wpdb; + if ( ! in_array( $type, array( 'comments', 'posts' ), true ) ) { + return array(); + } + + switch ( $type ) { + case 'posts': + $table = $wpdb->posts; + $id = 'ID'; + $where_sql = Settings::get_blacklisted_post_types_sql(); + + break; + case 'comments': + $table = $wpdb->comments; + $id = 'comment_ID'; + $where_sql = Settings::get_comments_filter_sql(); + break; + } + + // TODO: Call $wpdb->prepare on the following query. + // phpcs:ignore WordPress.DB.PreparedSQL.InterpolatedNotPrepared + $results = $wpdb->get_results( "SELECT MAX({$id}) as max, MIN({$id}) as min, COUNT({$id}) as count FROM {$table} WHERE {$where_sql}" ); + if ( isset( $results[0] ) ) { + return $results[0]; + } + + return array(); + } + + /** + * Continue sending instead of enqueueing. + * + * @access public + */ + public function continue_enqueuing() { + $this->continue_sending(); + } + + /** + * Continue sending. + * + * @access public + */ + public function continue_sending() { + if ( ! ( new Lock() )->attempt( self::LOCK_NAME ) || ! $this->is_started() || $this->get_status()['finished'] ) { + return; + } + + $this->send(); + + ( new Lock() )->remove( self::LOCK_NAME ); + } + + /** + * Immediately send the next items to full sync. + * + * @access public + */ + public function send() { + $config = $this->get_status()['config']; + + $max_duration = Settings::get_setting( 'full_sync_send_duration' ); + $send_until = microtime( true ) + $max_duration; + + $progress = $this->get_status()['progress']; + + foreach ( $this->get_remaining_modules_to_send() as $module ) { + $progress[ $module->name() ] = $module->send_full_sync_actions( $config[ $module->name() ], $progress[ $module->name() ], $send_until ); + if ( ! $progress[ $module->name() ]['finished'] ) { + $this->update_status( array( 'progress' => $progress ) ); + + return; + } + } + + $this->send_full_sync_end(); + $this->update_status( array( 'progress' => $progress ) ); + } + + /** + * Get Modules that are configured to Full Sync and haven't finished sending + * + * @return array + */ + public function get_remaining_modules_to_send() { + $status = $this->get_status(); + + return array_filter( + Modules::get_modules(), + /** + * Select configured and not finished modules. + * + * @return bool + * @var $module Module + */ + function ( $module ) use ( $status ) { + // Skip module if not configured for this sync or module is done. + if ( ! isset( $status['config'][ $module->name() ] ) ) { + return false; + } + if ( ! $status['config'][ $module->name() ] ) { + return false; + } + if ( isset( $status['progress'][ $module->name() ]['finished'] ) ) { + if ( true === $status['progress'][ $module->name() ]['finished'] ) { + return false; + } + } + + return true; + } + ); + } + + /** + * Send 'jetpack_full_sync_end' and update 'finished' status. + * + * @access public + */ + public function send_full_sync_end() { + $range = $this->get_content_range(); + + /** + * Fires when a full sync ends. This action is serialized + * and sent to the server. + * + * @param string $checksum Deprecated since 7.3.0 - @see https://github.com/Automattic/jetpack/pull/11945/ + * @param array $range Range of the sync items, containing min and max IDs for some item types. + * + * @since 4.2.0 + * @since 7.3.0 Added $range arg. + */ + do_action( 'jetpack_full_sync_end', '', $range ); + $this->send_action( 'jetpack_full_sync_end', array( '', $range ) ); + + // Setting autoload to true means that it's faster to check whether we should continue enqueuing. + $this->update_status( array( 'finished' => time() ) ); + } + + /** + * Empty Function as we don't close buffers on Immediate Full Sync. + * + * @param Array $actions an array of actions, ignored for queueless sync. + */ + public function update_sent_progress_action( $actions ) { + return; + } +} diff --git a/plugins/jetpack/vendor/automattic/jetpack-sync/src/modules/class-module.php b/plugins/jetpack/vendor/automattic/jetpack-sync/src/modules/class-module.php index b8b57d87..554bc0e1 100644 --- a/plugins/jetpack/vendor/automattic/jetpack-sync/src/modules/class-module.php +++ b/plugins/jetpack/vendor/automattic/jetpack-sync/src/modules/class-module.php @@ -9,6 +9,8 @@ namespace Automattic\Jetpack\Sync\Modules; use Automattic\Jetpack\Sync\Listener; use Automattic\Jetpack\Sync\Replicastore; +use Automattic\Jetpack\Sync\Sender; +use Automattic\Jetpack\Sync\Settings; /** * Basic methods implemented by Jetpack Sync extensions. @@ -125,7 +127,7 @@ abstract class Module { * @param array $config Full sync configuration for this sync module. * @param int $max_items_to_enqueue Maximum number of items to enqueue. * @param boolean $state True if full sync has finished enqueueing this module, false otherwise. - * @return array Number of actions enqueued, and next module state. + * @return array Number of actions enqueued, and next module state. */ public function enqueue_full_sync_actions( $config, $max_items_to_enqueue, $state ) { // In subclasses, return the number of actions enqueued, and next module state (true == done). @@ -262,6 +264,94 @@ abstract class Module { } /** + * Given the Module Full Sync Configuration and Status return the next chunk of items to send. + * + * @param array $config This module Full Sync configuration. + * @param array $status This module Full Sync status. + * @param int $chunk_size Chunk size. + * + * @return array|object|null + */ + public function get_next_chunk( $config, $status, $chunk_size ) { + global $wpdb; + return $wpdb->get_col( + <<<SQL +SELECT {$this->id_field()} +FROM {$wpdb->{$this->table_name()}} +WHERE {$this->get_where_sql( $config )} +AND {$this->id_field()} < {$status['last_sent']} +ORDER BY {$this->id_field()} +DESC LIMIT {$chunk_size} +SQL + ); + } + + /** + * Return the initial last sent object. + * + * @return string|array initial status. + */ + public function get_initial_last_sent() { + return '~0'; + } + + /** + * Immediately send all items of a sync type as an action. + * + * @access protected + * + * @param string $config Full sync configuration for this module. + * @param array $status the current module full sync status. + * @param float $send_until timestamp until we want this request to send full sync events. + * + * @return array Status, the module full sync status updated. + */ + public function send_full_sync_actions( $config, $status, $send_until ) { + global $wpdb; + + if ( empty( $status['last_sent'] ) ) { + $status['last_sent'] = $this->get_initial_last_sent(); + } + + $limits = Settings::get_setting( 'full_sync_limits' )[ $this->name() ]; + + $chunks_sent = 0; + // phpcs:ignore WordPress.CodeAnalysis.AssignmentInCondition.FoundInWhileCondition + while ( $objects = $this->get_next_chunk( $config, $status, $limits['chunk_size'] ) ) { + if ( $chunks_sent++ === $limits['max_chunks'] || microtime( true ) >= $send_until ) { + return $status; + } + + $result = $this->send_action( 'jetpack_full_sync_' . $this->name(), array( $objects, $status['last_sent'] ) ); + + if ( is_wp_error( $result ) || $wpdb->last_error ) { + return $status; + } + // The $ids are ordered in descending order. + $status['last_sent'] = end( $objects ); + $status['sent'] += count( $objects ); + } + + if ( ! $wpdb->last_error ) { + $status['finished'] = true; + } + + return $status; + } + + + /** + * Immediately sends a single item without firing or enqueuing it + * + * @param string $action_name The action. + * @param array $data The data associated with the action. + */ + public function send_action( $action_name, $data = null ) { + $sender = Sender::get_instance(); + return $sender->send_action( $action_name, $data ); + } + + /** * Retrieve chunk IDs with previous interval end. * * @access protected @@ -460,4 +550,33 @@ abstract class Module { return $results; } + + /** + * Return Total number of objects. + * + * @param array $config Full Sync config. + * + * @return int total + */ + public function total( $config ) { + global $wpdb; + $table = $wpdb->{$this->table_name()}; + $where = $this->get_where_sql( $config ); + + // phpcs:ignore WordPress.DB.PreparedSQL.InterpolatedNotPrepared + return $wpdb->get_var( "SELECT COUNT(*) FROM $table WHERE $where" ); + } + + /** + * Retrieve the WHERE SQL clause based on the module config. + * + * @access public + * + * @param array $config Full sync configuration for this sync module. + * @return string WHERE SQL clause, or `null` if no comments are specified in the module config. + */ + public function get_where_sql( $config ) { + return '1=1'; + } + } diff --git a/plugins/jetpack/vendor/automattic/jetpack-sync/src/modules/class-network-options.php b/plugins/jetpack/vendor/automattic/jetpack-sync/src/modules/class-network-options.php index c30ae8c7..60c458c8 100644 --- a/plugins/jetpack/vendor/automattic/jetpack-sync/src/modules/class-network-options.php +++ b/plugins/jetpack/vendor/automattic/jetpack-sync/src/modules/class-network-options.php @@ -126,6 +126,29 @@ class Network_Options extends Module { } /** + * Send the network options actions for full sync. + * + * @access public + * + * @param array $config Full sync configuration for this sync module. + * @param int $send_until The timestamp until the current request can send. + * @param array $state This module Full Sync status. + * + * @return array This module Full Sync status. + */ + public function send_full_sync_actions( $config, $send_until, $state ) { // phpcs:ignore VariableAnalysis.CodeAnalysis.VariableAnalysis.UnusedVariable + if ( ! is_multisite() ) { + return array( null, true ); + } + + // we call this instead of do_action when sending immediately. + $this->send_action( 'jetpack_full_sync_network_options', array( true ) ); + + // The number of actions enqueued, and next module state (true == done). + return array( 'finished' => true ); + } + + /** * Retrieve an estimated number of actions that will be enqueued. * * @access public @@ -233,4 +256,16 @@ class Network_Options extends Module { return $args; } + + /** + * Return Total number of objects. + * + * @param array $config Full Sync config. + * + * @return int total + */ + public function total( $config ) { + return count( $this->network_options_whitelist ); + } + } diff --git a/plugins/jetpack/vendor/automattic/jetpack-sync/src/modules/class-options.php b/plugins/jetpack/vendor/automattic/jetpack-sync/src/modules/class-options.php index 2c323a2b..0f9b2f11 100644 --- a/plugins/jetpack/vendor/automattic/jetpack-sync/src/modules/class-options.php +++ b/plugins/jetpack/vendor/automattic/jetpack-sync/src/modules/class-options.php @@ -136,6 +136,25 @@ class Options extends Module { } /** + * Send the options actions for full sync. + * + * @access public + * + * @param array $config Full sync configuration for this sync module. + * @param int $send_until The timestamp until the current request can send. + * @param array $state This module Full Sync status. + * + * @return array This module Full Sync status. + */ + public function send_full_sync_actions( $config, $send_until, $state ) { // phpcs:ignore VariableAnalysis.CodeAnalysis.VariableAnalysis.UnusedVariable + // we call this instead of do_action when sending immediately. + $this->send_action( 'jetpack_full_sync_options', array( true ) ); + + // The number of actions enqueued, and next module state (true == done). + return array( 'finished' => true ); + } + + /** * Retrieve an estimated number of actions that will be enqueued. * * @access public @@ -341,4 +360,16 @@ class Options extends Module { return $args; } + + /** + * Return Total number of objects. + * + * @param array $config Full Sync config. + * + * @return int total + */ + public function total( $config ) { + return count( Defaults::get_options_whitelist() ); + } + } diff --git a/plugins/jetpack/vendor/automattic/jetpack-sync/src/modules/class-term-relationships.php b/plugins/jetpack/vendor/automattic/jetpack-sync/src/modules/class-term-relationships.php index 3cad885d..17a183dc 100644 --- a/plugins/jetpack/vendor/automattic/jetpack-sync/src/modules/class-term-relationships.php +++ b/plugins/jetpack/vendor/automattic/jetpack-sync/src/modules/class-term-relationships.php @@ -139,6 +139,46 @@ class Term_Relationships extends Module { } /** + * Return the initial last sent object. + * + * @return string|array initial status. + */ + public function get_initial_last_sent() { + return array( + 'object_id' => self::MAX_INT, + 'term_taxonomy_id' => self::MAX_INT, + ); + } + + /** + * Given the Module Full Sync Configuration and Status return the next chunk of items to send. + * + * @param array $config This module Full Sync configuration. + * @param array $status This module Full Sync status. + * @param int $chunk_size Chunk size. + * + * @return array|object|null + */ + public function get_next_chunk( $config, $status, $chunk_size ) { + global $wpdb; + + return $wpdb->get_results( + $wpdb->prepare( + "SELECT object_id, term_taxonomy_id + FROM $wpdb->term_relationships + WHERE ( object_id = %d AND term_taxonomy_id < %d ) OR ( object_id < %d ) + ORDER BY object_id DESC, term_taxonomy_id + DESC LIMIT %d", + $status['last_sent']['object_id'], + $status['last_sent']['term_taxonomy_id'], + $status['last_sent']['object_id'], + $chunk_size + ), + ARRAY_A + ); + } + + /** * * Enqueue all $items within `jetpack_full_sync_term_relationships` actions. * diff --git a/plugins/jetpack/vendor/automattic/jetpack-sync/src/modules/class-terms.php b/plugins/jetpack/vendor/automattic/jetpack-sync/src/modules/class-terms.php index 36afc5d7..2292356a 100644 --- a/plugins/jetpack/vendor/automattic/jetpack-sync/src/modules/class-terms.php +++ b/plugins/jetpack/vendor/automattic/jetpack-sync/src/modules/class-terms.php @@ -14,14 +14,6 @@ use Automattic\Jetpack\Sync\Settings; * Class to handle sync for terms. */ class Terms extends Module { - /** - * Whitelist for taxonomies we want to sync. - * - * @access private - * - * @var array - */ - private $taxonomy_whitelist; /** * Sync module name. @@ -53,7 +45,7 @@ class Terms extends Module { * @return string */ public function table_name() { - return 'terms'; + return 'term_taxonomy'; } /** @@ -264,27 +256,6 @@ class Terms extends Module { } /** - * Set the taxonomy whitelist. - * - * @access public - * - * @param array $taxonomies The new taxonomyy whitelist. - */ - public function set_taxonomy_whitelist( $taxonomies ) { - $this->taxonomy_whitelist = $taxonomies; - } - - /** - * Set module defaults. - * Define the taxonomy whitelist to be the default one. - * - * @access public - */ - public function set_defaults() { - $this->taxonomy_whitelist = Defaults::$default_taxonomy_whitelist; - } - - /** * Expand the term taxonomy IDs to terms within a hook before they are serialized and sent to the server. * * @access public @@ -319,4 +290,5 @@ class Terms extends Module { public function expand_terms_for_relationship( $relationship ) { return get_term_by( 'term_taxonomy_id', $relationship->term_taxonomy_id ); } + } diff --git a/plugins/jetpack/vendor/automattic/jetpack-sync/src/modules/class-themes.php b/plugins/jetpack/vendor/automattic/jetpack-sync/src/modules/class-themes.php index 57535527..bbccebf0 100644 --- a/plugins/jetpack/vendor/automattic/jetpack-sync/src/modules/class-themes.php +++ b/plugins/jetpack/vendor/automattic/jetpack-sync/src/modules/class-themes.php @@ -497,6 +497,25 @@ class Themes extends Module { } /** + * Send the themes actions for full sync. + * + * @access public + * + * @param array $config Full sync configuration for this sync module. + * @param int $send_until The timestamp until the current request can send. + * @param array $state This module Full Sync status. + * + * @return array This module Full Sync status. + */ + public function send_full_sync_actions( $config, $send_until, $state ) { // phpcs:ignore VariableAnalysis.CodeAnalysis.VariableAnalysis.UnusedVariable + // we call this instead of do_action when sending immediately. + $this->send_action( 'jetpack_full_sync_theme_data', array( true ) ); + + // The number of actions enqueued, and next module state (true == done). + return array( 'finished' => true ); + } + + /** * Retrieve an estimated number of actions that will be enqueued. * * @access public @@ -822,4 +841,16 @@ class Themes extends Module { private function is_theme_switch() { return did_action( 'after_switch_theme' ); } + + /** + * Return Total number of objects. + * + * @param array $config Full Sync config. + * + * @return int total + */ + public function total( $config ) { + return 1; + } + } diff --git a/plugins/jetpack/vendor/automattic/jetpack-sync/src/modules/class-updates.php b/plugins/jetpack/vendor/automattic/jetpack-sync/src/modules/class-updates.php index d99c9c57..beeb9ca4 100644 --- a/plugins/jetpack/vendor/automattic/jetpack-sync/src/modules/class-updates.php +++ b/plugins/jetpack/vendor/automattic/jetpack-sync/src/modules/class-updates.php @@ -374,6 +374,25 @@ class Updates extends Module { } /** + * Send the updates actions for full sync. + * + * @access public + * + * @param array $config Full sync configuration for this sync module. + * @param int $send_until The timestamp until the current request can send. + * @param array $state This module Full Sync status. + * + * @return array This module Full Sync status. + */ + public function send_full_sync_actions( $config, $send_until, $state ) { // phpcs:ignore VariableAnalysis.CodeAnalysis.VariableAnalysis.UnusedVariable + // we call this instead of do_action when sending immediately. + $this->send_action( 'jetpack_full_sync_updates', array( true ) ); + + // The number of actions enqueued, and next module state (true == done). + return array( 'finished' => true ); + } + + /** * Retrieve an estimated number of actions that will be enqueued. * * @access public @@ -493,4 +512,16 @@ class Updates extends Module { public function reset_data() { delete_option( self::UPDATES_CHECKSUM_OPTION_NAME ); } + + /** + * Return Total number of objects. + * + * @param array $config Full Sync config. + * + * @return int total + */ + public function total( $config ) { + return 3; + } + } diff --git a/plugins/jetpack/vendor/automattic/jetpack-sync/src/modules/class-users.php b/plugins/jetpack/vendor/automattic/jetpack-sync/src/modules/class-users.php index 21974a5b..3b259a98 100644 --- a/plugins/jetpack/vendor/automattic/jetpack-sync/src/modules/class-users.php +++ b/plugins/jetpack/vendor/automattic/jetpack-sync/src/modules/class-users.php @@ -49,7 +49,18 @@ class Users extends Module { * @return string */ public function table_name() { - return 'users'; + return 'usermeta'; + } + + /** + * The id field in the database. + * + * @access public + * + * @return string + */ + public function id_field() { + return 'user_id'; } /** diff --git a/plugins/jetpack/vendor/automattic/jetpack-sync/src/modules/class-woocommerce.php b/plugins/jetpack/vendor/automattic/jetpack-sync/src/modules/class-woocommerce.php index 1c336342..0cbecb48 100644 --- a/plugins/jetpack/vendor/automattic/jetpack-sync/src/modules/class-woocommerce.php +++ b/plugins/jetpack/vendor/automattic/jetpack-sync/src/modules/class-woocommerce.php @@ -58,6 +58,17 @@ class WooCommerce extends Module { private $order_item_table_name; /** + * The table in the database. + * + * @access public + * + * @return string + */ + public function table_name() { + return $this->order_item_table_name; + } + + /** * Constructor. * * @global $wpdb @@ -270,7 +281,7 @@ class WooCommerce extends Module { * @param array $config Full sync configuration for this sync module. * @return string WHERE SQL clause. */ - private function get_where_sql( $config ) { // phpcs:ignore VariableAnalysis.CodeAnalysis.VariableAnalysis.UnusedVariable + public function get_where_sql( $config ) { // phpcs:ignore VariableAnalysis.CodeAnalysis.VariableAnalysis.UnusedVariable return '1=1'; } |