save.rb 1012 B

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