save.rb 704 B

123456789101112131415161718192021222324252627282930
  1. # Copyright (C) 2012-2024 Zammad Foundation, https://zammad-foundation.org/
  2. class Sequencer::Unit::Import::Common::Model::Save < Sequencer::Unit::Base
  3. prepend ::Sequencer::Unit::Import::Common::Model::Mixin::Skip::Action
  4. include ::Sequencer::Unit::Import::Common::Model::Mixin::HandleFailure
  5. uses :instance, :action, :dry_run
  6. provides :instance
  7. skip_action :skipped, :failed, :unchanged
  8. def process
  9. return if dry_run
  10. return if instance.blank?
  11. save!
  12. end
  13. def save!
  14. BulkImportInfo.enable
  15. instance.save!
  16. rescue => e
  17. handle_failure(e)
  18. # unset instance if something went wrong
  19. state.provide(:instance, nil)
  20. ensure
  21. BulkImportInfo.disable
  22. end
  23. end