-
Notifications
You must be signed in to change notification settings - Fork 7
/
cleanup_spam.php
88 lines (69 loc) · 2.16 KB
/
cleanup_spam.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
#!/usr/bin/env php
<?php
/**
* This will restore the MantisBT database to its previous state after a
* user has spammed the tracker by mass-adding bug notes.
*
* Instructions:
* 1. Specify user id of the spammer in variable below and save the script
* in MantisBT folder
* 2. Run the script
*/
$t_user_id = 37486;
# -----------------------------------------------------------------------------
include( 'core.php' );
ob_end_flush();
ob_end_flush();
user_ensure_exists( $t_user_id );
echo "Ready to restore bugtracker after spamming by user id $t_user_id ("
. user_get_name( $t_user_id )
. ")\n";
readline( "Press (ctrl-c to abort)\n" );
# Identify all modified bugs (from bugnotes added by spammer)
$t_query = '
SELECT DISTINCT bug_id
FROM {bugnote}
WHERE reporter_id=' . db_param();
$t_updated_bugs = db_query( $t_query, array( $t_user_id ) );
# Delete history records generated by the spammer
echo "Deleting history records...\n";
$t_query = '
DELETE FROM {bug_history}
WHERE type=' . BUGNOTE_ADDED . ' AND user_id=' . db_param();
db_query( $t_query, array( $t_user_id ) );
# Reset bugs' last updated date
echo "Restoring bugs' last updated date...\n";
while( $t_bug = db_fetch_array( $t_updated_bugs ) ) {
$t_bug_id = $t_bug['bug_id'];
# Get timestamp of most recent remaining history entry
$t_query = '
SELECT date_modified
FROM {bug_history}
WHERE bug_id=' . db_param() . '
ORDER BY id DESC
LIMIT 1';
$t_last_updated = db_result( db_query( $t_query, array( $t_bug_id ) ) );
if( !$t_last_updated ) {
# No history record found, use bug's submitted date
$t_last_updated = bug_get_field( $t_bug_id, 'date_submitted' );
}
# Set last_updated date
$t_query = '
UPDATE {bug}
SET last_updated=' . db_param() . '
WHERE id=' . db_param();
db_query( $t_query, array( $t_last_updated, $t_bug_id ) );
}
# Delete bugnotes
echo "Deleting bugnotes...\n";
$t_query = '
DELETE t.*
FROM {bugnote_text} t
JOIN {bugnote} n ON n.bugnote_text_id=t.id
WHERE n.reporter_id=' . db_param();
db_query( $t_query, array( $t_user_id ) );
$t_query = '
DELETE FROM {bugnote}
WHERE reporter_id=' . db_param();
db_query( $t_query, array( $t_user_id ) );
echo "Done\n";