art taylor

 
Filed under

Drupal

 

Migrating content from Drupal (v4.7) to Posterous

I figured it was time to suffer through another blog migration and moved everything over to Posterous.  This probably wasn't important at all, since I don't think I have the pre-2001 entries around anywhere, and the ones since then are pretty much narcissistic omphaloskepsis.  But, it gave me an opportunity to prune out many of the semi-offensive posts and migrate to an easier posting platform.  I haven't been updating mainly because I'm lazy.  Twitter is really the top of my level of effort right now.

Posterous doesn't expose the same sort of migration assistant that it does for Tumblr and friends.  Since the email interface does not appear to give control over the post dates, I had to use the API.

The first part of the problem involved pulling the data from Drupal.  I un-published the posts I was embarrassed by, or posts that were just pointless to migrate.  Then I pulled it all out of the db with 'echo "select node.title, created, body from node, node_revisions where node.nid = node_revisions.nid and status  = 1"| mysql -u [username] -p[password] [database]  > posterous_migration.txt'

I pulled the header row off (there's probably a flag to avoid emitting it in the first place, but I'm lazy.) and wrote a quick Ruby script to post the content to Posterous with the proper dates.

#!/usr/bin/env ruby

require 'net/http'

url=URI.parse(url)

r = File.open("posterous_migration.txt").readlines()

r.each {|line|
  title = line.split(/\t/)[0]
  raw_date = line.split(/\t/)[1]
  body = line.split(/\t/)[2].chomp
  new_body =  body.gsub("\"", "\\\\\"")
  new_body = body.gsub("\\n", "<br>")
  new_date = Time.at(Integer(raw_date)).ctime

  params = {"body" => "#{new_body}", 'autopost' => '0', 'date' => "#{new_date}", 'title' => "#{title}"}

  req = Net::HTTP::Post.new(url.path)
  req.basic_auth 'scoobydoo@example.com', 'password'
  req.set_form_data(params)
  res = Net::HTTP.new(url.host, url.port).start {|http| http.request(req) }
  case res
  when Net::HTTPSuccess, Net::HTTPRedirection
    # OK
  else
    res.error!
  end
}

And that was pretty much that.  I had some missing images due to using relative paths while originally composing them in Drupal, but that was easily resolved.  I also have some funky formatting, probably due to my nasty gsubs that I had there for an early attempt at passing all the information to curl.

Filed under  //   Drupal   Posterous  

Comments [0]

How to know when it's too early to upgrade your software

Hint, it's best to wait for a point release when the upgrade instructions consist of "It's probably best to upgrade to 4.7 before upgrading to 5.0. You should disable your contributed modules and themes first. You should not upgrade it in place because the directory structure has changed. Oh yeah, and for more detail, watch this videocast of mumbling quietly through the installation while typing in a transparent terminal."

Filed under  //   Drupal  

Comments [0]

Drupal 4.7.0 released

This had to have been the most painful web/db/php-based software upgrade ever.

$ cp drupal/sites/default/settings.php .
$ tar zxf drupal-4.7.0.tar.gz
$ cd drupal-4.7.0
$ cp -r * ../drupal
$ cp ../settings.php ../drupal/sites/default

And then, I had to hit update.php. Sheesh.

Filed under  //   Drupal  

Comments [0]

Blogger import into Drupal

I succeeded (more or less) in importing my ancient Blogger posts into Drupal.

I used this guide as a base, but the database format has changed significantly with Drupal version 4.7. node and node_revisions have been broken out into two tables, making the SQL generated by the php template not work. As a result, I had to change it slightly, to the following:

<?php
$nid = 213;
<Blogger>
$iid = '<$BlogItemNumber$>';
$nid++;
$node=array();

$node['title']=<<<ENDOFSTRING
<$BlogItemTitle$>
ENDOFSTRING;

if (trim($node['title']) == "") $node['title'] = "title";

$node['body']=<<<ENDOFSTRING
<$BlogItemBody$>
ENDOFSTRING;
$node['date']=strtotime('<$BlogItemDateTime$>');
$node['number']='<$BlogItemNumber$>';
$node['permalink']='<$BlogItemPermalinkURL$>';

echo "INSERT INTO node_revisions (nid, vid, title, uid, timestamp, teaser, body, format)
VALUES(".$nid.", ".$nid.", '".addslashes($node['title'])."', 1, ".$node['date'].", '".addslashes($node['body'])."', '".addslashes($node['body'])."', 3);\
\
";


echo "INSERT INTO node (nid, vid, type, title, uid, created, changed, comment, promote, moderate, sticky)
VALUES(".$nid.", ".$nid.", 'story', '".addslashes($node['title'])."', 1, ".$node['date'].", ".$node['date'].", 2, 1, 0, 0);\
\
";


<BlogItemComments>
$comment=array();
$comment['number']='<$BlogCommentNumber$>';
$comment['body']=<<
<$BlogCommentBody$>
ENDOFSTRING;
$comment['author']=<<<ENDOFSTRING
<$BlogCommentAuthor$>
ENDOFSTRING;
$comment['date']=strtotime('<$BlogCommentDateTime$>');

echo "insert into comments (nid, subject, comment, hostname, timestamp, thread, name) values(".$nid.", 'comment', '".addslashes($comment['body'])."', '127.0.0.1', '".$comment['date']."', '1/', '".addslashes($comment['author'])."');\
\
";

</BlogItemComments>
</Blogger>
?>

The changes should be self-explanatory. I also needed to do some escaping of $-values (whether symbolic dollar amounts, or inline perl/php), and I made a slight mistake on time settings, so I had to do a quick series of update node_revisions set timestamp = timestamp + 39600 where nid > 213; update node set created = created + 39600 where nid > 213; update node set changed = created where nid > 213; (yes, I know the last two could be combined) to account for an 11-hour time difference in posts. This wasn't a big deal, and after two to five years, who'd notice?

Because of the table drift in versions, I didn't mess with any of the php teaser fixes on the page mentioned above. I didn't want to mangle things more than I already had. I also didn't worry much about comments, because I never enabled them on Blogger.

In all, though, it was a pretty simple conversion, other than having > 500 posts titled "title" that I decided to change to "Untitled" for no good reason.

Filed under  //   Blogger   Drupal  

Comments [0]