Completed
Push — develop ( f5cfcc...e2baaf )
by Naveen
01:17
created
src/shortcodes/wordlift_shortcode_navigator.php 1 patch
Spacing   +110 added lines, -110 removed lines patch added patch discarded remove patch
@@ -22,28 +22,28 @@  discard block
 block discarded – undo
22 22
 
23 23
 	// Create the cache key.
24 24
 	$cache_key_params = $_REQUEST;
25
-	unset( $cache_key_params['uniqid'] );
26
-	$cache_key = array( 'request_params' => $cache_key_params );
25
+	unset($cache_key_params['uniqid']);
26
+	$cache_key = array('request_params' => $cache_key_params);
27 27
 
28 28
 	// Create the TTL cache and try to get the results.
29
-	$cache         = new Ttl_Cache( "navigator", 8 * 60 * 60 ); // 8 hours.
30
-	$cache_results = $cache->get( $cache_key );
29
+	$cache         = new Ttl_Cache("navigator", 8 * 60 * 60); // 8 hours.
30
+	$cache_results = $cache->get($cache_key);
31 31
 
32 32
 	// So that the endpoint can be used remotely
33
-	header( 'Access-Control-Allow-Origin: *' );
33
+	header('Access-Control-Allow-Origin: *');
34 34
 
35
-	if ( isset( $cache_results ) ) {
36
-		header( 'X-WordLift-Cache: HIT' );
35
+	if (isset($cache_results)) {
36
+		header('X-WordLift-Cache: HIT');
37 37
 
38 38
 		return $cache_results;
39 39
 	}
40 40
 
41
-	header( 'X-WordLift-Cache: MISS' );
41
+	header('X-WordLift-Cache: MISS');
42 42
 
43 43
 	$results = _wl_navigator_get_data();
44 44
 
45 45
 	// Put the result before sending the json to the client, since sending the json will terminate us.
46
-	$cache->put( $cache_key, $results );
46
+	$cache->put($cache_key, $results);
47 47
 
48 48
 	return $results;
49 49
 }
@@ -58,29 +58,29 @@  discard block
 block discarded – undo
58 58
  * @since 3.22.6
59 59
  *
60 60
  */
