Project

General

Profile

Feature #21623 » journal_for_lost_cust_values_when_cust_field_is_not_enabled_anymore.diff

Jérôme BATAILLE, 2016-01-05 15:57

View differences:

app/models/issue.rb
1512 1512
      end
1513 1513
      if @custom_values_before_change
1514 1514
        # custom fields changes
1515
        custom_field_values.each {|c|
1515

  
1516
        # Re-insert removed custom fields with nil value
1517
        # TODO check if custom_field_values has to be fixed to take that in account
1518
        cf_values = custom_field_values.dup # Dupped because cached in an instance variable
1519
        custom_fields = {}
1520
        @custom_values_before_change.each{|i, v|
1521
          cfv = cf_values.detect {|c| c.custom_field_id == i}
1522
          next if cfv # On a not deleted custom field, or already re-added
1523

  
1524
          cf = custom_fields[i]
1525
          if cf.nil?
1526
            cf = CustomField.find_by_id(i)
1527
          end
1528

  
1529
          # Custom field has not been deleted in between
1530
          if cf
1531
            cfv = CustomFieldValue.new
1532
            cfv.custom_field = cf
1533
            cfv.value = nil
1534

  
1535
            cf_values << cfv
1536
          end
1537
        }
1538

  
1539
        cf_values.each {|c|
1516 1540
          before = @custom_values_before_change[c.custom_field_id]
1517 1541
          after = c.value
1518 1542
          next if before == after || (before.blank? && after.blank?)
(1-1/3)