Completed
Push — add/sync-action ( 48c3b2...523b3d )
by
unknown
23:15 queued 11:55
created

Jetpack_JSON_API_Sync_Check_Endpoint::result()   A

Complexity

Conditions 3
Paths 3

Size

Total Lines 23
Code Lines 10

Duplication

Lines 0
Ratio 0 %

Importance

Changes 3
Bugs 0 Features 1
Metric Value
cc 3
eloc 10
c 3
b 0
f 1
nc 3
nop 0
dl 0
loc 23
rs 9.0856
1
<?php
2
3
require_once dirname(__FILE__).'/../../sync/class.jetpack-sync-wp-replicastore.php';
4
5
class Jetpack_JSON_API_Sync_Endpoint extends Jetpack_JSON_API_Endpoint {
6
	// POST /sites/%s/sync
7
	protected $needed_capabilities = 'manage_options';
8
9
	protected function result() {
10
		Jetpack::init();
11
		/** This action is documented in class.jetpack-sync-client.php */
12
		Jetpack_Sync_Actions::schedule_full_sync();
13
14
		return array( 'scheduled' => true );
15
	}
16
}
17
18
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...
19
	// POST /sites/%s/cached-data-check
20
	protected $needed_capabilities = array();
21
22
	protected function result() {
23
24
		Jetpack::init();
25
		/** This action is documented in class.jetpack.php */
26
27
		$sync_queue = Jetpack_Sync_Client::getInstance()->get_sync_queue();
28
29
		// lock sending from the queue while we compare checksums with the server
30
		$result = $sync_queue->lock( 30 ); // tries to acquire the lock for up to 30 seconds
31
32
		if ( !$result ) {
33
			return new WP_Error( 'unknown_error', 'Unknown error trying to lock the sync queue' );
34
		}
35
36
		if ( is_wp_error( $result ) ) {
37
			return $result;
38
		}
39
40
		$store = new Jetpack_Sync_WP_Replicastore();
41
42
		return $store->checksum_all();
43
44
	}
45
}
46