61
-function wl_network_navigator_wp_json( $request ) {
61
+function wl_network_navigator_wp_json($request) {
62 62
 
63 63
 	// Create the cache key.
64 64
 	$cache_key_params = $_REQUEST;
65
-	unset( $cache_key_params['uniqid'] );
66
-	$cache_key = array( 'request_params' => $cache_key_params );
65
+	unset($cache_key_params['uniqid']);
66
+	$cache_key = array('request_params' => $cache_key_params);
67 67
 
68 68
 	// Create the TTL cache and try to get the results.
69
-	$cache         = new Ttl_Cache( "network-navigator", 8 * 60 * 60 ); // 8 hours.
70
-	$cache_results = $cache->get( $cache_key );
69
+	$cache         = new Ttl_Cache("network-navigator", 8 * 60 * 60); // 8 hours.
70
+	$cache_results = $cache->get($cache_key);
71 71
 
72
-	if ( isset( $cache_results ) ) {
73
-		header( 'X-WordLift-Cache: HIT' );
72
+	if (isset($cache_results)) {
73
+		header('X-WordLift-Cache: HIT');
74 74
 
75 75
 		return $cache_results;
76 76
 	}
77 77
 
78
-	header( 'X-WordLift-Cache: MISS' );
78
+	header('X-WordLift-Cache: MISS');
79 79
 
80
-	$results = _wl_network_navigator_get_data( $request );
80
+	$results = _wl_network_navigator_get_data($request);
81 81
 
82 82
 	// Put the result before sending the json to the client, since sending the json will terminate us.
83
-	$cache->put( $cache_key, $results );
83
+	$cache->put($cache_key, $results);
84 84
 
85 85
 	return $results;
86 86
 
@@ -89,58 +89,58 @@  discard block
 block discarded – undo
89 89
 function _wl_navigator_get_data() {
90 90
 
91 91
 	// Post ID must be defined
92
-	if ( ! isset( $_GET['post_id'] ) ) {
93
-		wp_send_json_error( 'No post_id given' );
92
+	if ( ! isset($_GET['post_id'])) {
93
+		wp_send_json_error('No post_id given');
94 94
 
95 95
 		return array();
96 96
 	}
97 97
 
98 98
 	// Post ID must be defined
99
-	if ( ! isset( $_GET['uniqid'] ) ) {
100
-		wp_send_json_error( 'No uniqid given' );
99
+	if ( ! isset($_GET['uniqid'])) {
100
+		wp_send_json_error('No uniqid given');
101 101
 
102 102
 		return array();
103 103
 	}
104 104
 
105 105
 	// Limit the results (defaults to 4)
106
-	$navigator_length    = isset( $_GET['limit'] ) ? intval( $_GET['limit'] ) : 4;
107
-	$navigator_offset    = isset( $_GET['offset'] ) ? intval( $_GET['offset'] ) : 0;
108
-	$order_by            = isset( $_GET['sort'] ) ? sanitize_sql_orderby( $_GET['sort'] ) : 'ID DESC';
109
-	$post_types          = isset( $_GET['post_types'] ) ? (string) $_GET['post_types'] : '';
110
-	$post_types          = explode( ',', $post_types );
106
+	$navigator_length    = isset($_GET['limit']) ? intval($_GET['limit']) : 4;
107
+	$navigator_offset    = isset($_GET['offset']) ? intval($_GET['offset']) : 0;
108
+	$order_by            = isset($_GET['sort']) ? sanitize_sql_orderby($_GET['sort']) : 'ID DESC';
109
+	$post_types          = isset($_GET['post_types']) ? (string) $_GET['post_types'] : '';
110
+	$post_types          = explode(',', $post_types);
111 111
 	$existing_post_types = get_post_types();
112
-	$post_types          = array_values( array_intersect( $existing_post_types, $post_types ) );
112
+	$post_types          = array_values(array_intersect($existing_post_types, $post_types));
113 113
 	$current_post_id     = (int) $_GET['post_id'];
114
-	$current_post        = get_post( $current_post_id );
114
+	$current_post        = get_post($current_post_id);
115 115
 
116 116
 	$navigator_id = (string) $_GET['uniqid'];
117 117
 
118 118
 	// Post ID has to match an existing item
119
-	if ( null === $current_post ) {
120
-		wp_send_json_error( 'No valid post_id given' );
119
+	if (null === $current_post) {
120
+		wp_send_json_error('No valid post_id given');
121 121
 
122 122
 		return array();
123 123
 	}
124 124
 
125 125
 	// Determine navigator type and call respective _get_results
126
-	if ( get_post_type( $current_post_id ) === Wordlift_Entity_Service::TYPE_NAME ) {
126
+	if (get_post_type($current_post_id) === Wordlift_Entity_Service::TYPE_NAME) {
127 127
 
128
-		$referencing_posts = Navigator_Data::entity_navigator_get_results( $current_post_id, array(
128
+		$referencing_posts = Navigator_Data::entity_navigator_get_results($current_post_id, array(
129 129
 			'ID',
130 130
 			'post_title',
131
-		), $order_by, $navigator_length, $navigator_offset, $post_types );
131
+		), $order_by, $navigator_length, $navigator_offset, $post_types);
132 132
 	} else {
133
-		$referencing_posts = Navigator_Data::post_navigator_get_results( $current_post_id, array(
133
+		$referencing_posts = Navigator_Data::post_navigator_get_results($current_post_id, array(
134 134
 			'ID',
135 135
 			'post_title',
136
-		), $order_by, $navigator_length, $navigator_offset, $post_types );
136
+		), $order_by, $navigator_length, $navigator_offset, $post_types);
137 137
 
138 138
 	}
139 139
 
140 140
 	// loop over them and take the first one which is not already in the $related_posts
141 141
 	$results = array();
142
-	foreach ( $referencing_posts as $referencing_post ) {
143
-		$serialized_entity = wl_serialize_entity( $referencing_post->entity_id );
142
+	foreach ($referencing_posts as $referencing_post) {
143
+		$serialized_entity = wl_serialize_entity($referencing_post->entity_id);
144 144
 
145 145
 		/**
146 146
 		 * Use the thumbnail.
@@ -150,21 +150,21 @@  discard block
 block discarded – undo
150 150
 		 *
151 151
 		 * @since 3.19.3 We're using the medium size image.
152 152
 		 */
153
-		$thumbnail = get_the_post_thumbnail_url( $referencing_post, 'medium' );
153
+		$thumbnail = get_the_post_thumbnail_url($referencing_post, 'medium');
154 154
 
155 155
 		$result = array(
156 156
 			'post'   => array(
157 157
 				'id'        => $referencing_post->ID,
158
-				'permalink' => get_permalink( $referencing_post->ID ),
159
-				'title'     => html_entity_decode( $referencing_post->post_title, ENT_QUOTES, 'UTF-8' ),
158
+				'permalink' => get_permalink($referencing_post->ID),
159
+				'title'     => html_entity_decode($referencing_post->post_title, ENT_QUOTES, 'UTF-8'),
160 160
 				'thumbnail' => $thumbnail,
161
-				'srcset'    => Srcset_Util::get_srcset( $referencing_post->ID, Srcset_Util::NAVIGATOR_WIDGET )
161
+				'srcset'    => Srcset_Util::get_srcset($referencing_post->ID, Srcset_Util::NAVIGATOR_WIDGET)
162 162
 			),
163 163
 			'entity' => array(
164 164
 				'id'        => $referencing_post->entity_id,
165 165
 				'label'     => $serialized_entity['label'],
166 166
 				'mainType'  => $serialized_entity['mainType'],
167
-				'permalink' => get_permalink( $referencing_post->entity_id ),
167
+				'permalink' => get_permalink($referencing_post->entity_id),
168 168
 			),
169 169
 		);
170 170
 
@@ -172,61 +172,61 @@  discard block
 block discarded – undo
172 172
 	}
173 173
 
174 174
 
175
-	if ( count( $results ) < $navigator_length ) {
176
-		$results = apply_filters( 'wl_navigator_data_placeholder', $results, $navigator_id, $navigator_offset, $navigator_length );
175
+	if (count($results) < $navigator_length) {
176
+		$results = apply_filters('wl_navigator_data_placeholder', $results, $navigator_id, $navigator_offset, $navigator_length);
177 177
 	}
178 178
 
179 179
 	// Add filler posts if needed
180
-	$filler_count = $navigator_length - count( $results );
181
-	if ( $filler_count > 0 ) {
182
-		$referencing_post_ids = array_map( function ( $p ) {
180
+	$filler_count = $navigator_length - count($results);
181
+	if ($filler_count > 0) {
182
+		$referencing_post_ids = array_map(function($p) {
183 183
 			return $p->ID;
184
-		}, $referencing_posts );
184
+		}, $referencing_posts);
185 185
 		/**
186 186
 		 * @since 3.27.8
187 187
 		 * Filler posts are fetched using this util.
188 188
 		 */
189
-		$filler_posts_util       = new Filler_Posts_Util( $current_post_id, $post_types );
190
-		$post_ids_to_be_excluded = array_merge( array( $current_post_id ), $referencing_post_ids );
191
-		$filler_posts            = $filler_posts_util->get_filler_response( $filler_count, $post_ids_to_be_excluded );
192
-		$results                 = array_merge( $results, $filler_posts );
189
+		$filler_posts_util       = new Filler_Posts_Util($current_post_id, $post_types);
190
+		$post_ids_to_be_excluded = array_merge(array($current_post_id), $referencing_post_ids);
191
+		$filler_posts            = $filler_posts_util->get_filler_response($filler_count, $post_ids_to_be_excluded);
192
+		$results                 = array_merge($results, $filler_posts);
193 193
 	}
194 194
 
195 195
 	// Apply filters after fillers are added
196
-	foreach ( $results as $result_index => $result ) {
197
-		$results[ $result_index ]['post']   = apply_filters( 'wl_navigator_data_post', $result['post'], intval( $result['post']['id'] ), $navigator_id );
198
-		$results[ $result_index ]['entity'] = apply_filters( 'wl_navigator_data_entity', $result['entity'], intval( $result['entity']['id'] ), $navigator_id );
196
+	foreach ($results as $result_index => $result) {
197
+		$results[$result_index]['post']   = apply_filters('wl_navigator_data_post', $result['post'], intval($result['post']['id']), $navigator_id);
198
+		$results[$result_index]['entity'] = apply_filters('wl_navigator_data_entity', $result['entity'], intval($result['entity']['id']), $navigator_id);
199 199
 	}
200 200
 
201
-	$results = apply_filters( 'wl_navigator_results', $results, $navigator_id, $current_post_id );
201
+	$results = apply_filters('wl_navigator_results', $results, $navigator_id, $current_post_id);
202 202
 
203 203
 	return $results;
204 204
 }
205 205
 
206
-function _wl_network_navigator_get_data( $request ) {
206
+function _wl_network_navigator_get_data($request) {
207 207
 
208 208
 	// Limit the results (defaults to 4)
209
-	$navigator_length = isset( $request['limit'] ) ? intval( $request['limit'] ) : 4;
210
-	$navigator_offset = isset( $request['offset'] ) ? intval( $request['offset'] ) : 0;
209
+	$navigator_length = isset($request['limit']) ? intval($request['limit']) : 4;
210
+	$navigator_offset = isset($request['offset']) ? intval($request['offset']) : 0;
211 211
 	$navigator_id     = $request['uniqid'];
212
-	$order_by         = isset( $_GET['sort'] ) ? sanitize_sql_orderby( $_GET['sort'] ) : 'ID DESC';
212
+	$order_by         = isset($_GET['sort']) ? sanitize_sql_orderby($_GET['sort']) : 'ID DESC';
213 213
 
214 214
 	$entities = $request['entities'];
215 215
 
216 216
 	// Post ID has to match an existing item
217
-	if ( ! isset( $entities ) || empty( $entities ) ) {
218
-		wp_send_json_error( 'No valid entities provided' );
217
+	if ( ! isset($entities) || empty($entities)) {
218
+		wp_send_json_error('No valid entities provided');
219 219
 	}
220 220
 
221
-	$referencing_posts = _wl_network_navigator_get_results( $entities, array(
221
+	$referencing_posts = _wl_network_navigator_get_results($entities, array(
222 222
 		'ID',
223 223
 		'post_title',
224
-	), $order_by, $navigator_length, $navigator_offset );
224
+	), $order_by, $navigator_length, $navigator_offset);
225 225
 
226 226
 	// loop over them and take the first one which is not already in the $related_posts
227 227
 	$results = array();
228
-	foreach ( $referencing_posts as $referencing_post ) {
229
-		$serialized_entity = wl_serialize_entity( $referencing_post->entity_id );
228
+	foreach ($referencing_posts as $referencing_post) {
229
+		$serialized_entity = wl_serialize_entity($referencing_post->entity_id);
230 230
 
231 231
 		/**
232 232
 		 * Use the thumbnail.
@@ -236,33 +236,33 @@  discard block
 block discarded – undo
236 236
 		 *
237 237
 		 * @since 3.19.3 We're using the medium size image.
238 238
 		 */
239
-		$thumbnail = get_the_post_thumbnail_url( $referencing_post, 'medium' );
239
+		$thumbnail = get_the_post_thumbnail_url($referencing_post, 'medium');
240 240
 
241 241
 		$result = array(
242 242
 			'post'   => array(
243
-				'permalink' => get_permalink( $referencing_post->ID ),
243
+				'permalink' => get_permalink($referencing_post->ID),
244 244
 				'title'     => $referencing_post->post_title,
245 245
 				'thumbnail' => $thumbnail,
246 246
 			),
247 247
 			'entity' => array(
248 248
 				'label'     => $serialized_entity['label'],
249 249
 				'mainType'  => $serialized_entity['mainType'],
250
-				'permalink' => get_permalink( $referencing_post->entity_id ),
250
+				'permalink' => get_permalink($referencing_post->entity_id),
251 251
 			),
252 252
 		);
253 253
 
254
-		$result['post']   = apply_filters( 'wl_network_navigator_data_post', $result['post'], intval( $referencing_post->ID ), $navigator_id );
255
-		$result['entity'] = apply_filters( 'wl_network_navigator_data_entity', $result['entity'], intval( $referencing_post->entity_id ), $navigator_id );
254
+		$result['post']   = apply_filters('wl_network_navigator_data_post', $result['post'], intval($referencing_post->ID), $navigator_id);
255
+		$result['entity'] = apply_filters('wl_network_navigator_data_entity', $result['entity'], intval($referencing_post->entity_id), $navigator_id);
256 256
 
257 257
 		$results[] = $result;
258 258
 
259 259
 	}
260 260
 
261
-	if ( count( $results ) < $navigator_length ) {
262
-		$results = apply_filters( 'wl_network_navigator_data_placeholder', $results, $navigator_id, $navigator_offset, $navigator_length );
261
+	if (count($results) < $navigator_length) {
262
+		$results = apply_filters('wl_network_navigator_data_placeholder', $results, $navigator_id, $navigator_offset, $navigator_length);
263 263
 	}
264 264
 
265
-	$results = apply_filters( 'wl_network_navigator_results', $results, $navigator_id );
265
+	$results = apply_filters('wl_network_navigator_results', $results, $navigator_id);
266 266
 
267 267
 	return $results;
268 268
 
@@ -276,24 +276,24 @@  discard block
 block discarded – undo
276 276
 ) {
277 277
 	global $wpdb;
278 278
 
279
-	$select = implode( ', ', array_map( function ( $item ) {
279
+	$select = implode(', ', array_map(function($item) {
280 280
 		return "p.$item AS $item";
281
-	}, (array) $fields ) );
281
+	}, (array) $fields));
282 282
 
283
-	$order_by = implode( ', ', array_map( function ( $item ) {
283
+	$order_by = implode(', ', array_map(function($item) {
284 284
 		return "p.$item";
285
-	}, (array) $order_by ) );
285
+	}, (array) $order_by));
286 286
 
287
-	$entities_in = implode( ',', array_map( function ( $item ) {
288
-		$entity = Wordlift_Entity_Service::get_instance()->get_entity_post_by_uri( urldecode( $item ) );
289
-		if ( isset( $entity ) ) {
287
+	$entities_in = implode(',', array_map(function($item) {
288
+		$entity = Wordlift_Entity_Service::get_instance()->get_entity_post_by_uri(urldecode($item));
289
+		if (isset($entity)) {
290 290
 			return $entity->ID;
291 291
 		}
292
-	}, $entities ) );
292
+	}, $entities));
293 293
 
294 294
 	/** @noinspection SqlNoDataSourceInspection */
295 295
 	return $wpdb->get_results(
296
-		$wpdb->prepare( <<<EOF
296
+		$wpdb->prepare(<<<EOF
297 297
 SELECT %3\$s, p2.ID as entity_id
298 298
  FROM {$wpdb->prefix}wl_relation_instances r1
299 299
 	-- get the ID of the post entity in common between the object and the subject 2. 
@@ -319,7 +319,7 @@  discard block
 block discarded – undo
319 319
  LIMIT %1\$d
320 320
  OFFSET %2\$d
321 321
 EOF
322
-			, $limit, $offset, $select, $order_by )
322
+			, $limit, $offset, $select, $order_by)
323 323
 	);
324 324
 
325 325
 }
@@ -334,12 +334,12 @@  discard block
 block discarded – undo
334 334
 
335 335
 	// Temporary blocking the Navigator.
336 336
 	$results = wl_shortcode_navigator_data();
337
-	wl_core_send_json( $results );
337
+	wl_core_send_json($results);
338 338
 
339 339
 }
340 340
 
341
-add_action( 'wp_ajax_wl_navigator', 'wl_shortcode_navigator_ajax' );
342
-add_action( 'wp_ajax_nopriv_wl_navigator', 'wl_shortcode_navigator_ajax' );
341
+add_action('wp_ajax_wl_navigator', 'wl_shortcode_navigator_ajax');
342
+add_action('wp_ajax_nopriv_wl_navigator', 'wl_shortcode_navigator_ajax');
343 343
 
344 344
 /**
345 345
  * wp-json call for the navigator widget
@@ -347,13 +347,13 @@  discard block
 block discarded – undo
347 347
 function wl_shortcode_navigator_wp_json() {
348 348
 
349 349
 	$results = wl_shortcode_navigator_data();
350
-	if ( ob_get_contents() ) {
350
+	if (ob_get_contents()) {
351 351
 		ob_clean();
352 352
 	}
353 353
 
354 354
 	return array(
355 355
 		'items' => array(
356
-			array( 'values' => $results ),
356
+			array('values' => $results),
357 357
 		),
358 358
 	);
359 359
 
@@ -362,23 +362,23 @@  discard block
 block discarded – undo
362 362
 /**
363 363
  * Adding `rest_api_init` action for amp backend of navigator
364 364
  */
365
-add_action( 'rest_api_init', function () {
366
-	register_rest_route( WL_REST_ROUTE_DEFAULT_NAMESPACE, '/navigator', array(
365
+add_action('rest_api_init', function() {
366
+	register_rest_route(WL_REST_ROUTE_DEFAULT_NAMESPACE, '/navigator', array(
367 367
 		'methods'             => 'GET',
368 368
 		'permission_callback' => '__return_true',
369 369
 		'callback'            => 'wl_shortcode_navigator_wp_json'
370
-	) );
370
+	));
371 371
 } );
372 372
 
373 373
 /**
374 374
  * Adding `rest_api_init` action for backend of network navigator
375 375
  */
376
-add_action( 'rest_api_init', function () {
377
-	register_rest_route( WL_REST_ROUTE_DEFAULT_NAMESPACE, '/network-navigator', array(
376
+add_action('rest_api_init', function() {
377
+	register_rest_route(WL_REST_ROUTE_DEFAULT_NAMESPACE, '/network-navigator', array(
378 378
 		'methods'             => 'GET',
379 379
 		'callback'            => 'wl_network_navigator_wp_json',
380 380
 		'permission_callback' => '__return_true',
381
-	) );
381
+	));
382 382
 } );
383 383
 
384 384
 /**
@@ -386,24 +386,24 @@  discard block
 block discarded – undo
386 386
  *
387 387
  * @since 2.2.0
388 388
  */
389
-add_action( 'plugins_loaded', function () {
390
-	$action = array_key_exists( 'action', $_REQUEST ) ? (string) $_REQUEST['action'] : '';
391
-	if ( ! defined( 'DOING_AJAX' ) || ! DOING_AJAX || 'wl_navigator' !== $action ) {
389
+add_action('plugins_loaded', function() {
390
+	$action = array_key_exists('action', $_REQUEST) ? (string) $_REQUEST['action'] : '';
391
+	if ( ! defined('DOING_AJAX') || ! DOING_AJAX || 'wl_navigator' !== $action) {
392 392
 		return;
393 393
 	}
394 394
 
395
-	remove_action( 'plugins_loaded', 'rocket_init' );
396
-	remove_action( 'plugins_loaded', 'wpseo_premium_init', 14 );
397
-	remove_action( 'plugins_loaded', 'wpseo_init', 14 );
398
-}, 0 );
395
+	remove_action('plugins_loaded', 'rocket_init');
396
+	remove_action('plugins_loaded', 'wpseo_premium_init', 14);
397
+	remove_action('plugins_loaded', 'wpseo_init', 14);
398
+}, 0);
399 399
 
400
-add_action( 'init', function () {
401
-	$action = array_key_exists( 'action', $_REQUEST ) ? (string) $_REQUEST['action'] : '';
402
-	if ( ! defined( 'DOING_AJAX' ) || ! DOING_AJAX || 'wl_navigator' !== $action ) {
400
+add_action('init', function() {
401
+	$action = array_key_exists('action', $_REQUEST) ? (string) $_REQUEST['action'] : '';
402
+	if ( ! defined('DOING_AJAX') || ! DOING_AJAX || 'wl_navigator' !== $action) {
403 403
 		return;
404 404
 	}
405 405
 
406
-	remove_action( 'init', 'wp_widgets_init', 1 );
407
-	remove_action( 'init', 'gglcptch_init' );
408
-}, 0 );
406
+	remove_action('init', 'wp_widgets_init', 1);
407
+	remove_action('init', 'gglcptch_init');
408
+}, 0);
409 409
 
Please login to merge, or discard this patch.
src/wordlift/vocabulary/class-analysis-background-service.php 1 patch
Spacing   +18 added lines, -18 removed lines patch added patch discarded remove patch
@@ -25,13 +25,13 @@  discard block
 block discarded – undo
25 25
 	private $log;
26 26
 
27 27
 
28
-	public function __construct( $analysis_service ) {
28
+	public function __construct($analysis_service) {
29 29
 
30 30
 		$this->analysis_service = $analysis_service;
31 31
 
32
-		$this->analysis_background_process = new Analysis_Background_Process( $this );
32
+		$this->analysis_background_process = new Analysis_Background_Process($this);
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
 
37 37
 	public function start() {
@@ -55,7 +55,7 @@  discard block
 block discarded – undo
55 55
 
56 56
 		$state = $this->info();
57 57
 
58
-		return Terms_Compat::get_terms( Terms_Compat::get_public_taxonomies(), array(
58
+		return Terms_Compat::get_terms(Terms_Compat::get_public_taxonomies(), array(
59 59
 			'fields'     => 'ids',
60 60
 			'hide_empty' => false,
61 61
 			'number'     => $this->get_batch_size(),
@@ -66,12 +66,12 @@  discard block
 block discarded – undo
66 66
 					'compare' => 'NOT EXISTS'
67 67
 				)
68 68
 			),
69
-		) );
69
+		));
70 70
 	}
71 71
 
72 72
 	public function count() {
73 73
 
74
-		$count = count( Terms_Compat::get_terms(
74
+		$count = count(Terms_Compat::get_terms(
75 75
 			Terms_Compat::get_public_taxonomies(),
76 76
 			array(
77 77
 			'fields'     => 'ids',
@@ -84,9 +84,9 @@  discard block
 block discarded – undo
84 84
 					'compare' => 'NOT EXISTS'
85 85
 				)
86 86
 			),
87
-		) ) );
87
+		) ));
88 88
 
89
-		$this->log->debug( "Count returned as $count" );
89
+		$this->log->debug("Count returned as $count");
90 90
 
91 91
 
92 92
 		return $count;
@@ -105,23 +105,23 @@  discard block
 block discarded – undo
105 105
 	 *
106 106
 	 * @return bool
107 107
 	 */
108
-	public function perform_analysis_for_terms( $term_ids ) {
108
+	public function perform_analysis_for_terms($term_ids) {
109 109
 
110
-		foreach ( $term_ids as $term_id ) {
110
+		foreach ($term_ids as $term_id) {
111 111
 
112
-			$tag = get_term( $term_id );
112
+			$tag = get_term($term_id);
113 113
 
114 114
 			// This adds the entities to ttl cache
115
-			$result = $this->analysis_service->get_entities( $tag );
115
+			$result = $this->analysis_service->get_entities($tag);
116 116
 
117
-			$this->log->debug( "Received result " . var_export( $result ) . " for ${term_id}" );
117
+			$this->log->debug("Received result ".var_export($result)." for ${term_id}");
118 118
 
119 119
 			// then set the analysis complete flag.
120
-			update_term_meta( $term_id, self::ANALYSIS_DONE_FLAG, 1 );
120
+			update_term_meta($term_id, self::ANALYSIS_DONE_FLAG, 1);
121 121
 
122
-			if ( $result !== false ) {
123
-				if ( count( $result ) > 0 ) {
124
-					update_term_meta( $term_id, self::ENTITIES_PRESENT_FOR_TERM, 1 );
122
+			if ($result !== false) {
123
+				if (count($result) > 0) {
124
+					update_term_meta($term_id, self::ENTITIES_PRESENT_FOR_TERM, 1);
125 125
 				}
126 126
 			}
127 127
 
@@ -131,7 +131,7 @@  discard block
 block discarded – undo
131 131
 		 * This action fires when the analysis is complete for the current batch
132 132
 		 * @since 3.30.0
133 133
 		 */
134
-		do_action( 'wordlift_vocabulary_analysis_complete_for_terms_batch' );
134
+		do_action('wordlift_vocabulary_analysis_complete_for_terms_batch');
135 135
 
136 136
 		return true;
137 137
 
Please login to merge, or discard this patch.
src/wordlift/vocabulary/class-analysis-background-process.php 1 patch
Spacing   +33 added lines, -33 removed lines patch added patch discarded remove patch
@@ -24,10 +24,10 @@  discard block
 block discarded – undo
24 24
 	 *
25 25
 	 * @param $analysis_background_service Analysis_Background_Service A {@link Analysis_Background_Service} instance providing the supporting functions to this background process.
26 26
 	 */
27
-	public function __construct( $analysis_background_service ) {
27
+	public function __construct($analysis_background_service) {
28 28
 		parent::__construct();
29 29
 
30
-		$this->log = \Wordlift_Log_Service::get_logger( get_class() );
30
+		$this->log = \Wordlift_Log_Service::get_logger(get_class());
31 31
 
32 32
 		$this->analysis_background_service = $analysis_background_service;
33 33
 
@@ -45,23 +45,23 @@  discard block
 block discarded – undo
45 45
 	 *
46 46
 	 * @return int[]|false The next term IDs or false if there are no more.
47 47
 	 */
48
-	protected function task( $term_ids ) {
48
+	protected function task($term_ids) {
49 49
 
50 50
 		// Check if we must cancel.
51
-		if ( $this->must_cancel() ) {
51
+		if ($this->must_cancel()) {
52 52
 			$this->cancel();
53 53
 
54 54
 			return false;
55 55
 		}
56 56
 
57
-		if ( ! $term_ids || ! is_array( $term_ids ) ) {
57
+		if ( ! $term_ids || ! is_array($term_ids)) {
58 58
 			$this->cancel();
59 59
 			return false;
60 60
 		}
61 61
 
62
-		$this->log->debug( sprintf( "Synchronizing terms %s...", implode( ', ', $term_ids ) ) );
62
+		$this->log->debug(sprintf("Synchronizing terms %s...", implode(', ', $term_ids)));
63 63
 		// Sync the item.
64
-		return $this->sync_items( $term_ids );
64
+		return $this->sync_items($term_ids);
65 65
 	}
66 66
 
67 67
 	/**
@@ -70,21 +70,21 @@  discard block
 block discarded – undo
70 70
 	 * @return bool True if the process has been started, otherwise false.
71 71
 	 */
72 72
 	public function start() {
73
-		$this->log->debug( "Trying to start analysis bg service..." );
73
+		$this->log->debug("Trying to start analysis bg service...");
74 74
 		// Create a new Sync_Model state of `started`.
75
-		if ( ! $this->is_started( self::get_state() ) ) {
76
-			$this->log->debug( "Starting..." );
75
+		if ( ! $this->is_started(self::get_state())) {
76
+			$this->log->debug("Starting...");
77 77
 
78
-			$sync_state = new Sync_State( time(), 0, $this->analysis_background_service->count(), time(), 'started' );
79
-			update_option( self::WL_CMKG_ANALYSIS_BACKGROUND_PROCESS, $sync_state, false );
78
+			$sync_state = new Sync_State(time(), 0, $this->analysis_background_service->count(), time(), 'started');
79
+			update_option(self::WL_CMKG_ANALYSIS_BACKGROUND_PROCESS, $sync_state, false);
80 80
 
81 81
 			$next = $this->analysis_background_service->next();
82 82
 
83
-			$this->push_to_queue( $next );
83
+			$this->push_to_queue($next);
84 84
 			$this->save()->dispatch();
85 85
 
86
-			if ( $next && is_array( $next ) ) {
87
-				$this->log->debug( sprintf( 'Started with term IDs %s.', implode( ', ', $next ) ) );
86
+			if ($next && is_array($next)) {
87
+				$this->log->debug(sprintf('Started with term IDs %s.', implode(', ', $next)));
88 88
 			}
89 89
 
90 90
 			return true;
@@ -99,7 +99,7 @@  discard block
 block discarded – undo
99 99
 	 */
100 100
 	public function request_cancel() {
101 101
 
102
-		set_transient( "{$this->action}__cancel", true );
102
+		set_transient("{$this->action}__cancel", true);
103 103
 
104 104
 	}
105 105
 
@@ -111,8 +111,8 @@  discard block
 block discarded – undo
111 111
 	public static function get_state() {
112 112
 
113 113
 		try {
114
-			return get_option( self::WL_CMKG_ANALYSIS_BACKGROUND_PROCESS, Sync_State::unknown() );
115
-		} catch ( \Exception $e ) {
114
+			return get_option(self::WL_CMKG_ANALYSIS_BACKGROUND_PROCESS, Sync_State::unknown());
115
+		} catch (\Exception $e) {
116 116
 			return Sync_State::unknown();
117 117
 		}
118 118
 
@@ -125,8 +125,8 @@  discard block
 block discarded – undo
125 125
 	 *
126 126
 	 * @return bool True if the state is started.
127 127
 	 */
128
-	private function is_started( $state ) {
129
-		return $state instanceof Sync_State && 'started' === $state->state && 30 > ( time() - $state->last_update );
128
+	private function is_started($state) {
129
+		return $state instanceof Sync_State && 'started' === $state->state && 30 > (time() - $state->last_update);
130 130
 	}
131 131
 
132 132
 	/**
@@ -136,7 +136,7 @@  discard block
 block discarded – undo
136 136
 	 */
137 137
 	private function must_cancel() {
138 138
 
139
-		return get_transient( "{$this->action}__cancel" );
139
+		return get_transient("{$this->action}__cancel");
140 140
 	}
141 141
 
142 142
 	/**
@@ -144,18 +144,18 @@  discard block
 block discarded – undo
144 144
 	 */
145 145
 	public function cancel() {
146 146
 
147
-		$this->log->debug( "Cancelling synchronization..." );
147
+		$this->log->debug("Cancelling synchronization...");
148 148
 
149 149
 		// Cleanup the process data.
150 150
 		$this->cancel_process();
151 151
 
152 152
 		// Set the state to cancelled.
153 153
 		$state = self::get_state();
154
-		$state->set_state( 'cancelled' );
155
-		update_option( self::WL_CMKG_ANALYSIS_BACKGROUND_PROCESS, $state, false );
154
+		$state->set_state('cancelled');
155
+		update_option(self::WL_CMKG_ANALYSIS_BACKGROUND_PROCESS, $state, false);
156 156
 
157 157
 		// Finally delete the transient.
158
-		delete_transient( "{$this->action}__cancel" );
158
+		delete_transient("{$this->action}__cancel");
159 159
 
160 160
 	}
161 161
 
@@ -166,13 +166,13 @@  discard block
 block discarded – undo
166 166
 	 *
167 167
 	 * @return int[]|false The next term ID to process or false if processing is complete.
168 168
 	 */
169
-	private function sync_items( $term_ids ) {
169
+	private function sync_items($term_ids) {
170 170
 
171 171
 		// Sync this item.
172
-		if ( $this->analysis_background_service->perform_analysis_for_terms( $term_ids ) ) {
172
+		if ($this->analysis_background_service->perform_analysis_for_terms($term_ids)) {
173 173
 
174 174
 			$next       = $this->analysis_background_service->next();
175
-			$next_state = isset( $next ) ? 'started' : 'ended';
175
+			$next_state = isset($next) ? 'started' : 'ended';
176 176
 
177 177
 			/**
178 178
 			 * Update the synchronization meta data, by increasing the current index.
@@ -180,18 +180,18 @@  discard block
 block discarded – undo
180 180
 			 * @var Sync_State $sync The {@link Sync_State}.
181 181
 			 */
182 182
 			$state = self::get_state()
183
-			             ->increment_index( $this->analysis_background_service->get_batch_size() )
184
-			             ->set_state( $next_state );
185
-			update_option( self::WL_CMKG_ANALYSIS_BACKGROUND_PROCESS . '', $state, false );
183
+			             ->increment_index($this->analysis_background_service->get_batch_size())
184
+			             ->set_state($next_state);
185
+			update_option(self::WL_CMKG_ANALYSIS_BACKGROUND_PROCESS.'', $state, false);
186 186
 
187 187
 
188 188
 			// Return the next IDs or false if there aren't.
189
-			return isset( $next ) ? $next : false;
189
+			return isset($next) ? $next : false;
190 190
 		} else {
191 191
 			// Retry.
192 192
 			// @@todo: put a limit to the number of retries.
193 193
 
194
-			$this->log->error( sprintf( "Sync failed for terms %s.", implode( ', ', $term_ids ) ) );
194
+			$this->log->error(sprintf("Sync failed for terms %s.", implode(', ', $term_ids)));
195 195
 
196 196
 			return $term_ids;
197 197
 		}
Please login to merge, or discard this patch.