public static function get_instance()
 {
     if (null === self::$instance) {
         self::$instance = new self();
     }
     return self::$instance;
 }
 protected function enqueue_all_ids_as_action($action_name, $table_name, $id_field, $where_sql, $max_items_to_enqueue, $state)
 {
     global $wpdb;
     if (!$where_sql) {
         $where_sql = '1 = 1';
     }
     $items_per_page = 1000;
     $page = 1;
     $chunk_count = 0;
     $previous_max_id = $state ? $state : '~0';
     $listener = Jetpack_Sync_Listener::get_instance();
     // count down from max_id to min_id so we get newest posts/comments/etc first
     while ($ids = $wpdb->get_col("SELECT {$id_field} FROM {$table_name} WHERE {$where_sql} AND {$id_field} < {$previous_max_id} ORDER BY {$id_field} DESC LIMIT {$items_per_page}")) {
         // Request posts in groups of N for efficiency
         $chunked_ids = array_chunk($ids, self::ARRAY_CHUNK_SIZE);
         // if we hit our row limit, process and return
         if ($chunk_count + count($chunked_ids) >= $max_items_to_enqueue) {
             $remaining_items_count = $max_items_to_enqueue - $chunk_count;
             $remaining_items = array_slice($chunked_ids, 0, $remaining_items_count);
             $listener->bulk_enqueue_full_sync_actions($action_name, $remaining_items);
             $last_chunk = end($remaining_items);
             return array($remaining_items_count + $chunk_count, end($last_chunk));
         }
         $listener->bulk_enqueue_full_sync_actions($action_name, $chunked_ids);
         $chunk_count += count($chunked_ids);
         $page += 1;
         $previous_max_id = end($ids);
     }
     return array($chunk_count, true);
 }
 static function update_settings($new_settings)
 {
     $validated_settings = array_intersect_key($new_settings, self::$valid_settings);
     foreach ($validated_settings as $setting => $value) {
         update_option(self::SETTINGS_OPTION_PREFIX . $setting, $value, true);
         unset(self::$settings_cache[$setting]);
         // if we set the disabled option to true, clear the queues
         if ('disable' === $setting && !!$value) {
             require_once dirname(__FILE__) . '/class.jetpack-sync-listener.php';
             $listener = Jetpack_Sync_Listener::get_instance();
             $listener->get_sync_queue()->reset();
             $listener->get_full_sync_queue()->reset();
         }
     }
 }
 public function setUp()
 {
     parent::setUp();
     $this->listener = Jetpack_Sync_Listener::get_instance();
     $this->sender = Jetpack_Sync_Sender::get_instance();
     $this->setSyncClientDefaults();
     $this->server = new Jetpack_Sync_Server();
     // bind the sender to the server
     remove_all_filters('jetpack_sync_send_data');
     add_filter('jetpack_sync_send_data', array($this, 'serverReceive'), 10, 4);
     // bind the two storage systems to the server events
     $this->server_replica_storage = new Jetpack_Sync_Test_Replicastore();
     $this->server_replicator = new Jetpack_Sync_Server_Replicator($this->server_replica_storage);
     $this->server_replicator->init();
     $this->server_event_storage = new Jetpack_Sync_Server_Eventstore();
     $this->server_event_storage->init();
 }
Ejemplo n.º 5
0
 protected function enqueue_all_ids_as_action($action_name, $table_name, $id_field, $where_sql)
 {
     global $wpdb;
     if (!$where_sql) {
         $where_sql = '1 = 1';
     }
     $items_per_page = 1000;
     $page = 1;
     $chunk_count = 0;
     $previous_id = 0;
     $listener = Jetpack_Sync_Listener::get_instance();
     while ($ids = $wpdb->get_col("SELECT {$id_field} FROM {$table_name} WHERE {$where_sql} AND {$id_field} > {$previous_id} ORDER BY {$id_field} ASC LIMIT {$items_per_page}")) {
         // Request posts in groups of N for efficiency
         $chunked_ids = array_chunk($ids, self::ARRAY_CHUNK_SIZE);
         $listener->bulk_enqueue_full_sync_actions($action_name, $chunked_ids);
         $chunk_count += count($chunked_ids);
         $page += 1;
         $previous_id = end($ids);
     }
     return $chunk_count;
 }
 static function initialize_listener()
 {
     require_once dirname(__FILE__) . '/class.jetpack-sync-listener.php';
     self::$listener = Jetpack_Sync_Listener::get_instance();
 }
 public function reset_data()
 {
     $this->clear_status();
     require_once dirname(__FILE__) . '/class.jetpack-sync-listener.php';
     $listener = Jetpack_Sync_Listener::get_instance();
     $listener->get_full_sync_queue()->reset();
 }