#!/usr/local/bin/perl -w # this script converts the tags from the Tags plugin for MT3.2 # from http://www.sixapart.com/pronet/plugins/plugin/tags.html # because MT3.3's built-in conversion process groks something up # and you end up with bizarre and incomplete tags. use DBI; use Text::ParseWords; # enter your values here $db_driver = 'mysql'; $db_database = ''; $db_user = ''; $db_password = ''; $db_host = 'localhost'; # probably don't need to touch anything below my $dbh = DBI->connect("dbi:$db_driver:dbname=$db_database;host=$db_host", $db_user, $db_password) or die "\nCouldn't connect to database: " . DBI->errstr; # mt_tag - tag table # mt_objecttag - holding entry<>tag relations my $sth = $dbh->prepare("SELECT blog_id, blog_name from mt_blog"); my $entry_sth = $dbh->prepare("SELECT entry_id, entry_title, entry_keywords from mt_entry where entry_blog_id=?"); my $selecttag_sth = $dbh->prepare("SELECT tag_id from mt_tag where tag_name=?"); $sth->execute(); while ($curr_blog = $sth->fetchrow_hashref()) { $entry_sth->execute($curr_blog->{"blog_id"}); while ($curr_entry = $entry_sth->fetchrow_hashref()) { if (defined($curr_entry->{'entry_keywords'})) { $dbh->do("DELETE FROM mt_objecttag where objecttag_blog_id=".$curr_blog->{"blog_id"}." and objecttag_object_datasource='entry' and objecttag_object_id=".$curr_entry->{'entry_id'}); # @keywords = split(' ', $curr_entry->{'entry_keywords'}); @keywords = "ewords(" ", 0, $curr_entry->{'entry_keywords'}); foreach $kw (@keywords) { $selecttag_sth->execute($kw); if ($selecttag_sth->rows() == 0) { $dbh->do("INSERT INTO mt_tag (tag_name) values ('$kw')"); $selecttag_sth->execute($kw); # to get the freshly inserted tag id } $tag = $selecttag_sth->fetchrow_hashref(); $dbh->do("INSERT INTO mt_objecttag (objecttag_blog_id, objecttag_object_datasource, objecttag_object_id, objecttag_tag_id) values (".$curr_blog->{"blog_id"}.", 'entry', ".$curr_entry->{"entry_id"}.", ".$tag->{"tag_id"}.")"); $selecttag_sth->finish; } } } } $dbh->disconnect; print "Done, tags fixed.\n";