Completed
Push — add/sync-partial-sync-checksum... ( f2c23a...c8643b )
by
unknown
14:51 queued 06:36
created

Jetpack_JSON_API_Sync_Histogram_Endpoint::result()   B

Complexity

Conditions 6
Paths 20

Size

Total Lines 37

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 6
nc 20
nop 0
dl 0
loc 37
rs 8.7057
c 0
b 0
f 0
1
<?php
2
3
use Automattic\Jetpack\Sync\Actions;
4
use Automattic\Jetpack\Sync\Modules;
5
use Automattic\Jetpack\Sync\Queue;
6
use Automattic\Jetpack\Sync\Queue_Buffer;
7
use Automattic\Jetpack\Sync\Replicastore;
8
use Automattic\Jetpack\Sync\Sender;
9
use Automattic\Jetpack\Sync\Settings;
10
11
// POST /sites/%s/sync
12
class Jetpack_JSON_API_Sync_Endpoint extends Jetpack_JSON_API_Endpoint {
13
14
	/**
15
	 * This endpoint allows authentication both via a blog and a user token.
16
	 * If a user token is used, that user should have `manage_options` capability.
17
	 *
18
	 * @var array|string
19
	 */
20
	protected $needed_capabilities = 'manage_options';
21
22
	protected function validate_call( $_blog_id, $capability, $check_manage_active = true ) {
23
		return parent::validate_call( $_blog_id, $capability, false );
24
	}
25
26
	protected function result() {
27
		$args = $this->input();
28
		$modules = null;
29
30
		// convert list of modules in comma-delimited format into an array
31
		// of "$modulename => true"
32 View Code Duplication
		if ( isset( $args['modules'] ) && ! empty( $args['modules'] ) ) {
33
			$modules = array_map( '__return_true', array_flip( array_map( 'trim', explode( ',', $args['modules'] ) ) ) );
34
		}
35
36 View Code Duplication
		foreach ( array( 'posts', 'comments', 'users' ) as $module_name ) {
37
			if ( 'users' === $module_name && isset( $args[ $module_name ] ) && 'initial' === $args[ $module_name ] ) {
38
				$modules[ 'users' ] = 'initial';
39
			} elseif ( isset( $args[ $module_name ] ) ) {
40
				$ids = explode( ',', $args[ $module_name ] );
41
				if ( count( $ids ) > 0 ) {
42
					$modules[ $module_name ] = $ids;
43
				}
44
			}
45
		}
46
47
		if ( empty( $modules ) ) {
48
			$modules = null;
49
		}
50
		return array( 'scheduled' => Actions::do_full_sync( $modules ) );
51
	}
52
53
	protected function validate_queue( $query ) {
54
		if ( ! isset( $query ) ) {
55
			return new WP_Error( 'invalid_queue', 'Queue name is required', 400 );
0 ignored issues
show
Unused Code introduced by
The call to WP_Error::__construct() has too many arguments starting with 'invalid_queue'.

This check compares calls to functions or methods with their respective definitions. If the call has more arguments than are defined, it raises an issue.

If a function is defined several times with a different number of parameters, the check may pick up the wrong definition and report false positives. One codebase where this has been known to happen is Wordpress.

In this case you can add the @ignore PhpDoc annotation to the duplicate definition and it will be ignored.

Loading history...
56
		}
57
58 View Code Duplication
		if ( ! in_array( $query, array( 'sync', 'full_sync', 'immediate' ) ) ) {
59
			return new WP_Error( 'invalid_queue', 'Queue name should be sync, full_sync or immediate', 400 );
0 ignored issues
show
Unused Code introduced by
The call to WP_Error::__construct() has too many arguments starting with 'invalid_queue'.

This check compares calls to functions or methods with their respective definitions. If the call has more arguments than are defined, it raises an issue.

If a function is defined several times with a different number of parameters, the check may pick up the wrong definition and report false positives. One codebase where this has been known to happen is Wordpress.

In this case you can add the @ignore PhpDoc annotation to the duplicate definition and it will be ignored.

Loading history...
60
		}
61
		return $query;
62
	}
63
}
64
65
// GET /sites/%s/sync/status
66
class Jetpack_JSON_API_Sync_Status_Endpoint extends Jetpack_JSON_API_Sync_Endpoint {
67
	protected function result() {
68
		$args   = $this->query_args();
69
		$fields = isset( $args['fields'] ) ? $args['fields'] : array();
70
		return Actions::get_sync_status( $fields );
71
	}
72
}
73
74
// GET /sites/%s/data-check
75
class Jetpack_JSON_API_Sync_Check_Endpoint extends Jetpack_JSON_API_Sync_Endpoint {
76
	protected function result() {
77
		$store = new Replicastore();
78
		return $store->checksum_all();
79
	}
80
}
81
82
// GET /sites/%s/data-histogram
83
class Jetpack_JSON_API_Sync_Histogram_Endpoint extends Jetpack_JSON_API_Sync_Endpoint {
84
	protected function result() {
85
		$args = $this->query_args();
86
87
		if ( isset( $args['columns'] ) ) {
88
			$columns = array_map( 'trim', explode( ',', $args['columns'] ) );
89
		} else {
90
			$columns = null; // go with defaults
91
		}
92
93
		$store = new Replicastore();
94
95
		if ( ! isset( $args['strip_non_ascii'] ) ) {
96
			$args['strip_non_ascii'] = true;
97
		}
98
99
		/**
100
		 * Hack: nullify the values of `start_id` and `end_id` if we're only requesting ranges.
101
		 *
102
		 * The endpoint doesn't support nullable values :(
103
		 */
104
		if ( true === $args['only_range_edges'] ) {
105
			if ( 0 === $args['start_id'] ) {
106
				$args['start_id'] = null;
107
			}
108
109
			if ( 0 === $args['end_id'] ) {
110
				$args['end_id'] = null;
111
			}
112
		}
113
114
		$histogram = $store->checksum_histogram( $args['object_type'], $args['buckets'], $args['start_id'], $args['end_id'], $columns, $args['strip_non_ascii'], $args['shared_salt'], $args['only_range_edges'] );
115
116
		// Hack to disable Sync during this call, so we can resolve faster.
117
		Actions::mark_sync_read_only();
118
119
		return array( 'histogram' => $histogram, 'type' => $store->get_checksum_type() );
120
	}
121
}
122
123
// POST /sites/%s/sync/settings
124
class Jetpack_JSON_API_Sync_Modify_Settings_Endpoint extends Jetpack_JSON_API_Sync_Endpoint {
125
	protected function result() {
126
		$args = $this->input();
127
128
		$sync_settings = Settings::get_settings();
129
130
		foreach ( $args as $key => $value ) {
131
			if ( $value !== false ) {
132
				if ( is_numeric( $value ) ) {
133
					$value = (int) $value;
134
				}
135
136
				// special case for sending empty arrays - a string with value 'empty'
137
				if ( $value === 'empty' ) {
138
					$value = array();
139
				}
140
141
				$sync_settings[ $key ] = $value;
142
			}
143
		}
144
145
		Settings::update_settings( $sync_settings );
146
147
		// re-fetch so we see what's really being stored
148
		return Settings::get_settings();
149
	}
150
}
151
152
// GET /sites/%s/sync/settings
153
class Jetpack_JSON_API_Sync_Get_Settings_Endpoint extends Jetpack_JSON_API_Sync_Endpoint {
154
	protected function result() {
155
156
		return Settings::get_settings();
157
	}
158
}
159
160
// GET /sites/%s/sync/object
161
class Jetpack_JSON_API_Sync_Object extends Jetpack_JSON_API_Sync_Endpoint {
162
	protected function result() {
163
		$args = $this->query_args();
164
165
		$module_name = $args['module_name'];
166
167
		if ( ! $sync_module = Modules::get_module( $module_name ) ) {
168
			return new WP_Error( 'invalid_module', 'You specified an invalid sync module' );
0 ignored issues
show
Unused Code introduced by
The call to WP_Error::__construct() has too many arguments starting with 'invalid_module'.

This check compares calls to functions or methods with their respective definitions. If the call has more arguments than are defined, it raises an issue.

If a function is defined several times with a different number of parameters, the check may pick up the wrong definition and report false positives. One codebase where this has been known to happen is Wordpress.

In this case you can add the @ignore PhpDoc annotation to the duplicate definition and it will be ignored.

Loading history...
169
		}
170
171
		$object_type = $args['object_type'];
172
		$object_ids  = $args['object_ids'];
173
174
		$codec = Sender::get_instance()->get_codec();
175
176
		Settings::set_is_syncing( true );
177
		$objects = $codec->encode( $sync_module->get_objects_by_id( $object_type, $object_ids ) );
178
		Settings::set_is_syncing( false );
179
180
		return array(
181
			'objects' => $objects,
182
			'codec' => $codec->name(),
183
		);
184
	}
185
}
186
187
class Jetpack_JSON_API_Sync_Now_Endpoint extends Jetpack_JSON_API_Sync_Endpoint {
188
	protected function result() {
189
		$args = $this->input();
190
		$queue_name = $this->validate_queue( $args['queue'] );
191
192
		if ( is_wp_error( $queue_name ) ){
193
			return $queue_name;
194
		}
195
196
		$sender = Sender::get_instance();
197
		$response = $sender->do_sync_for_queue( new Queue( $args['queue'] ) );
0 ignored issues
show
Documentation introduced by
new \Automattic\Jetpack\...c\Queue($args['queue']) is of type object<Automattic\Jetpack\Sync\Queue>, but the function expects a object<Automattic\Jetpac...tic\Jetpack\Sync\Queue>.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
198
199
		return array(
200
			'response' => $response
201
		);
202
	}
203
}
204
205
class Jetpack_JSON_API_Sync_Checkout_Endpoint extends Jetpack_JSON_API_Sync_Endpoint {
206
	protected function result() {
207
		$args       = $this->input();
208
		$queue_name = $this->validate_queue( $args['queue'] );
209
210
		if ( is_wp_error( $queue_name ) ) {
211
			return $queue_name;
212
		}
213
214
		if ( $args['number_of_items'] < 1 || $args['number_of_items'] > 100 ) {
215
			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 );
0 ignored issues
show
Unused Code introduced by
The call to WP_Error::__construct() has too many arguments starting with 'invalid_number_of_items'.

This check compares calls to functions or methods with their respective definitions. If the call has more arguments than are defined, it raises an issue.

If a function is defined several times with a different number of parameters, the check may pick up the wrong definition and report false positives. One codebase where this has been known to happen is Wordpress.

In this case you can add the @ignore PhpDoc annotation to the duplicate definition and it will be ignored.

Loading history...
216
		}
217
218
		$number_of_items = absint( $args['number_of_items'] );
219
220
		if ( 'immediate' === $queue_name ) {
221
			return $this->immediate_full_sync_pull( $number_of_items );
222
		}
223
224
		return $this->queue_pull( $queue_name, $number_of_items, $args );
225
	}
