Completed
Push — master ( 587793...0cd805 )
by Naveen
01:22 queued 12s
created
dataset/background/stages/class-sync-background-process-posts-stage.php 2 patches
Indentation   +34 added lines, -34 removed lines patch added patch discarded remove patch
@@ -8,49 +8,49 @@  discard block
 block discarded – undo
8 8
 
9 9
 class Sync_Background_Process_Posts_Stage {
10 10
 
11
-	/**
12
-	 * @var Sync_Object_Adapter_Factory
13
-	 */
14
-	private $sync_object_adapter_factory;
11
+    /**
12
+     * @var Sync_Object_Adapter_Factory
13
+     */
14
+    private $sync_object_adapter_factory;
15 15
 
16
-	/**
17
-	 * Sync_Background_Process_Posts_Stage constructor.
18
-	 *
19
-	 * @param Sync_Object_Adapter_Factory $sync_object_adapter_factory
20
-	 */
21
-	public function __construct( $sync_object_adapter_factory ) {
22
-		$this->sync_object_adapter_factory = $sync_object_adapter_factory;
23
-	}
16
+    /**
17
+     * Sync_Background_Process_Posts_Stage constructor.
18
+     *
19
+     * @param Sync_Object_Adapter_Factory $sync_object_adapter_factory
20
+     */
21
+    public function __construct( $sync_object_adapter_factory ) {
22
+        $this->sync_object_adapter_factory = $sync_object_adapter_factory;
23
+    }
24 24
 
25
-	public function count() {
25
+    public function count() {
26 26
 
27
-		$post_types = get_post_types( array( 'public' => true ) );
27
+        $post_types = get_post_types( array( 'public' => true ) );
28 28
 
29
-		global $wpdb;
30
-		$in_post_type = implode( "','", array_map( 'esc_sql', $post_types ) );
31
-		$sql          = "
29
+        global $wpdb;
30
+        $in_post_type = implode( "','", array_map( 'esc_sql', $post_types ) );
31
+        $sql          = "
32 32
 			SELECT COUNT( 1 )
33 33
 			FROM $wpdb->posts
34 34
 			WHERE post_type IN ('$in_post_type')
35 35
 				AND post_status IN ( 'publish',  'future', 'draft', 'pending', 'private' )
36 36
 			";
37 37
 
38
-		return $wpdb->get_var( $sql ); // phpcs:ignore WordPress.DB.PreparedSQL.NotPrepared
39
-	}
38
+        return $wpdb->get_var( $sql ); // phpcs:ignore WordPress.DB.PreparedSQL.NotPrepared
39
+    }
40 40
 
41
-	/**
42
-	 * @param int $offset
43
-	 * @param int $limit
44
-	 *
45
-	 * @return Sync_Object_Adapter[]
46
-	 */
47
-	public function get_sync_object_adapters( $offset, $limit ) {
41
+    /**
42
+     * @param int $offset
43
+     * @param int $limit
44
+     *
45
+     * @return Sync_Object_Adapter[]
46
+     */
47
+    public function get_sync_object_adapters( $offset, $limit ) {
48 48
 
49
-		$post_types = get_post_types( array( 'public' => true ) );
49
+        $post_types = get_post_types( array( 'public' => true ) );
50 50
 
51
-		global $wpdb;
52
-		$in_post_type = implode( "','", array_map( 'esc_sql', $post_types ) );
53
-		$sql          = "
51
+        global $wpdb;
52
+        $in_post_type = implode( "','", array_map( 'esc_sql', $post_types ) );
53
+        $sql          = "
54 54
 			SELECT ID
55 55
 			FROM $wpdb->posts
56 56
 			WHERE post_type IN ('$in_post_type')
@@ -59,10 +59,10 @@  discard block
 block discarded – undo
59 59
 			LIMIT %d, %d
60 60
 			";
61 61
 
62
-		$ids = $wpdb->get_col( $wpdb->prepare( $sql, $offset, $limit ) ); // phpcs:ignore WordPress.DB.PreparedSQL.NotPrepared
62
+        $ids = $wpdb->get_col( $wpdb->prepare( $sql, $offset, $limit ) ); // phpcs:ignore WordPress.DB.PreparedSQL.NotPrepared
63 63
 
64
-		return $this->sync_object_adapter_factory
65
-			->create_many( Object_Type_Enum::POST, array_map( 'intval', $ids ) );
66
-	}
64
+        return $this->sync_object_adapter_factory
65
+            ->create_many( Object_Type_Enum::POST, array_map( 'intval', $ids ) );
66
+    }
67 67
 
68 68
 }
Please login to merge, or discard this patch.
Spacing   +9 added lines, -9 removed lines patch added patch discarded remove patch
@@ -18,16 +18,16 @@  discard block
 block discarded – undo
18 18
 	 *
19 19
 	 * @param Sync_Object_Adapter_Factory $sync_object_adapter_factory
20 20
 	 */
