1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/** |
4
|
|
|
* Hook hit logger class. |
5
|
|
|
* |
6
|
|
|
* @package wordpoints-hooks-api |
7
|
|
|
* @since 1.0.0 |
8
|
|
|
*/ |
9
|
|
|
|
10
|
|
|
/** |
11
|
|
|
* Logs hook hits. |
12
|
|
|
* |
13
|
|
|
* @since 1.0.0 |
14
|
|
|
*/ |
15
|
|
|
class WordPoints_Hook_Hit_Logger { |
16
|
|
|
|
17
|
|
|
/** |
18
|
|
|
* The fire for which a hit might occur. |
19
|
|
|
* |
20
|
|
|
* @since 1.0.0 |
21
|
|
|
* |
22
|
|
|
* @var WordPoints_Hook_Fire |
23
|
|
|
*/ |
24
|
|
|
protected $fire; |
25
|
|
|
|
26
|
|
|
/** |
27
|
|
|
* @param WordPoints_Hook_Fire $fire The fire that might be logged as a hit. |
28
|
|
|
*/ |
29
|
|
|
public function __construct( WordPoints_Hook_Fire $fire ) { |
30
|
|
|
|
31
|
|
|
$this->fire = $fire; |
32
|
|
|
} |
33
|
|
|
|
34
|
|
|
/** |
35
|
|
|
* Logs a hit for this fire. |
36
|
|
|
* |
37
|
|
|
* @since 1.0.0 |
38
|
|
|
* |
39
|
|
|
* @return int|false The hit ID, or false if logging the hit failed. |
40
|
|
|
*/ |
41
|
|
|
public function log_hit() { |
42
|
|
|
|
43
|
|
|
global $wpdb; |
44
|
|
|
|
45
|
|
|
$signature = wordpoints_hooks_get_event_signature( $this->fire->event_args ); |
46
|
|
|
|
47
|
|
|
$inserted = $wpdb->insert( |
48
|
|
|
$wpdb->wordpoints_hook_hits |
49
|
|
|
, array( |
50
|
|
|
'fire_type' => $this->fire->firer->get_slug(), |
51
|
|
|
'signature' => $signature, |
52
|
|
|
'event' => $this->fire->reaction->get_event_slug(), |
53
|
|
|
'reactor' => $this->fire->reaction->get_reactor_slug(), |
54
|
|
|
'reaction_type' => $this->fire->reaction->get_storage_group_slug(), |
55
|
|
|
'reaction_id' => $this->fire->reaction->ID, |
|
|
|
|
56
|
|
|
'date' => current_time( 'mysql' ), |
57
|
|
|
) |
58
|
|
|
); |
59
|
|
|
|
60
|
|
|
if ( ! $inserted ) { |
61
|
|
|
return false; |
62
|
|
|
} |
63
|
|
|
|
64
|
|
|
$hit_id = $wpdb->insert_id; |
65
|
|
|
|
66
|
|
|
$supersedes = $this->fire->get_superseded_hit(); |
67
|
|
|
|
68
|
|
|
if ( $supersedes ) { |
69
|
|
|
$wpdb->update( |
70
|
|
|
$wpdb->wordpoints_hook_hits |
71
|
|
|
, array( 'superseded_by' => $hit_id ) |
72
|
|
|
, array( 'id' => $supersedes->id ) |
73
|
|
|
, array( '%d' ) |
74
|
|
|
, array( '%d' ) |
75
|
|
|
); |
76
|
|
|
} |
77
|
|
|
|
78
|
|
|
return $hit_id; |
79
|
|
|
} |
80
|
|
|
} |
81
|
|
|
|
82
|
|
|
// EOF |
83
|
|
|
|
If you access a property on an interface, you most likely code against a concrete implementation of the interface.
Available Fixes
Adding an additional type check:
Changing the type hint: