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
23 23
namespace :redmine do
24 24
	desc 'Jira migration script'
25 25
	task :migrate_from_jira => :environment do
26 26
		
27 27
		module JiraMigrate
28
			priorities = Enumeration.get_values('IPRI')
28
			priorities = IssuePriority.all
29 29
			DEFAULT_PRIORITY = priorities[0]
30 30

  
31 31
			DEFAULT_STATUS = IssueStatus.default
32
			assigned_status = IssueStatus.find_by_position(2)
33
			resolved_status = IssueStatus.find_by_position(3)
34
			feedback_status = IssueStatus.find_by_position(4)
32
			assigned_status = IssueStatus.find_by_name("Assigned")
33
			resolved_status = IssueStatus.find_by_name("Resolved")
34
			feedback_status = IssueStatus.find_by_name("Feedback")
35 35
			closed_status = IssueStatus.find :first, :conditions => { :is_closed => true }
36 36

  
37 37
			STATUS_MAPPING = {'open' => DEFAULT_STATUS,
38 38
												'reopened' => feedback_status,
39 39
												'resolved' => resolved_status,
......
42 42
												}
43 43

  
44 44
#			TRACKER_BUG = Tracker.find_by_position(1)
45 45
#			TRACKER_FEATURE = Tracker.find_by_position(2)
46 46
#			TRACKER_TASK = Tracker.find_by_position(4)
47
			TRACKER_BUG = Tracker.find_by_position(2)
48
			TRACKER_FEATURE = Tracker.find_by_position(3)
49
			TRACKER_TASK = Tracker.find_by_position(6)
47
			TRACKER_BUG = Tracker.find_by_name("Bug")
48
			TRACKER_FEATURE = Tracker.find_by_name("Feature")
49
			TRACKER_TASK = Tracker.find_by_name("Task")
50 50
			DEFAULT_TRACKER = TRACKER_BUG
51 51
			TRACKER_MAPPING = {'bug' => TRACKER_BUG,
52 52
												 'enhancement' => TRACKER_FEATURE,
53 53
												 'task' => TRACKER_TASK,
54 54
												 'new feature' =>TRACKER_FEATURE
......
127 127
					# finally, a default user is used if the new user is not valid
128 128
					u = User.find(:first) unless u.save
129 129
				end
130 130
				# Make sure he is a member of the project
131 131
				if project && !u.member_of?(project)
132
					role = DEFAULT_ROLE
133
					role = ROLE_MAPPING['admin'] if u.admin
134
					Member.create(:user => u, :project => project, :role => role)
132
					roles = [DEFAULT_ROLE]
133
					roles = [ROLE_MAPPING['admin']] if u.admin
134
					Member.create(:user => u, :project => project, :roles => roles)
135 135
					u.reload
136 136
				end
137 137
				u
138 138
			end
139 139

  
......
174 174
						project = Project.find_by_identifier(identifier)
175 175
						if !project
176 176
							# create the target project
177 177
							project = Project.new :name => identifier.humanize,
178 178
																		:description => "Imported project from jira (#{identifier.upcase})." #identifier.humanize
179
							project.parent_id = @target_project.id
180 179
							project.identifier = identifier
181 180
							puts "Unable to create a sub project with identifier '#{identifier}'!" unless project.save
181
							project.move_to_child_of(@target_project.id)
182 182
							# enable issues for the created project
183 183
							project.enabled_module_names = ['issue_tracking']
184 184
						end
185 185
						project.trackers << TRACKER_BUG
186 186
						project.trackers << TRACKER_FEATURE
......
247 247
								i.save
248 248
							end
249 249

  
250 250
							# force the issue update date back. it gets overwritten on save time.
251 251
							Issue.connection.execute <<-end
252
								update issues set updated_on = "#{Time.parse(issue.updated).to_s :db}" where id = #{i.id}
252
								update issues set updated_on = '#{Time.parse(issue.updated).to_s :db}' where id = #{i.id}
253 253
							end
254 254

  
255 255
							migrated_issues += 1
256 256

  
257 257
							# Comments
......
343 343
		puts
344 344

  
345 345
		JiraMigrate.migrate
346 346
	end
347 347
end
348

  
(2-2/9)