226
227
	function queue_pull( $queue_name, $number_of_items, $args ){
228
		$queue = new Queue( $queue_name );
229
230
		if ( 0 === $queue->size() ) {
231
			return new WP_Error( 'queue_size', 'The queue is empty and there is nothing to send', 400 );
0 ignored issues
show
Unused Code introduced by
The call to WP_Error::__construct() has too many arguments starting with 'queue_size'.

This check compares calls to functions or methods with their respective definitions. If the call has more arguments than are defined, it raises an issue.

If a function is defined several times with a different number of parameters, the check may pick up the wrong definition and report false positives. One codebase where this has been known to happen is Wordpress.

In this case you can add the @ignore PhpDoc annotation to the duplicate definition and it will be ignored.

Loading history...
232
		}
233
234
		$sender = Sender::get_instance();
235
236
		// try to give ourselves as much time as possible.
237
		set_time_limit( 0 );
238
239
		if ( $args['pop'] ) {
240
			$buffer = new Queue_Buffer( 'pop', $queue->pop( $number_of_items ) );
0 ignored issues
show
Bug introduced by
It seems like $queue->pop($number_of_items) targeting Automattic\Jetpack\Sync\Queue::pop() can also be of type null or object; however, Automattic\Jetpack\Sync\...e_Buffer::__construct() does only seem to accept array, maybe add an additional type check?

This check looks at variables that are passed out again to other methods.

If the outgoing method call has stricter type requirements than the method itself, an issue is raised.

An additional type check may prevent trouble.

Loading history...
241
		} else {
242
			// let's delete the checkin state.
243
			if ( $args['force'] ) {
244
				$queue->unlock();
245
			}
246
			$buffer = $this->get_buffer( $queue, $number_of_items );
247
		}
248
		// Check that the $buffer is not checkout out already.
249
		if ( is_wp_error( $buffer ) ) {
250
			return new WP_Error( 'buffer_open', "We couldn't get the buffer it is currently checked out", 400 );
0 ignored issues
show
Unused Code introduced by
The call to WP_Error::__construct() has too many arguments starting with 'buffer_open'.

This check compares calls to functions or methods with their respective definitions. If the call has more arguments than are defined, it raises an issue.

If a function is defined several times with a different number of parameters, the check may pick up the wrong definition and report false positives. One codebase where this has been known to happen is Wordpress.

In this case you can add the @ignore PhpDoc annotation to the duplicate definition and it will be ignored.

Loading history...
251
		}
252
253
		if ( ! is_object( $buffer ) ) {
254
			return new WP_Error( 'buffer_non-object', 'Buffer is not an object', 400 );
0 ignored issues
show
Unused Code introduced by
The call to WP_Error::__construct() has too many arguments starting with 'buffer_non-object'.

This check compares calls to functions or methods with their respective definitions. If the call has more arguments than are defined, it raises an issue.

If a function is defined several times with a different number of parameters, the check may pick up the wrong definition and report false positives. One codebase where this has been known to happen is Wordpress.

In this case you can add the @ignore PhpDoc annotation to the duplicate definition and it will be ignored.

Loading history...
255
		}
256
257
		Settings::set_is_syncing( true );
258
		list( $items_to_send, $skipped_items_ids ) = $sender->get_items_to_send( $buffer, $args['encode'] );
259
		Settings::set_is_syncing( false );
260
261
		return array(
262
			'buffer_id'      => $buffer->id,
263
			'items'          => $items_to_send,
264
			'skipped_items'  => $skipped_items_ids,
265
			'codec'          => $args['encode'] ? $sender->get_codec()->name() : null,
266
			'sent_timestamp' => time(),
267
		);
268
	}
