Class: Topics::MergeService

Inherits:
Object
  • Object
show all
Defined in:
app/services/topics/merge_service.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(source_topic, target_topic) ⇒ MergeService

Returns a new instance of MergeService.



7
8
9
10
# File 'app/services/topics/merge_service.rb', line 7

def initialize(source_topic, target_topic)
  @source_topic = source_topic
  @target_topic = target_topic
end

Instance Attribute Details

#source_topicObject

Returns the value of attribute source_topic.



5
6
7
# File 'app/services/topics/merge_service.rb', line 5

def source_topic
  @source_topic
end

#target_topicObject

Returns the value of attribute target_topic.



5
6
7
# File 'app/services/topics/merge_service.rb', line 5

def target_topic
  @target_topic
end

Instance Method Details

#executeObject



12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
# File 'app/services/topics/merge_service.rb', line 12

def execute
  validate_parameters!

  ::Projects::ProjectTopic.transaction do
    move_project_topics
    refresh_target_topic_counters
    delete_source_topic
  end

  ServiceResponse.success
rescue ArgumentError => e
  ServiceResponse.error(message: e.message)
rescue StandardError => e
  Gitlab::ErrorTracking.track_exception(e, source_topic_id: source_topic.id, target_topic_id: target_topic.id)
  ServiceResponse.error(message: _('Topics could not be merged!'))
end