@@ -5,14 +5,15 @@ class BEA_CSF_Relations {
5
5
const BEA_CSF_RELATIONS_CACHE_GROUP = 'relations-cache-group ' ;
6
6
7
7
/**
8
- * @return int|mixed
9
- *
10
8
* @param $emitter_blog_id
11
9
* @param $emitter_id
12
10
* @param $receiver_blog_id
13
11
* @param $receiver_id
14
12
*
15
13
* @param $type
14
+ *
15
+ * @return int|mixed
16
+ *
16
17
*/
17
18
public static function merge ( $ type , $ emitter_blog_id , $ emitter_id , $ receiver_blog_id , $ receiver_id , $ strict_mode = false ) {
18
19
// Test with right emitter/receiver direction
@@ -33,14 +34,15 @@ public static function merge( $type, $emitter_blog_id, $emitter_id, $receiver_bl
33
34
}
34
35
35
36
/**
36
- * @return int
37
- *
38
37
* @param $emitter_blog_id
39
38
* @param $emitter_id
40
39
* @param $receiver_blog_id
41
40
* @param $receiver_id
42
41
*
43
42
* @param $type
43
+ *
44
+ * @return int
45
+ *
44
46
*/
45
47
public static function insert ( $ type , $ emitter_blog_id , $ emitter_id , $ receiver_blog_id , $ receiver_id ) {
46
48
global $ wpdb ;
@@ -64,10 +66,10 @@ public static function insert( $type, $emitter_blog_id, $emitter_id, $receiver_b
64
66
/**
65
67
* Delete a row with this primary ID.
66
68
*
67
- * @return mixed
68
- *
69
69
* @param $id
70
70
*
71
+ * @return mixed
72
+ *
71
73
*/
72
74
public static function delete ( $ id ) {
73
75
global $ wpdb ;
@@ -90,12 +92,13 @@ public static function delete( $id ) {
90
92
/**
91
93
* Delete relation for an object_id for emitter and receiver context
92
94
*
93
- * @return true
94
- *
95
95
* @param integer $blog_id
96
96
* @param integer $object_id
97
97
*
98
98
* @param string $type
99
+ *
100
+ * @return true
101
+ *
99
102
*/
100
103
public static function delete_by_object_id ( $ type , $ blog_id , $ object_id ) {
101
104
self ::delete_by_emitter ( $ type , $ blog_id , $ object_id );
@@ -107,10 +110,10 @@ public static function delete_by_object_id( $type, $blog_id, $object_id ) {
107
110
/**
108
111
* Delete data relation for a blog
109
112
*
110
- * @return true
111
- *
112
113
* @param integer $blog_id
113
114
*
115
+ * @return true
116
+ *
114
117
*/
115
118
public static function delete_by_blog_id ( $ blog_id ) {
116
119
global $ wpdb ;
@@ -157,12 +160,13 @@ public static function delete_by_blog_id( $blog_id ) {
157
160
}
158
161
159
162
/**
160
- * @return false|int
161
- *
162
163
* @param $emitter_blog_id
163
164
* @param $emitter_id
164
165
*
165
166
* @param $type
167
+ *
168
+ * @return false|int
169
+ *
166
170
*/
167
171
public static function delete_by_emitter ( $ type , $ emitter_blog_id , $ emitter_id ) {
168
172
global $ wpdb ;
@@ -196,12 +200,13 @@ public static function delete_by_emitter( $type, $emitter_blog_id, $emitter_id )
196
200
}
197
201
198
202
/**
199
- * @return false|int
200
- *
201
203
* @param $receiver_blog_id
202
204
* @param $receiver_id
203
205
*
204
206
* @param $type
207
+ *
208
+ * @return false|int
209
+ *
205
210
*/
206
211
public static function delete_by_receiver ( $ type , $ receiver_blog_id , $ receiver_id ) {
207
212
global $ wpdb ;
@@ -235,14 +240,15 @@ public static function delete_by_receiver( $type, $receiver_blog_id, $receiver_i
235
240
}
236
241
237
242
/**
238
- * @return false|int
239
- *
240
243
* @param $emitter_blog_id
241
244
* @param $emitter_id
242
245
* @param $receiver_blog_id
243
246
* @param $receiver_id
244
247
*
245
248
* @param $type
249
+ *
250
+ * @return false|int
251
+ *
246
252
*/
247
253
public static function delete_by_emitter_and_receiver ( $ type , $ emitter_blog_id , $ emitter_id , $ receiver_blog_id , $ receiver_id ) {
248
254
global $ wpdb ;
@@ -280,10 +286,10 @@ public static function delete_by_emitter_and_receiver( $type, $emitter_blog_id,
280
286
}
281
287
282
288
/**
283
- * @return mixed
284
- *
285
289
* @param $id
286
290
*
291
+ * @return mixed
292
+ *
287
293
*/
288
294
public static function get ( $ id ) {
289
295
global $ wpdb ;
@@ -294,15 +300,15 @@ public static function get( $id ) {
294
300
}
295
301
296
302
/**
297
- * @return integer|false
298
- *
299
303
* @param int $emitter_blog_id
300
304
* @param int $receiver_blog_id
301
305
* @param int $emitter_id
302
306
* @param int $receiver_id
303
307
*
304
308
* @param string|array $type
305
309
*
310
+ * @return integer|false
311
+ *
306
312
* @author Alexandre Sadowski
307
313
*/
308
314
public static function get_object_for_any ( $ type , $ emitter_blog_id , $ receiver_blog_id , $ emitter_id , $ receiver_id , $ direct = false ) {
@@ -342,11 +348,12 @@ public static function get_object_for_any( $type, $emitter_blog_id, $receiver_bl
342
348
/**
343
349
* Get all hierachy of relation for a content
344
350
*
345
- * @return array
346
- *
347
351
* @param $emitter_blog_id
348
352
* @param $emitter_id
349
353
* @param $type
354
+ *
355
+ * @return array
356
+ *
350
357
*/
351
358
public static function get_relations_hierarchy ( $ type , $ emitter_blog_id , $ emitter_id ) {
352
359
$ hierarchy = [];
@@ -370,14 +377,14 @@ public static function get_relations_hierarchy( $type, $emitter_blog_id, $emitte
370
377
}
371
378
372
379
/**
373
- * @return int
374
- *
375
380
* @param int $emitter_blog_id
376
381
* @param int $receiver_blog_id
377
382
* @param int $emitter_id
378
383
*
379
384
* @param string|array $types
380
385
*
386
+ * @return int
387
+ *
381
388
* @author Alexandre Sadowski
382
389
*/
383
390
public static function get_object_id_for_receiver ( $ types , $ emitter_blog_id , $ receiver_blog_id , $ emitter_id ) {
@@ -395,14 +402,14 @@ public static function get_object_id_for_receiver( $types, $emitter_blog_id, $re
395
402
}
396
403
397
404
/**
398
- * @return int
399
- *
400
405
* @param int $emitter_blog_id
401
406
* @param int $receiver_blog_id
402
407
* @param int $receiver_id
403
408
*
404
409
* @param string|array $types
405
410
*
411
+ * @return int
412
+ *
406
413
* @author Alexandre Sadowski
407
414
*/
408
415
public static function get_object_id_for_emitter ( $ types , $ emitter_blog_id , $ receiver_blog_id , $ receiver_id ) {
@@ -420,18 +427,18 @@ public static function get_object_id_for_emitter( $types, $emitter_blog_id, $rec
420
427
}
421
428
422
429
/**
423
- * @return mixed
424
- *
425
430
* @param int $receiver_blog_id
426
431
* @param int $receiver_id
427
432
*
428
433
* @param string|array $types
429
434
*
435
+ * @return mixed
436
+ *
430
437
* @author Alexandre Sadowski
431
438
*/
432
439
public static function current_object_is_synchronized ( $ types , $ receiver_blog_id , $ receiver_id ) {
433
440
global $ wpdb ;
434
- $ cache_id = self ::get_cache_id ( $ types , $ receiver_blog_id , $ receiver_id );
441
+ $ cache_id = self ::get_cache_id ( $ types , ( int ) $ receiver_blog_id , ( int ) $ receiver_id );
435
442
$ relation = wp_cache_get ( $ cache_id , self ::BEA_CSF_RELATIONS_CACHE_GROUP , false , $ found );
436
443
if ( $ found ) {
437
444
return $ relation ;
@@ -448,6 +455,7 @@ public static function current_object_is_synchronized( $types, $receiver_blog_id
448
455
if ( null !== $ result ) {
449
456
wp_cache_set ( $ cache_id , $ result , self ::BEA_CSF_RELATIONS_CACHE_GROUP );
450
457
}
458
+
451
459
return $ result ;
452
460
}
453
461
@@ -512,10 +520,10 @@ public static function get_results_by_receiver_blog_id( $blog_id ) {
512
520
}
513
521
514
522
/**
515
- * @return mixed
516
- *
517
523
* @param int $quantity
518
524
*
525
+ * @return mixed
526
+ *
519
527
*/
520
528
public static function get_results ( $ quantity = 100 ) {
521
529
global $ wpdb ;
@@ -530,13 +538,14 @@ public static function get_results( $quantity = 100 ) {
530
538
*
531
539
* @param int $blog_id
532
540
* @param array $types_relation
541
+ *
542
+ * @return mixed
533
543
* @example [
534
544
* 'taxonomy',
535
545
* 'attachment',
536
546
* 'posttype',
537
547
* ]
538
548
*
539
- * @return mixed
540
549
*/
541
550
public static function get_types_relation_by_receiver_blog_id ( int $ blog_id , array $ types_relation = [] ) {
542
551
if ( empty ( $ types_relation ) ) {
@@ -580,24 +589,27 @@ function ( $v ) {
580
589
* @param string|array $types
581
590
* @param int $receiver_blog_id
582
591
* @param int $receiver_id
592
+ *
583
593
* @return string
584
594
*/
585
595
private static function get_cache_id ( $ types , int $ receiver_blog_id , int $ receiver_id ): string {
586
596
$ type = 'post ' ;
587
597
if ( 'taxonomy ' === $ types || ( is_array ( $ types ) && in_array ( 'taxonomy ' , $ types , true ) ) ) {
588
598
$ type = 'taxonomy ' ;
589
599
}
600
+
590
601
return $ receiver_blog_id . '- ' . $ receiver_id . '- ' . $ type ;
591
602
}
592
603
593
604
/**
594
605
* Delete all relation caches matching query results
595
606
*
596
607
* @param stdClass $relation
608
+ *
597
609
* @return void
598
610
*/
599
611
public static function delete_relation_cache ( stdClass $ relation ) {
600
- $ cache_id = self ::get_cache_id ( $ relation ->type , $ relation ->receiver_blog_id , $ relation ->receiver_id );
612
+ $ cache_id = self ::get_cache_id ( $ relation ->type , ( int ) $ relation ->receiver_blog_id , ( int ) $ relation ->receiver_id );
601
613
wp_cache_delete ( $ cache_id , self ::BEA_CSF_RELATIONS_CACHE_GROUP );
602
614
603
615
}
0 commit comments