Completed
Push — add/sync-action ( 3cad0f...8bf709 )
by
unknown
10:42 queued 01:16
created

Jetpack_JSON_API_Sync_Check_Endpoint::result()   B

Complexity

Conditions 3
Paths 3

Size

Total Lines 27
Code Lines 13

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 3
eloc 13
nc 3
nop 0
dl 0
loc 27
rs 8.8571
c 1
b 0
f 0
1
<?php
2
3
class Jetpack_JSON_API_Sync_Endpoint extends Jetpack_JSON_API_Endpoint {
4
	// POST /sites/%s/sync
5
	protected $needed_capabilities = 'manage_options';
6
7
	protected function result() {
8
		Jetpack::init();
9
		/** This action is documented in class.jetpack-sync-client.php */
10
		Jetpack_Sync_Actions::schedule_full_sync();
11
12
		return array( 'scheduled' => true );
13
	}
14
}
15
16
class Jetpack_JSON_API_Sync_Check_Endpoint extends Jetpack_JSON_API_Endpoint {
0 ignored issues
show
Coding Style Compatibility introduced by
PSR1 recommends that each class should be in its own file to aid autoloaders.

Having each class in a dedicated file usually plays nice with PSR autoloaders and is therefore a well established practice. If you use other autoloaders, you might not want to follow this rule.

Loading history...
17
	// POST /sites/%s/cached-data-check
18
	protected $needed_capabilities = 'manage_options';
19
20
	protected function result() {
21
		Jetpack::init();
22
		/** This action is documented in class.jetpack.php */
23
24
		$sync_queue = Jetpack_Sync_Client::getInstance()->get_sync_queue();
25
26
		// lock sending from the queue while we compare checksums with the server
27
		$result = $sync_queue->lock( 30 ); // tries to acquire the lock for up to 30 seconds
28
29
		if ( !$result ) {
30
			return new WP_Error( 'unknown_error', 'Unknown error trying to lock the sync queue' );
31
		}
32
33
		if ( is_wp_error( $result ) ) {
34
			return $result;
35
		}
36
37
		$store = new Jetpack_Sync_WP_Replicastore();
38
39
		// get the local checksums and return them
40
		$checksums = array(
41
			'posts' => $store->posts_checksum(),
42
			'comments' => $store->comments_checksum()
43
		);
44
		
45
		return $checksums;
46
	}
47
}