1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace awssat\Visits; |
4
|
|
|
|
5
|
|
|
class Reset extends Visits |
6
|
|
|
{ |
7
|
|
|
protected $visits; |
8
|
|
|
|
9
|
|
|
/** |
10
|
|
|
* Reset constructor. |
11
|
|
|
* @param Visits $parent |
12
|
|
|
* @param Keys $keys |
13
|
|
|
* @param $method |
14
|
|
|
* @param $args |
15
|
|
|
*/ |
16
|
|
|
public function __construct(Visits $parent, $method, $args) |
17
|
|
|
{ |
18
|
|
|
parent::__construct($parent->subject); |
19
|
|
|
$this->keys = $parent->keys; |
20
|
|
|
|
21
|
|
|
if (method_exists($this, $method)) { |
22
|
|
|
if (empty($args)) { |
23
|
|
|
$this->$method(); |
24
|
|
|
} else { |
25
|
|
|
$this->$method($args); |
26
|
|
|
} |
27
|
|
|
} |
28
|
|
|
} |
29
|
|
|
|
30
|
|
|
/** |
31
|
|
|
* Reset everything |
32
|
|
|
* |
33
|
|
|
*/ |
34
|
|
|
public function factory() |
35
|
|
|
{ |
36
|
|
|
$this->visits(); |
37
|
|
|
$this->periods(); |
38
|
|
|
$this->ips(); |
39
|
|
|
$this->lists(); |
40
|
|
|
$this->allcountries(); |
41
|
|
|
$this->allrefs(); |
42
|
|
|
} |
43
|
|
|
|
44
|
|
|
/** |
45
|
|
|
* reset all time visits |
46
|
|
|
*/ |
47
|
|
|
public function visits() |
48
|
|
|
{ |
49
|
|
|
if ($this->keys->id) { |
50
|
|
|
$this->redis->zrem($this->keys->visits, $this->keys->id); |
51
|
|
|
$this->redis->del($this->keys->visits . "_countries:{$this->keys->id}"); |
52
|
|
|
$this->redis->del($this->keys->visits . "_referers:{$this->keys->id}"); |
53
|
|
|
|
54
|
|
|
foreach ($this->periods as $period => $days) { |
55
|
|
|
$this->redis->zrem($this->keys->period($period), $this->keys->id); |
56
|
|
|
} |
57
|
|
|
|
58
|
|
|
$this->ips(); |
59
|
|
|
} else { |
60
|
|
|
$this->redis->del($this->keys->visits); |
61
|
|
|
$this->redis->del($this->keys->visits . '_total'); |
62
|
|
|
} |
63
|
|
|
|
64
|
|
|
} |
65
|
|
|
|
66
|
|
|
public function allrefs() |
67
|
|
|
{ |
68
|
|
|
$cc = $this->redis->keys($this->keys->visits . '_referers:*'); |
69
|
|
|
|
70
|
|
|
if (count($cc)) { |
71
|
|
|
$this->redis->del($cc); |
72
|
|
|
} |
73
|
|
|
} |
74
|
|
|
|
75
|
|
|
|
76
|
|
|
public function allcountries() |
77
|
|
|
{ |
78
|
|
|
$cc = $this->redis->keys($this->keys->visits . '_countries:*'); |
79
|
|
|
|
80
|
|
|
if (count($cc)) { |
81
|
|
|
$this->redis->del($cc); |
82
|
|
|
} |
83
|
|
|
} |
84
|
|
|
|
85
|
|
|
/** |
86
|
|
|
* reset day,week counters |
87
|
|
|
*/ |
88
|
|
|
public function periods() |
89
|
|
|
{ |
90
|
|
|
foreach ($this->periods as $period => $days) { |
91
|
|
|
$periodKey = $this->keys->period($period); |
92
|
|
|
$this->redis->del($periodKey); |
93
|
|
|
$this->redis->del($periodKey . '_total'); |
94
|
|
|
} |
95
|
|
|
} |
96
|
|
|
|
97
|
|
|
/** |
98
|
|
|
* reset ips protection |
99
|
|
|
* @param string $ips |
100
|
|
|
*/ |
101
|
|
|
public function ips($ips = '*') |
102
|
|
|
{ |
103
|
|
|
$ips = $this->redis->keys($this->keys->ip($ips)); |
104
|
|
|
|
105
|
|
|
if (count($ips)) { |
106
|
|
|
$this->redis->del($ips); |
107
|
|
|
} |
108
|
|
|
} |
109
|
|
|
|
110
|
|
|
/** |
111
|
|
|
* reset lists top/low |
112
|
|
|
*/ |
113
|
|
|
public function lists() |
114
|
|
|
{ |
115
|
|
|
$lists = $this->redis->keys($this->keys->cache()); |
116
|
|
|
if (count($lists)) { |
117
|
|
|
$this->redis->del($lists); |
118
|
|
|
} |
119
|
|
|
} |
120
|
|
|
} |
121
|
|
|
|