Project

General

Profile

Feature #21623 » redmine_3.2.0_21623.diff

Jérôme BATAILLE, 2016-04-07 01:06

View differences:

app/models/journal.rb
228 228
    end
229 229
    if @custom_values_before_change
230 230
      # custom fields changes
231
      journalized.custom_field_values.each {|c|
231

  
232
      ##################
233
      # Smile fix #21623 : re-insert removed custom fields with nil value
234
      # TODO check if custom_field_values has to be fixed to take that in account
235
      cf_values = journalized.custom_field_values.dup # Dupped because cached in an instance variable
236
      custom_fields = {} # cached locally
237
      @custom_values_before_change.each{|i, v|
238
        cfv = cf_values.detect {|c| c.custom_field_id == i}
239
        next if cfv # On a not deleted custom field, or already re-added
240

  
241
        cf = custom_fields[i]
242
        if cf.nil?
243
          cf = CustomField.find_by_id(i)
244
        end
245

  
246
        if cf # Custom field has not been deleted in between
247
          cfv = CustomFieldValue.new
248
          cfv.custom_field = cf
249
          cfv.value = nil
250

  
251
          # Re-add it in the list
252
          cf_values << cfv
253
        end
254
      }
255
      # END -- Smile fix #21623
256
      #########################
257

  
258
      # Smile fix #21623 : journalized.custom_field_values -> cf_values
259
      cf_values.each {|c|
232 260
        before = @custom_values_before_change[c.custom_field_id]
233 261
        after = c.value
234 262
        next if before == after || (before.blank? && after.blank?)
(2-2/3)