Skip to content

Commit

Permalink
Fixed bug in update_without_clone where cloning would still occur.
Browse files Browse the repository at this point in the history
  • Loading branch information
gaspard committed Aug 28, 2013
1 parent 1efddc8 commit d58367e
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 18 deletions.
17 changes: 12 additions & 5 deletions app/controllers/nodes_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -423,11 +423,18 @@ def update
params['node'] ||= {}
file, file_error = get_attachment
params['node']['file'] = file if file
# Make sure we load the correct version for edited v_lang
lang = params['node']['v_lang'] || visitor.lang
@node.version(lang)
@v_status_before_update = @node.v_status
@node.update_attributes_with_transformation(params['node'])

#============= [TRANSACTION HERE to prevent double version bug on double submit
# This can only fix the issue if Version creation/saving is not done after_commit !!
Node.transaction do
# Make sure we load the correct version for edited v_lang
lang = params['node']['v_lang'] || visitor.lang
@node.version(lang)
@v_status_before_update = @node.v_status
@node.update_attributes_with_transformation(params['node'])
end
#============= TO HERE TRANSACTION]

# What is this 'extfile' thing ?
@node.errors.add('extfile', file_error) if file_error

Expand Down
22 changes: 9 additions & 13 deletions lib/zena/use/workflow.rb
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ module Workflow
module VersionMethods
attr_reader :stored_workflow, :status_set
# Enable the use of version.backup = 'true' to force clone
attr_accessor :backup
attr_accessor :backup, :no_clone_on_change

def self.included(base)
base.before_save :store_workflow_changes
Expand Down Expand Up @@ -43,7 +43,7 @@ def should_clone?

# Return true if the version should be cloned if it was changed.
def clone_on_change?
if node && node.no_clone_on_change?
if @no_clone_on_change
false
else
# not same user
Expand Down Expand Up @@ -500,9 +500,9 @@ def update_attributes(new_attributes)
# Used when we want to update properties *without* changing author and/or creating new versions. This
# is needed when we want to synchronise some properties with an external application.
def update_attributes_without_clone(new_attributes)
@no_clone_on_change = true
Node.record_timestamps = false
Version.record_timestamps = false
version.no_clone_on_change = true
Node.record_timestamps = false
Version.record_timestamps = false
# We set v_status
if v_status == Zena::Status::Pub
# This forces index rebuild by selecting the :publish transition instead of :edit.
Expand All @@ -512,13 +512,9 @@ def update_attributes_without_clone(new_attributes)
end
apply(:update_attributes, attrs)
ensure
@no_clone_on_change = nil
Node.record_timestamps = true
Version.record_timestamps = true
end

def no_clone_on_change?
@no_clone_on_change == true
version.no_clone_on_change = nil
Node.record_timestamps = true
Version.record_timestamps = true
end

private
Expand Down Expand Up @@ -640,7 +636,7 @@ def set_current_version_before_update
end
end

unless @no_clone_on_change
unless version.no_clone_on_change
# Do not force updated_at sync when using "update_attributes_without_clone"
self.updated_at = Time.now unless changed? # force 'updated_at' sync
end
Expand Down

0 comments on commit d58367e

Please sign in to comment.