diff --git a/3rd-party/class.jetpack-amp-support.php b/3rd-party/class.jetpack-amp-support.php index 27f22d1bf78e..91d468acef4d 100644 --- a/3rd-party/class.jetpack-amp-support.php +++ b/3rd-party/class.jetpack-amp-support.php @@ -1,4 +1,7 @@ true ) ); - Jetpack_Sync_Actions::$sender->do_full_sync(); + if ( Jetpack::is_active() && ! Jetpack::validate_sync_error_idc_option() && Actions::sync_allowed() ) { + Actions::do_full_sync( array( 'functions' => true ) ); + Actions::$sender->do_full_sync(); } if ( Jetpack::validate_sync_error_idc_option() ) { diff --git a/_inc/lib/debugger/class-jetpack-debug-data.php b/_inc/lib/debugger/class-jetpack-debug-data.php index 50642de30eb9..97a58767219c 100644 --- a/_inc/lib/debugger/class-jetpack-debug-data.php +++ b/_inc/lib/debugger/class-jetpack-debug-data.php @@ -5,6 +5,10 @@ * @package jetpack */ +use Automattic\Jetpack\Sync\Functions; +use Automattic\Jetpack\Sync\Modules; +use Automattic\Jetpack\Sync\Sender; + /** * Class Jetpack_Debug_Data * @@ -266,14 +270,7 @@ public static function debug_data() { ); /** Sync Debug Information */ - /** Load Sync modules */ - require_once JETPACK__PLUGIN_DIR . 'sync/class.jetpack-sync-modules.php'; - /** Load Sync sender */ - require_once JETPACK__PLUGIN_DIR . 'sync/class.jetpack-sync-sender.php'; - /** Load Sync functions */ - require_once JETPACK__PLUGIN_DIR . 'sync/class.jetpack-sync-functions.php'; - - $sync_module = Jetpack_Sync_Modules::get_module( 'full-sync' ); + $sync_module = Modules::get_module( 'full-sync' ); if ( $sync_module ) { $sync_statuses = $sync_module->get_status(); $human_readable_sync_status = array(); @@ -289,7 +286,7 @@ public static function debug_data() { ); } - $queue = Jetpack_Sync_Sender::get_instance()->get_sync_queue(); + $queue = Sender::get_instance()->get_sync_queue(); $debug_info['sync_size'] = array( 'label' => 'Sync Queue Size', @@ -302,7 +299,7 @@ public static function debug_data() { 'private' => false, ); - $full_sync_queue = Jetpack_Sync_Sender::get_instance()->get_full_sync_queue(); + $full_sync_queue = Sender::get_instance()->get_full_sync_queue(); $debug_info['full_sync_size'] = array( 'label' => 'Full Sync Queue Size', @@ -321,8 +318,8 @@ public static function debug_data() { * Must follow sync debug since it depends on sync functionality. */ $idc_urls = array( - 'home' => Jetpack_Sync_Functions::home_url(), - 'siteurl' => Jetpack_Sync_Functions::site_url(), + 'home' => Functions::home_url(), + 'siteurl' => Functions::site_url(), 'WP_HOME' => Jetpack_Constants::is_defined( 'WP_HOME' ) ? Jetpack_Constants::get_constant( 'WP_HOME' ) : '', 'WP_SITEURL' => Jetpack_Constants::is_defined( 'WP_SITEURL' ) ? Jetpack_Constants::get_constant( 'WP_SITEURL' ) : '', ); diff --git a/class.jetpack-cli.php b/class.jetpack-cli.php index 67ff87b59248..8a9c8b22f6eb 100644 --- a/class.jetpack-cli.php +++ b/class.jetpack-cli.php @@ -1,5 +1,10 @@ $item ) { $collection[] = array( @@ -836,7 +841,7 @@ public function sync( $args, $assoc_args ) { break; case 'settings': WP_CLI::log( __( 'Sync Settings:', 'jetpack' ) ); - foreach( Jetpack_Sync_Settings::get_settings() as $setting => $item ) { + foreach( Settings::get_settings() as $setting => $item ) { $settings[] = array( 'setting' => $setting, 'value' => is_scalar( $item ) ? $item : json_encode( $item ) @@ -845,24 +850,23 @@ public function sync( $args, $assoc_args ) { WP_CLI\Utils\format_items( 'table', $settings, array( 'setting', 'value' ) ); case 'disable': - // Don't set it via the Jetpack_Sync_Settings since that also resets the queues. + // Don't set it via the Settings since that also resets the queues. update_option( 'jetpack_sync_settings_disable', 1 ); /* translators: %s is the site URL */ WP_CLI::log( sprintf( __( 'Sync Disabled on %s', 'jetpack' ), get_site_url() ) ); break; case 'enable': - Jetpack_Sync_Settings::update_settings( array( 'disable' => 0 ) ); + Settings::update_settings( array( 'disable' => 0 ) ); /* translators: %s is the site URL */ WP_CLI::log( sprintf( __( 'Sync Enabled on %s', 'jetpack' ), get_site_url() ) ); break; case 'reset': - // Don't set it via the Jetpack_Sync_Settings since that also resets the queues. + // Don't set it via the Settings since that also resets the queues. update_option( 'jetpack_sync_settings_disable', 1 ); /* translators: %s is the site URL */ WP_CLI::log( sprintf( __( 'Sync Disabled on %s. Use `wp jetpack sync enable` to enable syncing again.', 'jetpack' ), get_site_url() ) ); - require_once dirname( __FILE__ ) . '/sync/class.jetpack-sync-listener.php'; - $listener = Jetpack_Sync_Listener::get_instance(); + $listener = Listener::get_instance(); if ( empty( $assoc_args['queue'] ) ) { $listener->get_sync_queue()->reset(); $listener->get_full_sync_queue()->reset(); @@ -891,8 +895,8 @@ public function sync( $args, $assoc_args ) { break; case 'start': - if ( ! Jetpack_Sync_Actions::sync_allowed() ) { - if( ! Jetpack_Sync_Settings::get_setting( 'disable' ) ) { + if ( ! Actions::sync_allowed() ) { + if( ! Settings::get_setting( 'disable' ) ) { WP_CLI::error( __( 'Jetpack sync is not currently allowed for this site. It is currently disabled. Run `wp jetpack sync enable` to enable it.', 'jetpack' ) ); return; } @@ -911,11 +915,11 @@ public function sync( $args, $assoc_args ) { } // Get the original settings so that we can restore them later - $original_settings = Jetpack_Sync_Settings::get_settings(); + $original_settings = Settings::get_settings(); // Initialize sync settigns so we can sync as quickly as possible $sync_settings = wp_parse_args( - array_intersect_key( $assoc_args, Jetpack_Sync_Settings::$valid_settings ), + array_intersect_key( $assoc_args, Settings::$valid_settings ), array( 'sync_wait_time' => 0, 'enqueue_wait_time' => 0, @@ -923,7 +927,7 @@ public function sync( $args, $assoc_args ) { 'max_queue_size_full_sync' => 100000 ) ); - Jetpack_Sync_Settings::update_settings( $sync_settings ); + Settings::update_settings( $sync_settings ); // Convert comma-delimited string of modules to an array if ( ! empty( $assoc_args['modules'] ) ) { @@ -954,7 +958,7 @@ public function sync( $args, $assoc_args ) { } // Kick off a full sync - if ( Jetpack_Sync_Actions::do_full_sync( $modules ) ) { + if ( Actions::do_full_sync( $modules ) ) { if ( $modules ) { /* translators: %s is a comma separated list of Jetpack modules */ WP_CLI::log( sprintf( __( 'Initialized a new full sync with modules: %s', 'jetpack' ), join( ', ', array_keys( $modules ) ) ) ); @@ -964,7 +968,7 @@ public function sync( $args, $assoc_args ) { } else { // Reset sync settings to original. - Jetpack_Sync_Settings::update_settings( $original_settings ); + Settings::update_settings( $original_settings ); if ( $modules ) { /* translators: %s is a comma separated list of Jetpack modules */ @@ -977,7 +981,7 @@ public function sync( $args, $assoc_args ) { // Keep sending to WPCOM until there's nothing to send $i = 1; do { - $result = Jetpack_Sync_Actions::$sender->do_full_sync(); + $result = Actions::$sender->do_full_sync(); if ( is_wp_error( $result ) ) { $queue_empty_error = ( 'empty_queue_full_sync' == $result->get_error_code() ); if ( ! $queue_empty_error || ( $queue_empty_error && ( 1 == $i ) ) ) { @@ -995,7 +999,7 @@ public function sync( $args, $assoc_args ) { } while ( $result && ! is_wp_error( $result ) ); // Reset sync settings to original. - Jetpack_Sync_Settings::update_settings( $original_settings ); + Settings::update_settings( $original_settings ); WP_CLI::success( __( 'Finished syncing to WordPress.com', 'jetpack' ) ); break; @@ -1016,7 +1020,7 @@ public function sync( $args, $assoc_args ) { * @synopsis */ public function sync_queue( $args, $assoc_args ) { - if ( ! Jetpack_Sync_Actions::sync_allowed() ) { + if ( ! Actions::sync_allowed() ) { WP_CLI::error( __( 'Jetpack sync is not currently allowed for this site.', 'jetpack' ) ); } @@ -1033,8 +1037,7 @@ public function sync_queue( $args, $assoc_args ) { switch( $action ) { case 'peek': - require_once JETPACK__PLUGIN_DIR . 'sync/class.jetpack-sync-queue.php'; - $queue = new Jetpack_Sync_Queue( $mapped_queue_name ); + $queue = new Queue( $mapped_queue_name ); $items = $queue->peek( 100 ); if ( empty( $items ) ) { diff --git a/class.jetpack-xmlrpc-server.php b/class.jetpack-xmlrpc-server.php index 3ca6411d0176..7aaaa6046058 100644 --- a/class.jetpack-xmlrpc-server.php +++ b/class.jetpack-xmlrpc-server.php @@ -1,5 +1,9 @@ get_codec(); + $sync_module = Modules::get_module( $module_name ); + $codec = Sender::get_instance()->get_codec(); return $codec->encode( $sync_module->get_object_by_id( $object_type, $id ) ); } @@ -651,10 +653,9 @@ function sync_object( $args ) { * @return array */ function validate_urls_for_idc_mitigation() { - require_once JETPACK__PLUGIN_DIR . 'sync/class.jetpack-sync-functions.php'; return array( - 'home' => Jetpack_Sync_Functions::home_url(), - 'siteurl' => Jetpack_Sync_Functions::site_url(), + 'home' => Functions::home_url(), + 'siteurl' => Functions::site_url(), ); } diff --git a/class.jetpack.php b/class.jetpack.php index c572f1f4e73f..def18b5b679d 100644 --- a/class.jetpack.php +++ b/class.jetpack.php @@ -22,6 +22,10 @@ Flag for "activating" the plugin on sites where the activation hook never fired (auto-installs) */ +use Automattic\Jetpack\Sync\Functions; +use Automattic\Jetpack\Sync\Sender; +use Automattic\Jetpack\Sync\Users; + require_once( JETPACK__PLUGIN_DIR . '_inc/lib/class.media.php' ); class Jetpack { @@ -1449,8 +1453,8 @@ public static function file_system_write_access() { * @return string ( '1' | '0' ) **/ public static function is_version_controlled() { - _deprecated_function( __METHOD__, 'jetpack-4.2', 'Jetpack_Sync_Functions::is_version_controlled' ); - return (string) (int) Jetpack_Sync_Functions::is_version_controlled(); + _deprecated_function( __METHOD__, 'jetpack-4.2', 'Functions::is_version_controlled' ); + return (string) (int) Functions::is_version_controlled(); } /** @@ -1804,8 +1808,8 @@ function extra_oembed_providers() { * Synchronize connected user role changes */ function user_role_change( $user_id ) { - _deprecated_function( __METHOD__, 'jetpack-4.2', 'Jetpack_Sync_Users::user_role_change()' ); - Jetpack_Sync_Users::user_role_change( $user_id ); + _deprecated_function( __METHOD__, 'jetpack-4.2', 'Users::user_role_change()' ); + Users::user_role_change( $user_id ); } /** @@ -3357,8 +3361,7 @@ public static function disconnect( $update_activated_state = true ) { delete_transient( $transient_key ); // Delete all the sync related data. Since it could be taking up space. - require_once JETPACK__PLUGIN_DIR . 'sync/class.jetpack-sync-sender.php'; - Jetpack_Sync_Sender::get_instance()->uninstall(); + Sender::get_instance()->uninstall(); // Disable the Heartbeat cron Jetpack_Heartbeat::init()->deactivate(); @@ -6209,10 +6212,9 @@ public static function get_sync_error_idc_option( $response = array() ) { // in a transient to allow for autoloading and caching on subsequent views. $local_options = get_transient( 'jetpack_idc_local' ); if ( false === $local_options ) { - require_once JETPACK__PLUGIN_DIR . 'sync/class.jetpack-sync-functions.php'; $local_options = array( - 'home' => Jetpack_Sync_Functions::home_url(), - 'siteurl' => Jetpack_Sync_Functions::site_url(), + 'home' => Functions::home_url(), + 'siteurl' => Functions::site_url(), ); set_transient( 'jetpack_idc_local', $local_options, MINUTE_IN_SECONDS ); } diff --git a/composer.json b/composer.json index d62789bde481..6759f8079da3 100644 --- a/composer.json +++ b/composer.json @@ -9,7 +9,8 @@ }, "require": { "ext-openssl": "*", - "automattic/jetpack-logo": "@dev" + "automattic/jetpack-logo": "@dev", + "automattic/jetpack-sync": "@dev" }, "require-dev": { "dealerdirect/phpcodesniffer-composer-installer": "0.5.0", diff --git a/composer.lock b/composer.lock index 48df1ee81d8c..520e0e62c96f 100644 --- a/composer.lock +++ b/composer.lock @@ -4,7 +4,7 @@ "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies", "This file is @generated automatically" ], - "content-hash": "167f5c90d0f8c7224fdc8707e1ba107f", + "content-hash": "3441d93f564ebc5e82e349fe9db3a39c", "packages": [ { "name": "automattic/jetpack-logo", @@ -25,6 +25,26 @@ "GPL-2.0-or-later" ], "description": "A logo for Jetpack" + }, + { + "name": "automattic/jetpack-sync", + "version": "dev-try/sync-package", + "dist": { + "type": "path", + "url": "./packages/sync", + "reference": "bf7f14e0d3d9618cfad03c0a90fa5b0dd7528fbc", + "shasum": null + }, + "type": "library", + "autoload": { + "psr-4": { + "Automattic\\Jetpack\\Sync\\": "src/" + } + }, + "license": [ + "GPL-2.0-or-later" + ], + "description": "A library that allows syncing to the WP.com infrastructure." } ], "packages-dev": [ @@ -399,7 +419,8 @@ "aliases": [], "minimum-stability": "stable", "stability-flags": { - "automattic/jetpack-logo": 20 + "automattic/jetpack-logo": 20, + "automattic/jetpack-sync": 20 }, "prefer-stable": false, "prefer-lowest": false, diff --git a/jetpack.php b/jetpack.php index cf934b3670d6..4435d708e0c6 100644 --- a/jetpack.php +++ b/jetpack.php @@ -208,7 +208,6 @@ function jetpack_admin_missing_autoloader() { ?> require_once( JETPACK__PLUGIN_DIR . 'class.jetpack-client.php' ); require_once( JETPACK__PLUGIN_DIR . 'class.jetpack-data.php' ); require_once( JETPACK__PLUGIN_DIR . 'class.jetpack-client-server.php' ); -require_once( JETPACK__PLUGIN_DIR . 'sync/class.jetpack-sync-actions.php' ); require_once( JETPACK__PLUGIN_DIR . 'class.jetpack-options.php' ); require_once( JETPACK__PLUGIN_DIR . 'class.jetpack-user-agent.php' ); require_once( JETPACK__PLUGIN_DIR . 'class.jetpack-post-images.php' ); diff --git a/json-endpoints/jetpack/class.jetpack-json-api-plugins-endpoint.php b/json-endpoints/jetpack/class.jetpack-json-api-plugins-endpoint.php index 1df4fe667121..d4877f8be7a6 100644 --- a/json-endpoints/jetpack/class.jetpack-json-api-plugins-endpoint.php +++ b/json-endpoints/jetpack/class.jetpack-json-api-plugins-endpoint.php @@ -1,5 +1,7 @@ Jetpack_Sync_Actions::do_full_sync( $modules ) ); + return array( 'scheduled' => Actions::do_full_sync( $modules ) ); } protected function validate_queue( $query ) { @@ -52,15 +60,14 @@ class Jetpack_JSON_API_Sync_Status_Endpoint extends Jetpack_JSON_API_Sync_Endpoi protected function result() { $args = $this->query_args(); $fields = isset( $args['fields'] ) ? $args['fields'] : array(); - return Jetpack_Sync_Actions::get_sync_status( $fields ); + return Actions::get_sync_status( $fields ); } } // GET /sites/%s/data-check class Jetpack_JSON_API_Sync_Check_Endpoint extends Jetpack_JSON_API_Sync_Endpoint { protected function result() { - require_once JETPACK__PLUGIN_DIR . 'sync/class.jetpack-sync-wp-replicastore.php'; - $store = new Jetpack_Sync_WP_Replicastore(); + $store = new WP_Replicastore(); return $store->checksum_all(); } } @@ -76,8 +83,7 @@ protected function result() { $columns = null; // go with defaults } - require_once JETPACK__PLUGIN_DIR . 'sync/class.jetpack-sync-wp-replicastore.php'; - $store = new Jetpack_Sync_WP_Replicastore(); + $store = new WP_Replicastore(); if ( ! isset( $args['strip_non_ascii'] ) ) { $args['strip_non_ascii'] = true; @@ -93,9 +99,7 @@ class Jetpack_JSON_API_Sync_Modify_Settings_Endpoint extends Jetpack_JSON_API_Sy protected function result() { $args = $this->input(); - require_once JETPACK__PLUGIN_DIR . 'sync/class.jetpack-sync-settings.php'; - - $sync_settings = Jetpack_Sync_Settings::get_settings(); + $sync_settings = Settings::get_settings(); foreach ( $args as $key => $value ) { if ( $value !== false ) { @@ -112,19 +116,17 @@ protected function result() { } } - Jetpack_Sync_Settings::update_settings( $sync_settings ); + Settings::update_settings( $sync_settings ); // re-fetch so we see what's really being stored - return Jetpack_Sync_Settings::get_settings(); + return Settings::get_settings(); } } // GET /sites/%s/sync/settings class Jetpack_JSON_API_Sync_Get_Settings_Endpoint extends Jetpack_JSON_API_Sync_Endpoint { protected function result() { - require_once JETPACK__PLUGIN_DIR . 'sync/class.jetpack-sync-settings.php'; - - return Jetpack_Sync_Settings::get_settings(); + return Settings::get_settings(); } } @@ -135,21 +137,18 @@ protected function result() { $module_name = $args['module_name']; - require_once JETPACK__PLUGIN_DIR . 'sync/class.jetpack-sync-modules.php'; - - if ( ! $sync_module = Jetpack_Sync_Modules::get_module( $module_name ) ) { + if ( ! $sync_module = Modules::get_module( $module_name ) ) { return new WP_Error( 'invalid_module', 'You specified an invalid sync module' ); } $object_type = $args['object_type']; $object_ids = $args['object_ids']; - require_once JETPACK__PLUGIN_DIR . 'sync/class.jetpack-sync-sender.php'; - $codec = Jetpack_Sync_Sender::get_instance()->get_codec(); + $codec = Sender::get_instance()->get_codec(); - Jetpack_Sync_Settings::set_is_syncing( true ); + Settings::set_is_syncing( true ); $objects = $codec->encode( $sync_module->get_objects_by_id( $object_type, $object_ids ) ); - Jetpack_Sync_Settings::set_is_syncing( false ); + Settings::set_is_syncing( false ); return array( 'objects' => $objects, @@ -167,10 +166,8 @@ protected function result() { return $queue_name; } - require_once JETPACK__PLUGIN_DIR . 'sync/class.jetpack-sync-sender.php'; - - $sender = Jetpack_Sync_Sender::get_instance(); - $response = $sender->do_sync_for_queue( new Jetpack_Sync_Queue( $args['queue'] ) ); + $sender = Sender::get_instance(); + $response = $sender->do_sync_for_queue( new Queue( $args['queue'] ) ); return array( 'response' => $response @@ -191,15 +188,13 @@ protected function result() { return new WP_Error( 'invalid_number_of_items', 'Number of items needs to be an integer that is larger than 0 and less then 100', 400 ); } - require_once JETPACK__PLUGIN_DIR . 'sync/class.jetpack-sync-queue.php'; - $queue = new Jetpack_Sync_Queue( $queue_name ); + $queue = new Queue( $queue_name ); if ( 0 === $queue->size() ) { return new WP_Error( 'queue_size', 'The queue is empty and there is nothing to send', 400 ); } - require_once JETPACK__PLUGIN_DIR . 'sync/class.jetpack-sync-sender.php'; - $sender = Jetpack_Sync_Sender::get_instance(); + $sender = Sender::get_instance(); // try to give ourselves as much time as possible set_time_limit( 0 ); @@ -220,9 +215,9 @@ protected function result() { return new WP_Error( 'buffer_non-object', 'Buffer is not an object', 400 ); } - Jetpack_Sync_Settings::set_is_syncing( true ); + Settings::set_is_syncing( true ); list( $items_to_send, $skipped_items_ids, $items ) = $sender->get_items_to_send( $buffer, $args['encode'] ); - Jetpack_Sync_Settings::set_is_syncing( false ); + Settings::set_is_syncing( false ); return array( 'buffer_id' => $buffer->id, @@ -262,7 +257,6 @@ protected function result() { if ( is_wp_error( $queue_name ) ) { return $queue_name; } - require_once JETPACK__PLUGIN_DIR . 'sync/class.jetpack-sync-queue.php'; if ( ! isset( $request_body['buffer_id'] ) ) { return new WP_Error( 'missing_buffer_id', 'Please provide a buffer id', 400 ); @@ -276,8 +270,8 @@ protected function result() { $request_body ['buffer_id'] = preg_replace( '/[^A-Za-z0-9]/', '', $request_body['buffer_id'] ); $request_body['item_ids'] = array_filter( array_map( array( 'Jetpack_JSON_API_Sync_Close_Endpoint', 'sanitize_item_ids' ), $request_body['item_ids'] ) ); - $buffer = new Jetpack_Sync_Queue_Buffer( $request_body['buffer_id'], $request_body['item_ids'] ); - $queue = new Jetpack_Sync_Queue( $queue_name ); + $buffer = new Queue_Buffer( $request_body['buffer_id'], $request_body['item_ids'] ); + $queue = new Queue( $queue_name ); $response = $queue->close( $buffer, $request_body['item_ids'] ); @@ -312,8 +306,7 @@ protected function result() { return new WP_Error( 'invalid_queue', 'Queue name should be sync or full_sync', 400 ); } - require_once JETPACK__PLUGIN_DIR . 'sync/class.jetpack-sync-queue.php'; - $queue = new Jetpack_Sync_Queue( $args['queue'] ); + $queue = new Queue( $args['queue'] ); // False means that there was no lock to delete. $response = $queue->unlock(); diff --git a/json-endpoints/jetpack/class.wpcom-json-api-get-option-endpoint.php b/json-endpoints/jetpack/class.wpcom-json-api-get-option-endpoint.php index 3a76256f6249..b261f202c5f6 100644 --- a/json-endpoints/jetpack/class.wpcom-json-api-get-option-endpoint.php +++ b/json-endpoints/jetpack/class.wpcom-json-api-get-option-endpoint.php @@ -1,5 +1,7 @@ site_option = isset( $query_args['site_option'] ) ? $query_args['site_option'] : false; - require_once JETPACK__PLUGIN_DIR . '/sync/class.jetpack-sync-defaults.php'; /** * Filter the list of options that are manageable via the JSON API. * @@ -33,7 +34,7 @@ function validate_input( $object ) { * @param array The default list of site options. * @param bool Is the option a site option. */ - if ( ! in_array( $this->option_name, apply_filters( 'jetpack_options_whitelist', Jetpack_Sync_Defaults::$default_options_whitelist, $this->site_option ) ) ) { + if ( ! in_array( $this->option_name, apply_filters( 'jetpack_options_whitelist', Defaults::$default_options_whitelist, $this->site_option ) ) ) { return new WP_Error( 'option_name_not_in_whitelist', __( 'You must specify a whitelisted option_name', 'jetpack' ) ); } return true; diff --git a/modules/contact-form/grunion-contact-form.php b/modules/contact-form/grunion-contact-form.php index a26dc20c1d7e..3c64a88c0643 100644 --- a/modules/contact-form/grunion-contact-form.php +++ b/modules/contact-form/grunion-contact-form.php @@ -10,6 +10,8 @@ License: GPLv2 or later */ +use Automattic\Jetpack\Sync\Settings; + define( 'GRUNION_PLUGIN_DIR', plugin_dir_path( __FILE__ ) ); define( 'GRUNION_PLUGIN_URL', plugin_dir_url( __FILE__ ) ); @@ -1935,8 +1937,7 @@ static function _style_on() { * @return string HTML for the concat form. */ static function parse( $attributes, $content ) { - require_once JETPACK__PLUGIN_DIR . '/sync/class.jetpack-sync-settings.php'; - if ( Jetpack_Sync_Settings::is_syncing() ) { + if ( Settings::is_syncing() ) { return ''; } // Create a new Grunion_Contact_Form object (this class) diff --git a/modules/likes/jetpack-likes-settings.php b/modules/likes/jetpack-likes-settings.php index 390fea1e039a..a172603bd761 100644 --- a/modules/likes/jetpack-likes-settings.php +++ b/modules/likes/jetpack-likes-settings.php @@ -1,5 +1,7 @@ in_jetpack = ! ( defined( 'IS_WPCOM' ) && IS_WPCOM ); @@ -269,8 +271,7 @@ function is_post_likeable( $post_id = 0 ) { * similar logic and filters apply here, too. */ function is_likes_visible() { - require_once JETPACK__PLUGIN_DIR . '/sync/class.jetpack-sync-settings.php'; - if ( Jetpack_Sync_Settings::is_syncing() ) { + if ( Settings::is_syncing() ) { return false; } diff --git a/modules/related-posts/jetpack-related-posts.php b/modules/related-posts/jetpack-related-posts.php index f1d1007b79ac..7889e3f97fc5 100644 --- a/modules/related-posts/jetpack-related-posts.php +++ b/modules/related-posts/jetpack-related-posts.php @@ -1,4 +1,7 @@ \n\n"; diff --git a/modules/sharedaddy/sharing-service.php b/modules/sharedaddy/sharing-service.php index 382b1f3b8b1c..748511859383 100644 --- a/modules/sharedaddy/sharing-service.php +++ b/modules/sharedaddy/sharing-service.php @@ -1,5 +1,7 @@ post_type, Jetpack_Sync_Settings::get_setting( 'post_types_blacklist' ) ) ) { + if ( in_array( $post->post_type, Settings::get_setting( 'post_types_blacklist' ) ) ) { return false; } @@ -139,35 +134,33 @@ static function prevent_publicize_blacklisted_posts( $should_publicize, $post ) } static function set_is_importing_true() { - require_once dirname( __FILE__ ) . '/class.jetpack-sync-settings.php'; - Jetpack_Sync_Settings::set_importing( true ); + Settings::set_importing( true ); } static function send_data( $data, $codec_name, $sent_timestamp, $queue_id, $checkout_duration, $preprocess_duration ) { - require_once dirname( __FILE__ ) . '/class.jetpack-sync-functions.php'; - Jetpack::load_xml_rpc_client(); + \Jetpack::load_xml_rpc_client(); $query_args = array( 'sync' => '1', // add an extra parameter to the URL so we can tell it's a sync action 'codec' => $codec_name, // send the name of the codec used to encode the data 'timestamp' => $sent_timestamp, // send current server time so we can compensate for clock differences 'queue' => $queue_id, // sync or full_sync - 'home' => Jetpack_Sync_Functions::home_url(), // Send home url option to check for Identity Crisis server-side - 'siteurl' => Jetpack_Sync_Functions::site_url(), // Send siteurl option to check for Identity Crisis server-side + 'home' => Functions::home_url(), // Send home url option to check for Identity Crisis server-side + 'siteurl' => Functions::site_url(), // Send siteurl option to check for Identity Crisis server-side 'cd' => sprintf( '%.4f', $checkout_duration ), // Time spent retrieving queue items from the DB 'pd' => sprintf( '%.4f', $preprocess_duration ), // Time spent converting queue items into data to send ); // Has the site opted in to IDC mitigation? - if ( Jetpack::sync_idc_optin() ) { + if ( \Jetpack::sync_idc_optin() ) { $query_args['idc'] = true; } - if ( Jetpack_Options::get_option( 'migrate_for_idc', false ) ) { + if ( \Jetpack_Options::get_option( 'migrate_for_idc', false ) ) { $query_args['migrate_for_idc'] = true; } - $query_args['timeout'] = Jetpack_Sync_Settings::is_doing_cron() ? 30 : 15; + $query_args['timeout'] = Settings::is_doing_cron() ? 30 : 15; /** * Filters query parameters appended to the Sync request URL sent to WordPress.com. @@ -178,9 +171,9 @@ static function send_data( $data, $codec_name, $sent_timestamp, $queue_id, $chec */ $query_args = apply_filters( 'jetpack_sync_send_data_query_args', $query_args ); - $url = add_query_arg( $query_args, Jetpack::xmlrpc_api_url() ); + $url = add_query_arg( $query_args, \Jetpack::xmlrpc_api_url() ); - $rpc = new Jetpack_IXR_Client( + $rpc = new \Jetpack_IXR_Client( array( 'url' => $url, 'user_id' => JETPACK_MASTER_USER, @@ -206,13 +199,13 @@ static function send_data( $data, $codec_name, $sent_timestamp, $queue_id, $chec ); if ( in_array( $error_code, $allowed_idc_error_codes ) ) { - Jetpack_Options::update_option( + \Jetpack_Options::update_option( 'sync_error_idc', - Jetpack::get_sync_error_idc_option( $response ) + \Jetpack::get_sync_error_idc_option( $response ) ); } - return new WP_Error( + return new \WP_Error( 'sync_error_idc', esc_html__( 'Sync has been blocked from WordPress.com because it would cause an identity crisis', 'jetpack' ) ); @@ -246,7 +239,7 @@ static function do_full_sync( $modules = null ) { return false; } - $full_sync_module = Jetpack_Sync_Modules::get_module( 'full-sync' ); + $full_sync_module = Modules::get_module( 'full-sync' ); if ( ! $full_sync_module ) { return false; @@ -294,7 +287,7 @@ static function do_cron_sync_by_type( $type ) { self::initialize_sender(); - $time_limit = Jetpack_Sync_Settings::get_setting( 'cron_sync_time_limit' ); + $time_limit = Settings::get_setting( 'cron_sync_time_limit' ); $start_time = time(); do { @@ -314,28 +307,25 @@ static function do_cron_sync_by_type( $type ) { } static function initialize_listener() { - require_once dirname( __FILE__ ) . '/class.jetpack-sync-listener.php'; - self::$listener = Jetpack_Sync_Listener::get_instance(); + self::$listener = Listener::get_instance(); } static function initialize_sender() { - require_once dirname( __FILE__ ) . '/class.jetpack-sync-sender.php'; - self::$sender = Jetpack_Sync_Sender::get_instance(); + self::$sender = Sender::get_instance(); // bind the sending process add_filter( 'jetpack_sync_send_data', array( __CLASS__, 'send_data' ), 10, 6 ); } static function initialize_woocommerce() { - if ( false === class_exists( 'WooCommerce' ) ) { + if ( false === class_exists( '\\WooCommerce' ) ) { return; } - add_filter( 'jetpack_sync_modules', array( 'Jetpack_Sync_Actions', 'add_woocommerce_sync_module' ) ); + add_filter( 'jetpack_sync_modules', array( 'Actions', 'add_woocommerce_sync_module' ) ); } static function add_woocommerce_sync_module( $sync_modules ) { - require_once dirname( __FILE__ ) . '/class.jetpack-sync-module-woocommerce.php'; - $sync_modules[] = 'Jetpack_Sync_Module_WooCommerce'; + $sync_modules[] = 'Module_WooCommerce'; return $sync_modules; } @@ -343,12 +333,11 @@ static function initialize_wp_super_cache() { if ( false === function_exists( 'wp_cache_is_enabled' ) ) { return; } - add_filter( 'jetpack_sync_modules', array( 'Jetpack_Sync_Actions', 'add_wp_super_cache_sync_module' ) ); + add_filter( 'jetpack_sync_modules', array( 'Actions', 'add_wp_super_cache_sync_module' ) ); } static function add_wp_super_cache_sync_module( $sync_modules ) { - require_once dirname( __FILE__ ) . '/class.jetpack-sync-module-wp-super-cache.php'; - $sync_modules[] = 'Jetpack_Sync_Module_WP_Super_Cache'; + $sync_modules[] = 'Module_WP_Super_Cache'; return $sync_modules; } @@ -445,11 +434,10 @@ static function cleanup_on_upgrade( $new_version = null, $old_version = null ) { $is_new_sync_upgrade = version_compare( $old_version, '4.2', '>=' ); if ( ! empty( $old_version ) && $is_new_sync_upgrade && version_compare( $old_version, '4.5', '<' ) ) { - require_once dirname( __FILE__ ) . '/class.jetpack-sync-settings.php'; self::clear_sync_cron_jobs(); - Jetpack_Sync_Settings::update_settings( + Settings::update_settings( array( - 'render_filtered_content' => Jetpack_Sync_Defaults::$default_render_filtered_content, + 'render_filtered_content' => Defaults::$default_render_filtered_content, ) ); } @@ -464,7 +452,7 @@ static function cleanup_on_upgrade( $new_version = null, $old_version = null ) { static function get_sync_status( $fields = null ) { self::initialize_sender(); - $sync_module = Jetpack_Sync_Modules::get_module( 'full-sync' ); + $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() ); @@ -473,8 +461,7 @@ static function get_sync_status( $fields = null ) { $checksums = array(); if ( ! empty( $fields ) ) { - require_once JETPACK__PLUGIN_DIR . 'sync/class.jetpack-sync-wp-replicastore.php'; - $store = new Jetpack_Sync_WP_Replicastore(); + $store = new WP_Replicastore(); $fields_params = array_map( 'trim', explode( ',', $fields ) ); if ( in_array( 'posts_checksum', $fields_params, true ) ) { @@ -511,19 +498,19 @@ static function get_sync_status( $fields = null ) { } // Check for WooCommerce support -add_action( 'plugins_loaded', array( 'Jetpack_Sync_Actions', 'initialize_woocommerce' ), 5 ); +add_action( 'plugins_loaded', array( 'Actions', 'initialize_woocommerce' ), 5 ); // Check for WP Super Cache -add_action( 'plugins_loaded', array( 'Jetpack_Sync_Actions', 'initialize_wp_super_cache' ), 5 ); +add_action( 'plugins_loaded', array( 'Actions', 'initialize_wp_super_cache' ), 5 ); /* * 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( 'Jetpack_Sync_Actions', 'init' ), 90 ); +add_action( 'plugins_loaded', array( '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( 'Jetpack_Sync_Actions', 'cleanup_on_upgrade' ), 10, 2 ); -add_action( 'jetpack_user_authorized', array( 'Jetpack_Sync_Actions', 'do_initial_sync' ), 10, 0 ); +add_action( 'updating_jetpack_version', array( 'Actions', 'cleanup_on_upgrade' ), 10, 2 ); +add_action( 'jetpack_user_authorized', array( 'Actions', 'do_initial_sync' ), 10, 0 ); diff --git a/sync/interface.jetpack-sync-codec.php b/packages/sync/src/Codec.php similarity index 86% rename from sync/interface.jetpack-sync-codec.php rename to packages/sync/src/Codec.php index 1405d90c63b7..d0637989041c 100644 --- a/sync/interface.jetpack-sync-codec.php +++ b/packages/sync/src/Codec.php @@ -1,10 +1,12 @@ 'wp_max_upload_size', - 'is_main_network' => array( 'Jetpack', 'is_multi_network' ), - 'is_multi_site' => 'is_multisite', - 'main_network_site' => array( 'Jetpack_Sync_Functions', 'main_network_site_url' ), - 'site_url' => array( 'Jetpack_Sync_Functions', 'site_url' ), - 'home_url' => array( 'Jetpack_Sync_Functions', 'home_url' ), - 'single_user_site' => array( 'Jetpack', 'is_single_user_site' ), - 'updates' => array( 'Jetpack', 'get_updates' ), - 'has_file_system_write_access' => array( 'Jetpack_Sync_Functions', 'file_system_write_access' ), - 'is_version_controlled' => array( 'Jetpack_Sync_Functions', 'is_version_controlled' ), - 'taxonomies' => array( 'Jetpack_Sync_Functions', 'get_taxonomies' ), - 'post_types' => array( 'Jetpack_Sync_Functions', 'get_post_types' ), - 'post_type_features' => array( 'Jetpack_Sync_Functions', 'get_post_type_features' ), - 'shortcodes' => array( 'Jetpack_Sync_Functions', 'get_shortcodes' ), - 'rest_api_allowed_post_types' => array( 'Jetpack_Sync_Functions', 'rest_api_allowed_post_types' ), - 'rest_api_allowed_public_metadata' => array( '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( 'Jetpack_Sync_Functions', 'wp_version' ), - 'get_plugins' => array( 'Jetpack_Sync_Functions', 'get_plugins' ), - 'get_plugins_action_links' => array( 'Jetpack_Sync_functions', 'get_plugins_action_links' ), - 'active_modules' => array( 'Jetpack', 'get_active_modules' ), - 'hosting_provider' => array( 'Jetpack_Sync_Functions', 'get_hosting_provider' ), - 'locale' => 'get_locale', - 'site_icon_url' => array( 'Jetpack_Sync_Functions', 'site_icon_url' ), - 'roles' => array( 'Jetpack_Sync_Functions', 'roles' ), - 'timezone' => array( 'Jetpack_Sync_Functions', 'get_timezone' ), - 'available_jetpack_blocks' => array( 'Jetpack_Gutenberg', 'get_availability' ), // Includes both Gutenberg blocks *and* plugins - 'paused_themes' => array( 'Jetpack_Sync_Functions', 'get_paused_themes' ), - 'paused_plugins' => array( 'Jetpack_Sync_Functions', 'get_paused_plugins' ), + 'wp_max_upload_size' => '\\wp_max_upload_size', + 'is_main_network' => array( '\\Jetpack', 'is_multi_network' ), + 'is_multi_site' => '\\is_multisite', + 'main_network_site' => array( __NAMESPACE__ . '\\Functions', 'main_network_site_url' ), + 'site_url' => array( __NAMESPACE__ . '\\Functions', 'site_url' ), + 'home_url' => array( __NAMESPACE__ . '\\Functions', 'home_url' ), + 'single_user_site' => array( '\\Jetpack', 'is_single_user_site' ), + 'updates' => array( '\\Jetpack', 'get_updates' ), + 'has_file_system_write_access' => array( __NAMESPACE__ . '\\Functions', 'file_system_write_access' ), + 'is_version_controlled' => array( __NAMESPACE__ . '\\Functions', 'is_version_controlled' ), + 'taxonomies' => array( __NAMESPACE__ . '\\Functions', 'get_taxonomies' ), + 'post_types' => array( __NAMESPACE__ . '\\Functions', 'get_post_types' ), + 'post_type_features' => array( __NAMESPACE__ . '\\Functions', 'get_post_type_features' ), + 'shortcodes' => array( __NAMESPACE__ . '\\Functions', 'get_shortcodes' ), + 'rest_api_allowed_post_types' => array( __NAMESPACE__ . '\\Functions', 'rest_api_allowed_post_types' ), + 'rest_api_allowed_public_metadata' => array( __NAMESPACE__ . '\\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( __NAMESPACE__ . '\\Functions', 'wp_version' ), + 'get_plugins' => array( __NAMESPACE__ . '\\Functions', 'get_plugins' ), + 'get_plugins_action_links' => array( __NAMESPACE__ . '\\Functions', 'get_plugins_action_links' ), + 'active_modules' => array( '\\Jetpack', 'get_active_modules' ), + 'hosting_provider' => array( __NAMESPACE__ . '\\Functions', 'get_hosting_provider' ), + 'locale' => '\\get_locale', + 'site_icon_url' => array( __NAMESPACE__ . '\\Functions', 'site_icon_url' ), + 'roles' => array( __NAMESPACE__ . '\\Functions', 'roles' ), + 'timezone' => array( __NAMESPACE__ . '\\Functions', 'get_timezone' ), + 'available_jetpack_blocks' => array( '\\Jetpack_Gutenberg', 'get_availability' ), // Includes both Gutenberg blocks *and* plugins + 'paused_themes' => array( __NAMESPACE__ . '\\Functions', 'get_paused_themes' ), + 'paused_plugins' => array( __NAMESPACE__ . '\\Functions', 'get_paused_plugins' ), ); @@ -352,12 +355,12 @@ public static function get_callable_whitelist() { ); static $default_multisite_callable_whitelist = array( - 'network_name' => array( 'Jetpack', 'network_name' ), - 'network_allow_new_registrations' => array( 'Jetpack', 'network_allow_new_registrations' ), - 'network_add_new_users' => array( 'Jetpack', 'network_add_new_users' ), - 'network_site_upload_space' => array( 'Jetpack', 'network_site_upload_space' ), - 'network_upload_file_types' => array( 'Jetpack', 'network_upload_file_types' ), - 'network_enable_administration_menus' => array( 'Jetpack', 'network_enable_administration_menus' ), + 'network_name' => array( '\\Jetpack', 'network_name' ), + 'network_allow_new_registrations' => array( '\\Jetpack', 'network_allow_new_registrations' ), + 'network_add_new_users' => array( '\\Jetpack', 'network_add_new_users' ), + 'network_site_upload_space' => array( '\\Jetpack', 'network_site_upload_space' ), + 'network_upload_file_types' => array( '\\Jetpack', 'network_upload_file_types' ), + 'network_enable_administration_menus' => array( '\\Jetpack', 'network_enable_administration_menus' ), ); public static function get_multisite_callable_whitelist() { @@ -562,7 +565,7 @@ static function get_max_sync_execution_time() { static function get_default_setting( $setting ) { $default_name = "default_$setting"; // e.g. default_dequeue_max_bytes - return Jetpack_Sync_Defaults::$$default_name; + return self::$$default_name; } static $default_network_options_whitelist = array( diff --git a/sync/class.jetpack-sync-functions.php b/packages/sync/src/Functions.php similarity index 94% rename from sync/class.jetpack-sync-functions.php rename to packages/sync/src/Functions.php index efae4bf89a4c..0ebb42d0c41f 100644 --- a/sync/class.jetpack-sync-functions.php +++ b/packages/sync/src/Functions.php @@ -1,10 +1,12 @@ $default_value ) { + foreach ( Defaults::$default_post_type_attributes as $attribute_key => $default_value ) { if ( isset( $post_type->{ $attribute_key } ) ) { $sanitized_post_type[ $attribute_key ] = $post_type->{ $attribute_key }; } @@ -91,7 +93,7 @@ public static function sanitize_post_type( $post_type ) { public static function expand_synced_post_type( $sanitized_post_type, $post_type ) { $post_type = sanitize_key( $post_type ); - $post_type_object = new WP_Post_Type( $post_type, $sanitized_post_type ); + $post_type_object = new \WP_Post_Type( $post_type, $sanitized_post_type ); $post_type_object->add_supports(); $post_type_object->add_rewrite_rules(); $post_type_object->add_hooks(); @@ -141,10 +143,10 @@ public static function rest_api_allowed_public_metadata() { **/ public static function is_version_controlled() { - if ( ! class_exists( 'WP_Automatic_Updater' ) ) { + if ( ! class_exists( '\\WP_Automatic_Updater' ) ) { require_once ABSPATH . 'wp-admin/includes/class-wp-upgrader.php'; } - $updater = new WP_Automatic_Updater(); + $updater = new \WP_Automatic_Updater(); return (bool) strval( $updater->is_vcs_checkout( $context = ABSPATH ) ); } @@ -193,8 +195,8 @@ public static function get_raw_or_filtered_url( $url_type ) { : 'site_url'; if ( - ! Jetpack_Constants::is_defined( 'JETPACK_SYNC_USE_RAW_URL' ) || - Jetpack_Constants::get_constant( 'JETPACK_SYNC_USE_RAW_URL' ) + ! \Jetpack_Constants::is_defined( 'JETPACK_SYNC_USE_RAW_URL' ) || + \Jetpack_Constants::get_constant( 'JETPACK_SYNC_USE_RAW_URL' ) ) { $scheme = is_ssl() ? 'https' : 'http'; $url = self::get_raw_url( $url_type ); @@ -269,12 +271,12 @@ public static function get_raw_url( $option_name ) { // Since we disregard the constant for multisites in ms-default-filters.php, // let's also use the db value if this is a multisite. - if ( ! is_multisite() && Jetpack_Constants::is_defined( $constant ) ) { - $value = Jetpack_Constants::get_constant( $constant ); + if ( ! is_multisite() && \Jetpack_Constants::is_defined( $constant ) ) { + $value = \Jetpack_Constants::get_constant( $constant ); } else { // Let's get the option from the database so that we can bypass filters. This will help // ensure that we get more uniform values. - $value = Jetpack_Options::get_raw_option( $option_name ); + $value = \Jetpack_Options::get_raw_option( $option_name ); } return $value; @@ -326,7 +328,7 @@ public static function get_plugins() { */ public static function get_plugins_action_links( $plugin_file_singular = null ) { // Some sites may have DOM disabled in PHP fail early - if ( ! class_exists( 'DOMDocument' ) ) { + if ( ! class_exists( '\\DOMDocument' ) ) { return array(); } $plugins_action_links = get_option( 'jetpack_plugin_api_action_links', array() ); diff --git a/sync/class.jetpack-sync-json-deflate-array-codec.php b/packages/sync/src/JSON_Deflate_Array_Codec.php similarity index 88% rename from sync/class.jetpack-sync-json-deflate-array-codec.php rename to packages/sync/src/JSON_Deflate_Array_Codec.php index 04d3dd7df181..7cced0022e83 100644 --- a/sync/class.jetpack-sync-json-deflate-array-codec.php +++ b/packages/sync/src/JSON_Deflate_Array_Codec.php @@ -1,12 +1,12 @@ init_listeners( $handler ); $module->init_full_sync_listeners( $full_sync_handler ); } @@ -86,7 +83,7 @@ function force_recheck_queue_limit() { // prevent adding items to the queue if it hasn't sent an item for 15 mins // AND the queue is over 1000 items long (by default) function can_add_to_queue( $queue ) { - if ( ! Jetpack_Sync_Settings::is_sync_enabled() ) { + if ( ! Settings::is_sync_enabled() ) { return false; } @@ -142,12 +139,11 @@ function bulk_enqueue_full_sync_actions( $action_name, $args_array ) { $data_to_enqueue = array(); $user_id = get_current_user_id(); $currtime = microtime( true ); - $is_importing = Jetpack_Sync_Settings::is_importing(); + $is_importing = Settings::is_importing(); foreach ( $args_array as $args ) { $previous_end = isset( $args['previous_end'] ) ? $args['previous_end'] : null; - $args = isset( $args['ids'] ) ? $args['ids'] : $args; - + $args = isset( $args['ids'] ) ? $args['ids'] : $args; /** * Modify or reject the data within an action before it is enqueued locally. @@ -158,7 +154,7 @@ function bulk_enqueue_full_sync_actions( $action_name, $args_array ) { * * @param array The action parameters */ - $args = apply_filters( "jetpack_sync_before_enqueue_$action_name", $args ); + $args = apply_filters( "jetpack_sync_before_enqueue_$action_name", $args ); $action_data = array( $args ); if ( ! is_null( $previous_end ) ) { $action_data[] = $previous_end; @@ -182,7 +178,7 @@ function bulk_enqueue_full_sync_actions( $action_name, $args_array ) { function enqueue_action( $current_filter, $args, $queue ) { // don't enqueue an action during the outbound http request - this prevents recursion - if ( Jetpack_Sync_Settings::is_sending() ) { + if ( Settings::is_sending() ) { return; } @@ -238,7 +234,7 @@ function enqueue_action( $current_filter, $args, $queue ) { $args, get_current_user_id(), microtime( true ), - Jetpack_Sync_Settings::is_importing(), + Settings::is_importing(), $this->get_actor( $current_filter, $args ), ) ); @@ -249,16 +245,16 @@ function enqueue_action( $current_filter, $args, $queue ) { $args, get_current_user_id(), microtime( true ), - Jetpack_Sync_Settings::is_importing(), + Settings::is_importing(), ) ); } // since we've added some items, let's try to load the sender so we can send them as quickly as possible - if ( ! Jetpack_Sync_Actions::$sender ) { + if ( ! Actions::$sender ) { add_filter( 'jetpack_sync_sender_should_load', '__return_true' ); if ( did_action( 'init' ) ) { - Jetpack_Sync_Actions::add_sender_shutdown(); + Actions::add_sender_shutdown(); } } } @@ -270,7 +266,7 @@ function get_actor( $current_filter, $args ) { $user = wp_get_current_user(); } - $translated_role = Jetpack::translate_user_to_role( $user ); + $translated_role = \Jetpack::translate_user_to_role( $user ); $actor = array( 'wpcom_user_id' => null, @@ -314,10 +310,10 @@ function should_send_user_data_with_actor( $current_filter ) { } function set_defaults() { - $this->sync_queue = new Jetpack_Sync_Queue( 'sync' ); - $this->full_sync_queue = new Jetpack_Sync_Queue( 'full_sync' ); - $this->set_queue_size_limit( Jetpack_Sync_Settings::get_setting( 'max_queue_size' ) ); - $this->set_queue_lag_limit( Jetpack_Sync_Settings::get_setting( 'max_queue_lag' ) ); + $this->sync_queue = new Queue( 'sync' ); + $this->full_sync_queue = new Queue( 'full_sync' ); + $this->set_queue_size_limit( Settings::get_setting( 'max_queue_size' ) ); + $this->set_queue_lag_limit( Settings::get_setting( 'max_queue_lag' ) ); } function get_request_url() { diff --git a/sync/class.jetpack-sync-module.php b/packages/sync/src/Module.php similarity index 97% rename from sync/class.jetpack-sync-module.php rename to packages/sync/src/Module.php index b3fbe8685915..3684082c85e0 100644 --- a/sync/class.jetpack-sync-module.php +++ b/packages/sync/src/Module.php @@ -1,9 +1,11 @@ get_col( "SELECT {$id_field} FROM {$table_name} WHERE {$where_sql} AND {$id_field} < {$previous_interval_end} ORDER BY {$id_field} DESC LIMIT {$items_per_page}" ) ) { diff --git a/sync/class.jetpack-sync-module-attachments.php b/packages/sync/src/Module_Attachments.php similarity index 95% rename from sync/class.jetpack-sync-module-attachments.php rename to packages/sync/src/Module_Attachments.php index f68ba8328a6a..f581c4f73f6a 100644 --- a/sync/class.jetpack-sync-module-attachments.php +++ b/packages/sync/src/Module_Attachments.php @@ -1,6 +1,8 @@ callable_whitelist = array_merge( Jetpack_Sync_Defaults::get_callable_whitelist(), Jetpack_Sync_Defaults::get_multisite_callable_whitelist() ); + $this->callable_whitelist = array_merge( Defaults::get_callable_whitelist(), Defaults::get_multisite_callable_whitelist() ); } else { - $this->callable_whitelist = Jetpack_Sync_Defaults::get_callable_whitelist(); + $this->callable_whitelist = Defaults::get_callable_whitelist(); } } @@ -65,7 +65,7 @@ public function reset_data() { $url_callables = array( 'home_url', 'site_url', 'main_network_site_url' ); foreach ( $url_callables as $callable ) { - delete_option( Jetpack_Sync_Functions::HTTPS_CHECK_OPTION_PREFIX . $callable ); + delete_option( Functions::HTTPS_CHECK_OPTION_PREFIX . $callable ); } } @@ -80,7 +80,7 @@ function get_callable_whitelist() { public function get_all_callables() { // get_all_callables should run as the master user always. $current_user_id = get_current_user_id(); - wp_set_current_user( Jetpack_Options::get_option( 'master_user' ) ); + wp_set_current_user( \Jetpack_Options::get_option( 'master_user' ) ); $callables = array_combine( array_keys( $this->get_callable_whitelist() ), array_map( array( $this, 'get_callable' ), array_values( $this->get_callable_whitelist() ) ) @@ -127,7 +127,7 @@ public function unlock_plugin_action_link_and_callables() { public function set_plugin_action_links() { if ( - ! class_exists( 'DOMDocument' ) || + ! class_exists( '\\DOMDocument' ) || ! function_exists( 'libxml_use_internal_errors' ) || ! function_exists( 'mb_convert_encoding' ) ) { @@ -142,7 +142,7 @@ public function set_plugin_action_links() { if ( ! empty( $plugins_lock ) && ( isset( $current_screeen->id ) && $current_screeen->id !== 'plugins' ) ) { return; } - $plugins = array_keys( Jetpack_Sync_Functions::get_plugins() ); + $plugins = array_keys( Functions::get_plugins() ); foreach ( $plugins as $plugin_file ) { /** * Plugins often like to unset things but things break if they are not able to. @@ -203,7 +203,7 @@ public function should_send_callable( $callable_checksums, $name, $checksum ) { 'home_url', 'site_url', ); - if ( in_array( $name, $idc_override_callables ) && Jetpack_Options::get_option( 'migrate_for_idc' ) ) { + if ( in_array( $name, $idc_override_callables ) && \Jetpack_Options::get_option( 'migrate_for_idc' ) ) { return true; } @@ -212,7 +212,7 @@ public function should_send_callable( $callable_checksums, $name, $checksum ) { public function maybe_sync_callables() { if ( ! apply_filters( 'jetpack_check_and_send_callables', false ) ) { - if ( ! is_admin() || Jetpack_Sync_Settings::is_doing_cron() ) { + if ( ! is_admin() || Settings::is_doing_cron() ) { return; } @@ -221,7 +221,7 @@ public function maybe_sync_callables() { } } - set_transient( self::CALLABLES_AWAIT_TRANSIENT_NAME, microtime( true ), Jetpack_Sync_Defaults::$default_sync_callables_wait_time ); + set_transient( self::CALLABLES_AWAIT_TRANSIENT_NAME, microtime( true ), Defaults::$default_sync_callables_wait_time ); $callables = $this->get_all_callables(); @@ -229,8 +229,8 @@ public function maybe_sync_callables() { return; } - $callable_checksums = (array) Jetpack_Options::get_raw_option( self::CALLABLES_CHECKSUM_OPTION_NAME, array() ); - $has_changed = false; + $callable_checksums = (array) \Jetpack_Options::get_raw_option( self::CALLABLES_CHECKSUM_OPTION_NAME, array() ); + $has_changed = false; // only send the callables that have changed foreach ( $callables as $name => $value ) { $checksum = $this->get_check_sum( $value ); @@ -246,13 +246,13 @@ public function maybe_sync_callables() { */ do_action( 'jetpack_sync_callable', $name, $value ); $callable_checksums[ $name ] = $checksum; - $has_changed = true; + $has_changed = true; } else { $callable_checksums[ $name ] = $checksum; } } if ( $has_changed ) { - Jetpack_Options::update_raw_option( self::CALLABLES_CHECKSUM_OPTION_NAME, $callable_checksums ); + \Jetpack_Options::update_raw_option( self::CALLABLES_CHECKSUM_OPTION_NAME, $callable_checksums ); } } @@ -264,7 +264,7 @@ public function expand_callables( $args ) { foreach ( $callables as $name => $value ) { $callables_checksums[ $name ] = $this->get_check_sum( $value ); } - Jetpack_Options::update_raw_option( self::CALLABLES_CHECKSUM_OPTION_NAME, $callables_checksums ); + \Jetpack_Options::update_raw_option( self::CALLABLES_CHECKSUM_OPTION_NAME, $callables_checksums ); return $callables; } diff --git a/sync/class.jetpack-sync-module-comments.php b/packages/sync/src/Module_Comments.php similarity index 95% rename from sync/class.jetpack-sync-module-comments.php rename to packages/sync/src/Module_Comments.php index 0a0ee16f1c59..64bb3c6e0027 100644 --- a/sync/class.jetpack-sync-module-comments.php +++ b/packages/sync/src/Module_Comments.php @@ -1,6 +1,8 @@ get_metadata( $comment_ids, 'comment', Jetpack_Sync_Settings::get_setting( 'comment_meta_whitelist' ) ), + $this->get_metadata( $comment_ids, 'comment', Settings::get_setting( 'comment_meta_whitelist' ) ), $previous_interval_end, ); } diff --git a/sync/class.jetpack-sync-module-constants.php b/packages/sync/src/Module_Constants.php similarity index 92% rename from sync/class.jetpack-sync-module-constants.php rename to packages/sync/src/Module_Constants.php index f3af31951ce2..f73248682fbc 100644 --- a/sync/class.jetpack-sync-module-constants.php +++ b/packages/sync/src/Module_Constants.php @@ -1,8 +1,8 @@ get_all_constants(); if ( empty( $constants ) ) { diff --git a/sync/class.jetpack-sync-module-full-sync.php b/packages/sync/src/Module_Full_Sync.php similarity index 83% rename from sync/class.jetpack-sync-module-full-sync.php rename to packages/sync/src/Module_Full_Sync.php index c50b6df74c0e..ab241da892d7 100644 --- a/sync/class.jetpack-sync-module-full-sync.php +++ b/packages/sync/src/Module_Full_Sync.php @@ -1,18 +1,20 @@ name() ] = true; } } // set default configuration, calculate totals, and save configuration if totals > 0 - foreach ( Jetpack_Sync_Modules::get_modules() as $module ) { + foreach ( Modules::get_modules() as $module ) { $module_name = $module->name(); $module_config = isset( $module_configs[ $module_name ] ) ? $module_configs[ $module_name ] : false; @@ -88,7 +90,7 @@ function start( $module_configs = null ) { 0, // queued false, // current state ); - } else if ( $include_empty && $total_items === 0 ) { + } elseif ( $include_empty && $total_items === 0 ) { $empty[ $module_name ] = true; } } @@ -122,15 +124,15 @@ function continue_enqueuing( $configs = null, $enqueue_status = null ) { } // if full sync queue is full, don't enqueue more items - $max_queue_size_full_sync = Jetpack_Sync_Settings::get_setting( 'max_queue_size_full_sync' ); - $full_sync_queue = new Jetpack_Sync_Queue( 'full_sync' ); + $max_queue_size_full_sync = Settings::get_setting( 'max_queue_size_full_sync' ); + $full_sync_queue = new Queue( 'full_sync' ); $available_queue_slots = $max_queue_size_full_sync - $full_sync_queue->size(); if ( $available_queue_slots <= 0 ) { return; } else { - $remaining_items_to_enqueue = min( Jetpack_Sync_Settings::get_setting( 'max_enqueue_full_sync' ), $available_queue_slots ); + $remaining_items_to_enqueue = min( Settings::get_setting( 'max_enqueue_full_sync' ), $available_queue_slots ); } if ( ! $configs ) { @@ -141,7 +143,7 @@ function continue_enqueuing( $configs = null, $enqueue_status = null ) { $enqueue_status = $this->get_enqueue_status(); } - foreach ( Jetpack_Sync_Modules::get_modules() as $module ) { + foreach ( Modules::get_modules() as $module ) { $module_name = $module->name(); // skip module if not configured for this sync or module is done @@ -202,13 +204,13 @@ function get_range( $type ) { case 'posts': $table = $wpdb->posts; $id = 'ID'; - $where_sql = Jetpack_Sync_Settings::get_blacklisted_post_types_sql(); + $where_sql = Settings::get_blacklisted_post_types_sql(); break; case 'comments': $table = $wpdb->comments; $id = 'comment_ID'; - $where_sql = Jetpack_Sync_Settings::get_comments_filter_sql(); + $where_sql = Settings::get_comments_filter_sql(); break; } $results = $wpdb->get_results( "SELECT MAX({$id}) as max, MIN({$id}) as min, COUNT({$id}) as count FROM {$table} WHERE {$where_sql}" ); @@ -247,7 +249,7 @@ function update_sent_progress_action( $actions ) { $this->update_status_option( 'send_started', time() ); } - foreach ( Jetpack_Sync_Modules::get_modules() as $module ) { + foreach ( Modules::get_modules() as $module ) { $module_actions = $module->get_full_sync_actions(); $status_option_name = "{$module->name()}_sent"; $total_option_name = "{$status_option_name}_total"; @@ -349,7 +351,7 @@ public function get_status() { $enqueue_status = $this->get_enqueue_status(); - foreach ( Jetpack_Sync_Modules::get_modules() as $module ) { + foreach ( Modules::get_modules() as $module ) { $name = $module->name(); if ( ! isset( $enqueue_status[ $name ] ) ) { @@ -381,60 +383,59 @@ public function get_status() { public function clear_status() { $prefix = self::STATUS_OPTION_PREFIX; - Jetpack_Options::delete_raw_option( "{$prefix}_started" ); - Jetpack_Options::delete_raw_option( "{$prefix}_params" ); - Jetpack_Options::delete_raw_option( "{$prefix}_queue_finished" ); - Jetpack_Options::delete_raw_option( "{$prefix}_send_started" ); - Jetpack_Options::delete_raw_option( "{$prefix}_finished" ); + \Jetpack_Options::delete_raw_option( "{$prefix}_started" ); + \Jetpack_Options::delete_raw_option( "{$prefix}_params" ); + \Jetpack_Options::delete_raw_option( "{$prefix}_queue_finished" ); + \Jetpack_Options::delete_raw_option( "{$prefix}_send_started" ); + \Jetpack_Options::delete_raw_option( "{$prefix}_finished" ); $this->delete_enqueue_status(); - foreach ( Jetpack_Sync_Modules::get_modules() as $module ) { - Jetpack_Options::delete_raw_option( "{$prefix}_{$module->name()}_sent" ); - Jetpack_Options::delete_raw_option( "{$prefix}_{$module->name()}_sent_total" ); + foreach ( Modules::get_modules() as $module ) { + \Jetpack_Options::delete_raw_option( "{$prefix}_{$module->name()}_sent" ); + \Jetpack_Options::delete_raw_option( "{$prefix}_{$module->name()}_sent_total" ); } } public function reset_data() { $this->clear_status(); $this->delete_config(); - require_once dirname( __FILE__ ) . '/class.jetpack-sync-listener.php'; - $listener = Jetpack_Sync_Listener::get_instance(); + $listener = Listener::get_instance(); $listener->get_full_sync_queue()->reset(); } private function get_status_option( $name, $default = null ) { - $value = Jetpack_Options::get_raw_option( self::STATUS_OPTION_PREFIX . "_$name", $default ); + $value = \Jetpack_Options::get_raw_option( self::STATUS_OPTION_PREFIX . "_$name", $default ); return is_numeric( $value ) ? intval( $value ) : $value; } private function update_status_option( $name, $value, $autoload = false ) { - Jetpack_Options::update_raw_option( self::STATUS_OPTION_PREFIX . "_$name", $value, $autoload ); + \Jetpack_Options::update_raw_option( self::STATUS_OPTION_PREFIX . "_$name", $value, $autoload ); } private function set_enqueue_status( $new_status ) { - Jetpack_Options::update_raw_option( 'jetpack_sync_full_enqueue_status', $new_status ); + \Jetpack_Options::update_raw_option( 'jetpack_sync_full_enqueue_status', $new_status ); } private function delete_enqueue_status() { - return Jetpack_Options::delete_raw_option( 'jetpack_sync_full_enqueue_status' ); + return \Jetpack_Options::delete_raw_option( 'jetpack_sync_full_enqueue_status' ); } private function get_enqueue_status() { - return Jetpack_Options::get_raw_option( 'jetpack_sync_full_enqueue_status' ); + return \Jetpack_Options::get_raw_option( 'jetpack_sync_full_enqueue_status' ); } private function set_config( $config ) { - Jetpack_Options::update_raw_option( 'jetpack_sync_full_config', $config ); + \Jetpack_Options::update_raw_option( 'jetpack_sync_full_config', $config ); } private function delete_config() { - return Jetpack_Options::delete_raw_option( 'jetpack_sync_full_config' ); + return \Jetpack_Options::delete_raw_option( 'jetpack_sync_full_config' ); } private function get_config() { - return Jetpack_Options::get_raw_option( 'jetpack_sync_full_config' ); + return \Jetpack_Options::get_raw_option( 'jetpack_sync_full_config' ); } private function write_option( $name, $value ) { diff --git a/sync/class.jetpack-sync-module-import.php b/packages/sync/src/Module_Import.php similarity index 95% rename from sync/class.jetpack-sync-module-import.php rename to packages/sync/src/Module_Import.php index 4b5dd83d36ed..ca97a26b57f4 100644 --- a/sync/class.jetpack-sync-module-import.php +++ b/packages/sync/src/Module_Import.php @@ -1,8 +1,8 @@ network_options_whitelist = Jetpack_Sync_Defaults::$default_network_options_whitelist; + $this->network_options_whitelist = Defaults::$default_network_options_whitelist; } function enqueue_full_sync_actions( $config, $max_items_to_enqueue, $state ) { diff --git a/sync/class.jetpack-sync-module-options.php b/packages/sync/src/Module_Options.php similarity index 93% rename from sync/class.jetpack-sync-module-options.php rename to packages/sync/src/Module_Options.php index 287e73b9fe53..d924e8cb4db0 100644 --- a/sync/class.jetpack-sync-module-options.php +++ b/packages/sync/src/Module_Options.php @@ -1,6 +1,8 @@ options_whitelist = Jetpack_Sync_Defaults::get_options_whitelist(); + $this->options_whitelist = Defaults::get_options_whitelist(); } function set_options_whitelist( $options ) { @@ -104,7 +106,7 @@ function get_options_whitelist() { } function update_options_contentless() { - $this->options_contentless = Jetpack_Sync_Defaults::get_options_contentless(); + $this->options_contentless = Defaults::get_options_contentless(); } function get_options_contentless() { @@ -157,9 +159,9 @@ function jetpack_sync_core_icon() { // If there's a core icon, maybe update the option. If not, fall back to Jetpack's. if ( ! empty( $url ) && $url !== jetpack_site_icon_url() ) { // This is the option that is synced with dotcom - Jetpack_Options::update_option( 'site_icon_url', $url ); + \Jetpack_Options::update_option( 'site_icon_url', $url ); } elseif ( empty( $url ) ) { - Jetpack_Options::delete_option( 'site_icon_url' ); + \Jetpack_Options::delete_option( 'site_icon_url' ); } } diff --git a/sync/class.jetpack-sync-module-plugins.php b/packages/sync/src/Module_Plugins.php similarity index 98% rename from sync/class.jetpack-sync-module-plugins.php rename to packages/sync/src/Module_Plugins.php index 876526abb6a5..e5bcbc8fbbc8 100644 --- a/sync/class.jetpack-sync-module-plugins.php +++ b/packages/sync/src/Module_Plugins.php @@ -1,6 +1,8 @@ Jetpack_Constants::is_true( 'JETPACK_PLUGIN_AUTOUPDATE' ), + 'is_autoupdate' => \Jetpack_Constants::is_true( 'JETPACK_PLUGIN_AUTOUPDATE' ), ); $errors = $this->get_errors( $upgrader->skin ); if ( $errors ) { diff --git a/sync/class.jetpack-sync-module-posts.php b/packages/sync/src/Module_Posts.php similarity index 93% rename from sync/class.jetpack-sync-module-posts.php rename to packages/sync/src/Module_Posts.php index 0384b64ffe1d..d4ae51304e4c 100644 --- a/sync/class.jetpack-sync-module-posts.php +++ b/packages/sync/src/Module_Posts.php @@ -1,8 +1,8 @@ post_type, Jetpack_Sync_Settings::get_setting( 'post_types_blacklist' ) ) ) { + if ( in_array( $post->post_type, Settings::get_setting( 'post_types_blacklist' ) ) ) { return false; } @@ -139,13 +139,13 @@ function filter_meta( $args ) { function is_whitelisted_post_meta( $meta_key ) { // _wpas_skip_ is used by publicize - return in_array( $meta_key, Jetpack_Sync_Settings::get_setting( 'post_meta_whitelist' ) ) || wp_startswith( $meta_key, '_wpas_skip_' ); + return in_array( $meta_key, Settings::get_setting( 'post_meta_whitelist' ) ) || wp_startswith( $meta_key, '_wpas_skip_' ); } function is_post_type_allowed( $post_id ) { $post = get_post( intval( $post_id ) ); if ( $post->post_type ) { - return ! in_array( $post->post_type, Jetpack_Sync_Settings::get_setting( 'post_types_blacklist' ) ); + return ! in_array( $post->post_type, Settings::get_setting( 'post_types_blacklist' ) ); } return false; } @@ -219,7 +219,7 @@ function filter_post_content_and_add_links( $post_object ) { } /** This filter is already documented in core. wp-includes/post-template.php */ - if ( Jetpack_Sync_Settings::get_setting( 'render_filtered_content' ) && $post_type->public ) { + if ( Settings::get_setting( 'render_filtered_content' ) && $post_type->public ) { global $shortcode_tags; /** * Filter prevents some shortcodes from expanding. @@ -318,7 +318,7 @@ public function wp_insert_post( $post_ID, $post = null, $update = null ) { false; $state = array( - 'is_auto_save' => (bool) Jetpack_Constants::get_constant( 'DOING_AUTOSAVE' ), + 'is_auto_save' => (bool) \Jetpack_Constants::get_constant( 'DOING_AUTOSAVE' ), 'previous_status' => $previous_status, 'just_published' => $just_published, 'is_gutenberg_meta_box_update' => $this->is_gutenberg_meta_box_update(), @@ -423,9 +423,9 @@ public function expand_post_ids( $args ) { return array( $posts, - $this->get_metadata( $post_ids, 'post', Jetpack_Sync_Settings::get_setting( 'post_meta_whitelist' ) ), + $this->get_metadata( $post_ids, 'post', Settings::get_setting( 'post_meta_whitelist' ) ), $this->get_term_relationships( $post_ids ), - $previous_interval_end + $previous_interval_end, ); } } diff --git a/sync/class.jetpack-sync-module-protect.php b/packages/sync/src/Module_Protect.php similarity index 67% rename from sync/class.jetpack-sync-module-protect.php rename to packages/sync/src/Module_Protect.php index a8dcd43e83ed..d6d0e73ae100 100644 --- a/sync/class.jetpack-sync-module-protect.php +++ b/packages/sync/src/Module_Protect.php @@ -1,9 +1,11 @@ has_login_ability() && ! Jetpack_Constants::is_true( 'XMLRPC_REQUEST' ) ) { + $protect = \Jetpack_Protect_Module::instance(); + if ( $protect->has_login_ability() && ! \Jetpack_Constants::is_true( 'XMLRPC_REQUEST' ) ) { do_action( 'jetpack_valid_failed_login_attempt', $failed_attempt ); } } diff --git a/sync/class.jetpack-sync-module-stats.php b/packages/sync/src/Module_Stats.php similarity index 82% rename from sync/class.jetpack-sync-module-stats.php rename to packages/sync/src/Module_Stats.php index d23d3e008c81..47331fbc8d2f 100644 --- a/sync/class.jetpack-sync-module-stats.php +++ b/packages/sync/src/Module_Stats.php @@ -1,6 +1,8 @@ taxonomy_whitelist = Jetpack_Sync_Defaults::$default_taxonomy_whitelist; + $this->taxonomy_whitelist = Defaults::$default_taxonomy_whitelist; } public function expand_term_taxonomy_id( $args ) { list( $term_taxonomy_ids, $previous_end ) = $args; - return - array( 'terms' => get_terms( + return array( + 'terms' => get_terms( array( 'hide_empty' => false, 'term_taxonomy_id' => $term_taxonomy_ids, 'orderby' => 'term_taxonomy_id', - 'order' => 'DESC' + 'order' => 'DESC', ) ), - 'previous_end' => $previous_end + 'previous_end' => $previous_end, ); } } diff --git a/sync/class.jetpack-sync-module-themes.php b/packages/sync/src/Module_Themes.php similarity index 98% rename from sync/class.jetpack-sync-module-themes.php rename to packages/sync/src/Module_Themes.php index e8b4185d0b7d..8cecfeca8178 100644 --- a/sync/class.jetpack-sync-module-themes.php +++ b/packages/sync/src/Module_Themes.php @@ -1,6 +1,8 @@ theme_info(); - if ( ! $theme instanceof WP_Theme ) { + if ( ! $theme instanceof \WP_Theme ) { return; } $theme_info = array( @@ -324,7 +326,7 @@ public function check_upgrader( $upgrader, $details ) { foreach ( $details['themes'] as $theme_slug ) { $theme = wp_get_theme( $theme_slug ); - if ( ! $theme instanceof WP_Theme ) { + if ( ! $theme instanceof \WP_Theme ) { continue; } @@ -362,7 +364,7 @@ public function sync_theme_support( $new_name, $new_theme = null, $old_theme = n /** * Fires when the client needs to sync theme support info - * Only sends theme support attributes whitelisted in Jetpack_Sync_Defaults::$default_theme_support_whitelist + * Only sends theme support attributes whitelisted in Defaults::$default_theme_support_whitelist * * @since 4.2.0 * @@ -578,7 +580,7 @@ private function get_theme_support_info( $theme = null ) { if ( $theme === null ) { $theme = wp_get_theme(); - foreach ( Jetpack_Sync_Defaults::$default_theme_support_whitelist as $theme_feature ) { + foreach ( Defaults::$default_theme_support_whitelist as $theme_feature ) { $has_support = current_theme_supports( $theme_feature ); if ( $has_support ) { $theme_support[ $theme_feature ] = $_wp_theme_features[ $theme_feature ]; diff --git a/sync/class.jetpack-sync-module-updates.php b/packages/sync/src/Module_Updates.php similarity index 97% rename from sync/class.jetpack-sync-module-updates.php rename to packages/sync/src/Module_Updates.php index 4da4414fc073..6195ed63f600 100644 --- a/sync/class.jetpack-sync-module-updates.php +++ b/packages/sync/src/Module_Updates.php @@ -1,6 +1,8 @@ ID ); + $password_checker = new \Jetpack_Password_Checker( $user->ID ); $test_results = $password_checker->test( $password, true ); @@ -218,8 +220,8 @@ public function authenticate_handler( $user, $username, $password ) { $this->add_flags( $user->ID, array( - 'warning' => 'The password failed at least one strength test.', - 'failures' => $test_results['test_results']['failed'], + 'warning' => 'The password failed at least one strength test.', + 'failures' => $test_results['test_results']['failed'], ) ); @@ -246,7 +248,7 @@ function user_register_handler( $user_id, $old_user_data = null ) { return; } - if ( Jetpack_Constants::is_true( 'JETPACK_INVITE_ACCEPTED' ) ) { + if ( \Jetpack_Constants::is_true( 'JETPACK_INVITE_ACCEPTED' ) ) { $this->add_flags( $user_id, array( 'invitation_accepted' => true ) ); } /** @@ -267,7 +269,7 @@ function add_user_to_blog_handler( $user_id, $old_user_data = null ) { return; } - if ( Jetpack_Constants::is_true( 'JETPACK_INVITE_ACCEPTED' ) ) { + if ( \Jetpack_Constants::is_true( 'JETPACK_INVITE_ACCEPTED' ) ) { $this->add_flags( $user_id, array( 'invitation_accepted' => true ) ); } /** @@ -432,14 +434,17 @@ public function expand_users( $args ) { list( $user_ids, $previous_end ) = $args; return array( - 'users' => array_map( array( $this, 'sanitize_user_and_expand' ), get_users( - array( - 'include' => $user_ids, - 'orderby' => 'ID', - 'order' => 'DESC' + 'users' => array_map( + array( $this, 'sanitize_user_and_expand' ), + get_users( + array( + 'include' => $user_ids, + 'orderby' => 'ID', + 'order' => 'DESC', + ) ) - ) ), - 'previous_end' => $previous_end + ), + 'previous_end' => $previous_end, ); } diff --git a/sync/class.jetpack-sync-module-wp-super-cache.php b/packages/sync/src/Module_WP_Super_Cache.php similarity index 93% rename from sync/class.jetpack-sync-module-wp-super-cache.php rename to packages/sync/src/Module_WP_Super_Cache.php index 04d6c5dd4240..c2e69454082c 100644 --- a/sync/class.jetpack-sync-module-wp-super-cache.php +++ b/packages/sync/src/Module_WP_Super_Cache.php @@ -1,6 +1,8 @@ array( 'Jetpack_Sync_Module_WP_Super_Cache', 'get_wp_super_cache_globals' ), + 'wp_super_cache_globals' => array( 'Module_WP_Super_Cache', 'get_wp_super_cache_globals' ), ); public function name() { diff --git a/sync/class.jetpack-sync-module-woocommerce.php b/packages/sync/src/Module_WooCommerce.php similarity index 98% rename from sync/class.jetpack-sync-module-woocommerce.php rename to packages/sync/src/Module_WooCommerce.php index 962258a2ffa5..68cb182242a9 100644 --- a/sync/class.jetpack-sync-module-woocommerce.php +++ b/packages/sync/src/Module_WooCommerce.php @@ -1,8 +1,8 @@ set_defaults(); + } + } + + public static function get_module( $module_name ) { + foreach ( self::get_modules() as $module ) { + if ( $module->name() === $module_name ) { + return $module; + } + } + + return false; + } + + static function initialize_modules() { + /** + * Filters the list of class names of sync modules. + * If you add to this list, make sure any classes implement the + * Module interface. + * + * @since 4.2.0 + */ + $modules = apply_filters( 'jetpack_sync_modules', self::$default_sync_modules ); + + $modules = array_map( array( __NAMESPACE__ . '\\Modules', 'load_module' ), $modules ); + + return array_map( array( __NAMESPACE__ . '\\Modules', 'set_module_defaults' ), $modules ); + } + + static function load_module( $module_name ) { + return new $module_name(); + } + + static function set_module_defaults( $module ) { + $module->set_defaults(); + if ( method_exists( $module, 'set_late_default' ) ) { + add_action( 'init', array( $module, 'set_late_default' ), 90 ); + } + return $module; + } + +} diff --git a/sync/class.jetpack-sync-queue.php b/packages/sync/src/Queue.php similarity index 82% rename from sync/class.jetpack-sync-queue.php rename to packages/sync/src/Queue.php index ae40a597f459..9551399b0ed2 100644 --- a/sync/class.jetpack-sync-queue.php +++ b/packages/sync/src/Queue.php @@ -1,29 +1,6 @@ id = $id; - $this->items_with_ids = $items_with_ids; - } - - public function get_items() { - return array_combine( $this->get_item_ids(), $this->get_item_values() ); - } - - public function get_item_values() { - return Jetpack_Sync_Utils::get_item_values( $this->items_with_ids ); - } - - public function get_item_ids() { - return Jetpack_Sync_Utils::get_item_ids( $this->items_with_ids ); - } -} +namespace Automattic\Jetpack\Sync; /** * A persistent queue that can be flushed in increments of N items, @@ -31,7 +8,7 @@ public function get_item_ids() { * closed. This uses raw SQL for two reasons: speed, and not triggering * tons of added_option callbacks. */ -class Jetpack_Sync_Queue { +class Queue { public $id; private $row_iterator; @@ -77,7 +54,7 @@ function add_all( $items ) { $rows_added = $wpdb->query( $query . join( ',', $rows ) ); if ( count( $items ) === $rows_added ) { - return new WP_Error( 'row_count_mismatch', "The number of rows inserted didn't match the size of the input array" ); + return new \WP_Error( 'row_count_mismatch', "The number of rows inserted didn't match the size of the input array" ); } } @@ -85,7 +62,7 @@ function add_all( $items ) { function peek( $count = 1 ) { $items = $this->fetch_items( $count ); if ( $items ) { - return Jetpack_Sync_Utils::get_item_values( $items ); + return Utils::get_item_values( $items ); } return array(); @@ -157,7 +134,7 @@ function has_any_items() { function checkout( $buffer_size ) { if ( $this->get_checkout_id() ) { - return new WP_Error( 'unclosed_buffer', 'There is an unclosed buffer' ); + return new \WP_Error( 'unclosed_buffer', 'There is an unclosed buffer' ); } $buffer_id = uniqid(); @@ -174,7 +151,7 @@ function checkout( $buffer_size ) { return false; } - $buffer = new Jetpack_Sync_Queue_Buffer( $buffer_id, array_slice( $items, 0, $buffer_size ) ); + $buffer = new Queue_Buffer( $buffer_id, array_slice( $items, 0, $buffer_size ) ); return $buffer; } @@ -186,7 +163,7 @@ function checkout( $buffer_size ) { // exceeds the memory limit, but in that case it will send that item by itself. function checkout_with_memory_limit( $max_memory, $max_buffer_size = 500 ) { if ( $this->get_checkout_id() ) { - return new WP_Error( 'unclosed_buffer', 'There is an unclosed buffer' ); + return new \WP_Error( 'unclosed_buffer', 'There is an unclosed buffer' ); } $buffer_id = uniqid(); @@ -246,7 +223,7 @@ function checkout_with_memory_limit( $max_memory, $max_buffer_size = 500 ) { return false; } - $buffer = new Jetpack_Sync_Queue_Buffer( $buffer_id, $items ); + $buffer = new Queue_Buffer( $buffer_id, $items ); return $buffer; } @@ -289,7 +266,7 @@ function close( $buffer, $ids_to_remove = null ) { } function flush_all() { - $items = Jetpack_Sync_Utils::get_item_values( $this->fetch_items() ); + $items = Utils::get_item_values( $this->fetch_items() ); $this->reset(); return $items; @@ -316,11 +293,11 @@ function lock( $timeout = 30 ) { } if ( $tries === 30 ) { - return new WP_Error( 'lock_timeout', 'Timeout waiting for sync queue to empty' ); + return new \WP_Error( 'lock_timeout', 'Timeout waiting for sync queue to empty' ); } if ( $this->get_checkout_id() ) { - return new WP_Error( 'unclosed_buffer', 'There is an unclosed buffer' ); + return new \WP_Error( 'unclosed_buffer', 'There is an unclosed buffer' ); } // hopefully this means we can acquire a checkout? @@ -370,7 +347,7 @@ private function get_checkout_id() { private function set_checkout_id( $checkout_id ) { global $wpdb; - $expires = time() + Jetpack_Sync_Defaults::$default_sync_queue_lock_timeout; + $expires = time() + Defaults::$default_sync_queue_lock_timeout; $updated_num = $wpdb->query( $wpdb->prepare( "UPDATE $wpdb->options SET option_value = %s WHERE option_name = %s", @@ -440,39 +417,20 @@ private function fetch_items( $limit = null ) { } private function validate_checkout( $buffer ) { - if ( ! $buffer instanceof Jetpack_Sync_Queue_Buffer ) { - return new WP_Error( 'not_a_buffer', 'You must checkin an instance of Jetpack_Sync_Queue_Buffer' ); + if ( ! $buffer instanceof Queue_Buffer ) { + return new \WP_Error( 'not_a_buffer', 'You must checkin an instance of Queue_Buffer' ); } $checkout_id = $this->get_checkout_id(); if ( ! $checkout_id ) { - return new WP_Error( 'buffer_not_checked_out', 'There are no checked out buffers' ); + return new \WP_Error( 'buffer_not_checked_out', 'There are no checked out buffers' ); } if ( $checkout_id != $buffer->id ) { - return new WP_Error( 'buffer_mismatch', 'The buffer you checked in was not checked out' ); + return new \WP_Error( 'buffer_mismatch', 'The buffer you checked in was not checked out' ); } return true; } } - -class Jetpack_Sync_Utils { - - static function get_item_values( $items ) { - return array_map( array( __CLASS__, 'get_item_value' ), $items ); - } - - static function get_item_ids( $items ) { - return array_map( array( __CLASS__, 'get_item_id' ), $items ); - } - - private static function get_item_value( $item ) { - return $item->value; - } - - private static function get_item_id( $item ) { - return $item->id; - } -} diff --git a/packages/sync/src/Queue_Buffer.php b/packages/sync/src/Queue_Buffer.php new file mode 100644 index 000000000000..c37a2dc76e03 --- /dev/null +++ b/packages/sync/src/Queue_Buffer.php @@ -0,0 +1,28 @@ +id = $id; + $this->items_with_ids = $items_with_ids; + } + + public function get_items() { + return array_combine( $this->get_item_ids(), $this->get_item_values() ); + } + + public function get_item_values() { + return Utils::get_item_values( $this->items_with_ids ); + } + + public function get_item_ids() { + return Utils::get_item_ids( $this->items_with_ids ); + } +} diff --git a/sync/interface.jetpack-sync-replicastore.php b/packages/sync/src/Replicastore.php similarity index 98% rename from sync/interface.jetpack-sync-replicastore.php rename to packages/sync/src/Replicastore.php index c22f4e519628..29ff62a49466 100644 --- a/sync/interface.jetpack-sync-replicastore.php +++ b/packages/sync/src/Replicastore.php @@ -6,12 +6,14 @@ * To run tests: phpunit --testsuite sync --filter New_Sync */ +namespace Automattic\Jetpack\Sync; + /** * A high-level interface for objects that store synced WordPress data * Useful for ensuring that different storage mechanisms implement the * required semantics for storing all the data that we sync */ -interface iJetpack_Sync_Replicastore { +interface Replicastore { // remove all data public function reset(); diff --git a/sync/class.jetpack-sync-sender.php b/packages/sync/src/Sender.php similarity index 84% rename from sync/class.jetpack-sync-sender.php rename to packages/sync/src/Sender.php index 21f914819310..010d5d1ab2b3 100644 --- a/sync/class.jetpack-sync-sender.php +++ b/packages/sync/src/Sender.php @@ -1,17 +1,11 @@ init_before_send(); } } public function maybe_set_user_from_token() { - $jetpack = Jetpack::init(); + $jetpack = \Jetpack::init(); $verified_user = $jetpack->verify_xml_rpc_signature(); - if ( Jetpack_Constants::is_true( 'XMLRPC_REQUEST' ) && + if ( \Jetpack_Constants::is_true( 'XMLRPC_REQUEST' ) && ! is_wp_error( $verified_user ) && $verified_user ) { @@ -81,7 +75,7 @@ public function set_next_sync_time( $time, $queue_name ) { } public function do_full_sync() { - if ( ! Jetpack_Sync_Modules::get_module( 'full-sync' ) ) { + if ( ! Modules::get_module( 'full-sync' ) ) { return; } $this->continue_full_sync_enqueue(); @@ -97,7 +91,7 @@ private function continue_full_sync_enqueue() { return false; } - Jetpack_Sync_Modules::get_module( 'full-sync' )->continue_enqueuing(); + Modules::get_module( 'full-sync' )->continue_enqueuing(); $this->set_next_sync_time( time() + $this->get_enqueue_wait_time(), 'full-sync-enqueue' ); } @@ -109,21 +103,21 @@ public function do_sync() { public function do_sync_and_set_delays( $queue ) { // don't sync if importing if ( defined( 'WP_IMPORTING' ) && WP_IMPORTING ) { - return new WP_Error( 'is_importing' ); + return new \WP_Error( 'is_importing' ); } // don't sync if we are throttled if ( $this->get_next_sync_time( $queue->id ) > microtime( true ) ) { - return new WP_Error( 'sync_throttled' ); + return new \WP_Error( 'sync_throttled' ); } $start_time = microtime( true ); - Jetpack_Sync_Settings::set_is_syncing( true ); + Settings::set_is_syncing( true ); $sync_result = $this->do_sync_for_queue( $queue ); - Jetpack_Sync_Settings::set_is_syncing( false ); + Settings::set_is_syncing( false ); $exceeded_sync_wait_threshold = ( microtime( true ) - $start_time ) > (float) $this->get_sync_wait_threshold(); @@ -197,7 +191,7 @@ private function fastcgi_finish_request() { public function do_sync_for_queue( $queue ) { do_action( 'jetpack_sync_before_send_queue_' . $queue->id ); if ( $queue->size() === 0 ) { - return new WP_Error( 'empty_queue_' . $queue->id ); + return new \WP_Error( 'empty_queue_' . $queue->id ); } // now that we're sure we are about to sync, try to // ignore user abort so we can avoid getting into a @@ -207,7 +201,7 @@ public function do_sync_for_queue( $queue ) { } /* Don't make the request block till we finish, if possible. */ - if ( Jetpack_Constants::is_true( 'REST_REQUEST' ) || Jetpack_Constants::is_true('XMLRPC_REQUEST' ) ) { + if ( \Jetpack_Constants::is_true( 'REST_REQUEST' ) || \Jetpack_Constants::is_true( 'XMLRPC_REQUEST' ) ) { $this->fastcgi_finish_request(); } @@ -217,7 +211,7 @@ public function do_sync_for_queue( $queue ) { if ( ! $buffer ) { // buffer has no items - return new WP_Error( 'empty_buffer' ); + return new \WP_Error( 'empty_buffer' ); } if ( is_wp_error( $buffer ) ) { @@ -240,9 +234,9 @@ public function do_sync_for_queue( $queue ) { * @param double $time The current time * @param string $queue The queue used to send ('sync' or 'full_sync') */ - Jetpack_Sync_Settings::set_is_sending( true ); + Settings::set_is_sending( true ); $processed_item_ids = apply_filters( 'jetpack_sync_send_data', $items_to_send, $this->codec->name(), microtime( true ), $queue->id, $checkout_duration, $preprocess_duration ); - Jetpack_Sync_Settings::set_is_sending( false ); + Settings::set_is_sending( false ); } else { $processed_item_ids = $skipped_items_ids; $skipped_items_ids = array(); @@ -255,11 +249,11 @@ public function do_sync_for_queue( $queue ) { $queue->force_checkin(); } if ( is_wp_error( $processed_item_ids ) ) { - return new WP_Error( 'wpcom_error', $processed_item_ids->get_error_code() ); + return new \WP_Error( 'wpcom_error', $processed_item_ids->get_error_code() ); } // returning a WP_Error('wpcom_error') is a sign to the caller that we should wait a while // before syncing again - return new WP_Error( 'wpcom_error', 'jetpack_sync_send_data_false' ); + return new \WP_Error( 'wpcom_error', 'jetpack_sync_send_data_false' ); } else { // detect if the last item ID was an error $had_wp_error = is_wp_error( end( $processed_item_ids ) ); @@ -284,7 +278,7 @@ public function do_sync_for_queue( $queue ) { // returning a WP_Error is a sign to the caller that we should wait a while // before syncing again if ( $had_wp_error ) { - return new WP_Error( 'wpcom_error', $wp_error->get_error_code() ); + return new \WP_Error( 'wpcom_error', $wp_error->get_error_code() ); } } return true; @@ -303,15 +297,14 @@ function get_codec() { } function set_codec() { if ( function_exists( 'gzinflate' ) ) { - $this->codec = new Jetpack_Sync_JSON_Deflate_Array_Codec(); + $this->codec = new JSON_Deflate_Array_Codec(); } else { - $this->codec = new Jetpack_Sync_Simple_Codec(); + $this->codec = new Simple_Codec(); } } function send_checksum() { - require_once 'class.jetpack-sync-wp-replicastore.php'; - $store = new Jetpack_Sync_WP_Replicastore(); + $store = new WP_Replicastore(); do_action( 'jetpack_sync_checksum', $store->checksum_all() ); } @@ -371,27 +364,27 @@ function set_max_dequeue_time( $seconds ) { function set_defaults() { - $this->sync_queue = new Jetpack_Sync_Queue( 'sync' ); - $this->full_sync_queue = new Jetpack_Sync_Queue( 'full_sync' ); + $this->sync_queue = new Queue( 'sync' ); + $this->full_sync_queue = new Queue( 'full_sync' ); $this->set_codec(); // saved settings - Jetpack_Sync_Settings::set_importing( null ); - $settings = Jetpack_Sync_Settings::get_settings(); + Settings::set_importing( null ); + $settings = Settings::get_settings(); $this->set_dequeue_max_bytes( $settings['dequeue_max_bytes'] ); $this->set_upload_max_bytes( $settings['upload_max_bytes'] ); $this->set_upload_max_rows( $settings['upload_max_rows'] ); $this->set_sync_wait_time( $settings['sync_wait_time'] ); $this->set_enqueue_wait_time( $settings['enqueue_wait_time'] ); $this->set_sync_wait_threshold( $settings['sync_wait_threshold'] ); - $this->set_max_dequeue_time( Jetpack_Sync_Defaults::get_max_sync_execution_time() ); + $this->set_max_dequeue_time( Defaults::get_max_sync_execution_time() ); } function reset_data() { $this->reset_sync_queue(); $this->reset_full_sync_queue(); - foreach ( Jetpack_Sync_Modules::get_modules() as $module ) { + foreach ( Modules::get_modules() as $module ) { $module->reset_data(); } @@ -399,7 +392,7 @@ function reset_data() { delete_option( self::NEXT_SYNC_TIME_OPTION_NAME . '_' . $queue_name ); } - Jetpack_Sync_Settings::reset_data(); + Settings::reset_data(); } function uninstall() { diff --git a/sync/class.jetpack-sync-server.php b/packages/sync/src/Server.php similarity index 88% rename from sync/class.jetpack-sync-server.php rename to packages/sync/src/Server.php index dbd9172aa1d0..e0da4a42bc35 100644 --- a/sync/class.jetpack-sync-server.php +++ b/packages/sync/src/Server.php @@ -1,12 +1,12 @@ :( function __construct() { - $this->codec = new Jetpack_Sync_JSON_Deflate_Array_Codec(); + $this->codec = new JSON_Deflate_Array_Codec(); } - function set_codec( iJetpack_Sync_Codec $codec ) { + function set_codec( Codec $codec ) { $this->codec = $codec; } @@ -43,7 +43,7 @@ function remove_request_lock( $blog_id ) { function receive( $data, $token = null, $sent_timestamp = null, $queue_id = null ) { $start_time = microtime( true ); if ( ! is_array( $data ) ) { - return new WP_Error( 'action_decoder_error', 'Events must be an array' ); + return new \WP_Error( 'action_decoder_error', 'Events must be an array' ); } if ( $token && ! $this->attempt_request_lock( $token->blog_id ) ) { @@ -56,7 +56,7 @@ function receive( $data, $token = null, $sent_timestamp = null, $queue_id = null */ do_action( 'jetpack_sync_multi_request_fail', $token ); - return new WP_Error( 'concurrent_request_error', 'There is another request running for the same blog ID' ); + return new \WP_Error( 'concurrent_request_error', 'There is another request running for the same blog ID' ); } $events = wp_unslash( array_map( array( $this->codec, 'decode' ), $data ) ); diff --git a/sync/class.jetpack-sync-settings.php b/packages/sync/src/Settings.php similarity index 89% rename from sync/class.jetpack-sync-settings.php rename to packages/sync/src/Settings.php index e77588a87183..ab695008fc71 100644 --- a/sync/class.jetpack-sync-settings.php +++ b/packages/sync/src/Settings.php @@ -1,8 +1,8 @@ get_sync_queue()->reset(); $listener->get_full_sync_queue()->reset(); } diff --git a/sync/class.jetpack-sync-simple-codec.php b/packages/sync/src/Simple_Codec.php similarity index 61% rename from sync/class.jetpack-sync-simple-codec.php rename to packages/sync/src/Simple_Codec.php index 7bd9aaac3c25..fa49052702f1 100644 --- a/sync/class.jetpack-sync-simple-codec.php +++ b/packages/sync/src/Simple_Codec.php @@ -1,12 +1,12 @@ array( 'id' ), 'role' => 'administrator', @@ -64,18 +66,18 @@ static function maybe_demote_master_user( $user_id ) { $new_master = false; foreach ( $query->results as $result ) { $found_user_id = absint( $result->id ); - if ( $found_user_id && Jetpack::is_user_connected( $found_user_id ) ) { + if ( $found_user_id && \Jetpack::is_user_connected( $found_user_id ) ) { $new_master = $found_user_id; break; } } if ( $new_master ) { - Jetpack_Options::update_option( 'master_user', $new_master ); + \Jetpack_Options::update_option( 'master_user', $new_master ); } // else disconnect..? } } } -Jetpack_Sync_Users::init(); +Users::init(); diff --git a/packages/sync/src/Utils.php b/packages/sync/src/Utils.php new file mode 100644 index 000000000000..8417030a61f8 --- /dev/null +++ b/packages/sync/src/Utils.php @@ -0,0 +1,21 @@ +value; + } + + private static function get_item_id( $item ) { + return $item->id; + } +} diff --git a/sync/class.jetpack-sync-wp-replicastore.php b/packages/sync/src/WP_Replicastore.php similarity index 88% rename from sync/class.jetpack-sync-wp-replicastore.php rename to packages/sync/src/WP_Replicastore.php index 99826bd08712..f38d0ee0625d 100644 --- a/sync/class.jetpack-sync-wp-replicastore.php +++ b/packages/sync/src/WP_Replicastore.php @@ -1,15 +1,12 @@ table_checksum( $wpdb->posts, Jetpack_Sync_Defaults::$default_post_checksum_columns, 'ID', Jetpack_Sync_Settings::get_blacklisted_post_types_sql(), $min_id, $max_id ); + return $this->table_checksum( $wpdb->posts, Defaults::$default_post_checksum_columns, 'ID', Settings::get_blacklisted_post_types_sql(), $min_id, $max_id ); } public function post_meta_checksum( $min_id = null, $max_id = null ) { global $wpdb; - return $this->table_checksum( $wpdb->postmeta, Jetpack_Sync_Defaults::$default_post_meta_checksum_columns, 'meta_id', Jetpack_Sync_Settings::get_whitelisted_post_meta_sql(), $min_id, $max_id ); + return $this->table_checksum( $wpdb->postmeta, Defaults::$default_post_meta_checksum_columns, 'meta_id', Settings::get_whitelisted_post_meta_sql(), $min_id, $max_id ); } public function comment_count( $status = null, $min_id = null, $max_id = null ) { @@ -283,21 +280,21 @@ public function untrashed_post_comments( $post_id ) { public function comments_checksum( $min_id = null, $max_id = null ) { global $wpdb; - return $this->table_checksum( $wpdb->comments, Jetpack_Sync_Defaults::$default_comment_checksum_columns, 'comment_ID', Jetpack_Sync_Settings::get_comments_filter_sql(), $min_id, $max_id ); + return $this->table_checksum( $wpdb->comments, Defaults::$default_comment_checksum_columns, 'comment_ID', Settings::get_comments_filter_sql(), $min_id, $max_id ); } public function comment_meta_checksum( $min_id = null, $max_id = null ) { global $wpdb; - return $this->table_checksum( $wpdb->commentmeta, Jetpack_Sync_Defaults::$default_comment_meta_checksum_columns, 'meta_id', Jetpack_Sync_Settings::get_whitelisted_comment_meta_sql(), $min_id, $max_id ); + return $this->table_checksum( $wpdb->commentmeta, Defaults::$default_comment_meta_checksum_columns, 'meta_id', Settings::get_whitelisted_comment_meta_sql(), $min_id, $max_id ); } public function options_checksum() { global $wpdb; - $options_whitelist = "'" . implode( "', '", Jetpack_Sync_Defaults::$default_options_whitelist ) . "'"; + $options_whitelist = "'" . implode( "', '", Defaults::$default_options_whitelist ) . "'"; $where_sql = "option_name IN ( $options_whitelist )"; - return $this->table_checksum( $wpdb->options, Jetpack_Sync_Defaults::$default_option_checksum_columns, null, $where_sql, null, null ); + return $this->table_checksum( $wpdb->options, Defaults::$default_option_checksum_columns, null, $where_sql, null, null ); } @@ -495,7 +492,7 @@ private function ensure_taxonomy( $taxonomy ) { $taxonomies = $this->get_callable( 'taxonomies' ); if ( ! isset( $taxonomies[ $taxonomy ] ) ) { // doesn't exist, or somehow hasn't been synced - return new WP_Error( 'invalid_taxonomy', "The taxonomy '$taxonomy' doesn't exist" ); + return new \WP_Error( 'invalid_taxonomy', "The taxonomy '$taxonomy' doesn't exist" ); } $t = $taxonomies[ $taxonomy ]; @@ -655,37 +652,37 @@ function checksum_histogram( $object_type, $buckets, $start_id = null, $end_id = $object_count = $this->post_count( null, $start_id, $end_id ); $object_table = $wpdb->posts; $id_field = 'ID'; - $where_sql = Jetpack_Sync_Settings::get_blacklisted_post_types_sql(); + $where_sql = Settings::get_blacklisted_post_types_sql(); if ( empty( $columns ) ) { - $columns = Jetpack_Sync_Defaults::$default_post_checksum_columns; + $columns = Defaults::$default_post_checksum_columns; } break; case 'post_meta': $object_table = $wpdb->postmeta; - $where_sql = Jetpack_Sync_Settings::get_whitelisted_post_meta_sql(); + $where_sql = Settings::get_whitelisted_post_meta_sql(); $object_count = $this->meta_count( $object_table, $where_sql, $start_id, $end_id ); $id_field = 'meta_id'; if ( empty( $columns ) ) { - $columns = Jetpack_Sync_Defaults::$default_post_meta_checksum_columns; + $columns = Defaults::$default_post_meta_checksum_columns; } break; case 'comments': $object_count = $this->comment_count( null, $start_id, $end_id ); $object_table = $wpdb->comments; $id_field = 'comment_ID'; - $where_sql = Jetpack_Sync_Settings::get_comments_filter_sql(); + $where_sql = Settings::get_comments_filter_sql(); if ( empty( $columns ) ) { - $columns = Jetpack_Sync_Defaults::$default_comment_checksum_columns; + $columns = Defaults::$default_comment_checksum_columns; } break; case 'comment_meta': $object_table = $wpdb->commentmeta; - $where_sql = Jetpack_Sync_Settings::get_whitelisted_comment_meta_sql(); + $where_sql = Settings::get_whitelisted_comment_meta_sql(); $object_count = $this->meta_count( $object_table, $where_sql, $start_id, $end_id ); $id_field = 'meta_id'; if ( empty( $columns ) ) { - $columns = Jetpack_Sync_Defaults::$default_post_meta_checksum_columns; + $columns = Defaults::$default_post_meta_checksum_columns; } break; default: @@ -712,7 +709,7 @@ function checksum_histogram( $object_type, $buckets, $start_id = null, $end_id = ARRAY_N ); - if ( null === $first_id || null === $last_id ) { + if ( null === $first_id || null === $last_id ) { // Nothing to checksum here... break; } @@ -724,7 +721,7 @@ function checksum_histogram( $object_type, $buckets, $start_id = null, $end_id = return $value; } - if ( null === $first_id || null === $last_id ) { + if ( null === $first_id || null === $last_id ) { break; } elseif ( $first_id === $last_id ) { $histogram[ $first_id ] = $value; @@ -752,34 +749,34 @@ private function table_checksum( $table, $columns, $id_column, $where_sql = '1=1 if ( null !== $min_id && null !== $max_id ) { if ( $min_id === $max_id ) { - $min_id = intval( $min_id ); + $min_id = intval( $min_id ); $where_sql .= " AND $id_column = $min_id LIMIT 1"; } else { - $min_id = intval( $min_id ); - $max_id = intval( $max_id ); - $size = $max_id - $min_id; + $min_id = intval( $min_id ); + $max_id = intval( $max_id ); + $size = $max_id - $min_id; $where_sql .= " AND $id_column >= $min_id AND $id_column <= $max_id LIMIT $size"; } } else { if ( null !== $min_id ) { - $min_id = intval( $min_id ); + $min_id = intval( $min_id ); $where_sql .= " AND $id_column >= $min_id"; } if ( null !== $max_id ) { - $max_id = intval( $max_id ); + $max_id = intval( $max_id ); $where_sql .= " AND $id_column <= $max_id"; } } - $query = <<get_var( $wpdb->prepare( $query, $salt ) ); if ( $wpdb->last_error ) { - return new WP_Error( 'database_error', $wpdb->last_error ); + return new \WP_Error( 'database_error', $wpdb->last_error ); } return $result; diff --git a/sal/class.json-api-site-jetpack.php b/sal/class.json-api-site-jetpack.php index 0efcb3aadb1f..c1cd02bccc3a 100644 --- a/sal/class.json-api-site-jetpack.php +++ b/sal/class.json-api-site-jetpack.php @@ -1,5 +1,7 @@ set_defaults(); - } - } - - public static function get_module( $module_name ) { - foreach ( self::get_modules() as $module ) { - if ( $module->name() === $module_name ) { - return $module; - } - } - - return false; - } - - static function initialize_modules() { - /** - * Filters the list of class names of sync modules. - * If you add to this list, make sure any classes implement the - * Jetpack_Sync_Module interface. - * - * @since 4.2.0 - */ - $modules = apply_filters( 'jetpack_sync_modules', self::$default_sync_modules ); - - $modules = array_map( array( 'Jetpack_Sync_Modules', 'load_module' ), $modules ); - - return array_map( array( 'Jetpack_Sync_Modules', 'set_module_defaults' ), $modules ); - } - - static function load_module( $module_name ) { - return new $module_name(); - } - - static function set_module_defaults( $module ) { - $module->set_defaults(); - if ( method_exists( $module, 'set_late_default' ) ) { - add_action( 'init', array( $module, 'set_late_default' ), 90 ); - } - return $module; - } - -} diff --git a/uninstall.php b/uninstall.php index 366e62d13632..64a025c086c1 100644 --- a/uninstall.php +++ b/uninstall.php @@ -1,5 +1,7 @@ uninstall(); +Sender::get_instance()->uninstall();