add two modified version and documentation
[pyblosxom2wxr] / fix_comment.pl
1 #!/usr/bin /perl -w
2
3 use DBI;
4 my $dbh = DBI->connect('DBI:mysql:copyrighteous:localhost', 'mako')
5     or die "Cannot connect: " . $DBI::errstr;
6
7
8 $sql = qq`SELECT comment_ID, comment_author from wp_comments`;
9 $sth = $dbh->prepare($sql) or die "Cannot prepare: " . $dbh->errstr();
10 $sth->execute() or die "Cannot execute: " . $sth->errstr();
11
12 my @row;
13 my @fields;
14 while(@row = $sth->fetchrow_array()) {
15     my @record = @row;
16     push(@fields, \@record);
17 }
18 $sth->finish();
19
20 # now process the fields
21
22 my $new_username;
23 my $comment_id;
24 if (@fields != 0) {
25     foreach $line (@fields) {
26         # datestamp method
27         if (@$line[1] =~ /^.*\d{4}-\d{2}-\d{2} \d{2}:\d{2}:\d{2} (.*)$/) {
28             $new_username = $1;
29         }
30         # just the ip address
31         elsif (@$line[1] =~ /^\d+\.\d+\.\d+\.\d+ (.*)$/) {
32             $new_username = $1;
33         } else {
34             next;
35         }
36         
37         $comment_id = @$line[0];
38         #print "Old: ", @$line[1], "\n";
39         print "Updating: ", $comment_id, " ", $new_username, "\n";
40
41         $sql = qq`UPDATE wp_comments SET comment_author = "$new_username" WHERE comment_ID = $comment_id`;
42         $sth = $dbh->prepare($sql) or die "Cannot prepare: " .
43         $dbh->errstr();
44         $sth->execute() or die "Cannot execute: " . $sth->errstr();
45         $sth->finish();
46         #print "row $i - id is @$line[0], name is @$line[1]\n";
47     }
48 }
49
50
51
52
53
54
55

Benjamin Mako Hill || Want to submit a patch?