-
Notifications
You must be signed in to change notification settings - Fork 0
/
admin.php
427 lines (325 loc) · 13.6 KB
/
admin.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
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
<?php
require_once('path.php');
require_once('include/incl.php');
require_once('include/maintainer.php');
if(!$_SESSION['current']->hasPriv('admin'))
util_show_error_page_and_exit("Only admins are allowed in here");
apidb_header('AppDB Control Center');
function updateAppMaintainerStates()
{
$hResult = application::objectGetEntries('accepted');
$i = 0;
while($oRow = query_fetch_object($hResult))
{
$oApp = new application(null, $oRow);
$oApp->updateMaintainerState();
$i++;
}
echo "Updated $i entries";
}
function updateVersionMaintainerStates()
{
$hResult = version::objectGetEntries('accepted');
$i = 0;
while($oRow = query_fetch_object($hResult))
{
$oVersion = new version(null, $oRow);
$oVersion->updateMaintainerState();
$i++;
}
echo "Updated $i entries";
}
function deleteInactiveMaintainers()
{
$hResult = maintainer::getInactiveMaintainers(24);
$i = 0;
while($oRow = query_fetch_object($hResult))
{
$oMaintainer = new maintainer(null, $oRow);
$oMaintainer->delete();
$oUser = new User($oRow->userid);
$sEmail = $oUser->sEmail;
$sSubject = "Maintainer status removed";
$sMsg = "Your maintainer status has been removed because you have not logged into the AppDB in over 24 months.";
mail_appdb($sEmail, $sSubject, $sMsg);
$i++;
}
echo "Removed $i inactive maintainers.";
}
function fixNoteLinks()
{
// Notes shown for app and all versions
$hResult = query_parameters("SELECT * FROM appNotes WHERE versionId = '?'", APPNOTE_SHOW_FOR_ALL);
echo 'The following notes are set to show for app and all versions:<br />';
$iCount = 0;
$iSkipped = 0;
while(($oRow = query_fetch_object($hResult)))
{
$oNote = new note(null, $oRow);
$iNoteId = $oNote->objectGetId();
$oApp = new Application($oNote->iAppId);
echo 'ID: '.$oNote->objectGetId().'<br />';
echo 'App: '.$oApp->objectMakeLink().'<br />';
$aVersions = $oApp->GetVersions(true);
foreach($aVersions as $oVersion)
{
$iVersionId = $oVersion->objectGetId();
$hResultTag = query_parameters("SELECT COUNT(*) as count FROM tags_NoteVersion_assignments WHERE tagId = '?' AND taggedId = '?'", $iVersionId, $oRow->noteId);
$oRowTag = query_fetch_object($hResultTag);
if(!$oRowTag->count)
{
query_parameters("INSERT INTO tags_NoteVersion_assignments (tagId,taggedId) VALUES('$iVersionId','$iNoteId')");
$iCount++;
} else
{
$iSkipped++;
}
}
echo '<br />';
}
echo "<br /><br />Created $iCount tags ($iSkipped already existed)<br />";
// Notes shown for all versions
$hResult = query_parameters("SELECT * FROM appNotes WHERE versionId = '?'", APPNOTE_SHOW_FOR_VERSIONS);
echo '<br /><br />The following notes are set to show for all versions:<br />';
$iCount = 0;
$iSkipped = 0;
while(($oRow = query_fetch_object($hResult)))
{
$oNote = new note(null, $oRow);
$iNoteId = $oNote->objectGetId();
$oApp = new Application($oNote->iAppId);
echo 'ID: '.$oNote->objectGetId().'<br />';
echo 'App: '.$oApp->objectMakeLink().'<br />';
$aVersions = $oApp->GetVersions(true);
foreach($aVersions as $oVersion)
{
$iVersionId = $oVersion->objectGetId();
$hResultTag = query_parameters("SELECT COUNT(*) as count FROM tags_NoteVersion_assignments WHERE tagId = '?' AND taggedId = '?'", $iVersionId, $oRow->noteId);
$oRowTag = query_fetch_object($hResultTag);
if(!$oRowTag->count)
{
query_parameters("INSERT INTO tags_NoteVersion_assignments (tagId,taggedId) VALUES('?','?')", $iVersionId, $iNoteId);
$iCount++;
} else
{
$iSkipped++;
}
}
echo '<br />';
}
echo "<br /><br />Created $iCount tags ($iSkipped already existed)<br />";
// Notes shown for specific versions
$hResult = query_parameters("SELECT * FROM appNotes WHERE versionId = '?'", APPNOTE_SHOW_FOR_SPECIFIC_VERSIONS);
echo '<br /><br />The following notes are set to show for specific versions:<br />';
$iCount = 0;
$iSkipped =0;
while(($oRow = query_fetch_object($hResult)))
{
$oNote = new note(null, $oRow);
$iNoteId = $oNote->objectGetId();
$oApp = new Application($oNote->iAppId);
echo 'ID: '.$oNote->objectGetId().'<br />';
echo 'App: '.$oApp->objectMakeLink().'<br />';
echo '<br />';
$hResult2 = query_parameters("SELECT DISTINCT(versionId) FROM appNotes WHERE linkedWith = '?'", $oNote->objectGetId());
while(($oRow2 = query_fetch_object($hResult2)))
{
$iVersionId = $oRow2->versionId;
$hResultTag = query_parameters("SELECT COUNT(*) as count FROM tags_NoteVersion_assignments WHERE tagId = '?' AND taggedId = '?'", $iVersionId, $oRow->noteId);
$oRowTag = query_fetch_object($hResultTag);
if(!$oRowTag->count)
{
query_parameters("INSERT INTO tags_NoteVersion_assignments (tagId,taggedId) VALUES('?','?')", $iVersionId, $iNoteId);
$iCount++;
} else
{
$iSkipped++;
}
}
}
echo "<br /><br />Created $iCount tags ($iSkipped already existed)<br />";
// Notes shown for app
$hResult = query_parameters("SELECT * FROM appNotes WHERE versionId = '?'", APPNOTE_SHOW_FOR_APP);
echo '<br /><br />The following notes are set to show on app page:<br />';
$iCount = 0;
while(($oRow = query_fetch_object($hResult)))
{
$oNote = new note(null, $oRow);
$oApp = new Application($oNote->iAppId);
echo 'ID: '.$oNote->objectGetId().'<br />';
echo 'App: '.$oApp->objectMakeLink().'<br />';
echo '<br />';
$iCount++;
}
echo "<br />$iCount in total<br />";
// Create links for ordinary notes
echo "<br /><br />Creating tags for ordinary notes<br />";
$hResult = query_parameters("SELECT * FROM appNotes WHERE versionId > '0' AND linkedWith = '0'");
$iTagsCreated = 0;
$iSkipped = 0;
while(($oRow = query_fetch_object($hResult)))
{
$hResultTag = query_parameters("SELECT COUNT(*) as count FROM tags_NoteVersion_assignments WHERE tagId = '?' AND taggedId = '?'", $oRow->versionId, $oRow->noteId);
$oRowTag = query_fetch_object($hResultTag);
if(!$oRowTag->count)
{
query_parameters("INSERT INTO tags_NoteVersion_assignments (tagId,taggedId) VALUES('?','?')", $oRow->versionId, $oRow->noteId);
$iTagsCreated++;
} else
{
$iSkipped++;
}
}
echo "Created $iTagsCreated note tags ($iSkipped already existed)<br />";
echo "<br />Deleting note links<br />";
$hResult = query_parameters("DELETE FROM appNotes WHERE linkedWith != '0'");
echo "Deleted ".query_affected_rows()." links<br />";
}
function fixInvalidTestSubmitTime()
{
$sQuery = "UPDATE testResults SET submitTime = testedDate WHERE submitTime = '0000-00-00 00:00:00'";
$hResult = query_parameters($sQuery);
echo "Updated ".query_affected_rows()." test reports with invalid submit times.<br>";
}
function deleteOrphanComments()
{
$sQuery = "DELETE FROM appComments WHERE NOT EXISTS( SELECT appVersion.versionId FROM appVersion";
$sQuery.= " WHERE appVersion.versionId = appComments.versionId )";
$hResult = query_parameters($sQuery);
echo "Deleted ".query_affected_rows()." orphan comments.<br>";
}
function deleteOrphanVersions()
{
$sQuery = "DELETE FROM appVersion WHERE appId = 0 and state != 'deleted'";
$hResult = query_parameters($sQuery);
echo "Deleted ".query_affected_rows()." orphan versions.<br>";
}
function purgeRejectedDistributions()
{
$sQuery = "DELETE FROM distributions WHERE state = 'deleted'";
$hResult = query_parameters($sQuery);
echo "Removed " .query_affected_rows()." rejected distributions from database.<br>";
}
function purgeRejectedVendors()
{
$sQuery = "DELETE FROM vendor WHERE state = 'deleted'";
$hResult = query_parameters($sQuery);
echo "Removed " .query_affected_rows()." rejected vendors from database.<br>";
}
function deleteOldComments()
{
$sQuery = "DELETE FROM appComments USING appComments, appVersion WHERE appComments.versionId = appVersion.versionId AND appVersion.hasMaintainer = 'false' AND appComments.time <= DATE_SUB(CURDATE(), INTERVAL '12' MONTH)";
$hResult = query_parameters($sQuery);
echo "Deleted " .query_affected_rows()." comments older than 12 months from unmaintained entries.<br>";
}
function deleteOldErrorLogs()
{
$sQuery = "DELETE FROM error_log WHERE submitTime <= DATE_SUB(CURDATE(), INTERVAL '12' MONTH)";
$hResult = query_parameters($sQuery);
echo "Deleted " .query_affected_rows()." error log entries over 12 months old from database.<br>";
}
function updateVersionRatings()
{
$hResult = version::objectGetEntries('accepted');
$i = 0;
while($oRow = query_fetch_object($hResult))
{
$oVersion = new version(null, $oRow);
$oVersion->updateRatingInfo();
$i++;
}
echo "Updated $i entries";
}
function viewAppdbAdmins()
{
echo html_frame_start("AppDB Admins","90%","",0);
echo "<table width='100%' border=0 cellpadding=3 cellspacing=0>\n\n";
echo "<tr class=color1>\n";
echo "<td>Real name</td>\n";
echo "<td>Email</td>\n";
echo "<td>Last connected</td>\n";
echo "</tr>\n\n";
$sQuery = "SELECT user_list.userid, realname, email, stamp FROM user_list, user_privs WHERE user_list.userid = user_privs.userid AND user_privs.priv = 'admin' ORDER BY realname";
$hResult = query_parameters($sQuery);
$i = 0;
while($oRow = query_fetch_object($hResult))
{
$oUser = new User($oRow->userid);
echo "<tr class=color0>";
echo "<td>".$oUser->objectMakeLink()."</td>\n";
echo "<td>".$oUser->sEmail."</td>\n";
echo "<td>".$oUser->sStamp."</td>\n";
$i++;
}
echo "</table>";
echo html_frame_end();
echo "Found $i entries. <br>";
}
function showChoices()
{
echo '<div class="list-group">';
echo '<a href="admin.php?sAction=fixNoteLinks" class="list-group-item"><h4>Fix/Show note links</h4></a>';
echo '<a href="admin.php?sAction=fixInvalidTestSubmitTime" class="list-group-item"><h4>Fix Invalid Test Submission Times</h4></a>';
echo '<a href="admin.php?sAction=updateAppMaintainerStates" class="list-group-item"><h4>Update application maintainer states</h4></a>';
echo '<a href="admin.php?sAction=updateVersionMaintainerStates" class="list-group-item"><h4>Update version maintainer states</h4></a>';
echo '<a href="admin.php? sAction=deleteInactiveMaintainers" class="list-group-item"><h4>Delete inactive maintainers</h4></a>';
echo '<a href="admin.php?sAction=deleteOrphanComments" class="list-group-item"><h4>Delete orphan comments</h4></a>';
echo '<a href="admin.php?sAction=deleteOrphanVersions" class="list-group-item"><h4>Delete orphan versions</h4></a>';
echo '<a href="admin.php?sAction=purgeRejectedDistributions" class="list-group-item"><h4>Purge rejected distributions</h4></a>';
echo '<a href="admin.php?sAction=purgeRejectedVendors" class="list-group-item"><h4>Purge rejected vendors</h4></a>';
echo '<a href="admin.php?sAction=deleteOldComments" class="list-group-item"><h4>Delete old comments</h4></a>';
echo '<a href="admin.php?sAction=deleteOldErrorLogs" class="list-group-item"><h4>Delete old error logs</h4></a>';
echo '<a href ="'.BASE.'objectManager.php?sClass=error_log&sTitle=View+Error_log" class="list-group-item"><h4>View Error log entries</h4></a>';
echo '<a href="admin.php?sAction=updateVersionRatings" class="list-group-item"><h4>Update version ratings</h4></a>';
echo '<a href="admin.php?sAction=viewAppdbAdmins" class="list-group-item"><h4>View AppDB admins</h4></a>';
echo '</div>';
}
switch(getInput('sAction', $aClean))
{
case 'updateAppMaintainerStates':
updateAppMaintainerStates();
break;
case 'updateVersionMaintainerStates':
updateVersionMaintainerStates();
break;
case 'deleteInactiveMaintainers';
deleteInactiveMaintainers();
break;
case 'fixNoteLinks':
fixNoteLinks();
break;
case 'fixInvalidTestSubmitTime';
fixInvalidTestSubmitTime();
break;
case 'deleteOrphanComments':
deleteOrphanComments();
break;
case 'deleteOrphanVersions':
deleteOrphanVersions();
break;
case 'purgeRejectedDistributions':
purgeRejectedDistributions();
break;
case 'purgeRejectedVendors':
purgeRejectedVendors();
break;
case 'deleteOldComments':
deleteOldComments();
break;
case 'deleteOldErrorLogs':
deleteOldErrorLogs();
break;
case 'viewErrorLogEntries';
viewErrorLogEntries();
break;
case 'updateVersionRatings':
updateVersionRatings();
break;
case 'viewAppdbAdmins':
viewAppdbAdmins();
break;
default:
showChoices();
break;
}
apidb_footer();