#!/usr/bin/env ruby # OpenACS converter for typo by Lars Pind # Based on # MovableType 3.x converter for typo by Patrick Lenz # # MAKE BACKUPS OF EVERYTHING BEFORE RUNNING THIS SCRIPT! # THIS SCRIPT IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND require File.dirname(__FILE__) + '/../../config/environment' require "flickr_api" class OpenACS < ActiveRecord::Base establish_connection({ :adapter => "postgresql", :username => "username", :database => "database" }) end class OpenACSMigrate def initialize self.convert_entries end def convert_entries Content.delete_all ActiveRecord::Base.connection.add_column :contents, :openacs_id, :integer rescue nil entries = OpenACS.connection.select_all(%{ SELECT entry_id AS openacs_id, title, content AS body, entry_date AS created_at, title_url, first_names || ' ' || last_name AS author FROM pinds_blog_entries, acs_objects, cc_users WHERE acs_objects.object_id = pinds_blog_entries.entry_id AND acs_objects.creation_user = cc_users.user_id ORDER BY created_at }) puts "Converting #{entries.size} entries.." entries.each do |entry| a = Article.new a.attributes = entry.reject { |k,v| k =~ /title_url/ } if entry["title_url"] a.body = "

#{entry["title_url"]}

#{a.body}" end a.text_filter = "textile" a.allow_comments = true a.allow_pings = true a.save # Fetch comments OpenACS.connection.select_all(%{ SELECT cc_users.first_names || ' ' || cc_users.last_name AS author, cc_users.email AS email, cr_revisions.title AS title, cr_revisions.content AS body, acs_objects.creation_date AS created_at FROM general_comments, cr_items, cr_revisions, acs_objects, cc_users WHERE general_comments.object_id = #{entry['openacs_id']} AND cr_items.item_id = general_comments.comment_id AND cr_revisions.revision_id = cr_items.live_revision AND acs_objects.object_id = general_comments.comment_id AND cc_users.user_id = acs_objects.creation_user AND NOT EXISTS (SELECT 1 FROM trackback_pings WHERE trackback_pings.comment_id = general_comments.comment_id) }).each do |c| c["body"] = c["title"] + "\n\n" + c["body"] unless c["title"].blank? a.comments.create(c.reject { |k,v| k == "title" }) end end end end OpenACSMigrate.new