269
270
	public $items = [];
271
272
	public function jetpack_sync_send_data_listener() {
273
		foreach ( func_get_args()[0] as $key => $item ) {
274
			$this->items[ $key ] = $item;
275
		}
276
	}
277
278
	/**
279
	 * Check out a buffer of full sync actions.
280
	 *
281
	 * @param null $number_of_items Number of Actions to check-out.
282
	 *
283
	 * @return array Sync Actions to be returned to requestor
284
	 */
285
	public function immediate_full_sync_pull( $number_of_items = null ) {
286
		// try to give ourselves as much time as possible.
287
		set_time_limit( 0 );
288
289
		$original_send_data_cb = array( 'Automattic\Jetpack\Sync\Actions', 'send_data' );
290
		$temp_send_data_cb     = array( $this, 'jetpack_sync_send_data_listener' );
291
292
		Sender::get_instance()->set_enqueue_wait_time( 0 );
293
		remove_filter( 'jetpack_sync_send_data', $original_send_data_cb );
294
		add_filter( 'jetpack_sync_send_data', $temp_send_data_cb, 10, 6 );
295
		Sender::get_instance()->do_full_sync();
296
		remove_filter( 'jetpack_sync_send_data', $temp_send_data_cb );
297
		add_filter( 'jetpack_sync_send_data', $original_send_data_cb, 10, 6 );
298
299
		return array(
300
			'items'          => $this->items,
301
			'codec'          => Sender::get_instance()->get_codec()->name(),
302
			'sent_timestamp' => time(),
303
			'status'         => Actions::get_sync_status(),
304
		);
305
	}
