Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fixed a little bugs #2

Open
wants to merge 11 commits into
base: master
Choose a base branch
from
9 changes: 9 additions & 0 deletions app/models/redmine_merge.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
22 changes: 16 additions & 6 deletions app/models/source_attachment.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
7 changes: 5 additions & 2 deletions app/models/source_issue.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions app/models/source_journal.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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(source_journals.user_id)
end

RedmineMerge::Mapper.add_journal(source_journals.id, journal.id)
Expand Down
3 changes: 2 additions & 1 deletion app/models/source_time_entry.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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 te.user
te.project = Project.find_by_name(source_time_entry.project.name)
te.activity = TimeEntryActivity.find_by_name(source_time_entry.activity.name)

Expand Down
10 changes: 6 additions & 4 deletions app/models/source_user.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,17 @@ class SourceUser < ActiveRecord::Base

def self.migrate
all.each do |source_user|
next if User.find_by_mail(source_user.mail)
next if User.find_by_login(source_user.login)
next if source_user.login.blank? ## ignore the illegal user record in DB
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
3 changes: 2 additions & 1 deletion app/models/source_wiki_content.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down