mahiwaga

I'm not really all that mysterious

simplelog to mephisto

For some reason, I’ve never ever successfully utilized the converter infrastructure found in vendors/plugins/mephisto_converters/lib/converters, so I’ve generally had to cobble together my own kludge.

simplelog-to-mephisto.rb

  
require 'converters/base'
require 'converters/simplelog'

@users = User.find(:all)
default_user = @users.first
site = Site.find(1)

Simplelog::Post.find(:all).each do |sl|
  puts "Importing post #{sl.id}: #{sl.title}"
  mp = Article.new()
  mp.title        = sl.title
  mp.excerpt      = ''
  mp.body         = sl.body
  mp.created_at   = sl.created_at
  mp.published_at = sl.created_at
  mp.updated_at   = sl.modified_at
  mp.filter       = sl.text_filter + '_filter'
  mp.permalink    = sl.permalink
  mp.user         = default_user
  mp.updater      = default_user
  mp.site         = site
  mp.author_ip    = '127.0.0.1'
  mp.tag          = sl.tag.collect() * ', '
  mp.approved     = true
  mp.section_ids  = [1]
  mp.save!
end

Simplelog::Comment.find(:all).each do |sl|
  mp=Comment.new()
  mp.body         = sl.body
  mp.filter       = "markdown_filter"
  mp.created_at   = sl.created_at
  mp.updated_at   = sl.modified_at
  mp.published_at = sl.created_at
  mp.author       = sl.name
  mp.author_url   = sl.url
  mp.author_email = sl.email
  mp.author_ip    = sl.ip
  mp.article_id   = Article.find_by_title(Simplelog::Post.find_by_id(sl.post_id).title).id
  mp.approved     = true
  mp.save!
end

This relies on the following classes:

simplelog/author.rb

  
module Simplelog
  class Author  ActiveRecord::Base
    establish_connection configurations['simplelog']
    has_many :posts, :dependent => :destroy, :class_name => 'Simplelog::Post'
  end
end       

simplelog/comment.rb

  
module Simplelog
  class Comment  ActiveRecord::Base
    establish_connection configurations['simplelog']
    belongs_to :post, :class_name => 'Simplelog::Post'
  end
end        

simplelog/page.rb

  
module Simplelog
  class Page  ActiveRecord::Base
    establish_connection configurations['simplelog']
  end
end     

simplelog/post.rb

  
module Simplelog
  class Post  ActiveRecord::Base
    establish_connection configurations['simplelog']
    has_and_belongs_to_many :tag,
      :class_name => 'Simplelog::Tag',
      :join_table => 'tags_posts'
    belongs_to :author, :class_name => 'Simplelog::Author'
    has_many :comments, :conditions => ['is_approved = ?', true], :dependent => :destroy, :class_name => 'Simplelog::Comment'
  end
end       

simplelog/tag.rb

  
module Simplelog
  class Tag  ActiveRecord::Base
    establish_connection configurations['simplelog']
    has_and_belongs_to_many :post,
      :class_name => 'Simplelog::Post',
      :join_table => 'tags_post'
  end
end       

The Post definition and the Tag definition have a little voodoo for dealing with the transition from Rails 1.2 to Rails 2.0. In 1.2, acts_as_taggable names the join table backwards compared to 2.0, where it uses the normal semantics.

If this weren’t just a hack, I’d probably package it a little more nicely, but as it is, I’d appreciate any tips on how to actually get the converter infrastructure to work.

posted by Author's profile picture mahiwaga

Benazir Bhutto

I feel extremely saddened with thinking about Benazir Bhutto’s assassination, casting a shadow on the end of the year. News of her death rocketed across the blogosphere at near light speed.

On one hand, it was the first time in my life that I heard about a significant event solely throught the Internet. It illustrates the bizarre connectedness that it allows, as I scan articles from people I don’t know personally, but whom I’ve followed for upwards of almost two years now, all in my feed reader.

On the other hand, it also demonstrates how far humanity has to go before reaching any modicum of civilization. In a world where murder—indeed, mass murder—is a politically-acceptable expedient, I can’t help but wonder where the hell people ever got the idea that we were any better than animals.

I am suddenly reminded of A Canticle for Leibowitz, a prophetic speculative fiction novel written by Walter M. Miller, which poignantly portrays humanity’s penchant for cyclical self-destruction. (I am also suddenly reminded of the fact that Pakistan is a nuclear power.)

I am also reminded of the parallel with Benigno Aquino, Jr.’s assassination which occurred more than twenty-four years ago. I was way too young at the time to understand the import of that event, but its repercussions continue to echo to the present day.

A part of me hopes that Bhutto’s death can set about a revolution akin to the People’s Power Revolution in 1986. But another part of me realizes that all revolutions tend to be halted abruptly long before they attain their idealistic goals. The current political situation in the Philippines is testament to that, as is the neocon attempt in the U.S. to turn back the clock to the pre-FDR era (and some would say, to the pre-Abraham Lincoln era.)

I am horribly aware of the fact that he who has the most guns makes the rules, that people generally prefer expedience to actual justice, and that no good deed ever goes unpunished. But a new year is dawning, and as I’ve been wont to say: Dum spiro, spero.

posted by Author's profile picture mahiwaga