Revisions

gist: 87900 Download_button fork
public
Public Clone URL: git://gist.github.com/87900.git
arparticipants.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
#--
# 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