annotate .svn/pristine/cf/cf46c38f878a3a8e8d2ecb6560d5ca30550356b4.svn-base @ 1296:038ba2d95de8 redmine-2.2

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