123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960 |
- module Import
- module OTRS
- class Queue
- include Import::Helper
- include Import::OTRS::Helper
- MAPPING = {
- ChangeTime: :updated_at,
- CreateTime: :created_at,
- CreateBy: :created_by_id,
- ChangeBy: :updated_by_id,
- Name: :name,
- QueueID: :id,
- Comment: :note,
- }.freeze
- def initialize(queue)
- import(queue)
- end
- private
- def import(queue)
- create_or_update(map(queue))
- end
- def create_or_update(queue)
- return if updated?(queue)
- create(queue)
- end
- def updated?(queue)
- @local_queue = Group.find_by(id: queue[:id])
- return false if !@local_queue
- log "update Group.find_by(id: #{queue[:id]})"
- @local_queue.update!(queue)
- true
- end
- def create(queue)
- log "add Group.find_by(id: #{queue[:id]})"
- @local_queue = Group.new(queue)
- @local_queue.id = queue[:id]
- @local_queue.save
- reset_primary_key_sequence('groups')
- end
- def map(queue)
- {
- created_by_id: 1,
- updated_by_id: 1,
- active: active?(queue),
- }
- .merge(from_mapping(queue))
- end
- end
- end
- end
|