Completed
Push — add/sync-action ( ff861d...d04c20 )
by
unknown
10:36
created

Jetpack_JSON_API_Sync_Check_Endpoint   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 30
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 5

Importance

Changes 3
Bugs 1 Features 1
Metric Value
c 3
b 1
f 1
dl 0
loc 30
rs 10
wmc 4
lcom 1
cbo 5

1 Method

Rating   Name   Duplication   Size   Complexity  
B callback() 0 26 4
1
<?php
2
3
require_once '../../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...
Bug introduced by
There is one abstract method result in this class; you could implement it, or declare this class as abstract.
Loading history...
19
	// POST /sites/%s/cached-data-check
20
21
	public function callback( $path = '', $_blog_id = 0 ) {
22
		$blog_id = $this->api->switch_to_blog_and_validate_user( $this->api->get_blog_id( $_blog_id ) );
23
		if ( is_wp_error( $blog_id ) ) {
24
			return $blog_id;
25
		}
26
27
		Jetpack::init();
28
		/** This action is documented in class.jetpack.php */
29
30
		$sync_queue = Jetpack_Sync_Client::getInstance()->get_sync_queue();
31
32
		// lock sending from the queue while we compare checksums with the server
33
		$result = $sync_queue->lock( 30 ); // tries to acquire the lock for up to 30 seconds
34
35
		if ( !$result ) {
36
			return new WP_Error( 'unknown_error', 'Unknown error trying to lock the sync queue' );
37
		}
38
39
		if ( is_wp_error( $result ) ) {
40
			return $result;
41
		}
42
43
		$store = new Jetpack_Sync_WP_Replicastore();
44
45
		return $store->checksum_all();
46
	}
47
}