Completed
Push — fix/gulp-env ( ec4107...cf0b47 )
by
unknown
133:51 queued 124:05
created

Jetpack_Sync_Module_Updates   A

Complexity

Total Complexity 11

Size/Duplication

Total Lines 70
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 1

Importance

Changes 3
Bugs 0 Features 0
Metric Value
c 3
b 0
f 0
dl 0
loc 70
rs 10
wmc 11
lcom 0
cbo 1

9 Methods

Rating   Name   Duplication   Size   Complexity  
A init_before_send() 0 4 1
A enqueue_full_sync_actions() 0 11 1
A get_full_sync_actions() 0 3 1
A filter_upgrader_process_complete() 0 4 1
A expand_updates() 0 7 2
A name() 0 3 1
A init_listeners() 0 11 1
A get_all_updates() 0 7 1
A filter_update_keys() 0 9 2
1
<?php
2
3
class Jetpack_Sync_Module_Updates extends Jetpack_Sync_Module {
4
	function name() {
5
		return 'updates';
6
	}
7
8
	public function init_listeners( $callable ) {
9
		add_action( 'set_site_transient_update_plugins', $callable, 10, 1 );
10
		add_action( 'set_site_transient_update_themes', $callable, 10, 1 );
11
		add_action( 'set_site_transient_update_core', $callable, 10, 1 );
12
13
		// full sync
14
		add_action( 'jetpack_full_sync_updates', $callable );
15
16
		add_filter( 'jetpack_sync_before_enqueue_set_site_transient_update_plugins', array( $this, 'filter_update_keys' ), 10, 2 );
17
		add_filter( 'jetpack_sync_before_enqueue_upgrader_process_complete', array( $this, 'filter_upgrader_process_complete' ), 10, 2 );
18
	}
19
20
	public function init_before_send() {
21
		// full sync
22
		add_filter( 'jetpack_sync_before_send_jetpack_full_sync_updates', array( $this, 'expand_updates' ) );
23
	}
24
25
	public function enqueue_full_sync_actions() {
26
		/**
27
		 * Tells the client to sync all updates to the server
28
		 *
29
		 * @since 4.2.0
30
		 *
31
		 * @param boolean Whether to expand updates (should always be true)
32
		 */
33
		do_action( 'jetpack_full_sync_updates', true );
34
		return 1; // The number of actions enqueued
35
	}
36
37
	function get_full_sync_actions() {
38
		return array( 'jetpack_full_sync_updates' );
39
	}
40
41
	public function get_all_updates() {
42
		return array(
43
			'core' => get_site_transient( 'update_core' ),
44
			'plugins' => get_site_transient( 'update_plugins' ),
45
			'themes' => get_site_transient( 'update_themes' ),
46
		);
47
	}
48
49
	// removes unnecessary keys from synced updates data
50
	function filter_update_keys( $args ) {
51
		$updates = $args[0];
52
53
		if ( isset( $updates->no_update ) ) {
54
			unset( $updates->no_update );
55
		}
56
57
		return $args;
58
	}
59
60
	function filter_upgrader_process_complete( $args ) {
61
		array_shift( $args );
62
		return $args;
63
	}
64
65
	public function expand_updates( $args ) {
66
		if ( $args[0] ) {
67
			return $this->get_all_updates();
68
		}
69
70
		return $args;
71
	}
72
}
73