21
-	public function __construct( $sync_object_adapter_factory ) {
21
+	public function __construct($sync_object_adapter_factory) {
22 22
 		$this->sync_object_adapter_factory = $sync_object_adapter_factory;
23 23
 	}
24 24
 
25 25
 	public function count() {
26 26
 
27
-		$post_types = get_post_types( array( 'public' => true ) );
27
+		$post_types = get_post_types(array('public' => true));
28 28
 
29 29
 		global $wpdb;
30
-		$in_post_type = implode( "','", array_map( 'esc_sql', $post_types ) );
30
+		$in_post_type = implode("','", array_map('esc_sql', $post_types));
31 31
 		$sql          = "
32 32
 			SELECT COUNT( 1 )
33 33
 			FROM $wpdb->posts
@@ -35,7 +35,7 @@  discard block
 block discarded – undo
35 35
 				AND post_status IN ( 'publish',  'future', 'draft', 'pending', 'private' )
36 36
 			";
37 37
 
38
-		return $wpdb->get_var( $sql ); // phpcs:ignore WordPress.DB.PreparedSQL.NotPrepared
38
+		return $wpdb->get_var($sql); // phpcs:ignore WordPress.DB.PreparedSQL.NotPrepared
39 39
 	}
40 40
 
41 41
 	/**
@@ -44,12 +44,12 @@  discard block
 block discarded – undo
44 44
 	 *
45 45
 	 * @return Sync_Object_Adapter[]
46 46
 	 */
47
-	public function get_sync_object_adapters( $offset, $limit ) {
47
+	public function get_sync_object_adapters($offset, $limit) {
48 48
 
49
-		$post_types = get_post_types( array( 'public' => true ) );
49
+		$post_types = get_post_types(array('public' => true));
50 50
 
51 51
 		global $wpdb;
52
-		$in_post_type = implode( "','", array_map( 'esc_sql', $post_types ) );
52
+		$in_post_type = implode("','", array_map('esc_sql', $post_types));
53 53
 		$sql          = "
54 54
 			SELECT ID
55 55
 			FROM $wpdb->posts
@@ -59,10 +59,10 @@  discard block
 block discarded – undo
59 59
 			LIMIT %d, %d
60 60
 			";
61 61
 
62
-		$ids = $wpdb->get_col( $wpdb->prepare( $sql, $offset, $limit ) ); // phpcs:ignore WordPress.DB.PreparedSQL.NotPrepared
62
+		$ids = $wpdb->get_col($wpdb->prepare($sql, $offset, $limit)); // phpcs:ignore WordPress.DB.PreparedSQL.NotPrepared
63 63
 
64 64
 		return $this->sync_object_adapter_factory
65
-			->create_many( Object_Type_Enum::POST, array_map( 'intval', $ids ) );
65
+			->create_many(Object_Type_Enum::POST, array_map('intval', $ids));
66 66
 	}
67 67
 
68 68
 }
Please login to merge, or discard this patch.
dataset/background/stages/class-sync-background-process-users-stage.php 2 patches
Indentation   +32 added lines, -32 removed lines patch added patch discarded remove patch
@@ -7,39 +7,39 @@  discard block
 block discarded – undo
7 7
 
8 8
 class Sync_Background_Process_Users_Stage {
9 9
 
10
-	/**
11
-	 * @var Sync_Object_Adapter_Factory
12
-	 */
13
-	private $sync_object_adapter_factory;
10
+    /**
11
+     * @var Sync_Object_Adapter_Factory
12
+     */
13
+    private $sync_object_adapter_factory;
14 14
 
15
-	/**
16
-	 * Sync_Background_Process_Posts_Stage constructor.
17
-	 *
18
-	 * @param Sync_Object_Adapter_Factory $sync_object_adapter_factory
19
-	 */
20
-	public function __construct( $sync_object_adapter_factory ) {
21
-		$this->sync_object_adapter_factory = $sync_object_adapter_factory;
22
-	}
15
+    /**
16
+     * Sync_Background_Process_Posts_Stage constructor.
17
+     *
18
+     * @param Sync_Object_Adapter_Factory $sync_object_adapter_factory
19
+     */
20
+    public function __construct( $sync_object_adapter_factory ) {
21
+        $this->sync_object_adapter_factory = $sync_object_adapter_factory;
22
+    }
23 23
 
24
-	public function count() {
24
+    public function count() {
25 25
 
26
-		global $wpdb;
27
-		$in_post_type = $this->get_post_types_string();
28
-		$sql          = "
26
+        global $wpdb;
27
+        $in_post_type = $this->get_post_types_string();
28
+        $sql          = "
29 29
 			SELECT COUNT( DISTINCT post_author )
30 30
 			FROM $wpdb->posts
31 31
 			WHERE post_type IN ('$in_post_type')
32 32
 			AND post_status IN ( 'publish',  'future', 'draft', 'pending', 'private' )
33 33
 			";
34 34
 
35
-		return $wpdb->get_var( $sql ); // phpcs:ignore WordPress.DB.PreparedSQL.NotPrepared
36
-	}
35
+        return $wpdb->get_var( $sql ); // phpcs:ignore WordPress.DB.PreparedSQL.NotPrepared
36
+    }
37 37
 
38
-	public function get_sync_object_adapters( $offset, $limit ) {
38
+    public function get_sync_object_adapters( $offset, $limit ) {
39 39
 
40
-		global $wpdb;
41
-		$in_post_type = $this->get_post_types_string();
42
-		$sql          = "
40
+        global $wpdb;
41
+        $in_post_type = $this->get_post_types_string();
42
+        $sql          = "
43 43
 			SELECT DISTINCT post_author
44 44
 			FROM $wpdb->posts
45 45
 			WHERE post_type IN ('$in_post_type')
@@ -47,18 +47,18 @@  discard block
 block discarded – undo
47 47
 			LIMIT %d, %d
48 48
 			";
49 49
 
50
-		$ids = $wpdb->get_col( $wpdb->prepare( $sql, $offset, $limit ) ); // phpcs:ignore WordPress.DB.PreparedSQL.NotPrepared
50
+        $ids = $wpdb->get_col( $wpdb->prepare( $sql, $offset, $limit ) ); // phpcs:ignore WordPress.DB.PreparedSQL.NotPrepared
51 51
 
52
-		return $this->sync_object_adapter_factory->create_many( Object_Type_Enum::USER, $ids );
53
-	}
52
+        return $this->sync_object_adapter_factory->create_many( Object_Type_Enum::USER, $ids );
53
+    }
54 54
 
55
-	/**
56
-	 * @return string
57
-	 */
58
-	protected function get_post_types_string() {
59
-		$post_types = get_post_types( array( 'public' => true ) );
55
+    /**
56
+     * @return string
57
+     */
58
+    protected function get_post_types_string() {
59
+        $post_types = get_post_types( array( 'public' => true ) );
60 60
 
61
-		return implode( "','", array_map( 'esc_sql', $post_types ) );
62
-	}
61
+        return implode( "','", array_map( 'esc_sql', $post_types ) );
62
+    }
63 63
 
64 64
 }
Please login to merge, or discard this patch.
Spacing   +7 added lines, -7 removed lines patch added patch discarded remove patch
@@ -17,7 +17,7 @@  discard block
 block discarded – undo
17 17
 	 *
18 18
 	 * @param Sync_Object_Adapter_Factory $sync_object_adapter_factory
19 19
 	 */
20
-	public function __construct( $sync_object_adapter_factory ) {
20
+	public function __construct($sync_object_adapter_factory) {
21 21
 		$this->sync_object_adapter_factory = $sync_object_adapter_factory;
22 22
 	}
23 23
 
@@ -32,10 +32,10 @@  discard block
 block discarded – undo
32 32
 			AND post_status IN ( 'publish',  'future', 'draft', 'pending', 'private' )
33 33
 			";
34 34
 
35
-		return $wpdb->get_var( $sql ); // phpcs:ignore WordPress.DB.PreparedSQL.NotPrepared
35
+		return $wpdb->get_var($sql); // phpcs:ignore WordPress.DB.PreparedSQL.NotPrepared
36 36
 	}
37 37
 
38
-	public function get_sync_object_adapters( $offset, $limit ) {
38
+	public function get_sync_object_adapters($offset, $limit) {
39 39
 
40 40
 		global $wpdb;
41 41
 		$in_post_type = $this->get_post_types_string();
@@ -47,18 +47,18 @@  discard block
 block discarded – undo
47 47
 			LIMIT %d, %d
48 48
 			";
49 49
 
50
-		$ids = $wpdb->get_col( $wpdb->prepare( $sql, $offset, $limit ) ); // phpcs:ignore WordPress.DB.PreparedSQL.NotPrepared
50
+		$ids = $wpdb->get_col($wpdb->prepare($sql, $offset, $limit)); // phpcs:ignore WordPress.DB.PreparedSQL.NotPrepared
51 51
 
52
-		return $this->sync_object_adapter_factory->create_many( Object_Type_Enum::USER, $ids );
52
+		return $this->sync_object_adapter_factory->create_many(Object_Type_Enum::USER, $ids);
53 53
 	}
54 54
 
55 55
 	/**
56 56
 	 * @return string
57 57
 	 */
58 58
 	protected function get_post_types_string() {
59
-		$post_types = get_post_types( array( 'public' => true ) );
59
+		$post_types = get_post_types(array('public' => true));
60 60
 
61
-		return implode( "','", array_map( 'esc_sql', $post_types ) );
61
+		return implode("','", array_map('esc_sql', $post_types));
62 62
 	}
63 63
 
64 64
 }
Please login to merge, or discard this patch.
src/wordlift/dataset/background/stages/class-sync-background-stage.php 2 patches
Indentation   +2 added lines, -2 removed lines patch added patch discarded remove patch
@@ -4,8 +4,8 @@
 block discarded – undo
4 4
 
5 5
 interface Sync_Background_Process_Stage {
6 6
 
7
-	public function count();
7
+    public function count();
8 8
 
9
-	public function get_sync_object_adapters( $offset, $batch_size );
9
+    public function get_sync_object_adapters( $offset, $batch_size );
10 10
 
11 11
 }
Please login to merge, or discard this patch.
Spacing   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -6,6 +6,6 @@
 block discarded – undo
6 6
 
7 7
 	public function count();
8 8
 
9
-	public function get_sync_object_adapters( $offset, $batch_size );
9
+	public function get_sync_object_adapters($offset, $batch_size);
10 10
 
11 11
 }
Please login to merge, or discard this patch.
wordlift/dataset/background/class-sync-background-process-stopped-state.php 2 patches
Indentation   +19 added lines, -19 removed lines patch added patch discarded remove patch
@@ -4,31 +4,31 @@
 block discarded – undo
4 4
 
5 5
 class Sync_Background_Process_Stopped_State extends Abstract_Sync_Background_Process_State {
6 6
 
7
-	/**
8
-	 * @var Sync_Background_Process
9
-	 */
10
-	private $context;
7
+    /**
8
+     * @var Sync_Background_Process
9
+     */
10
+    private $context;
11 11
 
12
-	public function __construct( $context ) {
13
-		parent::__construct( Sync_Background_Process::STATE_STOPPED );
12
+    public function __construct( $context ) {
13
+        parent::__construct( Sync_Background_Process::STATE_STOPPED );
14 14
 
15
-		$this->context = $context;
16
-	}
15
+        $this->context = $context;
16
+    }
17 17
 
18
-	public function enter() {
19
-		$this->context->set_state( Sync_Background_Process::STATE_STOPPED );
20
-	}
18
+    public function enter() {
19
+        $this->context->set_state( Sync_Background_Process::STATE_STOPPED );
20
+    }
21 21
 
22
-	public function leave() {
23
-		$this->context->set_state( null );
24
-	}
22
+    public function leave() {
23
+        $this->context->set_state( null );
24
+    }
25 25
 
26
-	// phpcs:ignore VariableAnalysis.CodeAnalysis.VariableAnalysis.UnusedVariable
27
-	public function task( $item ) {
26
+    // phpcs:ignore VariableAnalysis.CodeAnalysis.VariableAnalysis.UnusedVariable
27
+    public function task( $item ) {
28 28
 
29
-		$this->context->cancel_process();
29
+        $this->context->cancel_process();
30 30
 
31
-		return false;
32
-	}
31
+        return false;
32
+    }
33 33
 
34 34
 }
Please login to merge, or discard this patch.
Spacing   +5 added lines, -5 removed lines patch added patch discarded remove patch
@@ -9,22 +9,22 @@
 block discarded – undo
9 9
 	 */
10 10
 	private $context;
11 11
 
