Index: trunk/phase3/maintenance/delete-idle-wiki-users.pl |
— | — | @@ -1,138 +0,0 @@ |
2 | | -#!/usr/bin/perl |
3 | | -# |
4 | | -# Nuke idle wiki accounts from the wiki's user database. |
5 | | -# |
6 | | -# Copyright (C) 2005 Ralf Baechle (ralf@linux-mips.org) |
7 | | -# |
8 | | -# This program is free software; you can redistribute it and/or modify it |
9 | | -# under the terms of the GNU General Public License as published by the |
10 | | -# Free Software Foundation; either version 2 of the License, or (at your |
11 | | -# option) any later version. |
12 | | -# |
13 | | -# THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED |
14 | | -# WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF |
15 | | -# MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN |
16 | | -# NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, |
17 | | -# INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT |
18 | | -# NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF |
19 | | -# USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON |
20 | | -# ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
21 | | -# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF |
22 | | -# THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
23 | | -# |
24 | | -# You should have received a copy of the GNU General Public License along |
25 | | -# with this program; if not, write to the Free Software Foundation, Inc., |
26 | | -# 675 Mass Ave, Cambridge, MA 02139, USA. |
27 | | -# |
28 | | - |
29 | | -my $database = "DBI:mysql:database=wikidb;host=localhost"; |
30 | | -my $dbuser = "wikiuser"; |
31 | | -my $dbpasswd = "password"; |
32 | | - |
33 | | -use strict; |
34 | | -use DBI(); |
35 | | - |
36 | | -my $verbose = 0; |
37 | | -my $for_real = 1; |
38 | | - |
39 | | -sub do_db_op |
40 | | -{ |
41 | | - my ($dbh, $sql) = @_; |
42 | | - |
43 | | - if ($verbose >= 3) { |
44 | | - print $sql . ";\n" |
45 | | - } |
46 | | - |
47 | | - if ($for_real == 1) { |
48 | | - $dbh->do($sql); |
49 | | - } |
50 | | -} |
51 | | - |
52 | | -sub undo_user |
53 | | -{ |
54 | | - my ($ref, $dbh, $sth, $killed); |
55 | | - |
56 | | - # Connect to the database. |
57 | | - $dbh = DBI->connect($database, $dbuser, $dbpasswd, {RaiseError => 1}); |
58 | | - |
59 | | - $sth = $dbh->prepare("SELECT * FROM user"); |
60 | | - $sth->execute(); |
61 | | - |
62 | | - $ref = $sth->fetchrow_hashref(); |
63 | | - |
64 | | - if ($sth->rows == 0) { |
65 | | - print "There is no user in this wiki.\n"; |
66 | | - return; |
67 | | - } |
68 | | - |
69 | | - while ($ref = $sth->fetchrow_hashref()) { |
70 | | - my ($user_id, $user_name, $cph, $oph, $edits); |
71 | | - |
72 | | - $user_name = $ref->{user_name}; |
73 | | - $user_id = $ref->{user_id}; |
74 | | - if ($verbose >= 2) { |
75 | | - print "Annihilating user " . $user_name . |
76 | | - " has user_id " . $user_id . ".\n"; |
77 | | - } |
78 | | - |
79 | | - $cph = $dbh->prepare("SELECT * FROM cur where " . |
80 | | - "cur_user = $user_id" . |
81 | | - " AND " . |
82 | | - "cur_user_text = " . $dbh->quote("$user_name")); |
83 | | - $cph->execute(); |
84 | | - |
85 | | - $oph = $dbh->prepare("SELECT * FROM old where " . |
86 | | - "old_user = $user_id" . |
87 | | - " AND " . |
88 | | - "old_user_text = " . $dbh->quote("$user_name")); |
89 | | - $oph->execute(); |
90 | | - |
91 | | - $edits = $cph->rows + $oph->rows; |
92 | | - |
93 | | - $cph->finish(); |
94 | | - $oph->finish(); |
95 | | - |
96 | | - if ($edits == 0) { |
97 | | - if ($verbose >= 2) { |
98 | | - print "Keeping user " . $user_name . |
99 | | - ", user_id " . $user_id . ".\n"; |
100 | | - } |
101 | | - |
102 | | - do_db_op($dbh, |
103 | | - "DELETE FROM user WHERE user_name = " . |
104 | | - $dbh->quote("$user_name") . |
105 | | - " AND " . |
106 | | - "user_id = $user_id"); |
107 | | - |
108 | | - $killed++; |
109 | | - } |
110 | | - } |
111 | | - |
112 | | - $sth->finish(); |
113 | | - |
114 | | - $dbh->disconnect(); |
115 | | - |
116 | | - if ($verbose >= 1) { |
117 | | - print "Killed " . $killed . " users\n"; |
118 | | - } |
119 | | -} |
120 | | - |
121 | | -my (@users, $user, $this, $opts); |
122 | | - |
123 | | -@users = (); |
124 | | -$opts = 1; |
125 | | - |
126 | | -foreach $this (@ARGV) { |
127 | | - if ($opts == 1 && $this eq '-v') { |
128 | | - $verbose++; |
129 | | - } elsif ($opts == 1 && $this eq '--verbose') { |
130 | | - $verbose = 1; |
131 | | - } elsif ($opts == 1 && $this eq '--') { |
132 | | - $opts = 0; |
133 | | - } else { |
134 | | - push(@users, $this); |
135 | | - } |
136 | | -} |
137 | | - |
138 | | -undo_user(); |
139 | | - |