Skip to content

Commit

Permalink
Fixes #18382 - Save action prior to save/destroy
Browse files Browse the repository at this point in the history
on action triggering
  • Loading branch information
jlsherrill authored and iNecas committed Feb 15, 2017
1 parent 11f441d commit 3976ab0
Showing 1 changed file with 9 additions and 17 deletions.
26 changes: 9 additions & 17 deletions app/models/foreman_tasks/concerns/action_triggering.rb
Expand Up @@ -4,13 +4,14 @@ module ActionTriggering
extend ActiveSupport::Concern

included do
after_create :plan_create_action
after_update :plan_update_action
after_destroy :plan_destroy_action
after_create :plan_hook_action
after_update :plan_hook_action
after_destroy :plan_hook_action

alias_method_chain :save, :dynflow_task_wrap
end

# These three *_action methods are called before the save/destroy actually occurs
# @override
def create_action; end

Expand Down Expand Up @@ -70,18 +71,8 @@ def sync_action!
@dynflow_sync_action = true
end

def plan_create_action
plan_action(create_action, self) if create_action
true
end

def plan_update_action
plan_action(update_action, self) if update_action
true
end

def plan_destroy_action
plan_action(destroy_action, self) if destroy_action
def plan_hook_action
plan_action(@_dynflow_hook_action, self) if @_dynflow_hook_action
true
end

Expand Down Expand Up @@ -116,20 +107,21 @@ def dynflow_task_wrap(method)
end
@_dynflow_task_wrapped = true

action = case method
@_dynflow_hook_action = case method
when :save
new_record? ? create_action : update_action
when :destroy
destroy_action
else
raise 'unexpected method'
end
ensure_not_in_transaction! if action
ensure_not_in_transaction! if @_dynflow_hook_action
yield.tap do |result|
execute_planned_action if result
sync_action_flag_reset!
end
ensure
@_dynflow_hook_action = nil
@_dynflow_task_wrapped = false
end

Expand Down

0 comments on commit 3976ab0

Please sign in to comment.