function start()
 {
     /**
      * Fires when a full sync begins. This action is serialized
      * and sent to the server so that it can clear the replica storage,
      * and/or reset other data.
      *
      * @since 4.1
      */
     do_action('jetpack_full_sync_start');
     $this->set_status_queuing_started();
     $this->enqueue_wp_version();
     $this->enqueue_all_constants();
     $this->enqueue_all_functions();
     $this->enqueue_all_options();
     if (is_multisite()) {
         $this->enqueue_all_network_options();
     }
     $this->enqueue_all_terms();
     $this->enqueue_all_theme_info();
     $this->enqueue_all_users();
     $this->enqueue_all_posts();
     $this->enqueue_all_comments();
     $this->enqueue_all_updates();
     $this->set_status_queuing_finished();
     $store = new Jetpack_Sync_WP_Replicastore();
     do_action('jetpack_full_sync_end', $store->checksum_all());
 }
 protected function assertDataIsSynced()
 {
     $local = new Jetpack_Sync_WP_Replicastore();
     $remote = $this->server_replica_storage;
     // Also pass the posts though the same filter other wise they woun't match any more.
     $local_posts = array_map(array($this->client, 'filter_post_content_and_add_links'), $local->get_posts());
     $this->assertEquals($local_posts, $remote->get_posts());
     $this->assertEquals($local->get_comments(), $remote->get_comments());
 }
 protected function result()
 {
     $args = $this->query_args();
     if (isset($args['columns'])) {
         $columns = array_map('trim', explode(',', $args['columns']));
     } else {
         $columns = null;
         // go with defaults
     }
     require_once JETPACK__PLUGIN_DIR . 'sync/class.jetpack-sync-wp-replicastore.php';
     $store = new Jetpack_Sync_WP_Replicastore();
     return $store->checksum_histogram($args['object_type'], $args['buckets'], $args['start_id'], $args['end_id'], $columns, $args['strip_non_ascii']);
 }
 protected function result()
 {
     Jetpack::init();
     $client = Jetpack_Sync_Client::getInstance();
     $sync_queue = $client->get_sync_queue();
     // lock sending from the queue while we compare checksums with the server
     $result = $sync_queue->lock(30);
     // tries to acquire the lock for up to 30 seconds
     if (!$result) {
         $sync_queue->unlock();
         return new WP_Error('unknown_error', 'Unknown error trying to lock the sync queue');
     }
     if (is_wp_error($result)) {
         $sync_queue->unlock();
         return $result;
     }
     $store = new Jetpack_Sync_WP_Replicastore();
     $result = $store->checksum_all();
     $sync_queue->unlock();
     return $result;
 }
 function send_checksum()
 {
     require_once 'class.jetpack-sync-wp-replicastore.php';
     $store = new Jetpack_Sync_WP_Replicastore();
     do_action('jetpack_sync_checksum', $store->checksum_all());
 }
 protected function result()
 {
     require_once JETPACK__PLUGIN_DIR . 'sync/class.jetpack-sync-sender.php';
     $sender = Jetpack_Sync_Sender::get_instance();
     $sync_queue = $sender->get_sync_queue();
     // lock sending from the queue while we compare checksums with the server
     $result = $sync_queue->lock(30);
     // tries to acquire the lock for up to 30 seconds
     if (!$result) {
         $sync_queue->unlock();
         return new WP_Error('unknown_error', 'Unknown error trying to lock the sync queue');
     }
     if (is_wp_error($result)) {
         $sync_queue->unlock();
         return $result;
     }
     $args = $this->query_args();
     if (isset($args['columns'])) {
         $columns = array_map('trim', explode(',', $args['columns']));
     } else {
         $columns = null;
         // go with defaults
     }
     require_once JETPACK__PLUGIN_DIR . 'sync/class.jetpack-sync-wp-replicastore.php';
     $store = new Jetpack_Sync_WP_Replicastore();
     $result = $store->checksum_histogram($args['object_type'], $args['buckets'], $args['start_id'], $args['end_id'], $columns, $args['strip_non_ascii']);
     $sync_queue->unlock();
     return $result;
 }
 function start($modules = null)
 {
     $was_already_running = $this->is_started() && !$this->is_finished();
     // remove all evidence of previous full sync items and status
     $this->reset_data();
     $this->enable_queue_rate_limit();
     if ($was_already_running) {
         /**
          * Fires when a full sync is cancelled.
          *
          * @since 4.2.0
          */
         do_action('jetpack_full_sync_cancelled');
     }
     /**
      * Fires when a full sync begins. This action is serialized
      * and sent to the server so that it knows a full sync is coming.
      *
      * @since 4.2.0
      */
     do_action('jetpack_full_sync_start', $modules);
     $this->update_status_option('started', time());
     // configure modules
     if (!is_array($modules)) {
         $modules = array();
     }
     if (isset($modules['users']) && 'initial' === $modules['users']) {
         $user_module = Jetpack_Sync_Modules::get_module('users');
         $modules['users'] = $user_module->get_initial_sync_user_config();
     }
     // by default, all modules are fully enabled
     if (count($modules) === 0) {
         $default_module_config = true;
     } else {
         $default_module_config = false;
     }
     // set default configuration, calculate totals, and save configuration if totals > 0
     foreach (Jetpack_Sync_Modules::get_modules() as $module) {
         $module_name = $module->name();
         if (!isset($modules[$module_name])) {
             $modules[$module_name] = $default_module_config;
         }
         // check if this module is enabled
         if (!($module_config = $modules[$module_name])) {
             continue;
         }
         $total_items = $module->estimate_full_sync_actions($module_config);
         if (!is_null($total_items) && $total_items > 0) {
             $this->update_status_option("{$module_name}_total", $total_items);
             $this->update_status_option("{$module_name}_config", $module_config);
         }
     }
     foreach (Jetpack_Sync_Modules::get_modules() as $module) {
         $module_name = $module->name();
         $module_config = $modules[$module_name];
         // check if this module is enabled
         if (!$module_config) {
             continue;
         }
         $items_enqueued = $module->enqueue_full_sync_actions($module_config);
         if (!is_null($items_enqueued) && $items_enqueued > 0) {
             $this->update_status_option("{$module_name}_queued", $items_enqueued);
         }
     }
     $this->update_status_option('queue_finished', time());
     $store = new Jetpack_Sync_WP_Replicastore();
     /**
      * Fires when a full sync ends. This action is serialized
      * and sent to the server with checksums so that we can confirm the
      * sync was successful.
      *
      * @since 4.2.0
      */
     do_action('jetpack_full_sync_end', $store->checksum_all());
     $this->disable_queue_rate_limit();
     return true;
 }
 public static function generate_stats_array($prefix = '')
 {
     $return = array();
     $return["{$prefix}version"] = JETPACK__VERSION;
     $return["{$prefix}wp-version"] = get_bloginfo('version');
     $return["{$prefix}php-version"] = PHP_VERSION;
     $return["{$prefix}branch"] = floatval(JETPACK__VERSION);
     $return["{$prefix}wp-branch"] = floatval(get_bloginfo('version'));
     $return["{$prefix}php-branch"] = floatval(PHP_VERSION);
     $return["{$prefix}public"] = Jetpack_Options::get_option('public');
     $return["{$prefix}ssl"] = Jetpack::permit_ssl();
     $return["{$prefix}is-https"] = is_ssl() ? 'https' : 'http';
     $return["{$prefix}language"] = get_bloginfo('language');
     $return["{$prefix}charset"] = get_bloginfo('charset');
     $return["{$prefix}is-multisite"] = is_multisite() ? 'multisite' : 'singlesite';
     $return["{$prefix}identitycrisis"] = Jetpack::check_identity_crisis(1) ? 'yes' : 'no';
     $return["{$prefix}plugins"] = implode(',', Jetpack::get_active_plugins());
     $return["{$prefix}single-user-site"] = Jetpack::is_single_user_site();
     $return["{$prefix}manage-enabled"] = Jetpack::is_module_active('manage');
     // is-multi-network can have three values, `single-site`, `single-network`, and `multi-network`
     $return["{$prefix}is-multi-network"] = 'single-site';
     if (is_multisite()) {
         $return["{$prefix}is-multi-network"] = Jetpack::is_multi_network() ? 'multi-network' : 'single-network';
     }
     if (!empty($_SERVER['SERVER_ADDR']) || !empty($_SERVER['LOCAL_ADDR'])) {
         $ip = !empty($_SERVER['SERVER_ADDR']) ? $_SERVER['SERVER_ADDR'] : $_SERVER['LOCAL_ADDR'];
         $ip_arr = array_map('intval', explode('.', $ip));
         if (4 == count($ip_arr)) {
             $return["{$prefix}ip-2-octets"] = implode('.', array_slice($ip_arr, 0, 2));
         }
     }
     foreach (Jetpack::get_available_modules() as $slug) {
         $return["{$prefix}module-{$slug}"] = Jetpack::is_module_active($slug) ? 'on' : 'off';
     }
     require_once dirname(__FILE__) . '/sync/class.jetpack-sync-wp-replicastore.php';
     $store = new Jetpack_Sync_WP_Replicastore();
     $return["{$prefix}sync-checksum"] = json_encode($store->checksum_all());
     return $return;
 }