-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcheck.php
181 lines (136 loc) · 5.53 KB
/
check.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
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
<?php
/**
* check the integrity of the database for locations
*
* This page is used to check and update the database. Its usage is restricted to associates.
*
* @author Bernard Paques
* @author GnapZ
* @reference
* @license http://www.gnu.org/copyleft/lesser.txt GNU Lesser General Public License
*/
// include libraries
include_once '../shared/global.php';
include_once 'locations.php';
// load the skin
load_skin('locations');
// do not index this page
$context->sif('robots','noindex');
// the path to this page
$context['path_bar'] = array( 'locations/' => i18n::s('Locations') );
// the title of the page
$context['page_title'] = i18n::s('Maintenance');
// the user has to be an associate
if(!Surfer::is_associate()) {
Safe::header('Status: 401 Unauthorized', TRUE, 401);
Logger::error(i18n::s('You are not allowed to perform this operation.'));
// forward to the index page
$menu = array('locations/' => i18n::s('Locations'));
$context['text'] .= Skin::build_list($menu, 'menu_bar');
// look for unused locations
} elseif(isset($_REQUEST['action']) && ($_REQUEST['action'] == 'unused')) {
// scan locations
$context['text'] .= Skin::build_block(sprintf(i18n::s('Analyzing table %s...'), SQL::table_name('locations')), 'subtitle');
// scan up to 10000 items
$count = 0;
$query = "SELECT id, anchor, geo_place_name FROM ".SQL::table_name('locations')
." ORDER BY anchor LIMIT 0, 10000";
if(!($result = SQL::query($query))) {
$context['text'] .= Logger::error_pop().BR."\n";
return;
// parse the whole list
} else {
// fetch one anchor and the linked member
$errors_count = 0;
while($row = SQL::fetch($result)) {
// animate user screen and take care of time
$count++;
if(!($count%100)) {
$context['text'] .= sprintf(i18n::s('%d records have been processed'), $count).BR."\n";
// ensure enough execution time
Safe::set_time_limit(30);
}
// look only in articles
if(preg_match('/article:(.*)/', $row['anchor'], $matches) && ($article = Articles::get($matches[1]))) {
// check that the description has a reference to this location, or that the location is either an icon or a thumbnail
if(!preg_match('/\[location='.$row['id'].'.*\]/', $article['description'])) {
$context['text'] .= sprintf(i18n::s('Unused: %s'), 'location '.Skin::build_link(Locations::get_url($row['id']), $row['id'].' '.$row['geo_place_name'])).BR."\n";
if(++$errors_count >= 25) {
$context['text'] .= i18n::s('Too many successive errors. Aborted').BR."\n";
break;
}
} else
$errors_count = 0;
}
}
}
// ending message
$context['text'] .= sprintf(i18n::s('%d records have been processed'), $count).BR."\n";
// display the execution time
$time = round(get_micro_time() - $context['start_time'], 2);
$context['text'] .= '<p>'.sprintf(i18n::s('Script terminated in %.2f seconds.'), $time).'</p>';
// forward to the index page
$menu = array('locations/' => i18n::s('Locations'));
$context['text'] .= Skin::build_list($menu, 'menu_bar');
// look for orphans
} elseif(isset($_REQUEST['action']) && ($_REQUEST['action'] == 'orphans')) {
// scan locations
$context['text'] .= Skin::build_block(sprintf(i18n::s('Analyzing table %s...'), SQL::table_name('locations')), 'subtitle');
// scan up to 10000 items
$count = 0;
$query = "SELECT id, anchor, geo_place_name FROM ".SQL::table_name('locations')
." ORDER BY anchor LIMIT 0, 10000";
if(!($result = SQL::query($query))) {
$context['text'] .= Logger::error_pop().BR."\n";
return;
// parse the whole list
} else {
// fetch one anchor and the linked member
$errors_count = 0;
while($row = SQL::fetch($result)) {
// animate user screen and take care of time
$count++;
if(!($count%100)) {
$context['text'] .= sprintf(i18n::s('%d records have been processed'), $count).BR."\n";
// ensure enough execution time
Safe::set_time_limit(30);
}
// check that the anchor exists, if any
if($row['anchor'] && !Anchors::get($row['anchor'])) {
$context['text'] .= sprintf(i18n::s('Orphan: %s'), 'location '.Skin::build_link(Locations::get_url($row['id']), $row['id'].' '.$row['geo_place_name'])).BR."\n";
if(++$errors_count >= 5) {
$context['text'] .= i18n::s('Too many successive errors. Aborted').BR."\n";
break;
}
} else
$errors_count = 0;
}
}
// ending message
$context['text'] .= sprintf(i18n::s('%d records have been processed'), $count).BR."\n";
// display the execution time
$time = round(get_micro_time() - $context['start_time'], 2);
$context['text'] .= '<p>'.sprintf(i18n::s('Script terminated in %.2f seconds.'), $time).'</p>';
// forward to the index page
$menu = array('locations/' => i18n::s('Locations'));
$context['text'] .= Skin::build_list($menu, 'menu_bar');
// which check?
} else {
// the splash message
$context['text'] .= '<p>'.i18n::s('Please select the action to perform.')."</p>\n";
// the form
$context['text'] .= '<form method="post" action="'.$context['script_url'].'" id="main_form">';
// look for unused locations
$context['text'] .= '<p><input type="radio" name="action" id="action" value="unused" /> '.i18n::s('Look for unused locations').'</p>';
// look for orphan records
$context['text'] .= '<p><input type="radio" name="action" value="orphans" /> '.i18n::s('Look for orphan records').'</p>';
// the submit button
$context['text'] .= '<p>'.Skin::build_submit_button(i18n::s('Start')).'</p>'."\n";
// end of the form
$context['text'] .= '</form>';
// set the focus on the button
Page::insert_script('$("#action").focus();');
}
// render the skin
render_skin();
?>