add.rb 945 B

123456789101112131415161718192021222324252627282930313233343536
  1. # Copyright (C) 2012-2024 Zammad Foundation, https://zammad-foundation.org/
  2. class Sequencer::Unit::Import::Zendesk::Ticket::Comment::Attachment::Add < Sequencer::Unit::Base
  3. prepend ::Sequencer::Unit::Import::Common::Model::Mixin::Skip::Action
  4. include ::Sequencer::Unit::Import::Common::Model::Mixin::HandleFailure
  5. skip_action :skipped
  6. uses :instance, :resource, :response, :model_class
  7. def process
  8. ::Store.create!(
  9. object: model_class.name,
  10. o_id: instance.id,
  11. data: response.body,
  12. filename: resource.file_name,
  13. preferences: store_preferences,
  14. created_by_id: 1
  15. )
  16. rescue => e
  17. handle_failure(e)
  18. end
  19. private
  20. def store_preferences
  21. output = { 'Content-Type' => resource.content_type }
  22. if Store.resizable_mime? resource.content_type
  23. output[:resizable] = true
  24. output[:content_preview] = true
  25. end
  26. output
  27. end
  28. end