Project

General

Profile

Patch #26721 » project.rb.3.diff

jwjw yy, 2017-08-19 05:43

View differences:

app/models/project.rb
703 703
  # or nil if the module is not enabled for the project
704 704
  def enabled_module(name)
705 705
    name = name.to_s
706
    enabled_modules.detect {|m| m.name == name}
706
    enabled_modules.find_by(name: name)
707 707
  end
708 708

  
709 709
  # Return true if the module with the given name is enabled
......
741 741
  #   project.disable_module!("issue_tracking")
742 742
  #   project.disable_module!(project.enabled_modules.first)
743 743
  def disable_module!(target)
744
    target = enabled_modules.detect{|mod| target.to_s == mod.name} unless enabled_modules.include?(target)
744
    target = enabled_modules.find_by(name: target.to_s) unless enabled_modules.include?(target)
745 745
    target.destroy unless target.blank?
746 746
  end
747 747

  
......
986 986
      new_issue.custom_field_values = issue.custom_field_values.inject({}) {|h,v| h[v.custom_field_id] = v.value; h}
987 987
      # Reassign fixed_versions by name, since names are unique per project
988 988
      if issue.fixed_version && issue.fixed_version.project == project
989
        new_issue.fixed_version = self.versions.detect {|v| v.name == issue.fixed_version.name}
989
          new_issue.fixed_version = self.versions.find_by(name: issue.fixed_version.name)
990 990
      end
991 991
      # Reassign version custom field values
992 992
      new_issue.custom_field_values.each do |custom_value|
......
994 994
          versions = Version.where(:id => custom_value.value).to_a
995 995
          new_value = versions.map do |version|
996 996
            if version.project == project
997
              self.versions.detect {|v| v.name == version.name}.try(:id)
997
              self.versions.find_by(name: version.name).try(:id)
998 998
            else
999 999
              version.id
1000 1000
            end
......
1006 1006
      end
1007 1007
      # Reassign the category by name, since names are unique per project
1008 1008
      if issue.category
1009
        new_issue.category = self.issue_categories.detect {|c| c.name == issue.category.name}
1009
        new_issue.category = self.issue_categories.find_by(name: issue.category.name)
1010 1010
      end
1011 1011
      # Parent issue
1012 1012
      if issue.parent_id
(3-3/3)