forked from jasder/forgeplus
修改代码
This commit is contained in:
parent
28802cb833
commit
f13db9e369
|
@ -19,8 +19,7 @@ class SyncForgeJob < ApplicationJob
|
||||||
if new_user.present?
|
if new_user.present?
|
||||||
ActiveRecord::Base.transaction do
|
ActiveRecord::Base.transaction do
|
||||||
begin
|
begin
|
||||||
Watcher&.where(user_id: user_old_id).update_all(user_id: new_user.id)
|
|
||||||
ProjectTrend&.where(user_id: user_old_id).update_all(user_id: new_user.id)
|
|
||||||
sync_roles(roles_params, platform)
|
sync_roles(roles_params, platform)
|
||||||
if all_target_params.present?
|
if all_target_params.present?
|
||||||
all_target_params.each do |project|
|
all_target_params.each do |project|
|
||||||
|
@ -39,6 +38,13 @@ class SyncForgeJob < ApplicationJob
|
||||||
sync_projects(new_user, user_old_id,target_params, platform)
|
sync_projects(new_user, user_old_id,target_params, platform)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
Issue.select(:id, :assigned_to_id).where(assigned_to_id: user_old_id)&.update_all(assigned_to_id: new_user.id)
|
||||||
|
Issue.select(:id, :author_id).where(author_id: user_old_id)&.update_all(author_id: new_user.id)
|
||||||
|
Journal.select(:id,:user_id).where(user_id: user_old_id)&.update_all(user_id: new_user.id)
|
||||||
|
Watcher.select(:id,:user_id).where(user_id: user_old_id)&.update_all(user_id: new_user.id)
|
||||||
|
ProjectTrend.select(:id,:user_id).where(user_id: user_old_id)&.update_all(user_id: new_user.id)
|
||||||
|
PullRequest.select(:id,:user_id).where(user_id: user_old_id)&.update_all(user_id: new_user.id)
|
||||||
|
Version.select(:id,:user_id).where(user_id: user_old_id)&.update_all(user_id: new_user.id)
|
||||||
rescue Exception => e
|
rescue Exception => e
|
||||||
Rails.logger.info("#######_______forge_new_user_sync_failed___#########{e}")
|
Rails.logger.info("#######_______forge_new_user_sync_failed___#########{e}")
|
||||||
raise ActiveRecord::Rollback
|
raise ActiveRecord::Rollback
|
||||||
|
@ -133,6 +139,12 @@ class SyncForgeJob < ApplicationJob
|
||||||
project_identifier = repo_params["identifier"]
|
project_identifier = repo_params["identifier"]
|
||||||
end
|
end
|
||||||
|
|
||||||
|
if Project.exists?(identifier: project_identifier)
|
||||||
|
failed_dic = "public/sync_failed_users.dic"
|
||||||
|
File.open(failed_dic,"a") do |file|
|
||||||
|
file.puts "[\nTime---#{Time.now}\nproject_info---#{project}\n---]\n "
|
||||||
|
end
|
||||||
|
else
|
||||||
new_project = Project.new(project&.except!(*keys_to_delete).merge(user_id: new_user.id))
|
new_project = Project.new(project&.except!(*keys_to_delete).merge(user_id: new_user.id))
|
||||||
if new_project.save!(:validate => false)
|
if new_project.save!(:validate => false)
|
||||||
if project_identifier.present?
|
if project_identifier.present?
|
||||||
|
@ -149,7 +161,7 @@ class SyncForgeJob < ApplicationJob
|
||||||
ProjectScore.create!(project_score&.except!(*score_to_delete).merge(project_id: new_project.id))
|
ProjectScore.create!(project_score&.except!(*score_to_delete).merge(project_id: new_project.id))
|
||||||
end
|
end
|
||||||
|
|
||||||
sync_user_issues(new_project.id, new_user.id,old_user_id,issue_params, platform)
|
sync_user_issues(new_project.id, issue_params, platform)
|
||||||
sync_members(new_project.id, member_params,platform)
|
sync_members(new_project.id, member_params,platform)
|
||||||
sync_commits(new_project.id,new_project.gpid, commit_params,platform)
|
sync_commits(new_project.id,new_project.gpid, commit_params,platform)
|
||||||
sync_pull_requests(new_project.id,new_user.id, pr_params,platform)
|
sync_pull_requests(new_project.id,new_user.id, pr_params,platform)
|
||||||
|
@ -159,6 +171,7 @@ class SyncForgeJob < ApplicationJob
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
end
|
||||||
rescue Exception => e
|
rescue Exception => e
|
||||||
Rails.logger.info("#######_______projects_sync__failed__#########{e}")
|
Rails.logger.info("#######_______projects_sync__failed__#########{e}")
|
||||||
raise ActiveRecord::Rollback
|
raise ActiveRecord::Rollback
|
||||||
|
@ -247,7 +260,7 @@ class SyncForgeJob < ApplicationJob
|
||||||
|
|
||||||
def sync_members(project_id,members_params,platform)
|
def sync_members(project_id,members_params,platform)
|
||||||
Rails.logger.info("#######______sync_members_start__#######")
|
Rails.logger.info("#######______sync_members_start__#######")
|
||||||
member_to_delete = %w(id created_on user_id project_id)
|
member_to_delete = %w(id created_on project_id)
|
||||||
ActiveRecord::Base.transaction do
|
ActiveRecord::Base.transaction do
|
||||||
begin
|
begin
|
||||||
if members_params.present?
|
if members_params.present?
|
||||||
|
@ -256,7 +269,7 @@ class SyncForgeJob < ApplicationJob
|
||||||
member_user = m["member_user"]
|
member_user = m["member_user"]
|
||||||
member_user_exten = m["member_extension"]
|
member_user_exten = m["member_extension"]
|
||||||
member_roles = m["member_roles"]
|
member_roles = m["member_roles"]
|
||||||
member_issues = m["member_issues"]
|
# member_issues = m["member_issues"]
|
||||||
if member_user.present?
|
if member_user.present?
|
||||||
u = sync_user(member_user,member_user_exten, platform)
|
u = sync_user(member_user,member_user_exten, platform)
|
||||||
if u.present? && member.present?
|
if u.present? && member.present?
|
||||||
|
@ -264,7 +277,7 @@ class SyncForgeJob < ApplicationJob
|
||||||
unless Member.exists?(user_id: u.id, project_id: project_id)
|
unless Member.exists?(user_id: u.id, project_id: project_id)
|
||||||
new_member = Member.new(member&.except!(*member_to_delete).merge(project_id: project_id, user_id: u.id))
|
new_member = Member.new(member&.except!(*member_to_delete).merge(project_id: project_id, user_id: u.id))
|
||||||
if new_member.save!(:validate => false)
|
if new_member.save!(:validate => false)
|
||||||
sync_user_issues(project_id, u.id, member["user_id"],member_issues, platform)
|
# sync_user_issues(project_id,member_issues, platform)
|
||||||
sync_member_roles(new_member.id, member_roles,platform)
|
sync_member_roles(new_member.id, member_roles,platform)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
@ -304,9 +317,9 @@ class SyncForgeJob < ApplicationJob
|
||||||
end
|
end
|
||||||
|
|
||||||
#同步该用户的issues
|
#同步该用户的issues
|
||||||
def sync_user_issues(project_id, new_user_id,old_user_id,issues_all_params,platform)
|
def sync_user_issues(project_id, issues_all_params,platform)
|
||||||
Rails.logger.info("#######______sync_issues_start__#########")
|
Rails.logger.info("#######______sync_issues_start__#########")
|
||||||
issue_to_delete = %w(id project_id author_id created_on updated_on assigned_to_id)
|
issue_to_delete = %w(id project_id created_on updated_on)
|
||||||
ActiveRecord::Base.transaction do
|
ActiveRecord::Base.transaction do
|
||||||
begin
|
begin
|
||||||
if issues_all_params.present?
|
if issues_all_params.present?
|
||||||
|
@ -314,17 +327,11 @@ class SyncForgeJob < ApplicationJob
|
||||||
issue_params = is_params["issue_params"]
|
issue_params = is_params["issue_params"]
|
||||||
jours_params = is_params["jours_params"]
|
jours_params = is_params["jours_params"]
|
||||||
commit_params = is_params["commit_params"]
|
commit_params = is_params["commit_params"]
|
||||||
Issue.select(:id, :assigned_to_id).where(assigned_to_id: old_user_id)&.update_all(assigned_to_id: new_user_id)
|
|
||||||
|
|
||||||
if issue_params.present?
|
if issue_params.present?
|
||||||
issue_params = issue_params["issue"] if old_version_source.include?(platform) #trustie上需要
|
issue_params = issue_params["issue"] if old_version_source.include?(platform) #trustie上需要
|
||||||
assgin_user = issue_params["assigned_to_id"]
|
issue = Issue.new(issue_params&.except!(*issue_to_delete).merge(project_id: project_id))
|
||||||
if issue_params["assigned_to_id"].to_i == old_user_id
|
|
||||||
assgin_user = new_user_id
|
|
||||||
end
|
|
||||||
issue = Issue.new(issue_params&.except!(*issue_to_delete).merge(project_id: project_id, author_id: new_user_id, assigned_to_id: assgin_user))
|
|
||||||
if issue.save!(:validate => false)
|
if issue.save!(:validate => false)
|
||||||
sync_journals(new_user_id, issue.id, jours_params, platform)
|
sync_journals(issue.id, jours_params, platform)
|
||||||
sync_commit_issues(issue.id,project_id, commit_params, platform)
|
sync_commit_issues(issue.id,project_id, commit_params, platform)
|
||||||
else
|
else
|
||||||
Rails.logger.info("############______.errors.full_messages_____________##########{issue.errors.full_messages}")
|
Rails.logger.info("############______.errors.full_messages_____________##########{issue.errors.full_messages}")
|
||||||
|
@ -341,8 +348,8 @@ class SyncForgeJob < ApplicationJob
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|
||||||
def sync_journals(user_id, issue_id, jours_params,platform)
|
def sync_journals(issue_id, jours_params,platform)
|
||||||
Rails.logger.info("#######______sync_journals_start__########")
|
Rails.logger.info("#######______sync_journals_start__#######")
|
||||||
|
|
||||||
jour_to_delete = %w(id created_on journalized_id)
|
jour_to_delete = %w(id created_on journalized_id)
|
||||||
ActiveRecord::Base.transaction do
|
ActiveRecord::Base.transaction do
|
||||||
|
@ -350,12 +357,18 @@ class SyncForgeJob < ApplicationJob
|
||||||
if jours_params.present?
|
if jours_params.present?
|
||||||
Journal.transaction do
|
Journal.transaction do
|
||||||
jours_params.each do |i|
|
jours_params.each do |i|
|
||||||
if i.present?
|
new_journal = i["journal"]
|
||||||
i = i["journal"] if old_version_source.include?(platform) #trustie上需要
|
new_journal_detail = i["j_details"]
|
||||||
new_journal = Journal.new(i&.except!(*jour_to_delete).merge(journalized_id: issue_id, user_id: user_id))
|
if new_journal.present?
|
||||||
new_journal.save(:validate => false)
|
new_journal = new_journal["journal"] if old_version_source.include?(platform) #trustie上需要
|
||||||
end
|
new_journal = Journal.new(new_journal&.except!(*jour_to_delete).merge(journalized_id: issue_id))
|
||||||
|
if new_journal.save(:validate => false)
|
||||||
|
|
||||||
|
if new_journal_detail.present?
|
||||||
|
sync_journal_details(new_journal_detail, new_journal.id, platform)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
@ -368,6 +381,30 @@ class SyncForgeJob < ApplicationJob
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def sync_journal_details(jours_params,journal_id, platform)
|
||||||
|
Rails.logger.info("#######______sync_journal_detail_start__######")
|
||||||
|
|
||||||
|
jour_to_delete = %w(id journal_id)
|
||||||
|
ActiveRecord::Base.transaction do
|
||||||
|
begin
|
||||||
|
JournalDetail.transaction do
|
||||||
|
jours_params.each do |i|
|
||||||
|
if i.present?
|
||||||
|
i = i["journal_detail"] if old_version_source.include?(platform) #trustie上需要
|
||||||
|
new_journal_detail = JournalDetail.new(i&.except!(*jour_to_delete).merge(journal_id: journal_id))
|
||||||
|
new_journal_detail.save(:validate => false)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
Rails.logger.info("#######______sync_journal__detail_end__########")
|
||||||
|
|
||||||
|
rescue Exception => e
|
||||||
|
Rails.logger.info("#######________sync_journal___detail_failed__#########{e}")
|
||||||
|
raise ActiveRecord::Rollback
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
def sync_commit_issues(issue_id, project_id, commit_params,platform)
|
def sync_commit_issues(issue_id, project_id, commit_params,platform)
|
||||||
Rails.logger.info("#######______sync_commit_issues_start__########")
|
Rails.logger.info("#######______sync_commit_issues_start__########")
|
||||||
|
|
||||||
|
@ -398,7 +435,7 @@ class SyncForgeJob < ApplicationJob
|
||||||
def sync_pull_requests(project_id, user_id, pull_params,platform)
|
def sync_pull_requests(project_id, user_id, pull_params,platform)
|
||||||
Rails.logger.info("#######______sync_project_pull_requests_start__########")
|
Rails.logger.info("#######______sync_project_pull_requests_start__########")
|
||||||
|
|
||||||
commit_to_delete = %w(id user_id project_id created_at updated_at jenkins_output)
|
commit_to_delete = %w(id project_id created_at updated_at jenkins_output)
|
||||||
ActiveRecord::Base.transaction do
|
ActiveRecord::Base.transaction do
|
||||||
begin
|
begin
|
||||||
if pull_params.present?
|
if pull_params.present?
|
||||||
|
@ -406,7 +443,7 @@ class SyncForgeJob < ApplicationJob
|
||||||
pull_params.each do |i|
|
pull_params.each do |i|
|
||||||
if i.present?
|
if i.present?
|
||||||
i = i["pull_request"] if old_version_source.include?(platform) #trustie上需要
|
i = i["pull_request"] if old_version_source.include?(platform) #trustie上需要
|
||||||
newpr = PullRequest.new(i&.except!(*commit_to_delete).merge(user_id: user_id, project_id: project_id))
|
newpr = PullRequest.new(i&.except!(*commit_to_delete).merge(project_id: project_id))
|
||||||
newpr.save(:validate => false)
|
newpr.save(:validate => false)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -450,7 +487,7 @@ class SyncForgeJob < ApplicationJob
|
||||||
def sync_versions(project_id, new_user_id,version_params,platform)
|
def sync_versions(project_id, new_user_id,version_params,platform)
|
||||||
Rails.logger.info("#######______sync_project_versions_start__########")
|
Rails.logger.info("#######______sync_project_versions_start__########")
|
||||||
|
|
||||||
version_to_delete = %w(id created_on updated_on project_id user_id)
|
version_to_delete = %w(id created_on updated_on project_id)
|
||||||
ActiveRecord::Base.transaction do
|
ActiveRecord::Base.transaction do
|
||||||
begin
|
begin
|
||||||
if version_params.present?
|
if version_params.present?
|
||||||
|
@ -458,8 +495,8 @@ class SyncForgeJob < ApplicationJob
|
||||||
version_params.each do |i|
|
version_params.each do |i|
|
||||||
if i.present?
|
if i.present?
|
||||||
i = i["version"] if old_version_source.include?(platform) #trustie上需要
|
i = i["version"] if old_version_source.include?(platform) #trustie上需要
|
||||||
new_v = Version.new(i&.except!(*version_to_delete).merge(user_id: new_user_id, project_id: project_id))
|
new_v = Version.new(i&.except!(*version_to_delete).merge(project_id: project_id))
|
||||||
new_v.save(:validate => false)
|
new_v.save!(:validate => false)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
Loading…
Reference in New Issue