state_id.rb 742 B

1234567891011121314151617181920212223242526272829303132
  1. # Copyright (C) 2012-2024 Zammad Foundation, https://zammad-foundation.org/
  2. class Sequencer::Unit::Import::Zendesk::Ticket::StateId < Sequencer::Unit::Common::Provider::Named
  3. uses :resource
  4. private
  5. def state_id
  6. return default_state_id if local.blank?
  7. ::Ticket::State.select(:id).find_by(name: local)&.id || default_state_id
  8. end
  9. def local
  10. # When no mapping exist, try to find state in database.
  11. mapping.fetch(resource.status, resource.status)
  12. end
  13. def mapping
  14. {
  15. 'new' => 'new',
  16. 'pending' => 'pending reminder',
  17. 'solved' => 'closed',
  18. 'hold' => 'open'
  19. }.freeze
  20. end
  21. def default_state_id
  22. @default_state_id ||= ::Ticket::State.find_by(name: 'open')&.id
  23. end
  24. end