X-Git-Url: https://projects.mako.cc/source/pyblosxom2wxr/blobdiff_plain/63b7950374b42e5bb351e534dfa3c150c3d5a285..f34e97609dfb44f29bfb8aceac0e1170707ba6e0:/fix_comment.pl diff --git a/fix_comment.pl b/fix_comment.pl new file mode 100755 index 0000000..9baec03 --- /dev/null +++ b/fix_comment.pl @@ -0,0 +1,55 @@ +#!/usr/bin /perl -w + +use DBI; +my $dbh = DBI->connect('DBI:mysql:copyrighteous:localhost', 'mako') + or die "Cannot connect: " . $DBI::errstr; + + +$sql = qq`SELECT comment_ID, comment_author from wp_comments`; +$sth = $dbh->prepare($sql) or die "Cannot prepare: " . $dbh->errstr(); +$sth->execute() or die "Cannot execute: " . $sth->errstr(); + +my @row; +my @fields; +while(@row = $sth->fetchrow_array()) { + my @record = @row; + push(@fields, \@record); +} +$sth->finish(); + +# now process the fields + +my $new_username; +my $comment_id; +if (@fields != 0) { + foreach $line (@fields) { + # datestamp method + if (@$line[1] =~ /^.*\d{4}-\d{2}-\d{2} \d{2}:\d{2}:\d{2} (.*)$/) { + $new_username = $1; + } + # just the ip address + elsif (@$line[1] =~ /^\d+\.\d+\.\d+\.\d+ (.*)$/) { + $new_username = $1; + } else { + next; + } + + $comment_id = @$line[0]; + #print "Old: ", @$line[1], "\n"; + print "Updating: ", $comment_id, " ", $new_username, "\n"; + + $sql = qq`UPDATE wp_comments SET comment_author = "$new_username" WHERE comment_ID = $comment_id`; + $sth = $dbh->prepare($sql) or die "Cannot prepare: " . + $dbh->errstr(); + $sth->execute() or die "Cannot execute: " . $sth->errstr(); + $sth->finish(); + #print "row $i - id is @$line[0], name is @$line[1]\n"; + } +} + + + + + + +