Patch #13407 ยป migrate_from_mantis.patch
| lib/tasks/migrate_from_mantis.rake (working copy) | ||
|---|---|---|
|
def firstname
|
||
|
@firstname = realname.blank? ? username : realname.split.first[0..29]
|
||
|
@firstname.gsub!(/[^\w\s\'\-]/i, '')
|
||
|
@firstname
|
||
|
end
|
||
|
def lastname
|
||
|
@lastname = realname.blank? ? '-' : realname.split[1..-1].join(' ')[0..29]
|
||
|
@lastname.gsub!(/[^\w\s\'\-]/i, '')
|
||
|
@lastname = '-' if @lastname.blank?
|
||
|
@lastname
|
||
|
end
|
||
| ... | ... | |
|
has_many :news, :class_name => "MantisNews", :foreign_key => :project_id
|
||
|
has_many :members, :class_name => "MantisProjectUser", :foreign_key => :project_id
|
||
|
def name
|
||
|
read_attribute(:name)[0..29]
|
||
|
end
|
||
|
def identifier
|
||
|
read_attribute(:name).gsub(/[^a-z0-9\-]+/, '-').slice(0, Project::IDENTIFIER_MAX_LENGTH)
|
||
|
read_attribute(:name).underscore[0..19].gsub(/[^a-z0-9\-]/, '-')
|
||
|
end
|
||
|
end
|
||
|
class MantisProjectHierarchy < ActiveRecord::Base
|
||
|
self.table_name = :mantis_project_hierarchy_table;
|
||
|
end
|
||
|
class MantisVersion < ActiveRecord::Base
|
||
|
self.table_name = :mantis_project_version_table
|
||
| ... | ... | |
|
end
|
||
|
class MantisCategory < ActiveRecord::Base
|
||
|
self.table_name = :mantis_project_category_table
|
||
|
self.table_name = :mantis_category_table
|
||
|
end
|
||
|
class MantisProjectUser < ActiveRecord::Base
|
||
| ... | ... | |
|
end
|
||
|
def name
|
||
|
read_attribute(:name)[0..29]
|
||
|
read_attribute(:name)[0..29].gsub(/[^\w\s\'\-]/, '-')
|
||
|
end
|
||
|
end
|
||
| ... | ... | |
|
:last_login_on => user.last_visit
|
||
|
u.login = user.username
|
||
|
u.password = 'mantis'
|
||
|
u.status = User::STATUS_LOCKED if user.enabled != 1
|
||
|
u.status = User::STATUS_ACTIVE if user.enabled == true
|
||
|
u.status = User::STATUS_LOCKED if user.enabled != true
|
||
|
u.admin = true if user.access_level == 90
|
||
|
next unless u.save!
|
||
|
users_migrated += 1
|
||
| ... | ... | |
|
# Projects
|
||
|
print "Migrating projects"
|
||
|
Project.destroy_all
|
||
|
Project.destroy_all(:parent_id => nil)
|
||
|
projects_map = {}
|
||
|
versions_map = {}
|
||
|
categories_map = {}
|
||
| ... | ... | |
|
project.versions.each do |version|
|
||
|
v = Version.new :name => encode(version.version),
|
||
|
:description => encode(version.description),
|
||
|
:effective_date => (version.date_order ? version.date_order.to_date : nil)
|
||
|
:effective_date => Time.at(version.date_order).to_date
|
||
|
v.project = p
|
||
|
v.save
|
||
|
versions_map[version.id] = v.id
|
||
| ... | ... | |
|
# Project categories
|
||
|
project.categories.each do |category|
|
||
|
g = IssueCategory.new :name => category.category[0,30]
|
||
|
g = IssueCategory.new :name => category.name[0,30]
|
||
|
g.project = p
|
||
|
g.save
|
||
|
categories_map[category.category] = g.id
|
||
|
categories_map[category.id] = g.id
|
||
|
end
|
||
|
end
|
||
|
puts
|
||
|
# Project Hierarchy
|
||
|
print "Migrating project hierarchy..."
|
||
|
MantisProjectHierarchy.find(:all).each do |entry|
|
||
|
p = Project.find_by_id(projects_map[entry.child_id])
|
||
|
p.set_parent!(projects_map[entry.parent_id])
|
||
|
end
|
||
|
puts
|
||
|
# Bugs
|
||
|
print "Migrating bugs"
|
||
|
Issue.destroy_all
|
||
| ... | ... | |
|
:subject => encode(bug.summary),
|
||
|
:description => encode(bug.bug_text.full_description),
|
||
|
:priority => PRIORITY_MAPPING[bug.priority] || DEFAULT_PRIORITY,
|
||
|
:created_on => bug.date_submitted,
|
||
|
:updated_on => bug.last_updated
|
||
|
:created_on => Time.at(bug.date_submitted),
|
||
|
:updated_on => Time.at(bug.last_updated)
|
||
|
i.author = User.find_by_id(users_map[bug.reporter_id])
|
||
|
i.category = IssueCategory.find_by_project_id_and_name(i.project_id, bug.category[0,30]) unless bug.category.blank?
|
||
|
i.category = IssueCategory.find_by_id(categories_map[bug.category_id]) unless bug.category_id.blank?
|
||
|
i.fixed_version = Version.find_by_project_id_and_name(i.project_id, bug.fixed_in_version) unless bug.fixed_in_version.blank?
|
||
|
i.status = STATUS_MAPPING[bug.status] || DEFAULT_STATUS
|
||
|
i.tracker = (bug.severity == 10 ? TRACKER_FEATURE : TRACKER_BUG)
|
||
| ... | ... | |
|
bug.bug_notes.each do |note|
|
||
|
next unless users_map[note.reporter_id]
|
||
|
n = Journal.new :notes => encode(note.bug_note_text.note),
|
||
|
:created_on => note.date_submitted
|
||
|
:created_on => Time.at(note.date_submitted)
|
||
|
n.user = User.find_by_id(users_map[note.reporter_id])
|
||
|
n.journalized = i
|
||
|
n.save
|
||
| ... | ... | |
|
# Bug files
|
||
|
bug.bug_files.each do |file|
|
||
|
a = Attachment.new :created_on => file.date_added
|
||
|
a = Attachment.new :created_on => Time.at(file.date_added)
|
||
|
a.file = file
|
||
|
a.author = User.find :first
|
||
|
a.container = i
|
||
| ... | ... | |
|
next unless users_map[monitor.user_id]
|
||
|
i.add_watcher(User.find_by_id(users_map[monitor.user_id]))
|
||
|
end
|
||
|
# Fix updated time (setting some attribute breaks it)
|
||
|
i.updated_on = Time.at(bug.last_updated)
|
||
|
end
|
||
|
# update issue id sequence if needed (postgresql)
|
||
| ... | ... | |
|
n = News.new :project_id => projects_map[news.project_id],
|
||
|
:title => encode(news.headline[0..59]),
|
||
|
:description => encode(news.body),
|
||
|
:created_on => news.date_posted
|
||
|
:created_on => Time.at(news.date_posted)
|
||
|
n.author = User.find_by_id(users_map[news.poster_id])
|
||
|
n.save
|
||
|
print '.'
|
||