Completed
Push — add/sync-rest-2 ( ae2fc3...dfd2b5 )
by
unknown
137:46 queued 127:52
created

Jetpack_Sync::schedule_sync()   A

Complexity

Conditions 3
Paths 3

Size

Total Lines 9
Code Lines 6

Duplication

Lines 0
Ratio 0 %
Metric Value
dl 0
loc 9
rs 9.6666
cc 3
eloc 6
nc 3
nop 0
1
<?php
2
3
4
require_once 'class.jetpack-sync-client.php';
5
6
if ( is_multisite() ) {
7
	require_once 'class.jetpack-sync-network-options.php';
8
}
9
10
class Jetpack_Sync {
11
	static $client = null;
0 ignored issues
show
Coding Style introduced by
The visibility should be declared for property $client.

The PSR-2 coding standard requires that all properties in a class have their visibility explicitly declared. If you declare a property using

class A {
    var $property;
}

the property is implicitly global.

To learn more about the PSR-2, please see the PHP-FIG site on the PSR-2.

Loading history...
12
13
	static function init() {
14
15
		self::$client = Jetpack_Sync_Client::getInstance();
16
17
		// bind the do_sync process to shutdown
18
		add_action( 'shutdown', array( self::$client, 'do_sync' ) );
19
20
		// bind the sending process
21
		add_filter( 'jetpack_sync_client_send_data', array( __CLASS__, 'send_data' ) );
22
23
		// On jetpack version bump
24
		add_action( 'updating_jetpack_version', array( __CLASS__, 'schedule_full_sync' ) );
25
26
		// On jetpack registration
27
		add_action( 'jetpack_site_registered', array( __CLASS__, 'schedule_full_sync' ) );
28
	}
29
30
	static function send_data( $data ) {
31
		Jetpack::load_xml_rpc_client();
32
		$rpc = new Jetpack_IXR_Client( array(
33
			'user_id' => get_current_user_id(),
34
		) );
35
		$result = $rpc->query( 'jetpack.syncActions', $data );
36
		if ( ! $result ) {
37
			$error = $rpc->get_jetpack_error();
38
			error_log( $error->get_error_code() .': '.$error->get_error_message() );
39
		}
40
		return $result;
41
	}
42
43
	static function schedule_full_sync() {
44
		wp_schedule_single_event( time(), 'jetpack_sync_full' );
45
	}
46
47
	// static function get_data_to_sync() {
48
	// 	$send['current_user_id'] = get_current_user_id(); 
49
	// 	$send['options']        = Jetpack_Sync_Options::get_to_sync();
50
	// 	$send['options_delete'] = Jetpack_Sync_Options::get_to_delete();
51
	// 	$send['constants']      = self::sync_if_has_changed( Jetpack_Sync_Constants::$check_sum_id, Jetpack_Sync_Constants::get_all() );
52
53
	// 	$send['actions'] = self::get_actions_to_sync();
54
55
	// 	$send['post_meta']        = Jetpack_Sync_Meta::meta_to_sync( 'post' );
56
	// 	$send['post_meta_delete'] = Jetpack_Sync_Meta::meta_to_delete( 'post' );
57
58
	// 	$send['comments']            = Jetpack_Sync_Comments::comments_to_sync();
59
	// 	$send['delete_comments']     = Jetpack_Sync_Comments::comments_to_delete();
60
	// 	$send['comment_meta']        = Jetpack_Sync_Meta::meta_to_sync( 'comment' );
61
	// 	$send['comment_meta_delete'] = Jetpack_Sync_Meta::meta_to_delete( 'comment' );
62
63
	// 	$send['updates'] = Jetpack_Sync_Updates::get_to_sync();
64
	// 	$send['themes']  = Jetpack_Sync_Themes::get_to_sync();
65
66
	// 	if ( false === ( $do_check = get_transient( 'jetpack_sync_functions' ) ) ) {
67
	// 		$send['functions'] = self::sync_if_has_changed( Jetpack_Sync_Functions::$check_sum_id, Jetpack_Sync_Functions::get_all() );
68
	// 		set_transient( 'jetpack_sync_functions', true, MINUTE_IN_SECONDS );
69
	// 	}
70
	// 	if ( is_multisite() ) {
71
	// 		$send['network_options']        = Jetpack_Sync_Network_Options::get_to_sync();
72
	// 		$send['network_options_delete'] = Jetpack_Sync_Network_Options::get_to_delete();
73
	// 	}
74
75
	// 	return array_filter( $send );
76
	// }
77
78
79
	// TODO: use these for full sync
0 ignored issues
show
Coding Style Best Practice introduced by
Comments for TODO tasks are often forgotten in the code; it might be better to use a dedicated issue tracker.
Loading history...
80
81
	// static function get_all_data() {
82
	// 	$send['options']   = Jetpack_Sync_Options::get_all();
83
	// 	$send['constants'] = Jetpack_Sync_Constants::get_all();
84
	// 	$send['functions'] = Jetpack_Sync_Functions::get_all();
85
	// 	$send['updates']   = Jetpack_Sync_Updates::get_all();
86
	// 	$send['themes']    = Jetpack_Sync_Themes::get_all();
87
	// 	if ( is_multisite() ) {
88
	// 		$send['network_options'] = Jetpack_Sync_Network_Options::get_all();
89
	// 	}
90
91
	// 	return $send;
92
	// }
93
}
94
95
Jetpack_Sync::init();
96