summaryrefslogtreecommitdiffstats
path: root/app/models/journal.rb
diff options
context:
space:
mode:
authorJean-Philippe Lang <jp_lang@yahoo.fr>2016-09-03 07:26:49 +0000
committerJean-Philippe Lang <jp_lang@yahoo.fr>2016-09-03 07:26:49 +0000
commit55be3ef1727eb8381a2af6dd2e354a4f25ffa406 (patch)
tree048cb1a11cd3569e8d54a0fa50bef090b6f32f52 /app/models/journal.rb
parenta20458612ef3ada099416b3180e8a2f7d31458b3 (diff)
downloadredmine-55be3ef1727eb8381a2af6dd2e354a4f25ffa406.tar.gz
redmine-55be3ef1727eb8381a2af6dd2e354a4f25ffa406.zip
Journalize values that are cleared after project or tracker change (#21623).
git-svn-id: http://svn.redmine.org/redmine/trunk@15811 e93f8b46-1217-0410-a6f0-8f06a7374b81
Diffstat (limited to 'app/models/journal.rb')
-rw-r--r--app/models/journal.rb32
1 files changed, 20 insertions, 12 deletions
diff --git a/app/models/journal.rb b/app/models/journal.rb
index 3f1a34952..c43c4da9c 100644
--- a/app/models/journal.rb
+++ b/app/models/journal.rb
@@ -226,18 +226,26 @@ class Journal < ActiveRecord::Base
def journalize_changes
# attributes changes
if @attributes_before_change
- journalized.journalized_attribute_names.each {|attribute|
+ attrs = (journalized.journalized_attribute_names + @attributes_before_change.keys).uniq
+ attrs.each do |attribute|
before = @attributes_before_change[attribute]
after = journalized.send(attribute)
next if before == after || (before.blank? && after.blank?)
add_attribute_detail(attribute, before, after)
- }
+ end
end
+ # custom fields changes
if @custom_values_before_change
- # custom fields changes
- journalized.custom_field_values.each {|c|
- before = @custom_values_before_change[c.custom_field_id]
- after = c.value
+ values_by_custom_field_id = {}
+ @custom_values_before_change.each do |custom_field_id, value|
+ values_by_custom_field_id[custom_field_id] = nil
+ end
+ journalized.custom_field_values.each do |c|
+ values_by_custom_field_id[c.custom_field_id] = c.value
+ end
+
+ values_by_custom_field_id.each do |custom_field_id, after|
+ before = @custom_values_before_change[custom_field_id]
next if before == after || (before.blank? && after.blank?)
if before.is_a?(Array) || after.is_a?(Array)
@@ -246,16 +254,16 @@ class Journal < ActiveRecord::Base
# values removed
(before - after).reject(&:blank?).each do |value|
- add_custom_value_detail(c, value, nil)
+ add_custom_field_detail(custom_field_id, value, nil)
end
# values added
(after - before).reject(&:blank?).each do |value|
- add_custom_value_detail(c, nil, value)
+ add_custom_field_detail(custom_field_id, nil, value)
end
else
- add_custom_value_detail(c, before, after)
+ add_custom_field_detail(custom_field_id, before, after)
end
- }
+ end
end
start
end
@@ -266,8 +274,8 @@ class Journal < ActiveRecord::Base
end
# Adds a journal detail for a custom field value change
- def add_custom_value_detail(custom_value, old_value, value)
- add_detail('cf', custom_value.custom_field_id, old_value, value)
+ def add_custom_field_detail(custom_field_id, old_value, value)
+ add_detail('cf', custom_field_id, old_value, value)
end
# Adds a journal detail