Permalink
Browse files

Script to delete inactive users and their page revisions, useful to c…

…lear spam
  • Loading branch information...
dandv committed Aug 13, 2011
1 parent 1016ccc commit e51f3cd1970b8ff0f785c1a91e6d7fd6142c09ff
Showing with 101 additions and 2 deletions.
  1. +3 −0 Changes
  2. +7 −2 lib/MojoMojo/Schema/Result/Person.pm
  3. +91 −0 script/util/delete_inactive_users.pl
View
@@ -1,3 +1,6 @@
+ New features:
+ - script to delete inactive users and their page revisions, useful to clear spam (dandv)
+
Bug fixes:
- Check input for gallery pages (be numeric) and jsrpc/diff (page must exist). Fixes issue #83. (dandv)
- Ensure all 'jsrpc/diff' links have rel=nofollow. Avoid bogus search engine indexing. (dandv)
@@ -21,13 +21,18 @@ __PACKAGE__->add_columns(
size => undef,
is_auto_increment => 1
},
+
"active",
+ # -1 = user registered but hasn't confirmed e-mail address yet;
+ # 0 = manually set to inactive from Site Settings -> Users;
+ # 1 = active user
{
data_type => "INTEGER",
is_nullable => 0,
default_value => -1,
size => undef
},
+
"registered",
# { data_type => "BIGINT", is_nullable => 0, size => undef, epoch => 'ctime' },
@@ -217,7 +222,7 @@ sub valid_pass {
=head2 hashed
-Apply a sha1 hash to the inpout string.
+Apply a SHA1 hash to the input string.
=cut
@@ -246,7 +251,7 @@ sub music_formatted { $textile->process( shift->music ); }
=head2 movies_formatted
-Format a person's movies tastes.
+Format a person's movie tastes.
=cut
@@ -0,0 +1,91 @@
+#!/usr/bin/perl
+=head1 NAME
+
+delete_inactive_users.pl - Delete inactive users and their revisions. Use as a mass antispam tool,
+if you haven't deactivated users via /admini/.users for other reasons. Read the usage.
+
+=head1 AUTHOR
+
+Dan Dascalescu (dandv), http://dandascalescu.com
+
+=cut
+
+use strict;
+use warnings;
+
+use FindBin;
+use lib "$FindBin::Bin/../lib";
+use MojoMojo;
+
+die "Delete inactive users and their page revisions.
+
+These users are of two sorts: users that an admin has disabled from
+/.admin/user (most probably spammers) and unconfirmed users (they haven't
+confirmed their e-mail yet). The latter are again most probably spammers,
+but theoretically, a user who's changed their valid e-mail address and
+didn't confirm the new one would fall in that category too.
+
+This script will delete all unconfirmed and disabled users who've never
+edited pages, and will prompt you to delete disabled users who have edited
+pages. All their edits (page revisions) will also be deleted.
+
+To run this script, call it with an argument (meaning you've read this).
+" if not @ARGV;
+
+my $users;
+my $users_deleted = 0;
+
+$users = MojoMojo->model('DBIC::Person')->search(
+ { active => {'!=' => 1},
+ 'page_versions.creator' => undef # IS NULL
+ },
+ {join => 'page_versions'}
+);
+my $users_count = $users->count;
+if ($users_count > 0) {
+ print "Unconfirmed and disabled users without pages: $users_count. Delete? ('yes'/anything else): ";
+ my $answer = <STDIN>; chomp $answer;
+ if ($answer eq 'yes') {
+ $users_deleted += $users_count;
+ $users->delete;
+ }
+};
+
+# disabled users (active = 0, set so from the admin interface) who've edited pages are probably spammers
+$users = MojoMojo->model('DBIC::Person')->search(
+ {
+ active => 0,
+ 'page_versions.creator' => \'IS NOT NULL' # necessary because this is a LEFT JOIN
+ },
+ {join => 'page_versions'}
+);
+$users_count = $users->count;
+
+if ($users_count > 0) {
+ print "$users_count users disabled by an admin (probably spammers) have edited at least one page each. Delete (A)ll / (I)ndividually / (N)one? ";
+ my $answer = <STDIN>; chomp $answer;
+ if (uc $answer eq 'A') {
+ $users_deleted += $users_count;
+ $users->delete;
+ } elsif (uc $answer eq 'I') {
+ # delete the fuckers individually
+ while (my $user = $users->next) {
+ my @user_pages = $user->pages;
+ print "User ", $user->name, "has been disabled, and they edited ", scalar @user_pages, " pages:\n";
+ print map {' ' . $_->path . "\n" } @user_pages;
+ print "Delete this user? ('yes'/anything else) ";
+ my $answer = <STDIN>; chomp $answer;
+ if ($answer eq 'yes') {
+ # this nicely cascades to delete the revisions authored by the user in Content,
+ # and the Page and PageVersion if they are left without any Content revision
+ $user->delete;
+ $users_deleted++;
+ }
+ }
+ }
+}
+
+# Unconfirmed users (active = -1) who have edited pages are left alone. This can only mean that the user was
+# once active, but then changed their e-mail address and hasn't confirmed the new one.
+
+print "Deleted $users_deleted inactive users.\n";

0 comments on commit e51f3cd

Please sign in to comment.