Completed
Pull Request — master (#1641)
by Naveen
01:35
created
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.
src/wordlift/dataset/class-abstract-sync-object-adapter.php 2 patches
Indentation   +40 added lines, -40 removed lines patch added patch discarded remove patch
@@ -7,45 +7,45 @@
 block discarded – undo
7 7
 
8 8
 abstract class Abstract_Sync_Object_Adapter implements Sync_Object_Adapter {
9 9
 
10
-	private $object_id;
11
-
12
-	private $type;
13
-
14
-	private static $meta_name = array(
15
-		Object_Type_Enum::POST => 'post',
16
-		Object_Type_Enum::TERM => 'term',
17
-		Object_Type_Enum::USER => 'user',
18
-	);
19
-
20
-	/**
21
-	 * Sync_Object_Adapter constructor.
22
-	 *
23
-	 * @param int            $type One of Object_Type_Enum.
24
-	 * @param int            $object_id A post or term id.
25
-	 * @param Jsonld_Service
26
-	 *
27
-	 * @throws \Exception when an error occurs.
28
-	 */
29
-	public function __construct( $type, $object_id ) {
30
-
31
-		$this->type      = filter_var( $type, FILTER_VALIDATE_INT );
32
-		$this->object_id = filter_var( $object_id, FILTER_VALIDATE_INT );
33
-
34
-		if ( null === $this->type || ! isset( self::$meta_name[ $this->type ] ) ) {
35
-			throw new \Exception( 'Invalid $type.' );
36
-		}
37
-		if ( null === $this->object_id ) {
38
-			throw new \Exception( 'Invalid $object.' );
39
-		}
40
-
41
-	}
42
-
43
-	public function get_type() {
44
-		return $this->type;
45
-	}
46
-
47
-	public function get_object_id() {
48
-		return $this->object_id;
49
-	}
10
+    private $object_id;
11
+
12
+    private $type;
13
+
14
+    private static $meta_name = array(
15
+        Object_Type_Enum::POST => 'post',
16
+        Object_Type_Enum::TERM => 'term',
17
+        Object_Type_Enum::USER => 'user',
18
+    );
19
+
20
+    /**
21
+     * Sync_Object_Adapter constructor.
22
+     *
23
+     * @param int            $type One of Object_Type_Enum.
24
+     * @param int            $object_id A post or term id.
25
+     * @param Jsonld_Service
26
+     *
27
+     * @throws \Exception when an error occurs.
28
+     */
29
+    public function __construct( $type, $object_id ) {
30
+
31
+        $this->type      = filter_var( $type, FILTER_VALIDATE_INT );
32
+        $this->object_id = filter_var( $object_id, FILTER_VALIDATE_INT );
33
+
34
+        if ( null === $this->type || ! isset( self::$meta_name[ $this->type ] ) ) {
35
+            throw new \Exception( 'Invalid $type.' );
36
+        }
37
+        if ( null === $this->object_id ) {
38
+            throw new \Exception( 'Invalid $object.' );
39
+        }
40
+
41
+    }
42
+
43
+    public function get_type() {
44
+        return $this->type;
45
+    }
46
+
47
+    public function get_object_id() {
48
+        return $this->object_id;
49
+    }
50 50
 
51 51
 }
Please login to merge, or discard this patch.
Spacing   +7 added lines, -7 removed lines patch added patch discarded remove patch
@@ -26,16 +26,16 @@
 block discarded – undo
26 26
 	 *
27 27
 	 * @throws \Exception when an error occurs.
28 28
 	 */
29
-	public function __construct( $type, $object_id ) {
29
+	public function __construct($type, $object_id) {
30 30
 
31
-		$this->type      = filter_var( $type, FILTER_VALIDATE_INT );
32
-		$this->object_id = filter_var( $object_id, FILTER_VALIDATE_INT );
31
+		$this->type      = filter_var($type, FILTER_VALIDATE_INT);
32
+		$this->object_id = filter_var($object_id, FILTER_VALIDATE_INT);
33 33
 
34
-		if ( null === $this->type || ! isset( self::$meta_name[ $this->type ] ) ) {
35
-			throw new \Exception( 'Invalid $type.' );
34
+		if (null === $this->type || ! isset(self::$meta_name[$this->type])) {
35
+			throw new \Exception('Invalid $type.');
36 36
 		}
37
-		if ( null === $this->object_id ) {
38
-			throw new \Exception( 'Invalid $object.' );
37
+		if (null === $this->object_id) {
38
+			throw new \Exception('Invalid $object.');
39 39
 		}
40 40
 
41 41
 	}
Please login to merge, or discard this patch.
src/wordlift/dataset/class-sync-user-hooks.php 2 patches
Indentation   +105 added lines, -105 removed lines patch added patch discarded remove patch
@@ -7,110 +7,110 @@
 block discarded – undo
7 7
 use Wordlift\Object_Type_Enum;
8 8
 
9 9
 class Sync_User_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
-	 * Sync_User_Hooks constructor.
22
-	 *
23
-	 * @param Sync_Service $sync_service
24
-	 */
25
-	public function __construct( Sync_Service $sync_service ) {
26
-		parent::__construct();
27
-
28
-		$this->log = \Wordlift_Log_Service::get_logger( get_class() );
29
-
30
-		$this->sync_service = $sync_service;
31
-
32
-		$this->register_hooks();
33
-
34
-	}
35
-
36
-	private function register_hooks() {
37
-		/**
38
-		 * Register hooks for user and meta.
39
-		 */
40
-		add_action( 'user_register', array( $this, 'changed_user' ) );
41
-		add_action( 'profile_update', array( $this, 'changed_user' ) );
42
-		add_action( 'added_user_meta', array( $this, 'changed_user_meta' ), 10, 3 );
43
-		add_action( 'updated_user_meta', array( $this, 'changed_user_meta' ), 10, 3 );
44
-		add_action( 'deleted_user_meta', array( $this, 'changed_user_meta' ), 10, 3 );
45
-		add_action( 'delete_user', array( $this, 'delete_user' ) );
46
-
47
-	}
48
-
49
-	public function changed_user( $user_id ) {
50
-
51
-		$this->sync( $user_id );
52
-
53
-	}
54
-
55
-	public function changed_user_meta( $meta_id, $user_id, $meta_key ) {
56
-
57
-		if ( in_array(
58
-			$meta_key,
59
-			apply_filters(
60
-				'wl_dataset__sync_user_hooks__ignored_meta_keys',
61
-				apply_filters(
62
-					'wl_dataset__sync_hooks__ignored_meta_keys',
63
-					array(
64
-						'rich_editing',
65
-						'comment_shortcuts',
66
-						'admin_color',
67
-						'use_ssl',
68
-						'show_admin_bar_front',
69
-						'wptests_capabilities',
70
-						'wptests_user_level',
71
-						'dismissed_wp_pointers',
72
-						'entity_url',
73
-					)
74
-				)
75
-			),
76
-			true
77
-		) ) {
78
-			return;
79
-		}
80
-
81
-		$this->sync( $user_id );
82
-
83
-	}
84
-
85
-	private function sync( $user_id ) {
86
-		$this->enqueue( array( 'do_sync', $user_id ) );
87
-	}
88
-
89
-	public function do_sync( $user_id ) {
90
-
91
-		try {
92
-			$this->sync_service->sync_one( Object_Type_Enum::USER, (int) $user_id );
93
-		} catch ( \Exception $e ) {
94
-			$this->log->error( "An error occurred while trying to sync user $user_id: " . $e->getMessage(), $e );
95
-		}
96
-
97
-	}
98
-
99
-	public function delete_user( $user_id ) {
100
-		$this->enqueue( array( 'do_delete', $user_id ) );
101
-	}
102
-
103
-	public function do_delete( $user_id ) {
104
-		try {
105
-			$this->sync_service->delete_one(
106
-				Object_Type_Enum::USER,
107
-				$user_id,
108
-				Wordpress_User_Content_Legacy_Service::get_instance()->get_entity_id( Wordpress_Content_Id::create_user( $user_id ) )
109
-			);
110
-		} catch ( \Exception $e ) {
111
-			$this->log->error( "An error occurred while trying to delete user $user_id: " . $e->getMessage(), $e );
112
-		}
113
-
114
-	}
10
+    /**
11
+     * @var \Wordlift_Log_Service
12
+     */
13
+    private $log;
14
+
15
+    /**
16
+     * @var Sync_Service
17
+     */
18
+    private $sync_service;
19
+
20
+    /**
21
+     * Sync_User_Hooks constructor.
22
+     *
23
+     * @param Sync_Service $sync_service
24
+     */
25
+    public function __construct( Sync_Service $sync_service ) {
26
+        parent::__construct();
27
+
28
+        $this->log = \Wordlift_Log_Service::get_logger( get_class() );
29
+
30
+        $this->sync_service = $sync_service;
31
+
32
+        $this->register_hooks();
33
+
34
+    }
35
+
36
+    private function register_hooks() {
37
+        /**
38
+         * Register hooks for user and meta.
39
+         */
40
+        add_action( 'user_register', array( $this, 'changed_user' ) );
41
+        add_action( 'profile_update', array( $this, 'changed_user' ) );
42
+        add_action( 'added_user_meta', array( $this, 'changed_user_meta' ), 10, 3 );
43
+        add_action( 'updated_user_meta', array( $this, 'changed_user_meta' ), 10, 3 );
44
+        add_action( 'deleted_user_meta', array( $this, 'changed_user_meta' ), 10, 3 );
45
+        add_action( 'delete_user', array( $this, 'delete_user' ) );
46
+
47
+    }
48
+
49
+    public function changed_user( $user_id ) {
50
+
51
+        $this->sync( $user_id );
52
+
53
+    }
54
+
55
+    public function changed_user_meta( $meta_id, $user_id, $meta_key ) {
56
+
57
+        if ( in_array(
58
+            $meta_key,
59
+            apply_filters(
60
+                'wl_dataset__sync_user_hooks__ignored_meta_keys',
61
+                apply_filters(
62
+                    'wl_dataset__sync_hooks__ignored_meta_keys',
63
+                    array(
64
+                        'rich_editing',
65
+                        'comment_shortcuts',
66
+                        'admin_color',
67
+                        'use_ssl',
68
+                        'show_admin_bar_front',
69
+                        'wptests_capabilities',
70
+                        'wptests_user_level',
71
+                        'dismissed_wp_pointers',
72
+                        'entity_url',
73
+                    )
74
+                )
75
+            ),
76
+            true
77
+        ) ) {
78
+            return;
79
+        }
80
+
81
+        $this->sync( $user_id );
82
+
83
+    }
84
+
85
+    private function sync( $user_id ) {
86
+        $this->enqueue( array( 'do_sync', $user_id ) );
87
+    }
88
+
89
+    public function do_sync( $user_id ) {
90
+
91
+        try {
92
+            $this->sync_service->sync_one( Object_Type_Enum::USER, (int) $user_id );
93
+        } catch ( \Exception $e ) {
94
+            $this->log->error( "An error occurred while trying to sync user $user_id: " . $e->getMessage(), $e );
95
+        }
96
+
97
+    }
98
+
99
+    public function delete_user( $user_id ) {
100
+        $this->enqueue( array( 'do_delete', $user_id ) );
101
+    }
102
+
103
+    public function do_delete( $user_id ) {
104
+        try {
105
+            $this->sync_service->delete_one(
106
+                Object_Type_Enum::USER,
107
+                $user_id,
108
+                Wordpress_User_Content_Legacy_Service::get_instance()->get_entity_id( Wordpress_Content_Id::create_user( $user_id ) )
109
+            );
110
+        } catch ( \Exception $e ) {
111
+            $this->log->error( "An error occurred while trying to delete user $user_id: " . $e->getMessage(), $e );
112
+        }
113
+
114
+    }
115 115
 
116 116
 }
Please login to merge, or discard this patch.
Spacing   +26 added lines, -26 removed lines patch added patch discarded remove patch
@@ -22,10 +22,10 @@  discard block
 block discarded – undo
22 22
 	 *
23 23
 	 * @param Sync_Service $sync_service
24 24
 	 */
25
-	public function __construct( Sync_Service $sync_service ) {
25
+	public function __construct(Sync_Service $sync_service) {
26 26
 		parent::__construct();
27 27
 
28
-		$this->log = \Wordlift_Log_Service::get_logger( get_class() );
28
+		$this->log = \Wordlift_Log_Service::get_logger(get_class());
29 29
 
30 30
 		$this->sync_service = $sync_service;
31 31
 
@@ -37,24 +37,24 @@  discard block
 block discarded – undo
37 37
 		/**
38 38
 		 * Register hooks for user and meta.
39 39
 		 */
40
-		add_action( 'user_register', array( $this, 'changed_user' ) );
41
-		add_action( 'profile_update', array( $this, 'changed_user' ) );
42
-		add_action( 'added_user_meta', array( $this, 'changed_user_meta' ), 10, 3 );
43
-		add_action( 'updated_user_meta', array( $this, 'changed_user_meta' ), 10, 3 );
44
-		add_action( 'deleted_user_meta', array( $this, 'changed_user_meta' ), 10, 3 );
45
-		add_action( 'delete_user', array( $this, 'delete_user' ) );
40
+		add_action('user_register', array($this, 'changed_user'));
41
+		add_action('profile_update', array($this, 'changed_user'));
42
+		add_action('added_user_meta', array($this, 'changed_user_meta'), 10, 3);
43
+		add_action('updated_user_meta', array($this, 'changed_user_meta'), 10, 3);
44
+		add_action('deleted_user_meta', array($this, 'changed_user_meta'), 10, 3);
45
+		add_action('delete_user', array($this, 'delete_user'));
46 46
 
47 47
 	}
48 48
 
49
-	public function changed_user( $user_id ) {
49
+	public function changed_user($user_id) {
50 50
 
51
-		$this->sync( $user_id );
51
+		$this->sync($user_id);
52 52
 
53 53
 	}
54 54
 
55
-	public function changed_user_meta( $meta_id, $user_id, $meta_key ) {
55
+	public function changed_user_meta($meta_id, $user_id, $meta_key) {
56 56
 
57
-		if ( in_array(
57
+		if (in_array(
58 58
 			$meta_key,
59 59
 			apply_filters(
60 60
 				'wl_dataset__sync_user_hooks__ignored_meta_keys',
@@ -74,41 +74,41 @@  discard block
 block discarded – undo
74 74
 				)
75 75
 			),
76 76
 			true
77
-		) ) {
77
+		)) {
78 78
 			return;
79 79
 		}
80 80
 
81
-		$this->sync( $user_id );
81
+		$this->sync($user_id);
82 82
 
83 83
 	}
84 84
 
85
-	private function sync( $user_id ) {
86
-		$this->enqueue( array( 'do_sync', $user_id ) );
85
+	private function sync($user_id) {
86
+		$this->enqueue(array('do_sync', $user_id));
87 87
 	}
88 88
 
89
-	public function do_sync( $user_id ) {
89
+	public function do_sync($user_id) {
90 90
 
91 91
 		try {
92
-			$this->sync_service->sync_one( Object_Type_Enum::USER, (int) $user_id );
93
-		} catch ( \Exception $e ) {
94
-			$this->log->error( "An error occurred while trying to sync user $user_id: " . $e->getMessage(), $e );
92
+			$this->sync_service->sync_one(Object_Type_Enum::USER, (int) $user_id);
93
+		} catch (\Exception $e) {
94
+			$this->log->error("An error occurred while trying to sync user $user_id: ".$e->getMessage(), $e);
95 95
 		}
96 96
 
97 97
 	}
98 98
 
99
-	public function delete_user( $user_id ) {
100
-		$this->enqueue( array( 'do_delete', $user_id ) );
99
+	public function delete_user($user_id) {
100
+		$this->enqueue(array('do_delete', $user_id));
101 101
 	}
102 102
 
103
-	public function do_delete( $user_id ) {
103
+	public function do_delete($user_id) {
104 104
 		try {
105 105
 			$this->sync_service->delete_one(
106 106
 				Object_Type_Enum::USER,
107 107
 				$user_id,
108
-				Wordpress_User_Content_Legacy_Service::get_instance()->get_entity_id( Wordpress_Content_Id::create_user( $user_id ) )
108
+				Wordpress_User_Content_Legacy_Service::get_instance()->get_entity_id(Wordpress_Content_Id::create_user($user_id))
109 109
 			);
110
-		} catch ( \Exception $e ) {
111
-			$this->log->error( "An error occurred while trying to delete user $user_id: " . $e->getMessage(), $e );
110
+		} catch (\Exception $e) {
111
+			$this->log->error("An error occurred while trying to delete user $user_id: ".$e->getMessage(), $e);
112 112
 		}
113 113
 
114 114
 	}
Please login to merge, or discard this patch.
src/wordlift/dataset/class-sync-user-adapter.php 2 patches
Indentation   +28 added lines, -28 removed lines patch added patch discarded remove patch
@@ -6,33 +6,33 @@
 block discarded – undo
6 6
 
7 7
 class Sync_User_Adapter extends Abstract_Sync_Object_Adapter {
8 8
 
9
-	/**
10
-	 * Sync_User_Adapter constructor.
11
-	 *
12
-	 * @param int $user_id
13
-	 *
14
-	 * @throws \Exception when an error occurs.
15
-	 */
16
-	public function __construct( $user_id ) {
17
-		parent::__construct( Object_Type_Enum::USER, $user_id );
18
-	}
19
-
20
-	public function is_published() {
21
-		return true;
22
-	}
23
-
24
-	public function is_public() {
25
-		return true;
26
-	}
27
-
28
-	// phpcs:ignore VariableAnalysis.CodeAnalysis.VariableAnalysis.UnusedVariable
29
-	public function set_values( $arr ) {
30
-		// @@todo
31
-	}
32
-
33
-	// phpcs:ignore VariableAnalysis.CodeAnalysis.VariableAnalysis.UnusedVariable
34
-	public function get_value( $key ) {
35
-		// @@todo
36
-	}
9
+    /**
10
+     * Sync_User_Adapter constructor.
11
+     *
12
+     * @param int $user_id
13
+     *
14
+     * @throws \Exception when an error occurs.
15
+     */
16
+    public function __construct( $user_id ) {
17
+        parent::__construct( Object_Type_Enum::USER, $user_id );
18
+    }
19
+
20
+    public function is_published() {
21
+        return true;
22
+    }
23
+
24
+    public function is_public() {
25
+        return true;
26
+    }
27
+
28
+    // phpcs:ignore VariableAnalysis.CodeAnalysis.VariableAnalysis.UnusedVariable
29
+    public function set_values( $arr ) {
30
+        // @@todo
31
+    }
32
+
33
+    // phpcs:ignore VariableAnalysis.CodeAnalysis.VariableAnalysis.UnusedVariable
34
+    public function get_value( $key ) {
35
+        // @@todo
36
+    }
37 37
 
38 38
 }
Please login to merge, or discard this patch.
Spacing   +4 added lines, -4 removed lines patch added patch discarded remove patch
@@ -13,8 +13,8 @@  discard block
 block discarded – undo
13 13
 	 *
14 14
 	 * @throws \Exception when an error occurs.
15 15
 	 */
16
-	public function __construct( $user_id ) {
17
-		parent::__construct( Object_Type_Enum::USER, $user_id );
16
+	public function __construct($user_id) {
17
+		parent::__construct(Object_Type_Enum::USER, $user_id);
18 18
 	}
19 19
 
20 20
 	public function is_published() {
@@ -26,12 +26,12 @@  discard block
 block discarded – undo
26 26
 	}
27 27
 
28 28
 	// phpcs:ignore VariableAnalysis.CodeAnalysis.VariableAnalysis.UnusedVariable
29
-	public function set_values( $arr ) {
29
+	public function set_values($arr) {
30 30
 		// @@todo
31 31
 	}
32 32
 
33 33
 	// phpcs:ignore VariableAnalysis.CodeAnalysis.VariableAnalysis.UnusedVariable
34
-	public function get_value( $key ) {
34
+	public function get_value($key) {
35 35
 		// @@todo
36 36
 	}
37 37
 
Please login to merge, or discard this patch.
src/wordlift/dataset/class-sync-service.php 2 patches
Indentation   +266 added lines, -266 removed lines patch added patch discarded remove patch
@@ -7,271 +7,271 @@
 block discarded – undo
7 7
 use Wordlift\Object_Type_Enum;
8 8
 
9 9
 class Sync_Service {
10
-	const JSONLD_HASH = 'jsonld_hash';
11
-	const SYNCED_GMT  = 'synced_gmt';
12
-
13
-	/**
14
-	 * @var \Wordlift_Log_Service
15
-	 */
16
-	private $log;
17
-
18
-	/**
19
-	 * @var Api_Service
20
-	 */
21
-	private $api_service;
22
-
23
-	/**
24
-	 * @var Jsonld_Service
25
-	 */
26
-	private $jsonld_service;
27
-
28
-	/**
29
-	 * @var Sync_Background_Process
30
-	 */
31
-	private $sync_background_process;
32
-
33
-	/**
34
-	 * The number of posts processed in one call.
35
-	 *
36
-	 * @var int The batch size.
37
-	 */
38
-	private $batch_size;
39
-
40
-	/**
41
-	 * @var Sync_Object_Adapter_Factory
42
-	 */
43
-	private $sync_object_adapter_factory;
44
-
45
-	/**
46
-	 * @var Sync_Service
47
-	 */
48
-	private static $instance;
49
-	private $entity_service;
50
-
51
-	/**
52
-	 * Constructor.
53
-	 *
54
-	 * @param Api_Service                 $api_service The {@link Api_Service} used to communicate with the remote APIs.
55
-	 * @param Sync_Object_Adapter_Factory $sync_object_adapter_factory
56
-	 * @param Jsonld_Service              $jsonld_service
57
-	 * @param \Wordlift_Entity_Service    $entity_service
58
-	 */
59
-	public function __construct( $api_service, $sync_object_adapter_factory, $jsonld_service, $entity_service ) {
60
-
61
-		$this->log = \Wordlift_Log_Service::get_logger( get_class() );
62
-
63
-		$this->api_service                 = $api_service;
64
-		$this->sync_object_adapter_factory = $sync_object_adapter_factory;
65
-		$this->jsonld_service              = $jsonld_service;
66
-		$this->entity_service              = $entity_service;
67
-		$this->batch_size                  = 10;
68
-
69
-		// You need to initialize this early, otherwise the Background Process isn't registered in AJAX calls.
70
-		// $this->sync_background_process = new Sync_Background_Process( $this );;
71
-
72
-		// Exclude the JSONLD_HASH meta key from those that require a resync.
73
-		add_filter(
74
-			'wl_dataset__sync_hooks__ignored_meta_keys',
75
-			function ( $args ) {
76
-				$args[] = Sync_Service::JSONLD_HASH;
77
-				$args[] = Sync_Service::SYNCED_GMT;
78
-
79
-				return $args;
80
-			}
81
-		);
82
-
83
-		self::$instance = $this;
84
-	}
85
-
86
-	public static function get_instance() {
87
-		return self::$instance;
88
-	}
89
-
90
-	/**
91
-	 * @param int $type
92
-	 * @param int $object_id
93
-	 *
94
-	 * @return array|false
95
-	 * @throws \Exception when an error occurs.
96
-	 */
97
-	public function sync_one( $type, $object_id ) {
98
-
99
-		$object = $this->sync_object_adapter_factory->create( $type, $object_id );
100
-
101
-		return $this->sync_many( array( $object ) );
102
-	}
103
-
104
-	/**
105
-	 * @param $type string Post or User.
106
-	 * @param $object_id  int Post or User id
107
-	 * @param $uri string Entity uri , This needs to be supplied before deletion, if we
108
-	 * get it from meta it might not be available.
109
-	 *
110
-	 * @return bool
111
-	 */
112
-	public function delete_one( $type, $object_id, $uri ) {
113
-		// Entity URL isn't set, bail out.
114
-		if ( empty( $uri ) ) {
115
-			return false;
116
-		}
117
-
118
-		$response = $this->api_service->request(
119
-			'DELETE',
120
-			sprintf( '/middleware/dataset?uri=%s', rawurlencode( $uri ) )
121
-		);
122
-
123
-		// Update the sync date in case of success, otherwise log an error.
124
-		if ( ! $response->is_success() ) {
125
-			return false;
126
-		}
127
-
128
-		/**
129
-		 * Allow 3rd parties to run additional sync work.
130
-		 */
131
-		do_action( 'wl_sync__delete_one', $type, $object_id, $uri );
132
-
133
-		return true;
134
-	}
135
-
136
-	/**
137
-	 * @param Sync_Object_Adapter[] $objects
138
-	 * @param bool                  $force Force synchronization even if the json-ld hash hasn't changed.
139
-	 *
140
-	 * @return bool
141
-	 * @throws \Exception when an error occurs.
142
-	 */
143
-	public function sync_many( $objects, $force = false ) {
144
-
145
-		$hashes   = array();
146
-		$payloads = array();
147
-		/** @var Sync_Object_Adapter $object */
148
-		foreach ( $objects as $object ) {
149
-			// Bail out if no payload.
150
-			$payload_as_string = $this->get_payload_as_string( $object );
151
-			if ( empty( $payload_as_string ) ) {
152
-				continue;
153
-			}
154
-			$new_hash = sha1( $payload_as_string );
155
-			$old_hash = $object->get_value( self::JSONLD_HASH );
156
-
157
-			// JSON-LD hasn't changed, bail out.
158
-			$should_sync = $force || $new_hash !== $old_hash;
159
-			if ( ! apply_filters( 'wl_dataset__sync_service__sync_item', $should_sync, $object, $payload_as_string ) ) {
160
-				continue;
161
-			}
162
-
163
-			// Collect the hashes and the payloads.
164
-			$hashes[]   = array( $object, $new_hash, $payload_as_string );
165
-			$payloads[] = $payload_as_string;
166
-		}
167
-
168
-		// Bail out if payloads are empty.
169
-		if ( empty( $payloads ) ) {
170
-			return false;
171
-		}
172
-
173
-		// phpcs:ignore WordPress.NamingConventions.ValidHookName.UseUnderscores
174
-		$blocking = apply_filters( 'wl_feature__enable__sync-blocking', false );
175
-		$response = $this->api_service->request(
176
-			'POST',
177
-			'/middleware/dataset/batch',
178
-			array( 'Content-Type' => 'application/json' ),
179
-			// Put the payload in a JSON array w/o decoding/encoding again.
180
-			'[ ' . implode( ', ', $payloads ) . ' ]',
181
-			$blocking ? 60 : 0.001,
182
-			null,
183
-			array( 'blocking' => $blocking )
184
-		);
185
-
186
-		// Update the sync date in case of success, otherwise log an error.
187
-		if ( $blocking && ! $response->is_success() ) {
188
-			return false;
189
-		}
190
-
191
-		// If successful update the hashes and sync datetime.
192
-		foreach ( $hashes as $hash ) {
193
-			$object   = $hash[0];
194
-			$new_hash = $hash[1];
195
-
196
-			$object->set_values(
197
-				array(
198
-					self::JSONLD_HASH => $new_hash,
199
-					self::SYNCED_GMT  => current_time( 'mysql', true ),
200
-				)
201
-			);
202
-		}
203
-
204
-		/**
205
-		 * Allow 3rd parties to run additional sync work.
206
-		 */
207
-		do_action( 'wl_sync__sync_many', $hashes );
208
-
209
-		return true;
210
-	}
211
-
212
-	/**
213
-	 * @param Sync_Object_Adapter $object
214
-	 *
215
-	 * @return false|string
216
-	 * @throws \Exception when an error occurs.
217
-	 */
218
-	private function get_payload_as_string( $object ) {
219
-		$type             = $object->get_type();
220
-		$object_id        = $object->get_object_id();
221
-		$jsonld_as_string = wp_json_encode(
222
-			apply_filters(
223
-				'wl_dataset__sync_service__sync_item__jsonld',
224
-				$this->jsonld_service->get( $type, $object_id ),
225
-				$type,
226
-				$object_id
227
-			),
228
-			64
229
-		); // JSON_UNESCAPED_SLASHES
230
-		$uri              = $this->entity_service->get_uri( $object_id, $type );
231
-
232
-		// Entity URL isn't set, bail out.
233
-		if ( empty( $uri ) ) {
234
-			return false;
235
-		}
236
-
237
-		return wp_json_encode(
238
-			array(
239
-				'uri'     => $uri,
240
-				'model'   => $jsonld_as_string,
241
-				'private' => ! ( $object->is_public() && $object->is_published() ),
242
-			),
243
-			64
244
-		); // JSON_UNESCAPED_SLASHES
245
-	}
246
-
247
-	/**
248
-	 * @param $post_id
249
-	 *
250
-	 * @todo Complete the delete item.
251
-	 */
252
-	public function delete_item( $post_id ) {
253
-		$uri = $this->entity_service->get_uri( $post_id, Object_Type_Enum::POST );
254
-
255
-		if ( ! isset( $uri ) ) {
256
-			return;
257
-		}
258
-
259
-		// Make a request to the remote endpoint.
260
-		$this->api_service->request(
261
-			'DELETE',
262
-			'/middleware/dataset?uri=' . rawurlencode( $uri ),
263
-			array( 'Content-Type' => 'application/ld+json' )
264
-		);
265
-
266
-	}
267
-
268
-	public function get_batch_size() {
269
-
270
-		return $this->batch_size;
271
-	}
272
-
273
-	public function delete_all() {
274
-		$this->api_service->request( 'DELETE', '/middleware/dataset/all' );
275
-	}
10
+    const JSONLD_HASH = 'jsonld_hash';
11
+    const SYNCED_GMT  = 'synced_gmt';
12
+
13
+    /**
14
+     * @var \Wordlift_Log_Service
15
+     */
16
+    private $log;
17
+
18
+    /**
19
+     * @var Api_Service
20
+     */
21
+    private $api_service;
22
+
23
+    /**
24
+     * @var Jsonld_Service
25
+     */
26
+    private $jsonld_service;
27
+
28
+    /**
29
+     * @var Sync_Background_Process
30
+     */
31
+    private $sync_background_process;
32
+
33
+    /**
34
+     * The number of posts processed in one call.
35
+     *
36
+     * @var int The batch size.
37
+     */
38
+    private $batch_size;
39
+
40
+    /**
41
+     * @var Sync_Object_Adapter_Factory
42
+     */
43
+    private $sync_object_adapter_factory;
44
+
45
+    /**
46
+     * @var Sync_Service
47
+     */
48
+    private static $instance;
49
+    private $entity_service;
50
+
51
+    /**
52
+     * Constructor.
53
+     *
54
+     * @param Api_Service                 $api_service The {@link Api_Service} used to communicate with the remote APIs.
55
+     * @param Sync_Object_Adapter_Factory $sync_object_adapter_factory
56
+     * @param Jsonld_Service              $jsonld_service
57
+     * @param \Wordlift_Entity_Service    $entity_service
58
+     */
59
+    public function __construct( $api_service, $sync_object_adapter_factory, $jsonld_service, $entity_service ) {
60
+
61
+        $this->log = \Wordlift_Log_Service::get_logger( get_class() );
62
+
63
+        $this->api_service                 = $api_service;
64
+        $this->sync_object_adapter_factory = $sync_object_adapter_factory;
65
+        $this->jsonld_service              = $jsonld_service;
66
+        $this->entity_service              = $entity_service;
67
+        $this->batch_size                  = 10;
68
+
69
+        // You need to initialize this early, otherwise the Background Process isn't registered in AJAX calls.
70
+        // $this->sync_background_process = new Sync_Background_Process( $this );;
71
+
72
+        // Exclude the JSONLD_HASH meta key from those that require a resync.
73
+        add_filter(
74
+            'wl_dataset__sync_hooks__ignored_meta_keys',
75
+            function ( $args ) {
76
+                $args[] = Sync_Service::JSONLD_HASH;
77
+                $args[] = Sync_Service::SYNCED_GMT;
78
+
79
+                return $args;
80
+            }
81
+        );
82
+
83
+        self::$instance = $this;
84
+    }
85
+
86
+    public static function get_instance() {
87
+        return self::$instance;
88
+    }
89
+
90
+    /**
91
+     * @param int $type
92
+     * @param int $object_id
93
+     *
94
+     * @return array|false
95
+     * @throws \Exception when an error occurs.
96
+     */
97
+    public function sync_one( $type, $object_id ) {
98
+
99
+        $object = $this->sync_object_adapter_factory->create( $type, $object_id );
100
+
101
+        return $this->sync_many( array( $object ) );
102
+    }
103
+
104
+    /**
105
+     * @param $type string Post or User.
106
+     * @param $object_id  int Post or User id
107
+     * @param $uri string Entity uri , This needs to be supplied before deletion, if we
108
+     * get it from meta it might not be available.
109
+     *
110
+     * @return bool
111
+     */
112
+    public function delete_one( $type, $object_id, $uri ) {
113
+        // Entity URL isn't set, bail out.
114
+        if ( empty( $uri ) ) {
115
+            return false;
116
+        }
117
+
118
+        $response = $this->api_service->request(
119
+            'DELETE',
120
+            sprintf( '/middleware/dataset?uri=%s', rawurlencode( $uri ) )
121
+        );
122
+
123
+        // Update the sync date in case of success, otherwise log an error.
124
+        if ( ! $response->is_success() ) {
125
+            return false;
126
+        }
127
+
128
+        /**
129
+         * Allow 3rd parties to run additional sync work.
130
+         */
131
+        do_action( 'wl_sync__delete_one', $type, $object_id, $uri );
132
+
133
+        return true;
134
+    }
135
+
136
+    /**
137
+     * @param Sync_Object_Adapter[] $objects
138
+     * @param bool                  $force Force synchronization even if the json-ld hash hasn't changed.
139
+     *
140
+     * @return bool
141
+     * @throws \Exception when an error occurs.
142
+     */
143
+    public function sync_many( $objects, $force = false ) {
144
+
145
+        $hashes   = array();
146
+        $payloads = array();
147
+        /** @var Sync_Object_Adapter $object */
148
+        foreach ( $objects as $object ) {
149
+            // Bail out if no payload.
150
+            $payload_as_string = $this->get_payload_as_string( $object );
151
+            if ( empty( $payload_as_string ) ) {
152
+                continue;
153
+            }
154
+            $new_hash = sha1( $payload_as_string );
155
+            $old_hash = $object->get_value( self::JSONLD_HASH );
156
+
157
+            // JSON-LD hasn't changed, bail out.
158
+            $should_sync = $force || $new_hash !== $old_hash;
159
+            if ( ! apply_filters( 'wl_dataset__sync_service__sync_item', $should_sync, $object, $payload_as_string ) ) {
160
+                continue;
161
+            }
162
+
163
+            // Collect the hashes and the payloads.
164
+            $hashes[]   = array( $object, $new_hash, $payload_as_string );
165
+            $payloads[] = $payload_as_string;
166
+        }
167
+
168
+        // Bail out if payloads are empty.
169
+        if ( empty( $payloads ) ) {
170
+            return false;
171
+        }
172
+
173
+        // phpcs:ignore WordPress.NamingConventions.ValidHookName.UseUnderscores
174
+        $blocking = apply_filters( 'wl_feature__enable__sync-blocking', false );
175
+        $response = $this->api_service->request(
176
+            'POST',
177
+            '/middleware/dataset/batch',
178
+            array( 'Content-Type' => 'application/json' ),
179
+            // Put the payload in a JSON array w/o decoding/encoding again.
180
+            '[ ' . implode( ', ', $payloads ) . ' ]',
181
+            $blocking ? 60 : 0.001,
182
+            null,
183
+            array( 'blocking' => $blocking )
184
+        );
185
+
186
+        // Update the sync date in case of success, otherwise log an error.
187
+        if ( $blocking && ! $response->is_success() ) {
188
+            return false;
189
+        }
190
+
191
+        // If successful update the hashes and sync datetime.
192
+        foreach ( $hashes as $hash ) {
193
+            $object   = $hash[0];
194
+            $new_hash = $hash[1];
195
+
196
+            $object->set_values(
197
+                array(
198
+                    self::JSONLD_HASH => $new_hash,
199
+                    self::SYNCED_GMT  => current_time( 'mysql', true ),
200
+                )
201
+            );
202
+        }
203
+
204
+        /**
205
+         * Allow 3rd parties to run additional sync work.
206
+         */
207
+        do_action( 'wl_sync__sync_many', $hashes );
208
+
209
+        return true;
210
+    }
211
+
212
+    /**
213
+     * @param Sync_Object_Adapter $object
214
+     *
215
+     * @return false|string
216
+     * @throws \Exception when an error occurs.
217
+     */
218
+    private function get_payload_as_string( $object ) {
219
+        $type             = $object->get_type();
220
+        $object_id        = $object->get_object_id();
221
+        $jsonld_as_string = wp_json_encode(
222
+            apply_filters(
223
+                'wl_dataset__sync_service__sync_item__jsonld',
224
+                $this->jsonld_service->get( $type, $object_id ),
225
+                $type,
226
+                $object_id
227
+            ),
228
+            64
229
+        ); // JSON_UNESCAPED_SLASHES
230
+        $uri              = $this->entity_service->get_uri( $object_id, $type );
231
+
232
+        // Entity URL isn't set, bail out.
233
+        if ( empty( $uri ) ) {
234
+            return false;
235
+        }
236
+
237
+        return wp_json_encode(
238
+            array(
239
+                'uri'     => $uri,
240
+                'model'   => $jsonld_as_string,
241
+                'private' => ! ( $object->is_public() && $object->is_published() ),
242
+            ),
243
+            64
244
+        ); // JSON_UNESCAPED_SLASHES
245
+    }
246
+
247
+    /**
248
+     * @param $post_id
249
+     *
250
+     * @todo Complete the delete item.
251
+     */
252
+    public function delete_item( $post_id ) {
253
+        $uri = $this->entity_service->get_uri( $post_id, Object_Type_Enum::POST );
254
+
255
+        if ( ! isset( $uri ) ) {
256
+            return;
257
+        }
258
+
259
+        // Make a request to the remote endpoint.
260
+        $this->api_service->request(
261
+            'DELETE',
262
+            '/middleware/dataset?uri=' . rawurlencode( $uri ),
263
+            array( 'Content-Type' => 'application/ld+json' )
264
+        );
265
+
266
+    }
267
+
268
+    public function get_batch_size() {
269
+
270
+        return $this->batch_size;
271
+    }
272
+
273
+    public function delete_all() {
274
+        $this->api_service->request( 'DELETE', '/middleware/dataset/all' );
275
+    }
276 276
 
277 277
 }
Please login to merge, or discard this patch.
Spacing   +39 added lines, -39 removed lines patch added patch discarded remove patch
@@ -56,9 +56,9 @@  discard block
 block discarded – undo
56 56
 	 * @param Jsonld_Service              $jsonld_service
57 57
 	 * @param \Wordlift_Entity_Service    $entity_service
58 58
 	 */
59
-	public function __construct( $api_service, $sync_object_adapter_factory, $jsonld_service, $entity_service ) {
59
+	public function __construct($api_service, $sync_object_adapter_factory, $jsonld_service, $entity_service) {
60 60
 
61
-		$this->log = \Wordlift_Log_Service::get_logger( get_class() );
61
+		$this->log = \Wordlift_Log_Service::get_logger(get_class());
62 62
 
63 63
 		$this->api_service                 = $api_service;
64 64
 		$this->sync_object_adapter_factory = $sync_object_adapter_factory;
@@ -72,7 +72,7 @@  discard block
 block discarded – undo
72 72
 		// Exclude the JSONLD_HASH meta key from those that require a resync.
73 73
 		add_filter(
74 74
 			'wl_dataset__sync_hooks__ignored_meta_keys',
75
-			function ( $args ) {
75
+			function($args) {
76 76
 				$args[] = Sync_Service::JSONLD_HASH;
77 77
 				$args[] = Sync_Service::SYNCED_GMT;
78 78
 
@@ -94,11 +94,11 @@  discard block
 block discarded – undo
94 94
 	 * @return array|false
95 95
 	 * @throws \Exception when an error occurs.
96 96
 	 */
97
-	public function sync_one( $type, $object_id ) {
97
+	public function sync_one($type, $object_id) {
98 98
 
99
-		$object = $this->sync_object_adapter_factory->create( $type, $object_id );
99
+		$object = $this->sync_object_adapter_factory->create($type, $object_id);
100 100
 
101
-		return $this->sync_many( array( $object ) );
101
+		return $this->sync_many(array($object));
102 102
 	}
103 103
 
104 104
 	/**
@@ -109,26 +109,26 @@  discard block
 block discarded – undo
109 109
 	 *
110 110
 	 * @return bool
111 111
 	 */
112
-	public function delete_one( $type, $object_id, $uri ) {
112
+	public function delete_one($type, $object_id, $uri) {
113 113
 		// Entity URL isn't set, bail out.
114
-		if ( empty( $uri ) ) {
114
+		if (empty($uri)) {
115 115
 			return false;
116 116
 		}
117 117
 
118 118
 		$response = $this->api_service->request(
119 119
 			'DELETE',
120
-			sprintf( '/middleware/dataset?uri=%s', rawurlencode( $uri ) )
120
+			sprintf('/middleware/dataset?uri=%s', rawurlencode($uri))
121 121
 		);
122 122
 
123 123
 		// Update the sync date in case of success, otherwise log an error.
124
-		if ( ! $response->is_success() ) {
124
+		if ( ! $response->is_success()) {
125 125
 			return false;
126 126
 		}
127 127
 
128 128
 		/**
129 129
 		 * Allow 3rd parties to run additional sync work.
130 130
 		 */
131
-		do_action( 'wl_sync__delete_one', $type, $object_id, $uri );
131
+		do_action('wl_sync__delete_one', $type, $object_id, $uri);
132 132
 
133 133
 		return true;
134 134
 	}
@@ -140,63 +140,63 @@  discard block
 block discarded – undo
140 140
 	 * @return bool
141 141
 	 * @throws \Exception when an error occurs.
142 142
 	 */
143
-	public function sync_many( $objects, $force = false ) {
143
+	public function sync_many($objects, $force = false) {
144 144
 
145 145
 		$hashes   = array();
146 146
 		$payloads = array();
147 147
 		/** @var Sync_Object_Adapter $object */
148
-		foreach ( $objects as $object ) {
148
+		foreach ($objects as $object) {
149 149
 			// Bail out if no payload.
150
-			$payload_as_string = $this->get_payload_as_string( $object );
151
-			if ( empty( $payload_as_string ) ) {
150
+			$payload_as_string = $this->get_payload_as_string($object);
151
+			if (empty($payload_as_string)) {
152 152
 				continue;
153 153
 			}
154
-			$new_hash = sha1( $payload_as_string );
155
-			$old_hash = $object->get_value( self::JSONLD_HASH );
154
+			$new_hash = sha1($payload_as_string);
155
+			$old_hash = $object->get_value(self::JSONLD_HASH);
156 156
 
157 157
 			// JSON-LD hasn't changed, bail out.
158 158
 			$should_sync = $force || $new_hash !== $old_hash;
159
-			if ( ! apply_filters( 'wl_dataset__sync_service__sync_item', $should_sync, $object, $payload_as_string ) ) {
159
+			if ( ! apply_filters('wl_dataset__sync_service__sync_item', $should_sync, $object, $payload_as_string)) {
160 160
 				continue;
161 161
 			}
162 162
 
163 163
 			// Collect the hashes and the payloads.
164
-			$hashes[]   = array( $object, $new_hash, $payload_as_string );
164
+			$hashes[]   = array($object, $new_hash, $payload_as_string);
165 165
 			$payloads[] = $payload_as_string;
166 166
 		}
167 167
 
168 168
 		// Bail out if payloads are empty.
169
-		if ( empty( $payloads ) ) {
169
+		if (empty($payloads)) {
170 170
 			return false;
171 171
 		}
172 172
 
173 173
 		// phpcs:ignore WordPress.NamingConventions.ValidHookName.UseUnderscores
174
-		$blocking = apply_filters( 'wl_feature__enable__sync-blocking', false );
174
+		$blocking = apply_filters('wl_feature__enable__sync-blocking', false);
175 175
 		$response = $this->api_service->request(
176 176
 			'POST',
177 177
 			'/middleware/dataset/batch',
178
-			array( 'Content-Type' => 'application/json' ),
178
+			array('Content-Type' => 'application/json'),
179 179
 			// Put the payload in a JSON array w/o decoding/encoding again.
180
-			'[ ' . implode( ', ', $payloads ) . ' ]',
180
+			'[ '.implode(', ', $payloads).' ]',
181 181
 			$blocking ? 60 : 0.001,
182 182
 			null,
183
-			array( 'blocking' => $blocking )
183
+			array('blocking' => $blocking)
184 184
 		);
185 185
 
186 186
 		// Update the sync date in case of success, otherwise log an error.
187
-		if ( $blocking && ! $response->is_success() ) {
187
+		if ($blocking && ! $response->is_success()) {
188 188
 			return false;
189 189
 		}
190 190
 
191 191
 		// If successful update the hashes and sync datetime.
192
-		foreach ( $hashes as $hash ) {
192
+		foreach ($hashes as $hash) {
193 193
 			$object   = $hash[0];
194 194
 			$new_hash = $hash[1];
195 195
 
196 196
 			$object->set_values(
197 197
 				array(
198 198
 					self::JSONLD_HASH => $new_hash,
199
-					self::SYNCED_GMT  => current_time( 'mysql', true ),
199
+					self::SYNCED_GMT  => current_time('mysql', true),
200 200
 				)
201 201
 			);
202 202
 		}
@@ -204,7 +204,7 @@  discard block
 block discarded – undo
204 204
 		/**
205 205
 		 * Allow 3rd parties to run additional sync work.
206 206
 		 */
207
-		do_action( 'wl_sync__sync_many', $hashes );
207
+		do_action('wl_sync__sync_many', $hashes);
208 208
 
209 209
 		return true;
210 210
 	}
@@ -215,22 +215,22 @@  discard block
 block discarded – undo
215 215
 	 * @return false|string
216 216
 	 * @throws \Exception when an error occurs.
217 217
 	 */
218
-	private function get_payload_as_string( $object ) {
218
+	private function get_payload_as_string($object) {
219 219
 		$type             = $object->get_type();
220 220
 		$object_id        = $object->get_object_id();
221 221
 		$jsonld_as_string = wp_json_encode(
222 222
 			apply_filters(
223 223
 				'wl_dataset__sync_service__sync_item__jsonld',
224
-				$this->jsonld_service->get( $type, $object_id ),
224
+				$this->jsonld_service->get($type, $object_id),
225 225
 				$type,
226 226
 				$object_id
227 227
 			),
228 228
 			64
229 229
 		); // JSON_UNESCAPED_SLASHES
230
-		$uri              = $this->entity_service->get_uri( $object_id, $type );
230
+		$uri = $this->entity_service->get_uri($object_id, $type);
231 231
 
232 232
 		// Entity URL isn't set, bail out.
233
-		if ( empty( $uri ) ) {
233
+		if (empty($uri)) {
234 234
 			return false;
235 235
 		}
236 236
 
@@ -238,7 +238,7 @@  discard block
 block discarded – undo
238 238
 			array(
239 239
 				'uri'     => $uri,
240 240
 				'model'   => $jsonld_as_string,
241
-				'private' => ! ( $object->is_public() && $object->is_published() ),
241
+				'private' => ! ($object->is_public() && $object->is_published()),
242 242
 			),
243 243
 			64
244 244
 		); // JSON_UNESCAPED_SLASHES
@@ -249,18 +249,18 @@  discard block
 block discarded – undo
249 249
 	 *
250 250
 	 * @todo Complete the delete item.
251 251
 	 */
252
-	public function delete_item( $post_id ) {
253
-		$uri = $this->entity_service->get_uri( $post_id, Object_Type_Enum::POST );
252
+	public function delete_item($post_id) {
253
+		$uri = $this->entity_service->get_uri($post_id, Object_Type_Enum::POST);
254 254
 
255
-		if ( ! isset( $uri ) ) {
255
+		if ( ! isset($uri)) {
256 256
 			return;
257 257
 		}
258 258
 
259 259
 		// Make a request to the remote endpoint.
260 260
 		$this->api_service->request(
261 261
 			'DELETE',
262
-			'/middleware/dataset?uri=' . rawurlencode( $uri ),
263
-			array( 'Content-Type' => 'application/ld+json' )
262
+			'/middleware/dataset?uri='.rawurlencode($uri),
263
+			array('Content-Type' => 'application/ld+json')
264 264
 		);
265 265
 
266 266
 	}
@@ -271,7 +271,7 @@  discard block
 block discarded – undo
271 271
 	}
272 272
 
273 273
 	public function delete_all() {
274
-		$this->api_service->request( 'DELETE', '/middleware/dataset/all' );
274
+		$this->api_service->request('DELETE', '/middleware/dataset/all');
275 275
 	}
276 276
 
277 277
 }
Please login to merge, or discard this patch.
src/wordlift/dataset/index.php 2 patches
Indentation   +25 added lines, -25 removed lines patch added patch discarded remove patch
@@ -14,38 +14,38 @@
 block discarded – undo
14 14
 use Wordlift\Jsonld\Jsonld_Service;
15 15
 
16 16
 if ( ! defined( 'ABSPATH' ) ) {
17
-	exit;
17
+    exit;
18 18
 }
19 19
 
20 20
 // Register the Dataset JSON Endpoint.
21 21
 // phpcs:ignore WordPress.NamingConventions.ValidHookName.UseUnderscores
22 22
 if ( apply_filters( 'wl_feature__enable__dataset-ng', false ) ) {
23 23
 
24
-	$sync_object_adapter_factory = new Sync_Object_Adapter_Factory();
25
-	$sync_service                = new Sync_Service( Default_Api_Service::get_instance(), $sync_object_adapter_factory, Jsonld_Service::get_instance(), Wordlift_Entity_Service::get_instance() );
26
-	new Sync_Post_Hooks( $sync_service, $sync_object_adapter_factory );
27
-	new Sync_User_Hooks( $sync_service );
24
+    $sync_object_adapter_factory = new Sync_Object_Adapter_Factory();
25
+    $sync_service                = new Sync_Service( Default_Api_Service::get_instance(), $sync_object_adapter_factory, Jsonld_Service::get_instance(), Wordlift_Entity_Service::get_instance() );
26
+    new Sync_Post_Hooks( $sync_service, $sync_object_adapter_factory );
27
+    new Sync_User_Hooks( $sync_service );
28 28
 
29
-	// phpcs:ignore WordPress.NamingConventions.ValidHookName.UseUnderscores
30
-	if ( apply_filters( 'wl_feature__enable__no-vocabulary-terms', false ) ) {
31
-		new Sync_Term_Hooks( $sync_service, $sync_object_adapter_factory );
32
-	}
33
-	/**
34
-	 * @since 3.28.0
35
-	 * @see https://github.com/insideout10/wordlift-plugin/issues/1186
36
-	 */
37
-	new Sync_Hooks_Entity_Relation( Wordlift_Entity_Service::get_instance() );
29
+    // phpcs:ignore WordPress.NamingConventions.ValidHookName.UseUnderscores
30
+    if ( apply_filters( 'wl_feature__enable__no-vocabulary-terms', false ) ) {
31
+        new Sync_Term_Hooks( $sync_service, $sync_object_adapter_factory );
32
+    }
33
+    /**
34
+     * @since 3.28.0
35
+     * @see https://github.com/insideout10/wordlift-plugin/issues/1186
36
+     */
37
+    new Sync_Hooks_Entity_Relation( Wordlift_Entity_Service::get_instance() );
38 38
 
39
-	// phpcs:ignore WordPress.NamingConventions.ValidHookName.UseUnderscores
40
-	if ( apply_filters( 'wl_feature__enable__wordpress-ontology', false ) ) {
41
-		new Sync_Hooks_Wordpress_Ontology();
42
-	}
39
+    // phpcs:ignore WordPress.NamingConventions.ValidHookName.UseUnderscores
40
+    if ( apply_filters( 'wl_feature__enable__wordpress-ontology', false ) ) {
41
+        new Sync_Hooks_Wordpress_Ontology();
42
+    }
43 43
 
44
-	// phpcs:ignore WordPress.NamingConventions.ValidHookName.UseUnderscores
45
-	if ( apply_filters( 'wl_feature__enable__sync-background', false ) ) {
46
-		// Set up the sync background process.
47
-		$sync_background_process = new Sync_Background_Process( $sync_service, $sync_object_adapter_factory );
48
-		new Sync_Background_Process_Wpjson_Endpoint( $sync_background_process );
49
-		new Sync_Page();
50
-	}
44
+    // phpcs:ignore WordPress.NamingConventions.ValidHookName.UseUnderscores
45
+    if ( apply_filters( 'wl_feature__enable__sync-background', false ) ) {
46
+        // Set up the sync background process.
47
+        $sync_background_process = new Sync_Background_Process( $sync_service, $sync_object_adapter_factory );
48
+        new Sync_Background_Process_Wpjson_Endpoint( $sync_background_process );
49
+        new Sync_Page();
50
+    }
51 51
 }
Please login to merge, or discard this patch.
Spacing   +12 added lines, -12 removed lines patch added patch discarded remove patch
@@ -13,39 +13,39 @@
 block discarded – undo
13 13
 use Wordlift\Dataset\Sync_User_Hooks;
14 14
 use Wordlift\Jsonld\Jsonld_Service;
15 15
 
16
-if ( ! defined( 'ABSPATH' ) ) {
16
+if ( ! defined('ABSPATH')) {
17 17
 	exit;
18 18
 }
19 19
 
20 20
 // Register the Dataset JSON Endpoint.
21 21
 // phpcs:ignore WordPress.NamingConventions.ValidHookName.UseUnderscores
22
-if ( apply_filters( 'wl_feature__enable__dataset-ng', false ) ) {
22
+if (apply_filters('wl_feature__enable__dataset-ng', false)) {
23 23
 
24 24
 	$sync_object_adapter_factory = new Sync_Object_Adapter_Factory();
25
-	$sync_service                = new Sync_Service( Default_Api_Service::get_instance(), $sync_object_adapter_factory, Jsonld_Service::get_instance(), Wordlift_Entity_Service::get_instance() );
26
-	new Sync_Post_Hooks( $sync_service, $sync_object_adapter_factory );
27
-	new Sync_User_Hooks( $sync_service );
25
+	$sync_service                = new Sync_Service(Default_Api_Service::get_instance(), $sync_object_adapter_factory, Jsonld_Service::get_instance(), Wordlift_Entity_Service::get_instance());
26
+	new Sync_Post_Hooks($sync_service, $sync_object_adapter_factory);
27
+	new Sync_User_Hooks($sync_service);
28 28
 
29 29
 	// phpcs:ignore WordPress.NamingConventions.ValidHookName.UseUnderscores
30
-	if ( apply_filters( 'wl_feature__enable__no-vocabulary-terms', false ) ) {
31
-		new Sync_Term_Hooks( $sync_service, $sync_object_adapter_factory );
30
+	if (apply_filters('wl_feature__enable__no-vocabulary-terms', false)) {
31
+		new Sync_Term_Hooks($sync_service, $sync_object_adapter_factory);
32 32
 	}
33 33
 	/**
34 34
 	 * @since 3.28.0
35 35
 	 * @see https://github.com/insideout10/wordlift-plugin/issues/1186
36 36
 	 */
37
-	new Sync_Hooks_Entity_Relation( Wordlift_Entity_Service::get_instance() );
37
+	new Sync_Hooks_Entity_Relation(Wordlift_Entity_Service::get_instance());
38 38
 
39 39
 	// phpcs:ignore WordPress.NamingConventions.ValidHookName.UseUnderscores
40
-	if ( apply_filters( 'wl_feature__enable__wordpress-ontology', false ) ) {
40
+	if (apply_filters('wl_feature__enable__wordpress-ontology', false)) {
41 41
 		new Sync_Hooks_Wordpress_Ontology();
42 42
 	}
43 43
 
44 44
 	// phpcs:ignore WordPress.NamingConventions.ValidHookName.UseUnderscores
45
-	if ( apply_filters( 'wl_feature__enable__sync-background', false ) ) {
45
+	if (apply_filters('wl_feature__enable__sync-background', false)) {
46 46
 		// Set up the sync background process.
47
-		$sync_background_process = new Sync_Background_Process( $sync_service, $sync_object_adapter_factory );
48
-		new Sync_Background_Process_Wpjson_Endpoint( $sync_background_process );
47
+		$sync_background_process = new Sync_Background_Process($sync_service, $sync_object_adapter_factory);
48
+		new Sync_Background_Process_Wpjson_Endpoint($sync_background_process);
49 49
 		new Sync_Page();
50 50
 	}
51 51
 }
Please login to merge, or discard this patch.
src/wordlift/dataset/class-sync-hooks-wordpress-ontology.php 2 patches
Indentation   +60 added lines, -60 removed lines patch added patch discarded remove patch
@@ -7,65 +7,65 @@
 block discarded – undo
7 7
 // phpcs:ignore WordPress.WP.CapitalPDangit.MisspelledClassName
8 8
 class Sync_Hooks_Wordpress_Ontology {
9 9
 
10
-	const HTTP_PURL_ORG_WORDPRESS_1_0 = 'http://purl.org/wordpress/1.0/';
11
-
12
-	public function __construct() {
13
-		add_filter( 'wl_dataset__sync_service__sync_item__jsonld', array( $this, 'jsonld' ), 10, 3 );
14
-	}
15
-
16
-	public function jsonld( $jsonld, $type, $object_id ) {
17
-
18
-		$jsonld[0][ self::HTTP_PURL_ORG_WORDPRESS_1_0 . 'id' ] = $object_id;
19
-
20
-		switch ( $type ) {
21
-
22
-			case Object_Type_Enum::TERM:
23
-				$term = get_term( $object_id );
24
-
25
-				$jsonld[0][ self::HTTP_PURL_ORG_WORDPRESS_1_0 . 'type' ]        = 'term';
26
-				$jsonld[0][ self::HTTP_PURL_ORG_WORDPRESS_1_0 . 'name' ]        = $term->name;
27
-				$jsonld[0][ self::HTTP_PURL_ORG_WORDPRESS_1_0 . 'description' ] = $term->description;
28
-				break;
29
-
30
-			case Object_Type_Enum::USER:
31
-				$user = get_userdata( $object_id );
32
-
33
-				$jsonld[0][ self::HTTP_PURL_ORG_WORDPRESS_1_0 . 'type' ]        = 'user';
34
-				$jsonld[0][ self::HTTP_PURL_ORG_WORDPRESS_1_0 . 'displayName' ] = $user->display_name;
35
-				break;
36
-
37
-			case Object_Type_Enum::POST:
38
-				$post = get_post( $object_id );
39
-
40
-				$jsonld[0][ self::HTTP_PURL_ORG_WORDPRESS_1_0 . 'type' ]       = 'post';
41
-				$jsonld[0][ self::HTTP_PURL_ORG_WORDPRESS_1_0 . 'customType' ] = $post->post_type;
42
-				$jsonld[0][ self::HTTP_PURL_ORG_WORDPRESS_1_0 . 'title' ]      = $post->post_title;
43
-				$jsonld[0][ self::HTTP_PURL_ORG_WORDPRESS_1_0 . 'status' ]     = $post->post_status;
44
-				$content = has_blocks( $post ) ?
45
-					do_blocks( $post->post_content ) : do_shortcode( $post->post_content );
46
-				$jsonld[0][ self::HTTP_PURL_ORG_WORDPRESS_1_0 . 'content' ]   = $content;
47
-				$jsonld[0][ self::HTTP_PURL_ORG_WORDPRESS_1_0 . 'permalink' ] = get_permalink( $post );
48
-				$jsonld[0][ self::HTTP_PURL_ORG_WORDPRESS_1_0 . 'sticky' ]    = is_sticky( $post->ID );
49
-
50
-				$taxonomies = get_post_taxonomies( $post );
51
-				$_tmp_terms = array();
52
-				foreach ( $taxonomies as $taxonomy ) {
53
-					$terms = wp_get_post_terms( $post->ID, $taxonomy );
54
-					/** @var \WP_Term $term */
55
-					foreach ( $terms as $term ) {
56
-						$_tmp_terms[] = "$taxonomy:$term->name";
57
-					}
58
-				}
59
-				if ( ! empty( $_tmp_terms ) ) {
60
-					$jsonld[0][ self::HTTP_PURL_ORG_WORDPRESS_1_0 . 'terms' ] = $_tmp_terms;
61
-				}
62
-
63
-				break;
64
-
65
-			default:
66
-		}
67
-
68
-		return $jsonld;
69
-	}
10
+    const HTTP_PURL_ORG_WORDPRESS_1_0 = 'http://purl.org/wordpress/1.0/';
11
+
12
+    public function __construct() {
13
+        add_filter( 'wl_dataset__sync_service__sync_item__jsonld', array( $this, 'jsonld' ), 10, 3 );
14
+    }
15
+
16
+    public function jsonld( $jsonld, $type, $object_id ) {
17
+
18
+        $jsonld[0][ self::HTTP_PURL_ORG_WORDPRESS_1_0 . 'id' ] = $object_id;
19
+
20
+        switch ( $type ) {
21
+
22
+            case Object_Type_Enum::TERM:
23
+                $term = get_term( $object_id );
24
+
25
+                $jsonld[0][ self::HTTP_PURL_ORG_WORDPRESS_1_0 . 'type' ]        = 'term';
26
+                $jsonld[0][ self::HTTP_PURL_ORG_WORDPRESS_1_0 . 'name' ]        = $term->name;
27
+                $jsonld[0][ self::HTTP_PURL_ORG_WORDPRESS_1_0 . 'description' ] = $term->description;
28
+                break;
29
+
30
+            case Object_Type_Enum::USER:
31
+                $user = get_userdata( $object_id );
32
+
33
+                $jsonld[0][ self::HTTP_PURL_ORG_WORDPRESS_1_0 . 'type' ]        = 'user';
34
+                $jsonld[0][ self::HTTP_PURL_ORG_WORDPRESS_1_0 . 'displayName' ] = $user->display_name;
35
+                break;
36
+
37
+            case Object_Type_Enum::POST:
38
+                $post = get_post( $object_id );
39
+
40
+                $jsonld[0][ self::HTTP_PURL_ORG_WORDPRESS_1_0 . 'type' ]       = 'post';
41
+                $jsonld[0][ self::HTTP_PURL_ORG_WORDPRESS_1_0 . 'customType' ] = $post->post_type;
42
+                $jsonld[0][ self::HTTP_PURL_ORG_WORDPRESS_1_0 . 'title' ]      = $post->post_title;
43
+                $jsonld[0][ self::HTTP_PURL_ORG_WORDPRESS_1_0 . 'status' ]     = $post->post_status;
44
+                $content = has_blocks( $post ) ?
45
+                    do_blocks( $post->post_content ) : do_shortcode( $post->post_content );
46
+                $jsonld[0][ self::HTTP_PURL_ORG_WORDPRESS_1_0 . 'content' ]   = $content;
47
+                $jsonld[0][ self::HTTP_PURL_ORG_WORDPRESS_1_0 . 'permalink' ] = get_permalink( $post );
48
+                $jsonld[0][ self::HTTP_PURL_ORG_WORDPRESS_1_0 . 'sticky' ]    = is_sticky( $post->ID );
49
+
50
+                $taxonomies = get_post_taxonomies( $post );
51
+                $_tmp_terms = array();
52
+                foreach ( $taxonomies as $taxonomy ) {
53
+                    $terms = wp_get_post_terms( $post->ID, $taxonomy );
54
+                    /** @var \WP_Term $term */
55
+                    foreach ( $terms as $term ) {
56
+                        $_tmp_terms[] = "$taxonomy:$term->name";
57
+                    }
58
+                }
59
+                if ( ! empty( $_tmp_terms ) ) {
60
+                    $jsonld[0][ self::HTTP_PURL_ORG_WORDPRESS_1_0 . 'terms' ] = $_tmp_terms;
61
+                }
62
+
63
+                break;
64
+
65
+            default:
66
+        }
67
+
68
+        return $jsonld;
69
+    }
70 70
 
71 71
 }
Please login to merge, or discard this patch.
Spacing   +29 added lines, -29 removed lines patch added patch discarded remove patch
@@ -10,54 +10,54 @@
 block discarded – undo
10 10
 	const HTTP_PURL_ORG_WORDPRESS_1_0 = 'http://purl.org/wordpress/1.0/';
11 11
 
12 12
 	public function __construct() {
13
-		add_filter( 'wl_dataset__sync_service__sync_item__jsonld', array( $this, 'jsonld' ), 10, 3 );
13
+		add_filter('wl_dataset__sync_service__sync_item__jsonld', array($this, 'jsonld'), 10, 3);
14 14
 	}
15 15
 
16
-	public function jsonld( $jsonld, $type, $object_id ) {
16
+	public function jsonld($jsonld, $type, $object_id) {
17 17
 
18
-		$jsonld[0][ self::HTTP_PURL_ORG_WORDPRESS_1_0 . 'id' ] = $object_id;
18
+		$jsonld[0][self::HTTP_PURL_ORG_WORDPRESS_1_0.'id'] = $object_id;
19 19
 
20
-		switch ( $type ) {
20
+		switch ($type) {
21 21
 
22 22
 			case Object_Type_Enum::TERM:
23
-				$term = get_term( $object_id );
23
+				$term = get_term($object_id);
24 24
 
25
-				$jsonld[0][ self::HTTP_PURL_ORG_WORDPRESS_1_0 . 'type' ]        = 'term';
26
-				$jsonld[0][ self::HTTP_PURL_ORG_WORDPRESS_1_0 . 'name' ]        = $term->name;
27
-				$jsonld[0][ self::HTTP_PURL_ORG_WORDPRESS_1_0 . 'description' ] = $term->description;
25
+				$jsonld[0][self::HTTP_PURL_ORG_WORDPRESS_1_0.'type']        = 'term';
26
+				$jsonld[0][self::HTTP_PURL_ORG_WORDPRESS_1_0.'name']        = $term->name;
27
+				$jsonld[0][self::HTTP_PURL_ORG_WORDPRESS_1_0.'description'] = $term->description;
28 28
 				break;
29 29
 
30 30
 			case Object_Type_Enum::USER:
31
-				$user = get_userdata( $object_id );
31
+				$user = get_userdata($object_id);
32 32
 
33
-				$jsonld[0][ self::HTTP_PURL_ORG_WORDPRESS_1_0 . 'type' ]        = 'user';
34
-				$jsonld[0][ self::HTTP_PURL_ORG_WORDPRESS_1_0 . 'displayName' ] = $user->display_name;
33
+				$jsonld[0][self::HTTP_PURL_ORG_WORDPRESS_1_0.'type']        = 'user';
34
+				$jsonld[0][self::HTTP_PURL_ORG_WORDPRESS_1_0.'displayName'] = $user->display_name;
35 35
 				break;
36 36
 
37 37
 			case Object_Type_Enum::POST:
38
-				$post = get_post( $object_id );
39
-
40
-				$jsonld[0][ self::HTTP_PURL_ORG_WORDPRESS_1_0 . 'type' ]       = 'post';
41
-				$jsonld[0][ self::HTTP_PURL_ORG_WORDPRESS_1_0 . 'customType' ] = $post->post_type;
42
-				$jsonld[0][ self::HTTP_PURL_ORG_WORDPRESS_1_0 . 'title' ]      = $post->post_title;
43
-				$jsonld[0][ self::HTTP_PURL_ORG_WORDPRESS_1_0 . 'status' ]     = $post->post_status;
44
-				$content = has_blocks( $post ) ?
45
-					do_blocks( $post->post_content ) : do_shortcode( $post->post_content );
46
-				$jsonld[0][ self::HTTP_PURL_ORG_WORDPRESS_1_0 . 'content' ]   = $content;
47
-				$jsonld[0][ self::HTTP_PURL_ORG_WORDPRESS_1_0 . 'permalink' ] = get_permalink( $post );
48
-				$jsonld[0][ self::HTTP_PURL_ORG_WORDPRESS_1_0 . 'sticky' ]    = is_sticky( $post->ID );
49
-
50
-				$taxonomies = get_post_taxonomies( $post );
38
+				$post = get_post($object_id);
39
+
40
+				$jsonld[0][self::HTTP_PURL_ORG_WORDPRESS_1_0.'type']       = 'post';
41
+				$jsonld[0][self::HTTP_PURL_ORG_WORDPRESS_1_0.'customType'] = $post->post_type;
42
+				$jsonld[0][self::HTTP_PURL_ORG_WORDPRESS_1_0.'title']      = $post->post_title;
43
+				$jsonld[0][self::HTTP_PURL_ORG_WORDPRESS_1_0.'status']     = $post->post_status;
44
+				$content = has_blocks($post) ?
45
+					do_blocks($post->post_content) : do_shortcode($post->post_content);
46
+				$jsonld[0][self::HTTP_PURL_ORG_WORDPRESS_1_0.'content']   = $content;
47
+				$jsonld[0][self::HTTP_PURL_ORG_WORDPRESS_1_0.'permalink'] = get_permalink($post);
48
+				$jsonld[0][self::HTTP_PURL_ORG_WORDPRESS_1_0.'sticky']    = is_sticky($post->ID);
49
+
50
+				$taxonomies = get_post_taxonomies($post);
51 51
 				$_tmp_terms = array();
52
-				foreach ( $taxonomies as $taxonomy ) {
53
-					$terms = wp_get_post_terms( $post->ID, $taxonomy );
52
+				foreach ($taxonomies as $taxonomy) {
53
+					$terms = wp_get_post_terms($post->ID, $taxonomy);
54 54
 					/** @var \WP_Term $term */
55
-					foreach ( $terms as $term ) {
55
+					foreach ($terms as $term) {
56 56
 						$_tmp_terms[] = "$taxonomy:$term->name";
57 57
 					}
58 58
 				}
59
-				if ( ! empty( $_tmp_terms ) ) {
60
-					$jsonld[0][ self::HTTP_PURL_ORG_WORDPRESS_1_0 . 'terms' ] = $_tmp_terms;
59
+				if ( ! empty($_tmp_terms)) {
60
+					$jsonld[0][self::HTTP_PURL_ORG_WORDPRESS_1_0.'terms'] = $_tmp_terms;
61 61
 				}
62 62
 
63 63
 				break;
Please login to merge, or discard this patch.