Project

General

Profile

Feature #1385 » migrate_from_jira.rake.patch

A patch against the original rake task - Marcel Waldvogel, 2010-02-01 23:04

View differences:

/Users/marcel/redmine/ror/lib/tasks/migrate_from_jira.rake 2010-02-01 22:56:59.000000000 +0100
namespace :redmine do
desc 'Jira migration script'
task :migrate_from_jira => :environment do
module JiraMigrate
priorities = Enumeration.get_values('IPRI')
priorities = IssuePriority.all
DEFAULT_PRIORITY = priorities[0]
DEFAULT_STATUS = IssueStatus.default
assigned_status = IssueStatus.find_by_position(2)
resolved_status = IssueStatus.find_by_position(3)
feedback_status = IssueStatus.find_by_position(4)
assigned_status = IssueStatus.find_by_name("Assigned")
resolved_status = IssueStatus.find_by_name("Resolved")
feedback_status = IssueStatus.find_by_name("Feedback")
closed_status = IssueStatus.find :first, :conditions => { :is_closed => true }
STATUS_MAPPING = {'open' => DEFAULT_STATUS,
'reopened' => feedback_status,
'resolved' => resolved_status,
......
}
# TRACKER_BUG = Tracker.find_by_position(1)
# TRACKER_FEATURE = Tracker.find_by_position(2)
# TRACKER_TASK = Tracker.find_by_position(4)
TRACKER_BUG = Tracker.find_by_position(2)
TRACKER_FEATURE = Tracker.find_by_position(3)
TRACKER_TASK = Tracker.find_by_position(6)
TRACKER_BUG = Tracker.find_by_name("Bug")
TRACKER_FEATURE = Tracker.find_by_name("Feature")
TRACKER_TASK = Tracker.find_by_name("Task")
DEFAULT_TRACKER = TRACKER_BUG
TRACKER_MAPPING = {'bug' => TRACKER_BUG,
'enhancement' => TRACKER_FEATURE,
'task' => TRACKER_TASK,
'new feature' =>TRACKER_FEATURE
......
# finally, a default user is used if the new user is not valid
u = User.find(:first) unless u.save
end
# Make sure he is a member of the project
if project && !u.member_of?(project)
role = DEFAULT_ROLE
role = ROLE_MAPPING['admin'] if u.admin
Member.create(:user => u, :project => project, :role => role)
roles = [DEFAULT_ROLE]
roles = [ROLE_MAPPING['admin']] if u.admin
Member.create(:user => u, :project => project, :roles => roles)
u.reload
end
u
end
......
project = Project.find_by_identifier(identifier)
if !project
# create the target project
project = Project.new :name => identifier.humanize,
:description => "Imported project from jira (#{identifier.upcase})." #identifier.humanize
project.parent_id = @target_project.id
project.identifier = identifier
puts "Unable to create a sub project with identifier '#{identifier}'!" unless project.save
project.move_to_child_of(@target_project.id)
# enable issues for the created project
project.enabled_module_names = ['issue_tracking']
end
project.trackers << TRACKER_BUG
project.trackers << TRACKER_FEATURE
......
i.save
end
# force the issue update date back. it gets overwritten on save time.
Issue.connection.execute <<-end
update issues set updated_on = "#{Time.parse(issue.updated).to_s :db}" where id = #{i.id}
update issues set updated_on = '#{Time.parse(issue.updated).to_s :db}' where id = #{i.id}
end
migrated_issues += 1
# Comments
......
puts
JiraMigrate.migrate
end
end
(2-2/9)