state_update.rb 1.1 KB

123456789101112131415161718192021222324252627282930313233343536373839
  1. module Import
  2. module OTRS
  3. class History
  4. class StateUpdate < Import::OTRS::History
  5. def init_callback(history)
  6. data = history['Name']
  7. # "%%new%%open%%"
  8. from = nil
  9. to = nil
  10. if data =~ /%%(.+?)%%(.+?)%%/
  11. from = $1
  12. to = $2
  13. state_from = ::Ticket::State.lookup(name: from)
  14. state_to = ::Ticket::State.lookup(name: to)
  15. if state_from
  16. from_id = state_from.id
  17. end
  18. if state_to
  19. to_id = state_to.id
  20. end
  21. end
  22. @history_attributes = {
  23. id: history['HistoryID'],
  24. o_id: history['TicketID'],
  25. history_type: 'updated',
  26. history_object: 'Ticket',
  27. history_attribute: 'state',
  28. value_from: from,
  29. id_from: from_id,
  30. value_to: to,
  31. id_to: to_id,
  32. created_at: history['CreateTime'],
  33. created_by_id: history['CreateBy']
  34. }
  35. end
  36. end
  37. end
  38. end
  39. end