2022-01-01 13:38:12 +00:00
|
|
|
# Copyright (C) 2012-2022 Zammad Foundation, https://zammad-foundation.org/
|
2021-06-01 12:20:20 +00:00
|
|
|
|
2017-08-14 11:56:23 +00:00
|
|
|
class Sequencer
|
|
|
|
class Unit
|
|
|
|
module Import
|
|
|
|
module Common
|
|
|
|
module Model
|
|
|
|
class Save < Sequencer::Unit::Base
|
2018-08-15 10:05:54 +00:00
|
|
|
prepend ::Sequencer::Unit::Import::Common::Model::Mixin::Skip::Action
|
2017-08-14 11:56:23 +00:00
|
|
|
include ::Sequencer::Unit::Import::Common::Model::Mixin::HandleFailure
|
|
|
|
|
2018-08-15 10:05:54 +00:00
|
|
|
uses :instance, :action, :dry_run
|
2017-08-30 15:16:27 +00:00
|
|
|
provides :instance
|
2017-08-14 11:56:23 +00:00
|
|
|
|
2018-08-15 10:05:54 +00:00
|
|
|
skip_action :skipped, :failed, :unchanged
|
|
|
|
|
2017-08-14 11:56:23 +00:00
|
|
|
def process
|
|
|
|
return if dry_run
|
|
|
|
return if instance.blank?
|
2018-10-09 06:17:41 +00:00
|
|
|
|
2019-02-28 14:21:59 +00:00
|
|
|
save!
|
|
|
|
end
|
|
|
|
|
|
|
|
def save!
|
|
|
|
BulkImportInfo.enable
|
2017-08-14 11:56:23 +00:00
|
|
|
instance.save!
|
|
|
|
rescue => e
|
|
|
|
handle_failure(e)
|
2017-08-30 15:16:27 +00:00
|
|
|
|
|
|
|
# unset instance if something went wrong
|
|
|
|
state.provide(:instance, nil)
|
2019-02-28 14:21:59 +00:00
|
|
|
ensure
|
|
|
|
BulkImportInfo.disable
|
2017-08-14 11:56:23 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|