Class: ProjectUnification::SpecialHandlers::CollectingEventHandler
- Inherits:
-
Object
- Object
- ProjectUnification::SpecialHandlers::CollectingEventHandler
- Defined in:
- lib/project_unification/special_handlers.rb
Overview
Handler for CollectingEvent with verbatim_label conflict detection.
Unlike Image/Document/CVT, conflicting CEs cannot be automatically merged — they may have different data beyond the verbatim_label. The conflict is surfaced to the user (blocking the migration) so they can resolve it manually (rename or merge the CEs) before retrying.
Instance Attribute Summary collapse
-
#source_project_id ⇒ Object
readonly
Returns the value of attribute source_project_id.
-
#target_project_id ⇒ Object
readonly
Returns the value of attribute target_project_id.
Instance Method Summary collapse
- #detect_verbatim_label_duplicates ⇒ Object private
-
#initialize(source_project_id:, target_project_id:, options: {}) ⇒ CollectingEventHandler
constructor
A new instance of CollectingEventHandler.
- #migrate ⇒ Object
- #migrate_with_sql ⇒ Object private
Constructor Details
#initialize(source_project_id:, target_project_id:, options: {}) ⇒ CollectingEventHandler
Returns a new instance of CollectingEventHandler.
47 48 49 50 |
# File 'lib/project_unification/special_handlers.rb', line 47 def initialize(source_project_id:, target_project_id:, options: {}) @source_project_id = source_project_id @target_project_id = target_project_id end |
Instance Attribute Details
#source_project_id ⇒ Object (readonly)
Returns the value of attribute source_project_id.
45 46 47 |
# File 'lib/project_unification/special_handlers.rb', line 45 def source_project_id @source_project_id end |
#target_project_id ⇒ Object (readonly)
Returns the value of attribute target_project_id.
45 46 47 |
# File 'lib/project_unification/special_handlers.rb', line 45 def target_project_id @target_project_id end |
Instance Method Details
#detect_verbatim_label_duplicates ⇒ Object (private)
88 89 90 91 92 93 94 |
# File 'lib/project_unification/special_handlers.rb', line 88 def detect_verbatim_label_duplicates CollectingEvent.where(project_id: source_project_id) .where.not(verbatim_label: nil) .where(verbatim_label: CollectingEvent.where(project_id: target_project_id).select(:verbatim_label)) .distinct .pluck(:verbatim_label) end |
#migrate ⇒ Object
52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 |
# File 'lib/project_unification/special_handlers.rb', line 52 def migrate duplicates = detect_verbatim_label_duplicates result = { track: :special, model: 'CollectingEvent', migrated: 0, conflicts: [], errors: [] } if duplicates.any? duplicates.each do |label| result[:conflicts] << { model: 'CollectingEvent', conflict_fields: { verbatim_label: label }, errors: ["verbatim_label '#{label}' already exists in the target project — resolve manually before retrying"] } end return result end result[:migrated] = migrate_with_sql result rescue => e { track: :special, model: 'CollectingEvent', migrated: 0, conflicts: [], errors: [{ error: e., backtrace: e.backtrace.first(3) }] } end |
#migrate_with_sql ⇒ Object (private)
96 97 98 99 |
# File 'lib/project_unification/special_handlers.rb', line 96 def migrate_with_sql CollectingEvent.where(project_id: source_project_id) .update_all(project_id: target_project_id) end |