From 3a04d8a68110100713ea0cb70efc5cf0229dc5dc Mon Sep 17 00:00:00 2001 From: Riceball LEE Date: Fri, 29 Apr 2011 13:54:33 +0800 Subject: [PATCH 01/10] * [bug] ignore the illegal user record in DB --- app/models/source_user.rb | 1 + 1 file changed, 1 insertion(+) diff --git a/app/models/source_user.rb b/app/models/source_user.rb index a305489..2766187 100644 --- a/app/models/source_user.rb +++ b/app/models/source_user.rb @@ -4,6 +4,7 @@ class SourceUser < ActiveRecord::Base def self.migrate all.each do |source_user| + next if source_user.login.blank? ## ignore the illegal user record in DB next if User.find_by_mail(source_user.mail) next if User.find_by_login(source_user.login) next if source_user.type == "AnonymousUser" From 7230eb7a4842b3bc02d8541b1ae38e2829b528c7 Mon Sep 17 00:00:00 2001 From: Riceball LEE Date: Fri, 29 Apr 2011 14:04:21 +0800 Subject: [PATCH 02/10] * [bug] fixed the no author error by lookup for mail first * [bug] forget sync the fixed_version_id --- app/models/source_issue.rb | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/app/models/source_issue.rb b/app/models/source_issue.rb index 779969f..acfc7bd 100644 --- a/app/models/source_issue.rb +++ b/app/models/source_issue.rb @@ -15,10 +15,13 @@ def self.migrate issue = Issue.create!(source_issue.attributes) do |i| i.project = Project.find_by_name(source_issue.project.name) - i.author = User.find_by_login(source_issue.author.login) - i.assigned_to = User.find_by_login(source_issue.assigned_to.login) if source_issue.assigned_to + i.author = User.find_by_mail(source_issue.author.mail) + i.author = User.find_by_login(source_issue.author.login) if i.author.blank? + i.assigned_to = User.find_by_mail(source_issue.assigned_to.mail) if source_issue.assigned_to + i.assigned_to = User.find_by_login(source_issue.assigned_to.login) if source_issue.assigned_to and i.assigned_to.blank? i.status = IssueStatus.find_by_name(source_issue.status.name) i.tracker = Tracker.find_by_name(source_issue.tracker.name) + i.fixed_version_id = RedmineMerge::Mapper.get_new_version_id(source_issue.fixed_version_id) i.priority = IssuePriority.find_by_name(source_issue.priority.name) i.category = IssueCategory.find_by_name(source_issue.category.name) if source_issue.category end From 468a9127019285dace57f59cf1bf62c78033dad6 Mon Sep 17 00:00:00 2001 From: Riceball LEE Date: Fri, 29 Apr 2011 02:25:23 -0700 Subject: [PATCH 03/10] + keep user id mapping. --- app/models/redmine_merge.rb | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/app/models/redmine_merge.rb b/app/models/redmine_merge.rb index 72a2dda..c0d48d2 100644 --- a/app/models/redmine_merge.rb +++ b/app/models/redmine_merge.rb @@ -33,6 +33,15 @@ class Mapper WikiPages = {} Documents = {} Versions = {} + Users = {} + + def self.add_user(source_id, new_id) + Users[source_id] = new_id + end + + def self.get_new_user_id(source_id) + Users[source_id] + end def self.add_project(source_id, new_id) Projects[source_id] = new_id From 6c59e0981e34bec897264ffe3704d983c3501d4a Mon Sep 17 00:00:00 2001 From: Riceball LEE Date: Fri, 29 Apr 2011 03:01:02 -0700 Subject: [PATCH 04/10] + record the user id for mapping. --- app/models/source_user.rb | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/app/models/source_user.rb b/app/models/source_user.rb index 2766187..eb92e02 100644 --- a/app/models/source_user.rb +++ b/app/models/source_user.rb @@ -5,15 +5,16 @@ class SourceUser < ActiveRecord::Base def self.migrate all.each do |source_user| next if source_user.login.blank? ## ignore the illegal user record in DB - next if User.find_by_mail(source_user.mail) - next if User.find_by_login(source_user.login) next if source_user.type == "AnonymousUser" + user = User.find_by_mail(source_user.mail) + user = User.find_by_login(source_user.login) unless user - User.create!(source_user.attributes) do |u| + user = User.create!(source_user.attributes) do |u| u.login = source_user.login u.admin = source_user.admin u.hashed_password = source_user.hashed_password - end + end unless user + RedmineMerge::Mapper.add_user(source_user.id, user.id) end end end From d8c0ac6c1a75c6465e80662529d935e706cfa56f Mon Sep 17 00:00:00 2001 From: Riceball LEE Date: Fri, 29 Apr 2011 03:16:37 -0700 Subject: [PATCH 05/10] * [bug] fixed the journals.user_id is not updated. --- app/models/source_journal.rb | 1 + 1 file changed, 1 insertion(+) diff --git a/app/models/source_journal.rb b/app/models/source_journal.rb index 7d78552..30b63d1 100644 --- a/app/models/source_journal.rb +++ b/app/models/source_journal.rb @@ -10,6 +10,7 @@ def self.migrate journal = Journal.create!(source_journals.attributes) do |j| j.issue = Issue.find_by_subject(source_journals.issue.subject) + j.user_id = RedmineMerge::Mapper.get_new_user_id(sourcesource_journals.user_id) end RedmineMerge::Mapper.add_journal(source_journals.id, journal.id) From c9a9eeac4ad2059ee30fb320bb697bff9234a9ae Mon Sep 17 00:00:00 2001 From: Riceball LEE Date: Tue, 3 May 2011 02:32:15 -0700 Subject: [PATCH 06/10] * [bug] minor mistake fixed. --- app/models/source_journal.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/models/source_journal.rb b/app/models/source_journal.rb index 30b63d1..1532c16 100644 --- a/app/models/source_journal.rb +++ b/app/models/source_journal.rb @@ -10,7 +10,7 @@ def self.migrate journal = Journal.create!(source_journals.attributes) do |j| j.issue = Issue.find_by_subject(source_journals.issue.subject) - j.user_id = RedmineMerge::Mapper.get_new_user_id(sourcesource_journals.user_id) + j.user_id = RedmineMerge::Mapper.get_new_user_id(source_journals.user_id) end RedmineMerge::Mapper.add_journal(source_journals.id, journal.id) From 6840cfc6db2030052214bf1752bfb4b872e8ee71 Mon Sep 17 00:00:00 2001 From: Riceball LEE Date: Wed, 4 May 2011 09:06:15 +0800 Subject: [PATCH 07/10] * [bug] fixs the attach author and a little robustness improvements --- app/models/source_attachment.rb | 22 ++++++++++++++++------ 1 file changed, 16 insertions(+), 6 deletions(-) diff --git a/app/models/source_attachment.rb b/app/models/source_attachment.rb index 07ea91d..3f235dc 100644 --- a/app/models/source_attachment.rb +++ b/app/models/source_attachment.rb @@ -6,20 +6,30 @@ class SourceAttachment < ActiveRecord::Base def self.migrate all.each do |source_attachment| + next if Attachment.find(:first, :conditions => {:filename => source_attachment.filename, + :disk_filename => source_attachment.disk_filename, + :digest => source_attachment.digest, + :container_type => source_attachment.container_type}) Attachment.create!(source_attachment.attributes) do |a| - a.author = User.find_by_login(source_attachment.author.login) + a.author = User.find_by_mail(source_attachment.author.mail) + a.author = User.find_by_login(source_attachment.author.login) if a.author.blank? a.container = case source_attachment.container_type when "Issue" - Issue.find RedmineMerge::Mapper.get_new_issue_id(source_attachment.container_id) + id = RedmineMerge::Mapper.get_new_issue_id(source_attachment.container_id) + Issue.find id if id when "Document" - Document.find RedmineMerge::Mapper.get_new_document_id(source_attachment.container_id) + id = RedmineMerge::Mapper.get_new_document_id(source_attachment.container_id) + Document.find id if id when "WikiPage" - WikiPage.find RedmineMerge::Mapper.get_new_wiki_page_id(source_attachment.container_id) + id = RedmineMerge::Mapper.get_new_wiki_page_id(source_attachment.container_id) + WikiPage.find id if id when "Project" - Project.find RedmineMerge::Mapper.get_new_project_id(source_attachment.container_id) + id = RedmineMerge::Mapper.get_new_project_id(source_attachment.container_id) + Project.find id if id when "Version" - Version.find RedmineMerge::Mapper.get_new_version_id(source_attachment.container_id) + id = RedmineMerge::Mapper.get_new_version_id(source_attachment.container_id) + Version.find id if id end end From 9a99f4d3c0a8f3f11a1368bd0482fda17c3966d9 Mon Sep 17 00:00:00 2001 From: Riceball LEE Date: Thu, 12 May 2011 19:40:36 -0700 Subject: [PATCH 08/10] * [bug] user merge via mail first then login name. --- app/models/source_time_entry.rb | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/app/models/source_time_entry.rb b/app/models/source_time_entry.rb index cd43d9d..e993247 100644 --- a/app/models/source_time_entry.rb +++ b/app/models/source_time_entry.rb @@ -11,7 +11,8 @@ class SourceTimeEntry < ActiveRecord::Base def self.migrate all.each do |source_time_entry| TimeEntry.create!(source_time_entry.attributes) do |te| - te.user = User.find_by_login(source_time_entry.user.login) + te.user = User.find_by_mail(source_time_entry.user.mail) + te.user = User.find_by_login(source_time_entry.user.login) unless user te.project = Project.find_by_name(source_time_entry.project.name) te.activity = TimeEntryActivity.find_by_name(source_time_entry.activity.name) From 3029ba9c539091d63d72510ef0f4199f30983d0f Mon Sep 17 00:00:00 2001 From: Riceball LEE Date: Thu, 12 May 2011 20:46:30 -0700 Subject: [PATCH 09/10] * [bug] find auhtor via mail first then login name --- app/models/source_wiki_content.rb | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/app/models/source_wiki_content.rb b/app/models/source_wiki_content.rb index e4ab475..e99b123 100644 --- a/app/models/source_wiki_content.rb +++ b/app/models/source_wiki_content.rb @@ -9,7 +9,8 @@ def self.migrate WikiContent.create!(source_wiki_content.attributes) do |wc| wc.page = WikiPage.find(RedmineMerge::Mapper.get_new_wiki_page_id(source_wiki_content.page_id)) - wc.author = User.find_by_login(source_wiki_content.author.login) + wc.author = User.find_by_mail(source_wiki_content.author.mail) + wc.author = User.find_by_login(source_wiki_content.author.login) unless wc.author end end end From 7e613463b32017580eb71ae8b9fe5b672256daee Mon Sep 17 00:00:00 2001 From: Riceball LEE Date: Tue, 17 May 2011 03:11:21 -0700 Subject: [PATCH 10/10] * minior bug fixs. --- app/models/source_time_entry.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/models/source_time_entry.rb b/app/models/source_time_entry.rb index e993247..62c1cae 100644 --- a/app/models/source_time_entry.rb +++ b/app/models/source_time_entry.rb @@ -12,7 +12,7 @@ def self.migrate all.each do |source_time_entry| TimeEntry.create!(source_time_entry.attributes) do |te| te.user = User.find_by_mail(source_time_entry.user.mail) - te.user = User.find_by_login(source_time_entry.user.login) unless user + te.user = User.find_by_login(source_time_entry.user.login) unless te.user te.project = Project.find_by_name(source_time_entry.project.name) te.activity = TimeEntryActivity.find_by_name(source_time_entry.activity.name)