Project

General

Profile

Defect #38966 » remove_attachment_cf_values.patch

salman mp, 2023-09-06 23:32

View differences:

lib/plugins/acts_as_customizable/lib/acts_as_customizable.rb (revision 41653:c704208ed465fcb5f84cbfa7b6d4050e229d081b) → lib/plugins/acts_as_customizable/lib/acts_as_customizable.rb (revision 41653+:c704208ed465+)
38 38
          send :include, Redmine::Acts::Customizable::InstanceMethods
39 39
          validate :validate_custom_field_values
40 40
          after_save :save_custom_field_values
41
          before_destroy :remove_attachment_custom_values, prepend: true #prepent parameter is mandatory to call callback before deleting dependent custom_values
41 42
        end
42 43
      end
43 44

  
44 45
      module InstanceMethods
46
        def remove_attachment_custom_values
47
          attachment_cvs = custom_values.select{|cf| cf.custom_field.field_format == "attachment"}
48
          attachment_cvs.each do |cv|
49
            Attachment.find(cv.value).delete_from_disk
50
          end
51
        end
52

  
45 53
        def self.included(base)
46 54
          base.extend ClassMethods
47 55
        end
(1-1/4)