annotate .svn/pristine/45/455fac3716b45401a5e4d20e87294f2cbb2052cb.svn-base @ 1464:261b3d9a4903 redmine-2.4

Update to Redmine 2.4 branch rev 12663
author Chris Cannam
date Tue, 14 Jan 2014 14:37:42 +0000
parents
children
rev   line source
Chris@1464 1 # Redmine - project management software
Chris@1464 2 # Copyright (C) 2006-2013 Jean-Philippe Lang
Chris@1464 3 #
Chris@1464 4 # This program is free software; you can redistribute it and/or
Chris@1464 5 # modify it under the terms of the GNU General Public License
Chris@1464 6 # as published by the Free Software Foundation; either version 2
Chris@1464 7 # of the License, or (at your option) any later version.
Chris@1464 8 #
Chris@1464 9 # This program is distributed in the hope that it will be useful,
Chris@1464 10 # but WITHOUT ANY WARRANTY; without even the implied warranty of
Chris@1464 11 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
Chris@1464 12 # GNU General Public License for more details.
Chris@1464 13 #
Chris@1464 14 # You should have received a copy of the GNU General Public License
Chris@1464 15 # along with this program; if not, write to the Free Software
Chris@1464 16 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
Chris@1464 17
Chris@1464 18 desc 'Mantis migration script'
Chris@1464 19
Chris@1464 20 require 'active_record'
Chris@1464 21 require 'iconv' if RUBY_VERSION < '1.9'
Chris@1464 22 require 'pp'
Chris@1464 23
Chris@1464 24 namespace :redmine do
Chris@1464 25 task :migrate_from_mantis => :environment do
Chris@1464 26
Chris@1464 27 module MantisMigrate
Chris@1464 28
Chris@1464 29 DEFAULT_STATUS = IssueStatus.default
Chris@1464 30 assigned_status = IssueStatus.find_by_position(2)
Chris@1464 31 resolved_status = IssueStatus.find_by_position(3)
Chris@1464 32 feedback_status = IssueStatus.find_by_position(4)
Chris@1464 33 closed_status = IssueStatus.where(:is_closed => true).first
Chris@1464 34 STATUS_MAPPING = {10 => DEFAULT_STATUS, # new
Chris@1464 35 20 => feedback_status, # feedback
Chris@1464 36 30 => DEFAULT_STATUS, # acknowledged
Chris@1464 37 40 => DEFAULT_STATUS, # confirmed
Chris@1464 38 50 => assigned_status, # assigned
Chris@1464 39 80 => resolved_status, # resolved
Chris@1464 40 90 => closed_status # closed
Chris@1464 41 }
Chris@1464 42
Chris@1464 43 priorities = IssuePriority.all
Chris@1464 44 DEFAULT_PRIORITY = priorities[2]
Chris@1464 45 PRIORITY_MAPPING = {10 => priorities[1], # none
Chris@1464 46 20 => priorities[1], # low
Chris@1464 47 30 => priorities[2], # normal
Chris@1464 48 40 => priorities[3], # high
Chris@1464 49 50 => priorities[4], # urgent
Chris@1464 50 60 => priorities[5] # immediate
Chris@1464 51 }
Chris@1464 52
Chris@1464 53 TRACKER_BUG = Tracker.find_by_position(1)
Chris@1464 54 TRACKER_FEATURE = Tracker.find_by_position(2)
Chris@1464 55
Chris@1464 56 roles = Role.where(:builtin => 0).order('position ASC').all
Chris@1464 57 manager_role = roles[0]
Chris@1464 58 developer_role = roles[1]
Chris@1464 59 DEFAULT_ROLE = roles.last
Chris@1464 60 ROLE_MAPPING = {10 => DEFAULT_ROLE, # viewer
Chris@1464 61 25 => DEFAULT_ROLE, # reporter
Chris@1464 62 40 => DEFAULT_ROLE, # updater
Chris@1464 63 55 => developer_role, # developer
Chris@1464 64 70 => manager_role, # manager
Chris@1464 65 90 => manager_role # administrator
Chris@1464 66 }
Chris@1464 67
Chris@1464 68 CUSTOM_FIELD_TYPE_MAPPING = {0 => 'string', # String
Chris@1464 69 1 => 'int', # Numeric
Chris@1464 70 2 => 'int', # Float
Chris@1464 71 3 => 'list', # Enumeration
Chris@1464 72 4 => 'string', # Email
Chris@1464 73 5 => 'bool', # Checkbox
Chris@1464 74 6 => 'list', # List
Chris@1464 75 7 => 'list', # Multiselection list
Chris@1464 76 8 => 'date', # Date
Chris@1464 77 }
Chris@1464 78
Chris@1464 79 RELATION_TYPE_MAPPING = {1 => IssueRelation::TYPE_RELATES, # related to
Chris@1464 80 2 => IssueRelation::TYPE_RELATES, # parent of
Chris@1464 81 3 => IssueRelation::TYPE_RELATES, # child of
Chris@1464 82 0 => IssueRelation::TYPE_DUPLICATES, # duplicate of
Chris@1464 83 4 => IssueRelation::TYPE_DUPLICATES # has duplicate
Chris@1464 84 }
Chris@1464 85
Chris@1464 86 class MantisUser < ActiveRecord::Base
Chris@1464 87 self.table_name = :mantis_user_table
Chris@1464 88
Chris@1464 89 def firstname
Chris@1464 90 @firstname = realname.blank? ? username : realname.split.first[0..29]
Chris@1464 91 @firstname
Chris@1464 92 end
Chris@1464 93
Chris@1464 94 def lastname
Chris@1464 95 @lastname = realname.blank? ? '-' : realname.split[1..-1].join(' ')[0..29]
Chris@1464 96 @lastname = '-' if @lastname.blank?
Chris@1464 97 @lastname
Chris@1464 98 end
Chris@1464 99
Chris@1464 100 def email
Chris@1464 101 if read_attribute(:email).match(/^([^@\s]+)@((?:[-a-z0-9]+\.)+[a-z]{2,})$/i) &&
Chris@1464 102 !User.find_by_mail(read_attribute(:email))
Chris@1464 103 @email = read_attribute(:email)
Chris@1464 104 else
Chris@1464 105 @email = "#{username}@foo.bar"
Chris@1464 106 end
Chris@1464 107 end
Chris@1464 108
Chris@1464 109 def username
Chris@1464 110 read_attribute(:username)[0..29].gsub(/[^a-zA-Z0-9_\-@\.]/, '-')
Chris@1464 111 end
Chris@1464 112 end
Chris@1464 113
Chris@1464 114 class MantisProject < ActiveRecord::Base
Chris@1464 115 self.table_name = :mantis_project_table
Chris@1464 116 has_many :versions, :class_name => "MantisVersion", :foreign_key => :project_id
Chris@1464 117 has_many :categories, :class_name => "MantisCategory", :foreign_key => :project_id
Chris@1464 118 has_many :news, :class_name => "MantisNews", :foreign_key => :project_id
Chris@1464 119 has_many :members, :class_name => "MantisProjectUser", :foreign_key => :project_id
Chris@1464 120
Chris@1464 121 def identifier
Chris@1464 122 read_attribute(:name).gsub(/[^a-z0-9\-]+/, '-').slice(0, Project::IDENTIFIER_MAX_LENGTH)
Chris@1464 123 end
Chris@1464 124 end
Chris@1464 125
Chris@1464 126 class MantisVersion < ActiveRecord::Base
Chris@1464 127 self.table_name = :mantis_project_version_table
Chris@1464 128
Chris@1464 129 def version
Chris@1464 130 read_attribute(:version)[0..29]
Chris@1464 131 end
Chris@1464 132
Chris@1464 133 def description
Chris@1464 134 read_attribute(:description)[0..254]
Chris@1464 135 end
Chris@1464 136 end
Chris@1464 137
Chris@1464 138 class MantisCategory < ActiveRecord::Base
Chris@1464 139 self.table_name = :mantis_project_category_table
Chris@1464 140 end
Chris@1464 141
Chris@1464 142 class MantisProjectUser < ActiveRecord::Base
Chris@1464 143 self.table_name = :mantis_project_user_list_table
Chris@1464 144 end
Chris@1464 145
Chris@1464 146 class MantisBug < ActiveRecord::Base
Chris@1464 147 self.table_name = :mantis_bug_table
Chris@1464 148 belongs_to :bug_text, :class_name => "MantisBugText", :foreign_key => :bug_text_id
Chris@1464 149 has_many :bug_notes, :class_name => "MantisBugNote", :foreign_key => :bug_id
Chris@1464 150 has_many :bug_files, :class_name => "MantisBugFile", :foreign_key => :bug_id
Chris@1464 151 has_many :bug_monitors, :class_name => "MantisBugMonitor", :foreign_key => :bug_id
Chris@1464 152 end
Chris@1464 153
Chris@1464 154 class MantisBugText < ActiveRecord::Base
Chris@1464 155 self.table_name = :mantis_bug_text_table
Chris@1464 156
Chris@1464 157 # Adds Mantis steps_to_reproduce and additional_information fields
Chris@1464 158 # to description if any
Chris@1464 159 def full_description
Chris@1464 160 full_description = description
Chris@1464 161 full_description += "\n\n*Steps to reproduce:*\n\n#{steps_to_reproduce}" unless steps_to_reproduce.blank?
Chris@1464 162 full_description += "\n\n*Additional information:*\n\n#{additional_information}" unless additional_information.blank?
Chris@1464 163 full_description
Chris@1464 164 end
Chris@1464 165 end
Chris@1464 166
Chris@1464 167 class MantisBugNote < ActiveRecord::Base
Chris@1464 168 self.table_name = :mantis_bugnote_table
Chris@1464 169 belongs_to :bug, :class_name => "MantisBug", :foreign_key => :bug_id
Chris@1464 170 belongs_to :bug_note_text, :class_name => "MantisBugNoteText", :foreign_key => :bugnote_text_id
Chris@1464 171 end
Chris@1464 172
Chris@1464 173 class MantisBugNoteText < ActiveRecord::Base
Chris@1464 174 self.table_name = :mantis_bugnote_text_table
Chris@1464 175 end
Chris@1464 176
Chris@1464 177 class MantisBugFile < ActiveRecord::Base
Chris@1464 178 self.table_name = :mantis_bug_file_table
Chris@1464 179
Chris@1464 180 def size
Chris@1464 181 filesize
Chris@1464 182 end
Chris@1464 183
Chris@1464 184 def original_filename
Chris@1464 185 MantisMigrate.encode(filename)
Chris@1464 186 end
Chris@1464 187
Chris@1464 188 def content_type
Chris@1464 189 file_type
Chris@1464 190 end
Chris@1464 191
Chris@1464 192 def read(*args)
Chris@1464 193 if @read_finished
Chris@1464 194 nil
Chris@1464 195 else
Chris@1464 196 @read_finished = true
Chris@1464 197 content
Chris@1464 198 end
Chris@1464 199 end
Chris@1464 200 end
Chris@1464 201
Chris@1464 202 class MantisBugRelationship < ActiveRecord::Base
Chris@1464 203 self.table_name = :mantis_bug_relationship_table
Chris@1464 204 end
Chris@1464 205
Chris@1464 206 class MantisBugMonitor < ActiveRecord::Base
Chris@1464 207 self.table_name = :mantis_bug_monitor_table
Chris@1464 208 end
Chris@1464 209
Chris@1464 210 class MantisNews < ActiveRecord::Base
Chris@1464 211 self.table_name = :mantis_news_table
Chris@1464 212 end
Chris@1464 213
Chris@1464 214 class MantisCustomField < ActiveRecord::Base
Chris@1464 215 self.table_name = :mantis_custom_field_table
Chris@1464 216 set_inheritance_column :none
Chris@1464 217 has_many :values, :class_name => "MantisCustomFieldString", :foreign_key => :field_id
Chris@1464 218 has_many :projects, :class_name => "MantisCustomFieldProject", :foreign_key => :field_id
Chris@1464 219
Chris@1464 220 def format
Chris@1464 221 read_attribute :type
Chris@1464 222 end
Chris@1464 223
Chris@1464 224 def name
Chris@1464 225 read_attribute(:name)[0..29]
Chris@1464 226 end
Chris@1464 227 end
Chris@1464 228
Chris@1464 229 class MantisCustomFieldProject < ActiveRecord::Base
Chris@1464 230 self.table_name = :mantis_custom_field_project_table
Chris@1464 231 end
Chris@1464 232
Chris@1464 233 class MantisCustomFieldString < ActiveRecord::Base
Chris@1464 234 self.table_name = :mantis_custom_field_string_table
Chris@1464 235 end
Chris@1464 236
Chris@1464 237 def self.migrate
Chris@1464 238
Chris@1464 239 # Users
Chris@1464 240 print "Migrating users"
Chris@1464 241 User.delete_all "login <> 'admin'"
Chris@1464 242 users_map = {}
Chris@1464 243 users_migrated = 0
Chris@1464 244 MantisUser.all.each do |user|
Chris@1464 245 u = User.new :firstname => encode(user.firstname),
Chris@1464 246 :lastname => encode(user.lastname),
Chris@1464 247 :mail => user.email,
Chris@1464 248 :last_login_on => user.last_visit
Chris@1464 249 u.login = user.username
Chris@1464 250 u.password = 'mantis'
Chris@1464 251 u.status = User::STATUS_LOCKED if user.enabled != 1
Chris@1464 252 u.admin = true if user.access_level == 90
Chris@1464 253 next unless u.save!
Chris@1464 254 users_migrated += 1
Chris@1464 255 users_map[user.id] = u.id
Chris@1464 256 print '.'
Chris@1464 257 end
Chris@1464 258 puts
Chris@1464 259
Chris@1464 260 # Projects
Chris@1464 261 print "Migrating projects"
Chris@1464 262 Project.destroy_all
Chris@1464 263 projects_map = {}
Chris@1464 264 versions_map = {}
Chris@1464 265 categories_map = {}
Chris@1464 266 MantisProject.all.each do |project|
Chris@1464 267 p = Project.new :name => encode(project.name),
Chris@1464 268 :description => encode(project.description)
Chris@1464 269 p.identifier = project.identifier
Chris@1464 270 next unless p.save
Chris@1464 271 projects_map[project.id] = p.id
Chris@1464 272 p.enabled_module_names = ['issue_tracking', 'news', 'wiki']
Chris@1464 273 p.trackers << TRACKER_BUG unless p.trackers.include?(TRACKER_BUG)
Chris@1464 274 p.trackers << TRACKER_FEATURE unless p.trackers.include?(TRACKER_FEATURE)
Chris@1464 275 print '.'
Chris@1464 276
Chris@1464 277 # Project members
Chris@1464 278 project.members.each do |member|
Chris@1464 279 m = Member.new :user => User.find_by_id(users_map[member.user_id]),
Chris@1464 280 :roles => [ROLE_MAPPING[member.access_level] || DEFAULT_ROLE]
Chris@1464 281 m.project = p
Chris@1464 282 m.save
Chris@1464 283 end
Chris@1464 284
Chris@1464 285 # Project versions
Chris@1464 286 project.versions.each do |version|
Chris@1464 287 v = Version.new :name => encode(version.version),
Chris@1464 288 :description => encode(version.description),
Chris@1464 289 :effective_date => (version.date_order ? version.date_order.to_date : nil)
Chris@1464 290 v.project = p
Chris@1464 291 v.save
Chris@1464 292 versions_map[version.id] = v.id
Chris@1464 293 end
Chris@1464 294
Chris@1464 295 # Project categories
Chris@1464 296 project.categories.each do |category|
Chris@1464 297 g = IssueCategory.new :name => category.category[0,30]
Chris@1464 298 g.project = p
Chris@1464 299 g.save
Chris@1464 300 categories_map[category.category] = g.id
Chris@1464 301 end
Chris@1464 302 end
Chris@1464 303 puts
Chris@1464 304
Chris@1464 305 # Bugs
Chris@1464 306 print "Migrating bugs"
Chris@1464 307 Issue.destroy_all
Chris@1464 308 issues_map = {}
Chris@1464 309 keep_bug_ids = (Issue.count == 0)
Chris@1464 310 MantisBug.find_each(:batch_size => 200) do |bug|
Chris@1464 311 next unless projects_map[bug.project_id] && users_map[bug.reporter_id]
Chris@1464 312 i = Issue.new :project_id => projects_map[bug.project_id],
Chris@1464 313 :subject => encode(bug.summary),
Chris@1464 314 :description => encode(bug.bug_text.full_description),
Chris@1464 315 :priority => PRIORITY_MAPPING[bug.priority] || DEFAULT_PRIORITY,
Chris@1464 316 :created_on => bug.date_submitted,
Chris@1464 317 :updated_on => bug.last_updated
Chris@1464 318 i.author = User.find_by_id(users_map[bug.reporter_id])
Chris@1464 319 i.category = IssueCategory.find_by_project_id_and_name(i.project_id, bug.category[0,30]) unless bug.category.blank?
Chris@1464 320 i.fixed_version = Version.find_by_project_id_and_name(i.project_id, bug.fixed_in_version) unless bug.fixed_in_version.blank?
Chris@1464 321 i.status = STATUS_MAPPING[bug.status] || DEFAULT_STATUS
Chris@1464 322 i.tracker = (bug.severity == 10 ? TRACKER_FEATURE : TRACKER_BUG)
Chris@1464 323 i.id = bug.id if keep_bug_ids
Chris@1464 324 next unless i.save
Chris@1464 325 issues_map[bug.id] = i.id
Chris@1464 326 print '.'
Chris@1464 327 STDOUT.flush
Chris@1464 328
Chris@1464 329 # Assignee
Chris@1464 330 # Redmine checks that the assignee is a project member
Chris@1464 331 if (bug.handler_id && users_map[bug.handler_id])
Chris@1464 332 i.assigned_to = User.find_by_id(users_map[bug.handler_id])
Chris@1464 333 i.save(:validate => false)
Chris@1464 334 end
Chris@1464 335
Chris@1464 336 # Bug notes
Chris@1464 337 bug.bug_notes.each do |note|
Chris@1464 338 next unless users_map[note.reporter_id]
Chris@1464 339 n = Journal.new :notes => encode(note.bug_note_text.note),
Chris@1464 340 :created_on => note.date_submitted
Chris@1464 341 n.user = User.find_by_id(users_map[note.reporter_id])
Chris@1464 342 n.journalized = i
Chris@1464 343 n.save
Chris@1464 344 end
Chris@1464 345
Chris@1464 346 # Bug files
Chris@1464 347 bug.bug_files.each do |file|
Chris@1464 348 a = Attachment.new :created_on => file.date_added
Chris@1464 349 a.file = file
Chris@1464 350 a.author = User.first
Chris@1464 351 a.container = i
Chris@1464 352 a.save
Chris@1464 353 end
Chris@1464 354
Chris@1464 355 # Bug monitors
Chris@1464 356 bug.bug_monitors.each do |monitor|
Chris@1464 357 next unless users_map[monitor.user_id]
Chris@1464 358 i.add_watcher(User.find_by_id(users_map[monitor.user_id]))
Chris@1464 359 end
Chris@1464 360 end
Chris@1464 361
Chris@1464 362 # update issue id sequence if needed (postgresql)
Chris@1464 363 Issue.connection.reset_pk_sequence!(Issue.table_name) if Issue.connection.respond_to?('reset_pk_sequence!')
Chris@1464 364 puts
Chris@1464 365
Chris@1464 366 # Bug relationships
Chris@1464 367 print "Migrating bug relations"
Chris@1464 368 MantisBugRelationship.all.each do |relation|
Chris@1464 369 next unless issues_map[relation.source_bug_id] && issues_map[relation.destination_bug_id]
Chris@1464 370 r = IssueRelation.new :relation_type => RELATION_TYPE_MAPPING[relation.relationship_type]
Chris@1464 371 r.issue_from = Issue.find_by_id(issues_map[relation.source_bug_id])
Chris@1464 372 r.issue_to = Issue.find_by_id(issues_map[relation.destination_bug_id])
Chris@1464 373 pp r unless r.save
Chris@1464 374 print '.'
Chris@1464 375 STDOUT.flush
Chris@1464 376 end
Chris@1464 377 puts
Chris@1464 378
Chris@1464 379 # News
Chris@1464 380 print "Migrating news"
Chris@1464 381 News.destroy_all
Chris@1464 382 MantisNews.where('project_id > 0').all.each do |news|
Chris@1464 383 next unless projects_map[news.project_id]
Chris@1464 384 n = News.new :project_id => projects_map[news.project_id],
Chris@1464 385 :title => encode(news.headline[0..59]),
Chris@1464 386 :description => encode(news.body),
Chris@1464 387 :created_on => news.date_posted
Chris@1464 388 n.author = User.find_by_id(users_map[news.poster_id])
Chris@1464 389 n.save
Chris@1464 390 print '.'
Chris@1464 391 STDOUT.flush
Chris@1464 392 end
Chris@1464 393 puts
Chris@1464 394
Chris@1464 395 # Custom fields
Chris@1464 396 print "Migrating custom fields"
Chris@1464 397 IssueCustomField.destroy_all
Chris@1464 398 MantisCustomField.all.each do |field|
Chris@1464 399 f = IssueCustomField.new :name => field.name[0..29],
Chris@1464 400 :field_format => CUSTOM_FIELD_TYPE_MAPPING[field.format],
Chris@1464 401 :min_length => field.length_min,
Chris@1464 402 :max_length => field.length_max,
Chris@1464 403 :regexp => field.valid_regexp,
Chris@1464 404 :possible_values => field.possible_values.split('|'),
Chris@1464 405 :is_required => field.require_report?
Chris@1464 406 next unless f.save
Chris@1464 407 print '.'
Chris@1464 408 STDOUT.flush
Chris@1464 409 # Trackers association
Chris@1464 410 f.trackers = Tracker.all
Chris@1464 411
Chris@1464 412 # Projects association
Chris@1464 413 field.projects.each do |project|
Chris@1464 414 f.projects << Project.find_by_id(projects_map[project.project_id]) if projects_map[project.project_id]
Chris@1464 415 end
Chris@1464 416
Chris@1464 417 # Values
Chris@1464 418 field.values.each do |value|
Chris@1464 419 v = CustomValue.new :custom_field_id => f.id,
Chris@1464 420 :value => value.value
Chris@1464 421 v.customized = Issue.find_by_id(issues_map[value.bug_id]) if issues_map[value.bug_id]
Chris@1464 422 v.save
Chris@1464 423 end unless f.new_record?
Chris@1464 424 end
Chris@1464 425 puts
Chris@1464 426
Chris@1464 427 puts
Chris@1464 428 puts "Users: #{users_migrated}/#{MantisUser.count}"
Chris@1464 429 puts "Projects: #{Project.count}/#{MantisProject.count}"
Chris@1464 430 puts "Memberships: #{Member.count}/#{MantisProjectUser.count}"
Chris@1464 431 puts "Versions: #{Version.count}/#{MantisVersion.count}"
Chris@1464 432 puts "Categories: #{IssueCategory.count}/#{MantisCategory.count}"
Chris@1464 433 puts "Bugs: #{Issue.count}/#{MantisBug.count}"
Chris@1464 434 puts "Bug notes: #{Journal.count}/#{MantisBugNote.count}"
Chris@1464 435 puts "Bug files: #{Attachment.count}/#{MantisBugFile.count}"
Chris@1464 436 puts "Bug relations: #{IssueRelation.count}/#{MantisBugRelationship.count}"
Chris@1464 437 puts "Bug monitors: #{Watcher.count}/#{MantisBugMonitor.count}"
Chris@1464 438 puts "News: #{News.count}/#{MantisNews.count}"
Chris@1464 439 puts "Custom fields: #{IssueCustomField.count}/#{MantisCustomField.count}"
Chris@1464 440 end
Chris@1464 441
Chris@1464 442 def self.encoding(charset)
Chris@1464 443 @charset = charset
Chris@1464 444 end
Chris@1464 445
Chris@1464 446 def self.establish_connection(params)
Chris@1464 447 constants.each do |const|
Chris@1464 448 klass = const_get(const)
Chris@1464 449 next unless klass.respond_to? 'establish_connection'
Chris@1464 450 klass.establish_connection params
Chris@1464 451 end
Chris@1464 452 end
Chris@1464 453
Chris@1464 454 def self.encode(text)
Chris@1464 455 if RUBY_VERSION < '1.9'
Chris@1464 456 @ic ||= Iconv.new('UTF-8', @charset)
Chris@1464 457 @ic.iconv text
Chris@1464 458 else
Chris@1464 459 text.to_s.force_encoding(@charset).encode('UTF-8')
Chris@1464 460 end
Chris@1464 461 end
Chris@1464 462 end
Chris@1464 463
Chris@1464 464 puts
Chris@1464 465 if Redmine::DefaultData::Loader.no_data?
Chris@1464 466 puts "Redmine configuration need to be loaded before importing data."
Chris@1464 467 puts "Please, run this first:"
Chris@1464 468 puts
Chris@1464 469 puts " rake redmine:load_default_data RAILS_ENV=\"#{ENV['RAILS_ENV']}\""
Chris@1464 470 exit
Chris@1464 471 end
Chris@1464 472
Chris@1464 473 puts "WARNING: Your Redmine data will be deleted during this process."
Chris@1464 474 print "Are you sure you want to continue ? [y/N] "
Chris@1464 475 STDOUT.flush
Chris@1464 476 break unless STDIN.gets.match(/^y$/i)
Chris@1464 477
Chris@1464 478 # Default Mantis database settings
Chris@1464 479 db_params = {:adapter => 'mysql2',
Chris@1464 480 :database => 'bugtracker',
Chris@1464 481 :host => 'localhost',
Chris@1464 482 :username => 'root',
Chris@1464 483 :password => '' }
Chris@1464 484
Chris@1464 485 puts
Chris@1464 486 puts "Please enter settings for your Mantis database"
Chris@1464 487 [:adapter, :host, :database, :username, :password].each do |param|
Chris@1464 488 print "#{param} [#{db_params[param]}]: "
Chris@1464 489 value = STDIN.gets.chomp!
Chris@1464 490 db_params[param] = value unless value.blank?
Chris@1464 491 end
Chris@1464 492
Chris@1464 493 while true
Chris@1464 494 print "encoding [UTF-8]: "
Chris@1464 495 STDOUT.flush
Chris@1464 496 encoding = STDIN.gets.chomp!
Chris@1464 497 encoding = 'UTF-8' if encoding.blank?
Chris@1464 498 break if MantisMigrate.encoding encoding
Chris@1464 499 puts "Invalid encoding!"
Chris@1464 500 end
Chris@1464 501 puts
Chris@1464 502
Chris@1464 503 # Make sure bugs can refer bugs in other projects
Chris@1464 504 Setting.cross_project_issue_relations = 1 if Setting.respond_to? 'cross_project_issue_relations'
Chris@1464 505
Chris@1464 506 old_notified_events = Setting.notified_events
Chris@1464 507 old_password_min_length = Setting.password_min_length
Chris@1464 508 begin
Chris@1464 509 # Turn off email notifications temporarily
Chris@1464 510 Setting.notified_events = []
Chris@1464 511 Setting.password_min_length = 4
Chris@1464 512 # Run the migration
Chris@1464 513 MantisMigrate.establish_connection db_params
Chris@1464 514 MantisMigrate.migrate
Chris@1464 515 ensure
Chris@1464 516 # Restore previous settings
Chris@1464 517 Setting.notified_events = old_notified_events
Chris@1464 518 Setting.password_min_length = old_password_min_length
Chris@1464 519 end
Chris@1464 520
Chris@1464 521 end
Chris@1464 522 end