-
Notifications
You must be signed in to change notification settings - Fork 60
/
Copy pathdeleteignored.php
134 lines (105 loc) · 2.81 KB
/
deleteignored.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
<?php
require_once('global.php');
# cleaning up URLs that are supposed to be ignored
if ($ignoreURLs !== false && is_array($ignoreURLs)) {
$prefixes = array();
$regexes = array();
foreach ($ignoreURLs as $ignoreString) {
if (preg_match('/^[^a-zA-Z\\\s]/', $ignoreString))
{
$regexes[] = $ignoreString;
}
else
{
$prefixes[] = $ignoreString;
}
}
$ids = array();
if (count($prefixes) > 0 || !$enableNonHTTPURLs) {
# prefix-matching URLs
$query = 'SELECT id FROM urls WHERE ';
$first = true;
foreach ($prefixes as $prefix) {
# safeguard in case prefix is empty
if ($prefix == '') {
continue;
}
if ($first) {
$first = false;
} else {
$query .= ' OR ';
}
$query .= sprintf("LOCATE('%s', LOWER(url)) = 1", mysqli_real_escape_string($conn, $prefix));
}
if (!$enableNonHTTPURLs) {
if (!$first) {
$query .= ' OR ';
}
$query .= "(LOCATE('http://', LOWER(url)) <> 1 AND LOCATE('https://', LOWER(url)) <> 1)";
}
$result = mysqli_query($conn, $query);
if (!$result) {
error_log(mysqli_error($conn));
exit;
}
while($row = mysqli_fetch_assoc($result)) {
$ids[] = $row['id'];
}
}
# checking regexes - this takes time as we need to match every URL to every regex
if (count($regexes) > 0) {
$query = 'SELECT id, url FROM urls';
$result = mysqli_query($conn, $query);
if (!$result) {
error_log(mysqli_error($conn));
exit;
}
while($row = mysqli_fetch_assoc($result)) {
$matched = false;
foreach ($regexes as $regex) {
if (preg_match($regex, $row['url'])) {
$matched = true;
break;
}
}
if ($matched) {
$ids[] = $row['id'];
}
}
}
# deleting data for custom metrics
$query = sprintf("DELETE FROM metric WHERE url_id IN (%s)", implode(', ', $ids));
$result = mysqli_query($conn, $query);
if (!$result) {
error_log(mysqli_error($conn));
exit;
}
# deleting data for yslow v2
$query = sprintf("DELETE FROM yslow2 WHERE url_id IN (%s)", implode(', ', $ids));
$result = mysqli_query($conn, $query);
if (!$result) {
error_log(mysqli_error($conn));
exit;
}
# deleting data for pagespeed
$query = sprintf("DELETE FROM pagespeed WHERE url_id IN (%s)", implode(', ', $ids));
$result = mysqli_query($conn, $query);
if (!$result) {
error_log(mysqli_error($conn));
exit;
}
# deleting data for dynatrace
$query = sprintf("DELETE FROM dynatrace WHERE url_id IN (%s)", implode(', ', $ids));
$result = mysqli_query($conn, $query);
if (!$result) {
error_log(mysqli_error($conn));
exit;
}
# resetting urls aggregates
$query = sprintf("UPDATE urls SET last_update = NULL, yslow2_last_id = NULL, pagespeed_last_id = NULL, dynatrace_last_id = NULL WHERE id IN (%s)", implode(', ', $ids));
$result = mysqli_query($conn, $query);
if (!$result) {
error_log(mysqli_error($conn));
exit;
}
}