#!/usr/bin/perl -w # Call with single argument, path to MT directory that contains lib subdir use strict; local $|=1; my($MT_DIR); $MT_DIR = $ARGV[0]; unshift @INC, $MT_DIR . 'lib'; unshift @INC, $MT_DIR . 'extlib'; require MT; require MT::Blog; require MT::Entry; require MT::Trackback; require MT::TBPing; my $mt = MT->new( Config => $MT_DIR . 'mt.cfg', Directory => $MT_DIR ); my @blogs = MT::Blog->load({}, {sort => "name"}); my $blog; my $nBadPingCount = 0; foreach $blog (@blogs) { printf "Blog %s\n", $blog->name; my $iter = MT::Entry->load_iter({ blog_id => $blog->id }); my @entriesToUpdate; while (my $entry = $iter->()) { my $allow_pings = defined $entry->allow_pings ? $entry->allow_pings : 1; if ($entry->ping_count > 0) { printf "Entry \"%s\" Allow Pings \"%s\" Ping Count \"%01d\"\n", $entry->title, $allow_pings?"yes":"no", $entry->ping_count; my $ping = MT::Trackback->load({ entry_id => $entry->id }); my @tbPings = MT::TBPing->load({ tb_id => $ping->id }); my $tbPing; foreach $tbPing (@tbPings) { printf "Ping Title \"%s\" URL \"%s\" IP \"%s\"\n", $tbPing->title, $tbPing->source_url, $tbPing->ip; # identify the pings to delete if ($tbPing->title =~ /holdem|poker|casino|phentermine|texas|carisoprodol/i) { ++$nBadPingCount; $tbPing->remove() or die $entry->errstr; } } } if ($allow_pings == 1) { $entry->allow_pings(0); push @entriesToUpdate, $entry; } } foreach my $entry (@entriesToUpdate) { printf "Saving Entry %s\n", $entry->title; $entry->save() or die $entry->errstr; } } printf "Found %01d bad pings\n", $nBadPingCount;