306
307
	protected function get_buffer( $queue, $number_of_items ) {
308
		$start = time();
309
		$max_duration = 5; // this will try to get the buffer
310
311
		$buffer = $queue->checkout( $number_of_items );
312
		$duration = time() - $start;
313
314
		while( is_wp_error( $buffer ) && $duration < $max_duration ) {
315
			sleep( 2 );
316
			$duration = time() - $start;
317
			$buffer = $queue->checkout( $number_of_items );
318
		}
319
320
		if ( $buffer === false ) {
321
			return new WP_Error( 'queue_size', 'The queue is empty and there is nothing to send', 400 );
0 ignored issues
show
Unused Code introduced by
The call to WP_Error::__construct() has too many arguments starting with 'queue_size'.

This check compares calls to functions or methods with their respective definitions. If the call has more arguments than are defined, it raises an issue.

If a function is defined several times with a different number of parameters, the check may pick up the wrong definition and report false positives. One codebase where this has been known to happen is Wordpress.

In this case you can add the @ignore PhpDoc annotation to the duplicate definition and it will be ignored.

Loading history...
322
		}
323
324
		return $buffer;
325
	}
326
}
327
328
class Jetpack_JSON_API_Sync_Close_Endpoint extends Jetpack_JSON_API_Sync_Endpoint {
329
	protected function result() {
330
331
		$request_body = $this->input();
332
		$queue_name = $this->validate_queue( $request_body['queue'] );
333
334
		if ( is_wp_error( $queue_name ) ) {
335
			return $queue_name;
336
		}
337
338
		if ( ! isset( $request_body['buffer_id'] ) ) {
339
			return new WP_Error( 'missing_buffer_id', 'Please provide a buffer id', 400 );
0 ignored issues
show
Unused Code introduced by
The call to WP_Error::__construct() has too many arguments starting with 'missing_buffer_id'.

This check compares calls to functions or methods with their respective definitions. If the call has more arguments than are defined, it raises an issue.

If a function is defined several times with a different number of parameters, the check may pick up the wrong definition and report false positives. One codebase where this has been known to happen is Wordpress.

In this case you can add the @ignore PhpDoc annotation to the duplicate definition and it will be ignored.

Loading history...
340
		}
341
342
		if ( ! isset( $request_body['item_ids'] ) || ! is_array( $request_body['item_ids'] ) ) {
343
			return new WP_Error( 'missing_item_ids', 'Please provide a list of item ids in the item_ids argument', 400 );
0 ignored issues
show
Unused Code introduced by
The call to WP_Error::__construct() has too many arguments starting with 'missing_item_ids'.

This check compares calls to functions or methods with their respective definitions. If the call has more arguments than are defined, it raises an issue.

If a function is defined several times with a different number of parameters, the check may pick up the wrong definition and report false positives. One codebase where this has been known to happen is Wordpress.

In this case you can add the @ignore PhpDoc annotation to the duplicate definition and it will be ignored.

Loading history...
344
		}
345
346
		//Limit to A-Z,a-z,0-9,_,-
347
		$request_body ['buffer_id'] = preg_replace( '/[^A-Za-z0-9]/', '', $request_body['buffer_id'] );
348
		$request_body['item_ids'] = array_filter( array_map( array( 'Jetpack_JSON_API_Sync_Close_Endpoint', 'sanitize_item_ids' ), $request_body['item_ids'] ) );
349
350
		$queue = new Queue( $queue_name );
351
352
		$items = $queue->peek_by_id( $request_body['item_ids'] );
353
354
		// Update Full Sync Status if queue is "full_sync".
355
		if ( 'full_sync' === $queue_name ) {
356
			$full_sync_module = Modules::get_module( 'full-sync' );
357
358
			$full_sync_module->update_sent_progress_action( $items );
359
		}
360
361
		$buffer = new Queue_Buffer( $request_body['buffer_id'], $request_body['item_ids'] );
362
		$response = $queue->close( $buffer, $request_body['item_ids'] );
0 ignored issues
show
Documentation introduced by
$buffer is of type object<Automattic\Jetpack\Sync\Queue_Buffer>, but the function expects a object<Automattic\Jetpac...pack\Sync\Queue_Buffer>.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
363
364
		// Perform another checkout?
365
		if ( isset( $request_body['continue'] ) && $request_body['continue'] ) {
366
			if ( in_array( $queue_name, array( 'full_sync', 'immediate' ), true ) ) {
367
				// Send Full Sync Actions.
368
				Sender::get_instance()->do_full_sync();
369
			} else {
370
				// Send Incremental Sync Actions.
371
				if ( $queue->has_any_items() ) {
372
					Sender::get_instance()->do_sync();
373
				}
374
			}
375
		}
376
377
		if ( is_wp_error( $response ) ) {
378
			return $response;
379
		}
380
381
		return array(
382
			'success' => $response,
383
			'status' => Actions::get_sync_status(),
384
		);
385
	}
386
387
	protected static function sanitize_item_ids( $item ) {
388
		// lets not delete any options that don't start with jpsq_sync-
389
		if ( ! is_string( $item ) || substr( $item, 0, 5 ) !== 'jpsq_' ) {
390
			return null;
391
		}
392
		//Limit to A-Z,a-z,0-9,_,-,.
393
		return preg_replace( '/[^A-Za-z0-9-_.]/', '', $item );
394
	}
395
}
396
397
class Jetpack_JSON_API_Sync_Unlock_Endpoint extends Jetpack_JSON_API_Sync_Endpoint {
398
	protected function result() {
399
		$args = $this->input();
400
401
		if ( ! isset( $args['queue'] ) ) {
402
			return new WP_Error( 'invalid_queue', 'Queue name is required', 400 );
0 ignored issues
show
Unused Code introduced by
The call to WP_Error::__construct() has too many arguments starting with 'invalid_queue'.

This check compares calls to functions or methods with their respective definitions. If the call has more arguments than are defined, it raises an issue.

If a function is defined several times with a different number of parameters, the check may pick up the wrong definition and report false positives. One codebase where this has been known to happen is Wordpress.

In this case you can add the @ignore PhpDoc annotation to the duplicate definition and it will be ignored.

Loading history...
403
		}
404
405 View Code Duplication
		if ( ! in_array( $args['queue'], array( 'sync', 'full_sync' ) ) ) {
406
			return new WP_Error( 'invalid_queue', 'Queue name should be sync or full_sync', 400 );
0 ignored issues
show
Unused Code introduced by
The call to WP_Error::__construct() has too many arguments starting with 'invalid_queue'.

This check compares calls to functions or methods with their respective definitions. If the call has more arguments than are defined, it raises an issue.

If a function is defined several times with a different number of parameters, the check may pick up the wrong definition and report false positives. One codebase where this has been known to happen is Wordpress.

In this case you can add the @ignore PhpDoc annotation to the duplicate definition and it will be ignored.

Loading history...
407
		}
408
409
		$queue = new Queue( $args['queue'] );
410
411
		// False means that there was no lock to delete.
412
		$response = $queue->unlock();
413
		return array(
414
			'success' => $response
415
		);
416
	}
417
}
418
419
class Jetpack_JSON_API_Sync_Object_Id_Range extends Jetpack_JSON_API_Sync_Endpoint {
420
	protected function result() {
421
		$args = $this->query_args();
422
423
		$module_name = $args['sync_module'];
424
		$batch_size  = $args['batch_size'];
425
426
		if ( ! $this->is_valid_sync_module( $module_name ) ) {
427
			return new WP_Error( 'invalid_module', 'This sync module cannot be used to calculate a range.', 400 );
0 ignored issues
show
Unused Code introduced by
The call to WP_Error::__construct() has too many arguments starting with 'invalid_module'.

This check compares calls to functions or methods with their respective definitions. If the call has more arguments than are defined, it raises an issue.

If a function is defined several times with a different number of parameters, the check may pick up the wrong definition and report false positives. One codebase where this has been known to happen is Wordpress.

In this case you can add the @ignore PhpDoc annotation to the duplicate definition and it will be ignored.

Loading history...
428
		}
429
430
		$module = Modules::get_module( $module_name );
431
432
		return array(
433
			'ranges' => $module->get_min_max_object_ids_for_batches( $batch_size ),
434
		);
435
	}
436
437
	protected function is_valid_sync_module( $module_name ) {
438
		return in_array(
439
			$module_name,
440
			array(
441
				'comments',
442
				'posts',
443
				'terms',
444
				'term_relationships',
445
				'users',
446
			),
447
			true
448
		);
449
	}
450
}
451