annotate .svn/pristine/cf/cf46c38f878a3a8e8d2ecb6560d5ca30550356b4.svn-base @ 1298:4f746d8966dd redmine_2.3_integration

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