trabajo-afectivo/lib/sequencer/unit/import/common/model/save.rb

41 lines
1,012 B
Ruby
Raw Permalink Normal View History

2022-01-01 13:38:12 +00:00
# Copyright (C) 2012-2022 Zammad Foundation, https://zammad-foundation.org/
class Sequencer
class Unit
module Import
module Common
module Model
class Save < Sequencer::Unit::Base
prepend ::Sequencer::Unit::Import::Common::Model::Mixin::Skip::Action
include ::Sequencer::Unit::Import::Common::Model::Mixin::HandleFailure
uses :instance, :action, :dry_run
provides :instance
skip_action :skipped, :failed, :unchanged
def process
return if dry_run
return if instance.blank?
save!
end
def save!
BulkImportInfo.enable
instance.save!
rescue => e
handle_failure(e)
# unset instance if something went wrong
state.provide(:instance, nil)
ensure
BulkImportInfo.disable
end
end
end
end
end
end
end