12
-	public function __construct( $context ) {
13
-		parent::__construct( Sync_Background_Process::STATE_STOPPED );
12
+	public function __construct($context) {
13
+		parent::__construct(Sync_Background_Process::STATE_STOPPED);
14 14
 
15 15
 		$this->context = $context;
16 16
 	}
17 17
 
18 18
 	public function enter() {
19
-		$this->context->set_state( Sync_Background_Process::STATE_STOPPED );
19
+		$this->context->set_state(Sync_Background_Process::STATE_STOPPED);
20 20
 	}
21 21
 
22 22
 	public function leave() {
23
-		$this->context->set_state( null );
23
+		$this->context->set_state(null);
24 24
 	}
25 25
 
26 26
 	// phpcs:ignore VariableAnalysis.CodeAnalysis.VariableAnalysis.UnusedVariable
27
-	public function task( $item ) {
27
+	public function task($item) {
28 28
 
29 29
 		$this->context->cancel_process();
30 30
 
Please login to merge, or discard this patch.
wordlift/dataset/background/class-sync-background-process-started-state.php 2 patches
Indentation   +133 added lines, -133 removed lines patch added patch discarded remove patch
@@ -11,138 +11,138 @@
 block discarded – undo
11 11
 
12 12
 class Sync_Background_Process_Started_State extends Abstract_Sync_Background_Process_State {
13 13
 
14
-	/**
15
-	 * @var Sync_Background_Process
16
-	 */
17
-	private $context;
18
-
19
-	/**
20
-	 * @var Sync_Service
21
-	 */
22
-	private $sync_service;
23
-
24
-	/**
25
-	 * @var Sync_Background_Process_Stage[]
26
-	 */
27
-	private $stages;
28
-
29
-	private $batch_size = 5;
30
-	/**
31
-	 * @var bool
32
-	 */
33
-	private $reset;
34
-
35
-	/**
36
-	 * Sync_Background_Process_Started_State constructor.
37
-	 *
38
-	 * @param Sync_Background_Process     $context
39
-	 * @param Sync_Service                $sync_service
40
-	 * @param Sync_Object_Adapter_Factory $sync_object_adapter_factory
41
-	 * @param bool                        $reset Whether to reset the counters
42
-	 */
43
-	// phpcs:ignore VariableAnalysis.CodeAnalysis.VariableAnalysis.UnusedVariable
44
-	public function __construct( $context, $sync_service, $sync_object_adapter_factory, $reset = true ) {
45
-		parent::__construct( Sync_Background_Process::STATE_STARTED );
46
-
47
-		$this->context      = $context;
48
-		$this->sync_service = $sync_service;
49
-
50
-		$this->stages = array(
51
-			new Sync_Background_Process_Posts_Stage( $sync_object_adapter_factory ),
52
-			new Sync_Background_Process_Terms_Stage( $sync_object_adapter_factory ),
53
-			new Sync_Background_Process_Users_Stage( $sync_object_adapter_factory ),
54
-		);
55
-	}
56
-
57
-	public function enter() {
58
-		// Delete the KG contents.
59
-		$this->sync_service->delete_all();
60
-
61
-		// Clear caches.
62
-		do_action( 'wl_ttl_cache_cleaner__flush' );
63
-
64
-		$counts = array_map(
65
-			function ( $item ) {
66
-				return $item->count();
67
-			},
68
-			$this->stages
69
-		);
70
-
71
-		update_option( '_wl_sync_background_process_count', $counts, true );
72
-		update_option( '_wl_sync_background_process_stage', 0, true );
73
-		update_option( '_wl_sync_background_process_offset', 0, true );
74
-		update_option( '_wl_sync_background_process_started', time(), true );
75
-		update_option( '_wl_sync_background_process_updated', time(), true );
76
-
77
-		$this->context->set_state( Sync_Background_Process::STATE_STARTED );
78
-
79
-		$this->resume();
80
-	}
81
-
82
-	public function resume() {
83
-		$this->context->push_to_queue( true );
84
-		$this->context->save()->dispatch();
85
-	}
86
-
87
-	public function leave() {
88
-		$this->context->set_state( null );
89
-	}
90
-
91
-	// phpcs:ignore VariableAnalysis.CodeAnalysis.VariableAnalysis.UnusedVariable
92
-	public function task( $args ) {
93
-
94
-		$offset     = get_option( '_wl_sync_background_process_offset' );
95
-		$stage      = get_option( '_wl_sync_background_process_stage' );
96
-		$counts     = get_option( '_wl_sync_background_process_count' );
97
-		$batch_size = min( $counts[ $stage ] - $offset, $this->batch_size );
98
-
99
-		add_filter( 'wl_api_service__request', array( $this, 'api_service__request' ) );
100
-		try {
101
-			$object_adapters = $this->stages[ $stage ]->get_sync_object_adapters( $offset, $batch_size );
102
-			$this->sync_service->sync_many( $object_adapters, true );
103
-		// phpcs:ignore Generic.CodeAnalysis.EmptyStatement.DetectedCatch
104
-		} catch ( \Exception $e ) {
105
-			// ignored.
106
-		}
107
-		remove_filter( 'wl_api_service__request', array( $this, 'api_service__request' ) );
108
-
109
-		update_option( '_wl_sync_background_process_updated', time(), true );
110
-
111
-		// Increase the offset.
112
-		if ( ( $offset + $batch_size ) < $counts[ $stage ] ) {
113
-			update_option( '_wl_sync_background_process_offset', $offset + $batch_size, true );
114
-
115
-			return true;
116
-		}
117
-
118
-		// Increase the stage.
119
-		if ( ( $stage + 1 ) < count( $this->stages ) ) {
120
-			update_option( '_wl_sync_background_process_stage', $stage + 1, true );
121
-			update_option( '_wl_sync_background_process_offset', 0, true );
122
-
123
-			return true;
124
-		}
125
-
126
-		// Stop processing.
127
-		$this->context->stop();
128
-
129
-		return false;
130
-	}
131
-
132
-	/**
133
-	 * Hook to provide a request to update the status on the server.
134
-	 *
135
-	 * @param array $args
136
-	 *
137
-	 * @return mixed
138
-	 */
139
-	public function api_service__request( $args ) {
140
-
141
-		$state_header_value = str_replace( "\n", '', wp_json_encode( $this->context->get_info() ) );
142
-
143
-		$args['headers']['X-Wordlift-Dataset-Sync-State-V1'] = $state_header_value;
144
-
145
-		return $args;
146
-	}
14
+    /**
15
+     * @var Sync_Background_Process
16
+     */
17
+    private $context;
18
+
19
+    /**
20
+     * @var Sync_Service
21
+     */
22
+    private $sync_service;
23
+
24
+    /**
25
+     * @var Sync_Background_Process_Stage[]
26
+     */
27
+    private $stages;
28
+
29
+    private $batch_size = 5;
30
+    /**
31
+     * @var bool
32
+     */
33
+    private $reset;
34
+
35
+    /**
36
+     * Sync_Background_Process_Started_State constructor.
37
+     *
38
+     * @param Sync_Background_Process     $context
39
+     * @param Sync_Service                $sync_service
40
+     * @param Sync_Object_Adapter_Factory $sync_object_adapter_factory
41
+     * @param bool                        $reset Whether to reset the counters
42
+     */
43
+    // phpcs:ignore VariableAnalysis.CodeAnalysis.VariableAnalysis.UnusedVariable
44
+    public function __construct( $context, $sync_service, $sync_object_adapter_factory, $reset = true ) {
45
+        parent::__construct( Sync_Background_Process::STATE_STARTED );
46
+
47
+        $this->context      = $context;
48
+        $this->sync_service = $sync_service;
49
+
50
+        $this->stages = array(
51
+            new Sync_Background_Process_Posts_Stage( $sync_object_adapter_factory ),
52
+            new Sync_Background_Process_Terms_Stage( $sync_object_adapter_factory ),
53
+            new Sync_Background_Process_Users_Stage( $sync_object_adapter_factory ),
54
+        );
55
+    }
56
+
57
+    public function enter() {
58
+        // Delete the KG contents.
59
+        $this->sync_service->delete_all();
60
+
61
+        // Clear caches.
62
+        do_action( 'wl_ttl_cache_cleaner__flush' );
63
+
64
+        $counts = array_map(
65
+            function ( $item ) {
66
+                return $item->count();
67
+            },
68
+            $this->stages
69
+        );
70
+
71
+        update_option( '_wl_sync_background_process_count', $counts, true );
72
+        update_option( '_wl_sync_background_process_stage', 0, true );
73
+        update_option( '_wl_sync_background_process_offset', 0, true );
74
+        update_option( '_wl_sync_background_process_started', time(), true );
75
+        update_option( '_wl_sync_background_process_updated', time(), true );
76
+
77
+        $this->context->set_state( Sync_Background_Process::STATE_STARTED );
78
+
79
+        $this->resume();
80
+    }
81
+
82
+    public function resume() {
83
+        $this->context->push_to_queue( true );
84
+        $this->context->save()->dispatch();
85
+    }
86
+
87
+    public function leave() {
88
+        $this->context->set_state( null );
89
+    }
90
+
91
+    // phpcs:ignore VariableAnalysis.CodeAnalysis.VariableAnalysis.UnusedVariable
92
+    public function task( $args ) {
93
+
94
+        $offset     = get_option( '_wl_sync_background_process_offset' );
95
+        $stage      = get_option( '_wl_sync_background_process_stage' );
96
+        $counts     = get_option( '_wl_sync_background_process_count' );
97
+        $batch_size = min( $counts[ $stage ] - $offset, $this->batch_size );
98
+
99
+        add_filter( 'wl_api_service__request', array( $this, 'api_service__request' ) );
100
+        try {
101
+            $object_adapters = $this->stages[ $stage ]->get_sync_object_adapters( $offset, $batch_size );
102
+            $this->sync_service->sync_many( $object_adapters, true );
103
+        // phpcs:ignore Generic.CodeAnalysis.EmptyStatement.DetectedCatch
104
+        } catch ( \Exception $e ) {
105
+            // ignored.
106
+        }
107
+        remove_filter( 'wl_api_service__request', array( $this, 'api_service__request' ) );
108
+
109
+        update_option( '_wl_sync_background_process_updated', time(), true );
110
+
111
+        // Increase the offset.
112
+        if ( ( $offset + $batch_size ) < $counts[ $stage ] ) {
113
+            update_option( '_wl_sync_background_process_offset', $offset + $batch_size, true );
114
+
115
+            return true;
116
+        }
117
+
118
+        // Increase the stage.
119
+        if ( ( $stage + 1 ) < count( $this->stages ) ) {
120
+            update_option( '_wl_sync_background_process_stage', $stage + 1, true );
121
+            update_option( '_wl_sync_background_process_offset', 0, true );
122
+
123
+            return true;
124
+        }
125
+
126
+        // Stop processing.
127
+        $this->context->stop();
128
+
129
+        return false;
130
+    }
131
+
132
+    /**
133
+     * Hook to provide a request to update the status on the server.
134
+     *
135
+     * @param array $args
136
+     *
137
+     * @return mixed
138
+     */
139
+    public function api_service__request( $args ) {
140
+
141
+        $state_header_value = str_replace( "\n", '', wp_json_encode( $this->context->get_info() ) );
142
+
143
+        $args['headers']['X-Wordlift-Dataset-Sync-State-V1'] = $state_header_value;
144
+
145
+        return $args;
146
+    }
147 147
 
148 148
 }
Please login to merge, or discard this patch.
Spacing   +33 added lines, -33 removed lines patch added patch discarded remove patch
@@ -41,16 +41,16 @@  discard block
 block discarded – undo
41 41
 	 * @param bool                        $reset Whether to reset the counters
42 42
 	 */
43 43
 	// phpcs:ignore VariableAnalysis.CodeAnalysis.VariableAnalysis.UnusedVariable
44
-	public function __construct( $context, $sync_service, $sync_object_adapter_factory, $reset = true ) {
45
-		parent::__construct( Sync_Background_Process::STATE_STARTED );
44
+	public function __construct($context, $sync_service, $sync_object_adapter_factory, $reset = true) {
45
+		parent::__construct(Sync_Background_Process::STATE_STARTED);
46 46
 
47 47
 		$this->context      = $context;
48 48
 		$this->sync_service = $sync_service;
49 49
 
50 50
 		$this->stages = array(
51
-			new Sync_Background_Process_Posts_Stage( $sync_object_adapter_factory ),
52
-			new Sync_Background_Process_Terms_Stage( $sync_object_adapter_factory ),
53
-			new Sync_Background_Process_Users_Stage( $sync_object_adapter_factory ),
51
+			new Sync_Background_Process_Posts_Stage($sync_object_adapter_factory),
52
+			new Sync_Background_Process_Terms_Stage($sync_object_adapter_factory),
53
+			new Sync_Background_Process_Users_Stage($sync_object_adapter_factory),
54 54
 		);
55 55
 	}
56 56
 
@@ -59,66 +59,66 @@  discard block
 block discarded – undo
59 59
 		$this->sync_service->delete_all();
60 60
 
61 61
 		// Clear caches.
62
-		do_action( 'wl_ttl_cache_cleaner__flush' );
62
+		do_action('wl_ttl_cache_cleaner__flush');
63 63
 
64 64
 		$counts = array_map(
65
-			function ( $item ) {
65
+			function($item) {
66 66
 				return $item->count();
67 67
 			},
68 68
 			$this->stages
69 69
 		);
70 70
 
71
-		update_option( '_wl_sync_background_process_count', $counts, true );
72
-		update_option( '_wl_sync_background_process_stage', 0, true );
73
-		update_option( '_wl_sync_background_process_offset', 0, true );
74
-		update_option( '_wl_sync_background_process_started', time(), true );
75
-		update_option( '_wl_sync_background_process_updated', time(), true );
71
+		update_option('_wl_sync_background_process_count', $counts, true);
72
+		update_option('_wl_sync_background_process_stage', 0, true);
73
+		update_option('_wl_sync_background_process_offset', 0, true);
74
+		update_option('_wl_sync_background_process_started', time(), true);
75
+		update_option('_wl_sync_background_process_updated', time(), true);
76 76
 
77
-		$this->context->set_state( Sync_Background_Process::STATE_STARTED );
77
+		$this->context->set_state(Sync_Background_Process::STATE_STARTED);
78 78
 
79 79
 		$this->resume();
80 80
 	}
81 81
 
82 82
 	public function resume() {
83
-		$this->context->push_to_queue( true );
83
+		$this->context->push_to_queue(true);
84 84
 		$this->context->save()->dispatch();
85 85
 	}
86 86
 
87 87
 	public function leave() {
88
-		$this->context->set_state( null );
88
+		$this->context->set_state(null);
89 89
 	}
90 90
 
91 91
 	// phpcs:ignore VariableAnalysis.CodeAnalysis.VariableAnalysis.UnusedVariable
92
-	public function task( $args ) {
92
+	public function task($args) {
93 93
 
94
-		$offset     = get_option( '_wl_sync_background_process_offset' );
95
-		$stage      = get_option( '_wl_sync_background_process_stage' );
96
-		$counts     = get_option( '_wl_sync_background_process_count' );
97
-		$batch_size = min( $counts[ $stage ] - $offset, $this->batch_size );
94
+		$offset     = get_option('_wl_sync_background_process_offset');
95
+		$stage      = get_option('_wl_sync_background_process_stage');
96
+		$counts     = get_option('_wl_sync_background_process_count');
97
+		$batch_size = min($counts[$stage] - $offset, $this->batch_size);
98 98
 
99
-		add_filter( 'wl_api_service__request', array( $this, 'api_service__request' ) );
99
+		add_filter('wl_api_service__request', array($this, 'api_service__request'));
100 100
 		try {
101
-			$object_adapters = $this->stages[ $stage ]->get_sync_object_adapters( $offset, $batch_size );
102
-			$this->sync_service->sync_many( $object_adapters, true );
101
+			$object_adapters = $this->stages[$stage]->get_sync_object_adapters($offset, $batch_size);
102
+			$this->sync_service->sync_many($object_adapters, true);
103 103
 		// phpcs:ignore Generic.CodeAnalysis.EmptyStatement.DetectedCatch
104
-		} catch ( \Exception $e ) {
104
+		} catch (\Exception $e) {
105 105
 			// ignored.
106 106
 		}
107
-		remove_filter( 'wl_api_service__request', array( $this, 'api_service__request' ) );
107
+		remove_filter('wl_api_service__request', array($this, 'api_service__request'));
108 108
 
109
-		update_option( '_wl_sync_background_process_updated', time(), true );
109
+		update_option('_wl_sync_background_process_updated', time(), true);
110 110
 
111 111
 		// Increase the offset.
112
-		if ( ( $offset + $batch_size ) < $counts[ $stage ] ) {
113
-			update_option( '_wl_sync_background_process_offset', $offset + $batch_size, true );
112
+		if (($offset + $batch_size) < $counts[$stage]) {
113
+			update_option('_wl_sync_background_process_offset', $offset + $batch_size, true);
114 114
 
115 115
 			return true;
116 116
 		}
117 117
 
118 118
 		// Increase the stage.
119
-		if ( ( $stage + 1 ) < count( $this->stages ) ) {
120
-			update_option( '_wl_sync_background_process_stage', $stage + 1, true );
121
-			update_option( '_wl_sync_background_process_offset', 0, true );
119
+		if (($stage + 1) < count($this->stages)) {
120
+			update_option('_wl_sync_background_process_stage', $stage + 1, true);
121
+			update_option('_wl_sync_background_process_offset', 0, true);
122 122
 
123 123
 			return true;
124 124
 		}
@@ -136,9 +136,9 @@  discard block
 block discarded – undo
136 136
 	 *
137 137
 	 * @return mixed
138 138
 	 */
139
-	public function api_service__request( $args ) {
139
+	public function api_service__request($args) {
140 140
 
141
-		$state_header_value = str_replace( "\n", '', wp_json_encode( $this->context->get_info() ) );
141
+		$state_header_value = str_replace("\n", '', wp_json_encode($this->context->get_info()));
142 142
 
143 143
 		$args['headers']['X-Wordlift-Dataset-Sync-State-V1'] = $state_header_value;
144 144
 
Please login to merge, or discard this patch.
src/wordlift/dataset/class-sync-term-adapter.php 2 patches
Indentation   +37 added lines, -37 removed lines patch added patch discarded remove patch
@@ -5,42 +5,42 @@
 block discarded – undo
5 5
 use Wordlift\Object_Type_Enum;
6 6
 
7 7
 class Sync_Term_Adapter extends Abstract_Sync_Object_Adapter {
8
-	/**
9
-	 * @var int
10
-	 */
11
-	private $term_id;
12
-
13
-	/**
14
-	 * Sync_Term_Adapter constructor.
15
-	 *
16
-	 * @param int $term_id
17
-	 *
18
-	 * @throws \Exception when an error occurs.
19
-	 */
20
-	public function __construct( $term_id ) {
21
-		parent::__construct( Object_Type_Enum::TERM, $term_id );
22
-
23
-		$this->term_id = $term_id;
24
-	}
25
-
26
-	public function is_published() {
27
-		return $this->is_public();
28
-	}
29
-
30
-	public function is_public() {
31
-		$term = get_term( $this->term_id );
32
-
33
-		return get_taxonomy( $term->taxonomy )->public;
34
-	}
35
-
36
-	// phpcs:ignore VariableAnalysis.CodeAnalysis.VariableAnalysis.UnusedVariable
37
-	public function set_values( $arr ) {
38
-		// @@todo
39
-	}
40
-
41
-	// phpcs:ignore VariableAnalysis.CodeAnalysis.VariableAnalysis.UnusedVariable
42
-	public function get_value( $key ) {
43
-		// @@todo
44
-	}
8
+    /**
9
+     * @var int
10
+     */
11
+    private $term_id;
12
+
13
+    /**
14
+     * Sync_Term_Adapter constructor.
15
+     *
16
+     * @param int $term_id
17
+     *
18
+     * @throws \Exception when an error occurs.
19
+     */
20
+    public function __construct( $term_id ) {
21
+        parent::__construct( Object_Type_Enum::TERM, $term_id );
22
+
23
+        $this->term_id = $term_id;
24
+    }
25
+
26
+    public function is_published() {
27
+        return $this->is_public();
28
+    }
29
+
30
+    public function is_public() {
31
+        $term = get_term( $this->term_id );
32
+
33
+        return get_taxonomy( $term->taxonomy )->public;
34
+    }
35
+
36
+    // phpcs:ignore VariableAnalysis.CodeAnalysis.VariableAnalysis.UnusedVariable
37
+    public function set_values( $arr ) {
38
+        // @@todo
39
+    }
40
+
41
+    // phpcs:ignore VariableAnalysis.CodeAnalysis.VariableAnalysis.UnusedVariable
42
+    public function get_value( $key ) {
43
+        // @@todo
44
+    }
45 45
 
46 46
 }
Please login to merge, or discard this patch.
Spacing   +6 added lines, -6 removed lines patch added patch discarded remove patch
@@ -17,8 +17,8 @@  discard block
 block discarded – undo
17 17
 	 *
18 18
 	 * @throws \Exception when an error occurs.
19 19
 	 */
20
-	public function __construct( $term_id ) {
21
-		parent::__construct( Object_Type_Enum::TERM, $term_id );
20
+	public function __construct($term_id) {
21
+		parent::__construct(Object_Type_Enum::TERM, $term_id);
22 22
 
23 23
 		$this->term_id = $term_id;
24 24
 	}
@@ -28,18 +28,18 @@  discard block
 block discarded – undo
28 28
 	}
29 29
 
30 30
 	public function is_public() {
31
-		$term = get_term( $this->term_id );
31
+		$term = get_term($this->term_id);
32 32
 
33
-		return get_taxonomy( $term->taxonomy )->public;
33
+		return get_taxonomy($term->taxonomy)->public;
34 34
 	}
35 35
 
36 36
 	// phpcs:ignore VariableAnalysis.CodeAnalysis.VariableAnalysis.UnusedVariable
37
-	public function set_values( $arr ) {
37
+	public function set_values($arr) {
38 38
 		// @@todo
39 39
 	}
40 40
 
41 41
 	// phpcs:ignore VariableAnalysis.CodeAnalysis.VariableAnalysis.UnusedVariable
42
-	public function get_value( $key ) {
42
+	public function get_value($key) {
43 43
 		// @@todo
44 44
 	}
45 45
 
Please login to merge, or discard this patch.
src/wordlift/dataset/class-sync-post-hooks.php 2 patches
Indentation   +138 added lines, -138 removed lines patch added patch discarded remove patch
@@ -7,143 +7,143 @@
 block discarded – undo
7 7
 use Wordlift\Object_Type_Enum;
8 8
 
9 9
 class Sync_Post_Hooks extends Abstract_Sync_Hooks {
10
-	/**
11
-	 * @var \Wordlift_Log_Service
12
-	 */
13
-	private $log;
14
-
15
-	/**
16
-	 * @var Sync_Service
17
-	 */
18
-	private $sync_service;
19
-
20
-	/**
21
-	 * @var Sync_Object_Adapter_Factory
22
-	 */
23
-	private $sync_object_factory;
24
-
25
-	/**
26
-	 * Sync_Post_Hooks constructor.
27
-	 *
28
-	 * @param Sync_Service                $sync_service
29
-	 * @param Sync_Object_Adapter_Factory $sync_object_factory
30
-	 */
31
-	public function __construct( $sync_service, $sync_object_factory ) {
32
-		parent::__construct();
33
-
34
-		$this->log = \Wordlift_Log_Service::get_logger( get_class() );
35
-
36
-		$this->sync_service        = $sync_service;
37
-		$this->sync_object_factory = $sync_object_factory;
38
-
39
-		$this->register_hooks();
40
-	}
41
-
42
-	private function register_hooks() {
43
-		/**
44
-		 * Register hooks for post and meta.
45
-		 */
46
-		add_action( 'save_post', array( $this, 'save_post' ) );
47
-		add_action( 'added_post_meta', array( $this, 'changed_post_meta' ), 10, 4 );
48
-		add_action( 'updated_post_meta', array( $this, 'changed_post_meta' ), 10, 4 );
49
-		add_action( 'deleted_post_meta', array( $this, 'changed_post_meta' ), 10, 4 );
50
-
51
-		// running this on delete_post wouldnt work because at that time
52
-		// entity_url would be deleted, so we cant delete this item from KG.
53
-		add_action( 'before_delete_post', array( $this, 'delete_post' ) );
54
-
55
-		// Remove post when its trashed.
56
-		add_action( 'trashed_post', array( $this, 'delete_post' ) );
57
-		// Save the post when its untrashed.
58
-		add_action( 'untrashed_post', array( $this, 'save_post' ) );
59
-		// Get sticky posts changes.
60
-		add_action( 'update_option_sticky_posts', array( $this, 'sticky_posts' ), 10, 2 );
61
-
62
-	}
63
-
64
-	public function save_post( $post_id ) {
65
-
66
-		if ( ! in_array( get_post_type( $post_id ), \Wordlift_Entity_Service::valid_entity_post_types(), true ) ) {
67
-			return;
68
-		}
69
-
70
-		$this->sync( $post_id );
71
-
72
-	}
73
-
74
-	public function sticky_posts( $old_value, $value ) {
75
-		foreach ( $old_value as $post_id ) {
76
-			$this->sync( $post_id );
77
-		}
78
-
79
-		foreach ( $value as $post_id ) {
80
-			$this->sync( $post_id );
81
-		}
82
-	}
83
-
84
-	// phpcs:ignore VariableAnalysis.CodeAnalysis.VariableAnalysis.UnusedVariable
85
-	public function changed_post_meta( $meta_id, $post_id, $meta_key, $_meta_value ) {
86
-
87
-		if ( in_array(
88
-			$meta_key,
89
-			apply_filters(
90
-				'wl_dataset__sync_post_hooks__ignored_meta_keys',
91
-				apply_filters(
92
-					'wl_dataset__sync_hooks__ignored_meta_keys',
93
-					array(
94
-						'_pingme',
95
-						'_encloseme',
96
-						'entity_url',
97
-					)
98
-				)
99
-			),
100
-			true
101
-		)
102
-			 || ! in_array( get_post_type( $post_id ), \Wordlift_Entity_Service::valid_entity_post_types(), true )
103
-		) {
104
-			return;
105
-		}
106
-
107
-		$this->sync( $post_id );
108
-
109
-	}
110
-
111
-	private function sync( $post_id ) {
112
-		$this->enqueue( array( 'do_sync', $post_id ) );
113
-	}
114
-
115
-	public function do_sync( $post_id ) {
116
-		try {
117
-			$post = get_post( $post_id );
118
-			if ( ! isset( $post ) ) {
119
-				return;
120
-			}
121
-			$this->sync_service->sync_many(
122
-				array(
123
-					$this->sync_object_factory->create( Object_Type_Enum::POST, $post_id ),
124
-					$this->sync_object_factory->create( Object_Type_Enum::USER, $post->post_author ),
125
-				)
126
-			);
127
-		} catch ( \Exception $e ) {
128
-			$this->log->error( "An error occurred while trying to sync post $post_id: " . $e->getMessage(), $e );
129
-		}
130
-
131
-	}
132
-
133
-	public function delete_post( $post_id ) {
134
-		$this->enqueue( array( 'do_delete', $post_id ) );
135
-	}
136
-
137
-	public function do_delete( $post_id ) {
138
-		try {
139
-			$this->sync_service->delete_one(
140
-				Object_Type_Enum::POST,
141
-				$post_id,
142
-				Wordpress_Content_Service::get_instance()->get_entity_id( Wordpress_Content_Id::create_post( $post_id ) )
143
-			);
144
-		} catch ( \Exception $e ) {
145
-			$this->log->error( "An error occurred while trying to delete post $post_id: " . $e->getMessage(), $e );
146
-		}
147
-	}
10
+    /**
11
+     * @var \Wordlift_Log_Service
12
+     */
13
+    private $log;
14
+
15
+    /**
16
+     * @var Sync_Service
17
+     */
18
+    private $sync_service;
19
+
20
+    /**
21
+     * @var Sync_Object_Adapter_Factory
22
+     */
23
+    private $sync_object_factory;
24
+
25
+    /**
26
+     * Sync_Post_Hooks constructor.
27
+     *
28
+     * @param Sync_Service                $sync_service
29
+     * @param Sync_Object_Adapter_Factory $sync_object_factory
30
+     */
31
+    public function __construct( $sync_service, $sync_object_factory ) {
32
+        parent::__construct();
33
+
34
+        $this->log = \Wordlift_Log_Service::get_logger( get_class() );
35
+
36
+        $this->sync_service        = $sync_service;
37
+        $this->sync_object_factory = $sync_object_factory;
38
+
39
+        $this->register_hooks();
40
+    }
41
+
42
+    private function register_hooks() {
43
+        /**
44
+         * Register hooks for post and meta.
45
+         */
46
+        add_action( 'save_post', array( $this, 'save_post' ) );
47
+        add_action( 'added_post_meta', array( $this, 'changed_post_meta' ), 10, 4 );
48
+        add_action( 'updated_post_meta', array( $this, 'changed_post_meta' ), 10, 4 );
49
+        add_action( 'deleted_post_meta', array( $this, 'changed_post_meta' ), 10, 4 );
50
+
51
+        // running this on delete_post wouldnt work because at that time
52
+        // entity_url would be deleted, so we cant delete this item from KG.
53
+        add_action( 'before_delete_post', array( $this, 'delete_post' ) );
54
+
55
+        // Remove post when its trashed.
56
+        add_action( 'trashed_post', array( $this, 'delete_post' ) );
57
+        // Save the post when its untrashed.
58
+        add_action( 'untrashed_post', array( $this, 'save_post' ) );
59
+        // Get sticky posts changes.
60
+        add_action( 'update_option_sticky_posts', array( $this, 'sticky_posts' ), 10, 2 );
61
+
62
+    }
63
+
64
+    public function save_post( $post_id ) {
65
+
66
+        if ( ! in_array( get_post_type( $post_id ), \Wordlift_Entity_Service::valid_entity_post_types(), true ) ) {
67
+            return;
68
+        }
69
+
70
+        $this->sync( $post_id );
71
+
72
+    }
73
+
74
+    public function sticky_posts( $old_value, $value ) {
75
+        foreach ( $old_value as $post_id ) {
76
+            $this->sync( $post_id );
77
+        }
78
+
79
+        foreach ( $value as $post_id ) {
80
+            $this->sync( $post_id );
81
+        }
82
+    }
83
+
84
+    // phpcs:ignore VariableAnalysis.CodeAnalysis.VariableAnalysis.UnusedVariable
85
+    public function changed_post_meta( $meta_id, $post_id, $meta_key, $_meta_value ) {
86
+
87
+        if ( in_array(
88
+            $meta_key,
89
+            apply_filters(
90
+                'wl_dataset__sync_post_hooks__ignored_meta_keys',
91
+                apply_filters(
92
+                    'wl_dataset__sync_hooks__ignored_meta_keys',
93
+                    array(
94
+                        '_pingme',
95
+                        '_encloseme',
96
+                        'entity_url',
97
+                    )
98
+                )
99
+            ),
100
+            true
101
+        )
102
+             || ! in_array( get_post_type( $post_id ), \Wordlift_Entity_Service::valid_entity_post_types(), true )
103
+        ) {
104
+            return;
105
+        }
106
+
107
+        $this->sync( $post_id );
108
+
109
+    }
110
+
111
+    private function sync( $post_id ) {
112
+        $this->enqueue( array( 'do_sync', $post_id ) );
113
+    }
114
+
115
+    public function do_sync( $post_id ) {
116
+        try {
117
+            $post = get_post( $post_id );
118
+            if ( ! isset( $post ) ) {
119
+                return;
120
+            }
121
+            $this->sync_service->sync_many(
122
+                array(
123
+                    $this->sync_object_factory->create( Object_Type_Enum::POST, $post_id ),
124
+                    $this->sync_object_factory->create( Object_Type_Enum::USER, $post->post_author ),
125
+                )
126
+            );
127
+        } catch ( \Exception $e ) {
128
+            $this->log->error( "An error occurred while trying to sync post $post_id: " . $e->getMessage(), $e );
129
+        }
130
+
131
+    }
132
+
133
+    public function delete_post( $post_id ) {
134
+        $this->enqueue( array( 'do_delete', $post_id ) );
135
+    }
136
+
137
+    public function do_delete( $post_id ) {
138
+        try {
139
+            $this->sync_service->delete_one(
140
+                Object_Type_Enum::POST,
141
+                $post_id,
142
+                Wordpress_Content_Service::get_instance()->get_entity_id( Wordpress_Content_Id::create_post( $post_id ) )
143
+            );
144
+        } catch ( \Exception $e ) {
145
+            $this->log->error( "An error occurred while trying to delete post $post_id: " . $e->getMessage(), $e );
146
+        }
147
+    }
148 148
 
149 149
 }
Please login to merge, or discard this patch.
Spacing   +37 added lines, -37 removed lines patch added patch discarded remove patch
@@ -28,10 +28,10 @@  discard block
 block discarded – undo
28 28
 	 * @param Sync_Service                $sync_service
29 29
 	 * @param Sync_Object_Adapter_Factory $sync_object_factory
30 30
 	 */
31
-	public function __construct( $sync_service, $sync_object_factory ) {
31
+	public function __construct($sync_service, $sync_object_factory) {
32 32
 		parent::__construct();
33 33
 
34
-		$this->log = \Wordlift_Log_Service::get_logger( get_class() );
34
+		$this->log = \Wordlift_Log_Service::get_logger(get_class());
35 35
 
36 36
 		$this->sync_service        = $sync_service;
37 37
 		$this->sync_object_factory = $sync_object_factory;
@@ -43,48 +43,48 @@  discard block
 block discarded – undo
43 43
 		/**
44 44
 		 * Register hooks for post and meta.
45 45
 		 */
46
-		add_action( 'save_post', array( $this, 'save_post' ) );
47
-		add_action( 'added_post_meta', array( $this, 'changed_post_meta' ), 10, 4 );
48
-		add_action( 'updated_post_meta', array( $this, 'changed_post_meta' ), 10, 4 );
49
-		add_action( 'deleted_post_meta', array( $this, 'changed_post_meta' ), 10, 4 );
46
+		add_action('save_post', array($this, 'save_post'));
47
+		add_action('added_post_meta', array($this, 'changed_post_meta'), 10, 4);
48
+		add_action('updated_post_meta', array($this, 'changed_post_meta'), 10, 4);
49
+		add_action('deleted_post_meta', array($this, 'changed_post_meta'), 10, 4);
50 50
 
51 51
 		// running this on delete_post wouldnt work because at that time
52 52
 		// entity_url would be deleted, so we cant delete this item from KG.
53
-		add_action( 'before_delete_post', array( $this, 'delete_post' ) );
53
+		add_action('before_delete_post', array($this, 'delete_post'));
54 54
 
55 55
 		// Remove post when its trashed.
56
-		add_action( 'trashed_post', array( $this, 'delete_post' ) );
56
+		add_action('trashed_post', array($this, 'delete_post'));
57 57
 		// Save the post when its untrashed.
58
-		add_action( 'untrashed_post', array( $this, 'save_post' ) );
58
+		add_action('untrashed_post', array($this, 'save_post'));
59 59
 		// Get sticky posts changes.
60
-		add_action( 'update_option_sticky_posts', array( $this, 'sticky_posts' ), 10, 2 );
60
+		add_action('update_option_sticky_posts', array($this, 'sticky_posts'), 10, 2);
61 61
 
62 62
 	}
63 63
 
64
-	public function save_post( $post_id ) {
64
+	public function save_post($post_id) {
65 65
 
66
-		if ( ! in_array( get_post_type( $post_id ), \Wordlift_Entity_Service::valid_entity_post_types(), true ) ) {
66
+		if ( ! in_array(get_post_type($post_id), \Wordlift_Entity_Service::valid_entity_post_types(), true)) {
67 67
 			return;
68 68
 		}
69 69
 
70
-		$this->sync( $post_id );
70
+		$this->sync($post_id);
71 71
 
72 72
 	}
73 73
 
74
-	public function sticky_posts( $old_value, $value ) {
75
-		foreach ( $old_value as $post_id ) {
76
-			$this->sync( $post_id );
74
+	public function sticky_posts($old_value, $value) {
75
+		foreach ($old_value as $post_id) {
76
+			$this->sync($post_id);
77 77
 		}
78 78
 
79
-		foreach ( $value as $post_id ) {
80
-			$this->sync( $post_id );
79
+		foreach ($value as $post_id) {
80
+			$this->sync($post_id);
81 81
 		}
82 82
 	}
83 83
 
84 84
 	// phpcs:ignore VariableAnalysis.CodeAnalysis.VariableAnalysis.UnusedVariable
85
-	public function changed_post_meta( $meta_id, $post_id, $meta_key, $_meta_value ) {
85
+	public function changed_post_meta($meta_id, $post_id, $meta_key, $_meta_value) {
86 86
 
87
-		if ( in_array(
87
+		if (in_array(
88 88
 			$meta_key,
89 89
 			apply_filters(
90 90
 				'wl_dataset__sync_post_hooks__ignored_meta_keys',
@@ -99,50 +99,50 @@  discard block
 block discarded – undo
99 99
 			),
100 100
 			true
101 101
 		)
102
-			 || ! in_array( get_post_type( $post_id ), \Wordlift_Entity_Service::valid_entity_post_types(), true )
102
+			 || ! in_array(get_post_type($post_id), \Wordlift_Entity_Service::valid_entity_post_types(), true)
103 103
 		) {
104 104
 			return;
105 105
 		}
106 106
 
107
-		$this->sync( $post_id );
107
+		$this->sync($post_id);
108 108
 
109 109
 	}
110 110
 
111
-	private function sync( $post_id ) {
112
-		$this->enqueue( array( 'do_sync', $post_id ) );
111
+	private function sync($post_id) {
112
+		$this->enqueue(array('do_sync', $post_id));
113 113
 	}
114 114
 
115
-	public function do_sync( $post_id ) {
115
+	public function do_sync($post_id) {
116 116
 		try {
117
-			$post = get_post( $post_id );
118
-			if ( ! isset( $post ) ) {
117
+			$post = get_post($post_id);
118
+			if ( ! isset($post)) {
119 119
 				return;
120 120
 			}
121 121
 			$this->sync_service->sync_many(
122 122
 				array(
123
-					$this->sync_object_factory->create( Object_Type_Enum::POST, $post_id ),
124
-					$this->sync_object_factory->create( Object_Type_Enum::USER, $post->post_author ),
123
+					$this->sync_object_factory->create(Object_Type_Enum::POST, $post_id),
124
+					$this->sync_object_factory->create(Object_Type_Enum::USER, $post->post_author),
125 125
 				)
126 126
 			);
127
-		} catch ( \Exception $e ) {
128
-			$this->log->error( "An error occurred while trying to sync post $post_id: " . $e->getMessage(), $e );
127
+		} catch (\Exception $e) {
128
+			$this->log->error("An error occurred while trying to sync post $post_id: ".$e->getMessage(), $e);
129 129
 		}
130 130
 
131 131
 	}
132 132
 
133
-	public function delete_post( $post_id ) {
134
-		$this->enqueue( array( 'do_delete', $post_id ) );
133
+	public function delete_post($post_id) {
134
+		$this->enqueue(array('do_delete', $post_id));
135 135
 	}
136 136
 
137
-	public function do_delete( $post_id ) {
137
+	public function do_delete($post_id) {
138 138
 		try {
139 139
 			$this->sync_service->delete_one(
140 140
 				Object_Type_Enum::POST,
141 141
 				$post_id,
142
-				Wordpress_Content_Service::get_instance()->get_entity_id( Wordpress_Content_Id::create_post( $post_id ) )
142
+				Wordpress_Content_Service::get_instance()->get_entity_id(Wordpress_Content_Id::create_post($post_id))
143 143
 			);
144
-		} catch ( \Exception $e ) {
145
-			$this->log->error( "An error occurred while trying to delete post $post_id: " . $e->getMessage(), $e );
144
+		} catch (\Exception $e) {
145
+			$this->log->error("An error occurred while trying to delete post $post_id: ".$e->getMessage(), $e);
146 146
 		}
147 147
 	}
148 148
 
Please login to merge, or discard this patch.
src/wordlift/dataset/class-sync-term-hooks.php 2 patches
Indentation   +124 added lines, -124 removed lines patch added patch discarded remove patch
@@ -7,128 +7,128 @@
 block discarded – undo
7 7
 use Wordlift\Object_Type_Enum;
8 8
 
9 9
 class Sync_Term_Hooks extends Abstract_Sync_Hooks {
10
-	/**
11
-	 * @var \Wordlift_Log_Service
12
-	 */
13
-	private $log;
14
-
15
-	/**
16
-	 * @var Sync_Service
17
-	 */
18
-	private $sync_service;
19
-
20
-	/**
21
-	 * @var Sync_Object_Adapter_Factory
22
-	 */
23
-	private $sync_object_factory;
24
-
25
-	/**
26
-	 * Sync_Term_Hooks constructor.
27
-	 *
28
-	 * @param Sync_Service                $sync_service
29
-	 * @param Sync_Object_Adapter_Factory $sync_object_factory
30
-	 */
31
-	public function __construct( $sync_service, $sync_object_factory ) {
32
-		parent::__construct();
33
-
34
-		$this->log = \Wordlift_Log_Service::get_logger( get_class() );
35
-
36
-		$this->sync_service        = $sync_service;
37
-		$this->sync_object_factory = $sync_object_factory;
38
-
39
-		$this->register_hooks();
40
-	}
41
-
42
-	private function register_hooks() {
43
-		/**
44
-		 * Register hooks for post and meta.
45
-		 */
46
-		add_action( 'create_term', array( $this, 'do_sync' ) );
47
-		add_action( 'edit_term', array( $this, 'do_sync' ) );
48
-		add_action( 'added_term_meta', array( $this, 'changed_term_meta' ), 10, 4 );
49
-		add_action( 'updated_term_meta', array( $this, 'changed_term_meta' ), 10, 4 );
50
-		add_action( 'deleted_term_meta', array( $this, 'changed_term_meta' ), 10, 4 );
51
-		add_action( 'pre_delete_term', array( $this, 'delete_term' ) );
52
-
53
-	}
54
-
55
-	public function saved_term( $term_id ) {
56
-
57
-		// Sync all the terms without filtering.
58
-		$this->sync( $term_id );
59
-	}
60
-
61
-	// phpcs:ignore VariableAnalysis.CodeAnalysis.VariableAnalysis.UnusedVariable
62
-	public function changed_term_meta( $meta_id, $term_id, $meta_key, $_meta_value ) {
63
-
64
-		if ( in_array(
65
-			$meta_key,
66
-			apply_filters(
67
-				'wl_dataset__sync_post_hooks__ignored_meta_keys',
68
-				apply_filters(
69
-					'wl_dataset__sync_hooks__ignored_meta_keys',
70
-					array(
71
-						'_pingme',
72
-						'_encloseme',
73
-						'entity_url',
74
-					)
75
-				)
76
-			),
77
-			true
78
-		)
79
-		) {
80
-			return;
81
-		}
82
-
83
-		$this->sync( $term_id );
84
-
85
-	}
86
-
87
-	private function sync( $term_id ) {
88
-
89
-		$this->enqueue( array( 'do_sync', $term_id ) );
90
-	}
91
-
92
-	public function do_sync( $term_id ) {
93
-
94
-		try {
95
-			$term = get_term( $term_id );
96
-			if ( ! isset( $term ) ) {
97
-				return;
98
-			}
99
-			$this->sync_service->sync_many(
100
-				array(
101
-					$this->sync_object_factory->create( Object_Type_Enum::TERM, $term_id ),
102
-				)
103
-			);
104
-		} catch ( \Exception $e ) {
105
-			$this->log->error( "An error occurred while trying to sync post $term_id: " . $e->getMessage(), $e );
106
-		}
107
-	}
108
-
109
-	/**
110
-	 * @param $term \WP_Term
111
-	 *
112
-	 * @throws \Exception when an error occurs.
113
-	 */
114
-	public function delete_term( $term_id ) {
115
-		$args = array(
116
-			$term_id,
117
-			Wordpress_Term_Content_Legacy_Service::get_instance()
118
-				->get_entity_id( Wordpress_Content_Id::create_term( $term_id ) ),
119
-		);
120
-		// We can't postpone the execution for a `delete` because we would miss the actual data.
121
-		$this->do_delete( $args );
122
-	}
123
-
124
-	public function do_delete( $args ) {
125
-		$term_id         = $args[0];
126
-		$term_entity_uri = $args[1];
127
-
128
-		try {
129
-			$this->sync_service->delete_one( Object_Type_Enum::TERM, $term_id, $term_entity_uri );
130
-		} catch ( \Exception $e ) {
131
-			$this->log->error( "An error occurred while trying to delete term $term_id: " . $e->getMessage(), $e );
132
-		}
133
-	}
10
+    /**
11
+     * @var \Wordlift_Log_Service
12
+     */
13
+    private $log;
14
+
15
+    /**
16
+     * @var Sync_Service
17
+     */
18
+    private $sync_service;
19
+
20
+    /**
21
+     * @var Sync_Object_Adapter_Factory
22
+     */
23
+    private $sync_object_factory;
24
+
25
+    /**
26
+     * Sync_Term_Hooks constructor.
27
+     *
28
+     * @param Sync_Service                $sync_service
29
+     * @param Sync_Object_Adapter_Factory $sync_object_factory
30
+     */
31
+    public function __construct( $sync_service, $sync_object_factory ) {
32
+        parent::__construct();
33
+
34
+        $this->log = \Wordlift_Log_Service::get_logger( get_class() );
35
+
36
+        $this->sync_service        = $sync_service;
37
+        $this->sync_object_factory = $sync_object_factory;
38
+
39
+        $this->register_hooks();
40
+    }
41
+
42
+    private function register_hooks() {
43
+        /**
44
+         * Register hooks for post and meta.
45
+         */
46
+        add_action( 'create_term', array( $this, 'do_sync' ) );
47
+        add_action( 'edit_term', array( $this, 'do_sync' ) );
48
+        add_action( 'added_term_meta', array( $this, 'changed_term_meta' ), 10, 4 );
49
+        add_action( 'updated_term_meta', array( $this, 'changed_term_meta' ), 10, 4 );
50
+        add_action( 'deleted_term_meta', array( $this, 'changed_term_meta' ), 10, 4 );
51
+        add_action( 'pre_delete_term', array( $this, 'delete_term' ) );
52
+
53
+    }
54
+
55
+    public function saved_term( $term_id ) {
56
+
57
+        // Sync all the terms without filtering.
58
+        $this->sync( $term_id );
59
+    }
60
+
61
+    // phpcs:ignore VariableAnalysis.CodeAnalysis.VariableAnalysis.UnusedVariable
62
+    public function changed_term_meta( $meta_id, $term_id, $meta_key, $_meta_value ) {
63
+
64
+        if ( in_array(
65
+            $meta_key,
66
+            apply_filters(
67
+                'wl_dataset__sync_post_hooks__ignored_meta_keys',
68
+                apply_filters(
69
+                    'wl_dataset__sync_hooks__ignored_meta_keys',
70
+                    array(
71
+                        '_pingme',
72
+                        '_encloseme',
73
+                        'entity_url',
74
+                    )
75
+                )
76
+            ),
77
+            true
78
+        )
79
+        ) {
80
+            return;
81
+        }
82
+
83
+        $this->sync( $term_id );
84
+
85
+    }
86
+
87
+    private function sync( $term_id ) {
88
+
89
+        $this->enqueue( array( 'do_sync', $term_id ) );
90
+    }
91
+
92
+    public function do_sync( $term_id ) {
93
+
94
+        try {
95
+            $term = get_term( $term_id );
96
+            if ( ! isset( $term ) ) {
97
+                return;
98
+            }
99
+            $this->sync_service->sync_many(
100
+                array(
101
+                    $this->sync_object_factory->create( Object_Type_Enum::TERM, $term_id ),
102
+                )
103
+            );
104
+        } catch ( \Exception $e ) {
105
+            $this->log->error( "An error occurred while trying to sync post $term_id: " . $e->getMessage(), $e );
106
+        }
107
+    }
108
+
109
+    /**
110
+     * @param $term \WP_Term
111
+     *
112
+     * @throws \Exception when an error occurs.
113
+     */
114
+    public function delete_term( $term_id ) {
115
+        $args = array(
116
+            $term_id,
117
+            Wordpress_Term_Content_Legacy_Service::get_instance()
118
+                ->get_entity_id( Wordpress_Content_Id::create_term( $term_id ) ),
119
+        );
120
+        // We can't postpone the execution for a `delete` because we would miss the actual data.
121
+        $this->do_delete( $args );
122
+    }
123
+
124
+    public function do_delete( $args ) {
125
+        $term_id         = $args[0];
126
+        $term_entity_uri = $args[1];
127
+
128
+        try {
129
+            $this->sync_service->delete_one( Object_Type_Enum::TERM, $term_id, $term_entity_uri );
130
+        } catch ( \Exception $e ) {
131
+            $this->log->error( "An error occurred while trying to delete term $term_id: " . $e->getMessage(), $e );
132
+        }
133
+    }
134 134
 }
Please login to merge, or discard this patch.
Spacing   +28 added lines, -28 removed lines patch added patch discarded remove patch
@@ -28,10 +28,10 @@  discard block
 block discarded – undo
28 28
 	 * @param Sync_Service                $sync_service
29 29
 	 * @param Sync_Object_Adapter_Factory $sync_object_factory
30 30
 	 */
31
-	public function __construct( $sync_service, $sync_object_factory ) {
31
+	public function __construct($sync_service, $sync_object_factory) {
32 32
 		parent::__construct();
33 33
 
34
-		$this->log = \Wordlift_Log_Service::get_logger( get_class() );
34
+		$this->log = \Wordlift_Log_Service::get_logger(get_class());
35 35
 
36 36
 		$this->sync_service        = $sync_service;
37 37
 		$this->sync_object_factory = $sync_object_factory;
@@ -43,25 +43,25 @@  discard block
 block discarded – undo
43 43
 		/**
44 44
 		 * Register hooks for post and meta.
45 45
 		 */
46
-		add_action( 'create_term', array( $this, 'do_sync' ) );
47
-		add_action( 'edit_term', array( $this, 'do_sync' ) );
48
-		add_action( 'added_term_meta', array( $this, 'changed_term_meta' ), 10, 4 );
49
-		add_action( 'updated_term_meta', array( $this, 'changed_term_meta' ), 10, 4 );
50
-		add_action( 'deleted_term_meta', array( $this, 'changed_term_meta' ), 10, 4 );
51
-		add_action( 'pre_delete_term', array( $this, 'delete_term' ) );
46
+		add_action('create_term', array($this, 'do_sync'));
47
+		add_action('edit_term', array($this, 'do_sync'));
48
+		add_action('added_term_meta', array($this, 'changed_term_meta'), 10, 4);
49
+		add_action('updated_term_meta', array($this, 'changed_term_meta'), 10, 4);
50
+		add_action('deleted_term_meta', array($this, 'changed_term_meta'), 10, 4);
51
+		add_action('pre_delete_term', array($this, 'delete_term'));
52 52
 
53 53
 	}
54 54
 
55
-	public function saved_term( $term_id ) {
55
+	public function saved_term($term_id) {
56 56
 
57 57
 		// Sync all the terms without filtering.
58
-		$this->sync( $term_id );
58
+		$this->sync($term_id);
59 59
 	}
60 60
 
61 61
 	// phpcs:ignore VariableAnalysis.CodeAnalysis.VariableAnalysis.UnusedVariable
62
-	public function changed_term_meta( $meta_id, $term_id, $meta_key, $_meta_value ) {
62
+	public function changed_term_meta($meta_id, $term_id, $meta_key, $_meta_value) {
63 63
 
64
-		if ( in_array(
64
+		if (in_array(
65 65
 			$meta_key,
66 66
 			apply_filters(
67 67
 				'wl_dataset__sync_post_hooks__ignored_meta_keys',
@@ -80,29 +80,29 @@  discard block
 block discarded – undo
80 80
 			return;
81 81
 		}
82 82
 
83
-		$this->sync( $term_id );
83
+		$this->sync($term_id);
84 84
 
85 85
 	}
86 86
 
87
-	private function sync( $term_id ) {
87
+	private function sync($term_id) {
88 88
 
89
-		$this->enqueue( array( 'do_sync', $term_id ) );
89
+		$this->enqueue(array('do_sync', $term_id));
90 90
 	}
91 91
 
92
-	public function do_sync( $term_id ) {
92
+	public function do_sync($term_id) {
93 93
 
94 94
 		try {
95
-			$term = get_term( $term_id );
96
-			if ( ! isset( $term ) ) {
95
+			$term = get_term($term_id);
96
+			if ( ! isset($term)) {
97 97
 				return;
98 98
 			}
99 99
 			$this->sync_service->sync_many(
100 100
 				array(
101
-					$this->sync_object_factory->create( Object_Type_Enum::TERM, $term_id ),
101
+					$this->sync_object_factory->create(Object_Type_Enum::TERM, $term_id),
102 102
 				)
103 103
 			);
104
-		} catch ( \Exception $e ) {
105
-			$this->log->error( "An error occurred while trying to sync post $term_id: " . $e->getMessage(), $e );
104
+		} catch (\Exception $e) {
105
+			$this->log->error("An error occurred while trying to sync post $term_id: ".$e->getMessage(), $e);
106 106
 		}
107 107
 	}
108 108
 
@@ -111,24 +111,24 @@  discard block
 block discarded – undo
111 111
 	 *
112 112
 	 * @throws \Exception when an error occurs.
113 113
 	 */
114
-	public function delete_term( $term_id ) {
114
+	public function delete_term($term_id) {
115 115
 		$args = array(
116 116
 			$term_id,
117 117
 			Wordpress_Term_Content_Legacy_Service::get_instance()
118
-				->get_entity_id( Wordpress_Content_Id::create_term( $term_id ) ),
118
+				->get_entity_id(Wordpress_Content_Id::create_term($term_id)),
119 119
 		);
120 120
 		// We can't postpone the execution for a `delete` because we would miss the actual data.
121
-		$this->do_delete( $args );
121
+		$this->do_delete($args);
122 122
 	}
123 123
 
124
-	public function do_delete( $args ) {
124
+	public function do_delete($args) {
125 125
 		$term_id         = $args[0];
126 126
 		$term_entity_uri = $args[1];
127 127
 
128 128
 		try {
129
-			$this->sync_service->delete_one( Object_Type_Enum::TERM, $term_id, $term_entity_uri );
130
-		} catch ( \Exception $e ) {
131
-			$this->log->error( "An error occurred while trying to delete term $term_id: " . $e->getMessage(), $e );
129
+			$this->sync_service->delete_one(Object_Type_Enum::TERM, $term_id, $term_entity_uri);
130
+		} catch (\Exception $e) {
131
+			$this->log->error("An error occurred while trying to delete term $term_id: ".$e->getMessage(), $e);
132 132
 		}
133 133
 	}
134 134
 }
Please login to merge, or discard this patch.
src/wordlift/dataset/class-sync-object-adapter.php 2 patches
Indentation   +9 added lines, -9 removed lines patch added patch discarded remove patch
@@ -4,19 +4,19 @@
 block discarded – undo
4 4
 
5 5
 interface Sync_Object_Adapter {
6 6
 
7
-	/**
8
-	 * @return int see {@link Object_Type_Enum}
9
-	 */
10
-	public function get_type();
7
+    /**
8
+     * @return int see {@link Object_Type_Enum}
9
+     */
10
+    public function get_type();
11 11
 
12
-	public function get_object_id();
12
+    public function get_object_id();
13 13
 
14
-	public function is_published();
14
+    public function is_published();
15 15
 
16
-	public function is_public();
16
+    public function is_public();
17 17
 
18
-	public function set_values( $arr );
18
+    public function set_values( $arr );
19 19
 
20
-	public function get_value( $key );
20
+    public function get_value( $key );
21 21
 
22 22
 }
Please login to merge, or discard this patch.
Spacing   +2 added lines, -2 removed lines patch added patch discarded remove patch
@@ -15,8 +15,8 @@
 block discarded – undo
15 15
 
16 16
 	public function is_public();
17 17
 
18
-	public function set_values( $arr );
18
+	public function set_values($arr);
19 19
 
20
-	public function get_value( $key );
20
+	public function get_value($key);
21 21
 
22 22
 }
Please login to merge, or discard this patch.