Blogger import into Drupal

Submitted by reeses on Wed, 2006-04-05 04:38. |

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);\n\n";

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);\n\n";

<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'])."');\n\n";

</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.

Submitted by Anonymous on Sun, 2008-09-07 00:23.

I may also move my blog to Drupal soon. Thanks for the information.

Impotence Cure King: Viagra

No need to mention how Viagra has changed the lives of many men and athletes as well.
Even women can now waste some money on buying brand and generic forms of Viagra on-line, as they always do.
The official website of Viagra information contains what everyone needs to know before they buy online promoted Viagra or Cialis tablets. Only blue Viagra tablets are real.
Find an online pharmacy and buy Viagra for the price that you see is best for you. Find consumer details for Viagra here and keep it healthy.


Submitted by Anonymous on Mon, 2008-03-17 02:18.

Good Article, Author - Thanks!

discount online pharmacy | cheap canadian pharmacy

Submitted by Nick (not verified) on Fri, 2006-07-21 10:48.

I'm also seeing the problem reported by "noizy" about blogger constantly reporting 0% when republishing the index. It seems to hang if I try to preview the change. My guess is that perhaps blogger doesn't like the php code. I made the following changes to the template, then went and manually modified the html file that blogger posted.

<html>
<body>
&lt;?php
// strip "<?php" from top line of template
// insert rest of template
// strip "?>" from bottom line of template
?&gt;
</body>
</html>

Then log in to your account, remove the crap at the top and restor the "<?php" and "?>" at the beginning and end of the file.

Submitted by jpierre (not verified) on Fri, 2006-06-30 14:06.

I had imported Blogger into Drupal 4.6.
When upgraded to 4.7 ... the author names of comments done under blogger are showns as paths.
Any hints? if yes. I'll hight appreciate it.

Thanks :)

Submitted by reeses on Sun, 2006-07-02 17:24.

Sorry, I didn't bother to import comments because, well, I don't care enough about what people think regarding pictures of my cats or most of my boring entries. :/

Best of luck.

-a.

Submitted by noizy (not verified) on Tue, 2006-04-11 13:27.

about five minutes of head scratching, before I clicked to the fact that I was only getting the first post exported. Quickly became apparent what was wrong when I compared it to the script over at eglug.

anyway, thanks for the script - if I could only get blogger to co-operate (it seems to be hanging on 0% progress when republishing the index), then I'd be able to let you know if the whole process worked for me.

Submitted by reeses on Mon, 2006-04-10 21:30.

I'm a tard, and missed the tag when I converted the literal tag into ampersand escape codes. I appreciate the diligence, and I hope I didn't have you scratching your head when it didn't work.

Submitted by noizy (not verified) on Mon, 2006-04-10 20:50.

should the tag be between the...

$nid = 213;

$iid = '<$BlogItemNumber$>';

...lines?

Post new comment

Captcha Image: you will need to recognize the text in it.
Please type in the letters/numbers that are shown in the image above.