#--
# Copyright (c) 2009, Kenneth Kalmer, kenneth.kalmer@gmail.com
#
# Permission is hereby granted, free of charge, to any person obtaining a copy
# of this software and associated documentation files (the "Software"), to deal
# in the Software without restriction, including without limitation the rights
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
# copies of the Software, and to permit persons to whom the Software is
# furnished to do so, subject to the following conditions:
#
# The above copyright notice and this permission notice shall be included in
# all copies or substantial portions of the Software.
#
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
# the software.
#
# Made in Africa.
#++
$:.unshift('lib')
require 'rubygems'
require 'openwfe/extras/participants/active_participants'
require 'openwfe/extras/participants/ar_participants'
#
# a tool for converting from the deprecated ActiveParticipant to the new
# ArParticipant.
#
require 'optparse'
options = {
:adapter => 'mysql',
:username => 'root',
:password => nil,
:database => 'ruoterest_development',
:host => 'localhost',
:migrate => false
}
opts = OptionParser.new do |opts|
opts.banner = "Usage: arparticipants.rb [options]"
opts.separator ""
opts.separator "Migration options:"
opts.on("-m", "--migrate", "Perform migration to create ar_workitems table (defaults: #{options[:migrate]})") do |m|
options[:migrate] = true
end
opts.separator "Database connection options:"
opts.on("-a", "--adapter ADAPTER", "Specify ActiveRecord adapter (defaults: #{options[:adapter]})") do |a|
options[:adapter] = a
end
opts.on("-u", "--username USERNAME", "Database username (defaults: #{options[:username]})") do |u|
options[:username] = u
end
opts.on("-p", "--password PASSWORD", "Datbase password ((defaults: #{options[:password] || 'nothing'})") do |p|
options[:password] = p
end
opts.on("-d", "--database DATABASE", "Database name (defaults: #{options[:database]})") do |d|
options[:database] = d
end
opts.on("-l", "--host HOSTNAME", "Database host (defaults: #{options[:host]})") do |h|
options[:host] = h
end
opts.separator ""
opts.separator "WARNING: This script will clear the ar_workitems table!"
opts.separator ""
opts.on_tail("-h", "--help", "Show this message") do
puts opts
exit 1
end
end
opts.parse( ARGV )
# keep out the way
migrate = options.delete(:migrate)
# connect
puts "- Establishing database connection"
ActiveRecord::Base.establish_connection( options )
if migrate
puts "- Creating new ar_workitems table"
begin
OpenWFE::Extras::ArWorkitemTables.up
rescue => e
puts "!! #{e.message}"
end
end
# clear our target
puts "- Deleting all records in ar_workitems"
OpenWFE::Extras::ArWorkitem.delete_all
# loop and convert
puts "- Converting old workitems"
OpenWFE::Extras::Workitem.find(:all).each do |deprecated_wi|
puts "* Converting #{deprecated_wi.full_fei}"
OpenWFE::Extras::ArWorkitem.from_owfe_workitem( deprecated_wi.to_owfe_workitem )
end
puts "Done"
puts
puts "If you're happy with the migration you can remove your old workitems table"
puts