state_update.rb 1.2 KB

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