Class: Milestones::TransferService

Inherits:
Object
  • Object
show all
Defined in:
app/services/milestones/transfer_service.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(current_user, old_group, project) ⇒ TransferService

Returns a new instance of TransferService.



12
13
14
15
16
# File 'app/services/milestones/transfer_service.rb', line 12

def initialize(current_user, old_group, project)
  @current_user = current_user
  @old_group = old_group
  @project = project
end

Instance Attribute Details

#current_userObject (readonly)

Returns the value of attribute current_user.



10
11
12
# File 'app/services/milestones/transfer_service.rb', line 10

def current_user
  @current_user
end

#old_groupObject (readonly)

Returns the value of attribute old_group.



10
11
12
# File 'app/services/milestones/transfer_service.rb', line 10

def old_group
  @old_group
end

#projectObject (readonly)

Returns the value of attribute project.



10
11
12
# File 'app/services/milestones/transfer_service.rb', line 10

def project
  @project
end

Instance Method Details

#executeObject



18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
# File 'app/services/milestones/transfer_service.rb', line 18

def execute
  return unless old_group.present?

  Milestone.transaction do
    milestones_to_transfer.find_each do |milestone|
      new_milestone = find_or_create_milestone(milestone)

      update_issues_milestone(milestone, new_milestone)
      update_merge_requests_milestone(milestone.id, new_milestone&.id)

      delete_milestone_counts_caches(milestone)
      delete_milestone_counts_caches(new_milestone)
    end
  end
end