I know I said I was going to do this in PHP, but I’m tired of trying to figure out what’s wrong w/ my Eclipse PHP editor so I thought I’d just take a quick hack at the MT migration script in Ruby. Looking around for some stock MySQL connection code this morning (laziest programmer ever), I found this.
A couple of minutes later, I turned that into this:
#! /usr/bin/ruby
require 'rubygems'
require 'mysql'def with_db
dbh = Mysql.real_connect('localhost', 'username','password','databasename')
begin
yield dbh
ensure
dbh.close
end
end
#---
with_db do |db|
res = db.query('SELECT entry_id,entry_created_on,entry_basename FROM mt_entry WHERE entry_blog_id = 3;')
res.each { |row| puts "Redirect /archives/#{row[0]}.html http://www.redmonk.com/sogrady/archives/#{row[1]}/#{row[2]}.php" }
res.free
end
Which spits out a whole bunch of this:
Redirect /archives/2399.html http://www.redmonk.com/sogrady/archives/2006-10-19 11:00:39/scan_your_php_a.php
Redirect /archives/2400.html http://www.redmonk.com/sogrady/archives/2006-10-19 16:07:46/startup_camps_f.php
Redirect /archives/2401.html http://www.redmonk.com/sogrady/archives/2006-10-19 23:24:52/links_for_20061_16.php
Redirect /archives/2406.html http://www.redmonk.com/sogrady/archives/2006-10-20 23:22:05/links_for_20061_17.php
Redirect /archives/2409.html http://www.redmonk.com/sogrady/archives/2006-10-22 15:07:48/progress_w_trix.php
Redirect /archives/2410.html http://www.redmonk.com/sogrady/archives/2006-10-22 23:19:37/links_for_20061_18.php
Redirect /archives/2412.html http://www.redmonk.com/sogrady/archives/2006-10-23 11:27:20/attending_the_c.php
Redirect /archives/2413.html http://www.redmonk.com/sogrady/archives/2006-10-23 11:35:27/and_speaking_of_1.php
Redirect /archives/2416.html http://www.redmonk.com/sogrady/archives/2006-10-23 16:56:37/apologies_in_ad.php
Redirect /archives/2419.html http://www.redmonk.com/sogrady/archives/2006-10-23 23:25:56/links_for_20061_19.php
That’s mostly what I need, though I need to a.) pad the entry_id to six characters and b.) lose the time stamp in the date returns. Once that’s done, I can spit this out into a text file and I’ll more or less have a .htaccess file capable of handling the migration (I think). This is presuming, of course, that I can get WordPress to preserve the basenames from the existing MT installation – I’ll have to confirm that.
What am I missing?