Completed
Push — add/api/custom-taxonomies ( 892668...9a5833 )
by
unknown
10:04
created

Jetpack_JSON_API_Sync_Status_Endpoint::result()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 1
Metric Value
cc 1
eloc 3
c 1
b 0
f 1
nc 1
nop 0
dl 0
loc 4
rs 10
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_Status_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
	// GET /sites/%s/sync/status
20
	protected $needed_capabilities = 'manage_options';
21
22
	protected function result() {
23
		$client = Jetpack_Sync_Client::getInstance();
24
		return $client->get_full_sync_client()->get_status();
25
	}
26
}
27
28
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...
29
	// GET /sites/%s/cached-data-check
30
	protected $needed_capabilities = 'manage_options';
31
32
	protected function result() {
33
34
		Jetpack::init();
35
36
		$client = Jetpack_Sync_Client::getInstance();
37
		$sync_queue = $client->get_sync_queue();
38
39
		// lock sending from the queue while we compare checksums with the server
40
		$result = $sync_queue->lock( 30 ); // tries to acquire the lock for up to 30 seconds
41
42
		if ( !$result ) {
43
			$sync_queue->unlock();
44
			return new WP_Error( 'unknown_error', 'Unknown error trying to lock the sync queue' );
45
		}
46
47
		if ( is_wp_error( $result ) ) {
48
			$sync_queue->unlock();
49
			return $result;
50
		}
51
52
		$store = new Jetpack_Sync_WP_Replicastore();
53
54
		$result = $store->checksum_all();
55
56
		$sync_queue->unlock();
57
58
		return $result;
59
60
	}
61
}
62
63
class Jetpack_JSON_API_Sync_Modify_Settings_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...
64
	// POST /sites/%s/sync/settings
65
	protected $needed_capabilities = 'manage_options';
66
67
	protected function result() {
68
		$args = $this->input();
69
70
		$client = Jetpack_Sync_Client::getInstance();
71
		$sync_settings = $client->get_settings();
72
73
		foreach( $args as $key => $value ) {
74
			if ( $value !== false ) {
75
				if ( is_numeric( $value ) ) {
76
					$value = (int) $value;
77
				}
78
				$sync_settings[ $key ] = $value;
79
			}
80
		}
81
82
		$client->update_settings( $sync_settings );
83
84
		// re-fetch so we see what's really being stored
85
		return $client->get_settings();
86
	}
87
}
88
89
class Jetpack_JSON_API_Sync_Get_Settings_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...
90
	// GET /sites/%s/sync/settings
91
	protected $needed_capabilities = 'manage_options';
92
93
	protected function result() {
94
		$client = Jetpack_Sync_Client::getInstance();
95
		return $client->get_settings();
96
	}
97
}
98