Guest User

Untitled

a guest
Mar 4th, 2018
305
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.52 KB | None | 0 0
  1. #--
  2. # Copyright (c) 2009, Kenneth Kalmer, kenneth.kalmer@gmail.com
  3. #
  4. # Permission is hereby granted, free of charge, to any person obtaining a copy
  5. # of this software and associated documentation files (the "Software"), to deal
  6. # in the Software without restriction, including without limitation the rights
  7. # to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
  8. # copies of the Software, and to permit persons to whom the Software is
  9. # furnished to do so, subject to the following conditions:
  10. #
  11. # The above copyright notice and this permission notice shall be included in
  12. # all copies or substantial portions of the Software.
  13. #
  14. # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  15. # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  16. # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  17. # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  18. # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
  19. # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
  20. # the software.
  21. #
  22. # Made in Africa.
  23. #++
  24.  
  25.  
  26. $:.unshift('lib')
  27.  
  28.  
  29. require 'rubygems'
  30. require 'openwfe/extras/participants/active_participants'
  31. require 'openwfe/extras/participants/ar_participants'
  32.  
  33. #
  34. # a tool for converting from the deprecated ActiveParticipant to the new
  35. # ArParticipant.
  36. #
  37.  
  38. require 'optparse'
  39.  
  40. options = {
  41. :adapter => 'mysql',
  42. :username => 'root',
  43. :password => nil,
  44. :database => 'ruoterest_development',
  45. :host => 'localhost',
  46. :migrate => false
  47. }
  48. opts = OptionParser.new do |opts|
  49. opts.banner = "Usage: arparticipants.rb [options]"
  50. opts.separator ""
  51.  
  52. opts.separator "Migration options:"
  53. opts.on("-m", "--migrate", "Perform migration to create ar_workitems table (defaults: #{options[:migrate]})") do |m|
  54. options[:migrate] = true
  55. end
  56.  
  57. opts.separator "Database connection options:"
  58. opts.on("-a", "--adapter ADAPTER", "Specify ActiveRecord adapter (defaults: #{options[:adapter]})") do |a|
  59. options[:adapter] = a
  60. end
  61. opts.on("-u", "--username USERNAME", "Database username (defaults: #{options[:username]})") do |u|
  62. options[:username] = u
  63. end
  64. opts.on("-p", "--password PASSWORD", "Datbase password ((defaults: #{options[:password] || 'nothing'})") do |p|
  65. options[:password] = p
  66. end
  67. opts.on("-d", "--database DATABASE", "Database name (defaults: #{options[:database]})") do |d|
  68. options[:database] = d
  69. end
  70. opts.on("-l", "--host HOSTNAME", "Database host (defaults: #{options[:host]})") do |h|
  71. options[:host] = h
  72. end
  73.  
  74. opts.separator ""
  75. opts.separator "WARNING: This script will clear the ar_workitems table!"
  76.  
  77. opts.separator ""
  78. opts.on_tail("-h", "--help", "Show this message") do
  79. puts opts
  80. exit 1
  81. end
  82. end
  83.  
  84. opts.parse( ARGV )
  85.  
  86. # keep out the way
  87. migrate = options.delete(:migrate)
  88.  
  89. # connect
  90. puts "- Establishing database connection"
  91. ActiveRecord::Base.establish_connection( options )
  92.  
  93. if migrate
  94. puts "- Creating new ar_workitems table"
  95. begin
  96. OpenWFE::Extras::ArWorkitemTables.up
  97. rescue => e
  98. puts "!! #{e.message}"
  99. end
  100. end
  101.  
  102. # clear our target
  103. puts "- Deleting all records in ar_workitems"
  104. OpenWFE::Extras::ArWorkitem.delete_all
  105.  
  106. # loop and convert
  107. puts "- Converting old workitems"
  108. OpenWFE::Extras::Workitem.find(:all).each do |deprecated_wi|
  109. puts "* Converting #{deprecated_wi.full_fei}"
  110. OpenWFE::Extras::ArWorkitem.from_owfe_workitem( deprecated_wi.to_owfe_workitem )
  111. end
  112.  
  113. puts "Done"
  114. puts
  115. puts "If you're happy with the migration you can remove your old workitems table"
  116. puts
Add Comment
Please, Sign In to add comment