app/controllers/importer_controller.rb
# Returns the issue object associated with the given value of the given attribute.
# Raises NoIssueForUniqueValue if not found or MultipleIssuesForUniqueValue
Returns the issue object associated with the given value of the given attribute.
Raises NoIssueForUniqueValue if not found or MultipleIssuesForUniqueValue
Returns the issue object associated with the given value of the given attribute . Raises NoIssueForUniqueValue if not found or MultipleIssuesForUniqueValue
def issue_for_unique_attr(unique_attr, attr_value, row_data)
    if @issue_by_unique_attr.has_key?(attr_value)
      return @issue_by_unique_attr[attr_value]
    end
    if unique_attr == "id"
      issues = [Issue.find_by_id(attr_value)]
    else
      begin
        if Module.const_get('IssueQuery') && IssueQuery.is_a?(Class)
          query_class = IssueQuery
        end
      rescue NameError
        query_class = Query
      end
      query = query_class.new(:name => "_importer", :project => @project)
      query.add_filter("status_id", "*", [1])
      query.add_filter(unique_attr, "=", [attr_value])
      issues = Issue.find :all, :conditions => query.statement, :limit => 2, :include => [ :assigned_to, :status, :tracker, :project, :priority, :category, :fixed_version ]
    end
    if issues.size > 1
      @failed_count += 1
      @failed_issues[@failed_count] = row_data
      @messages << "Warning: Unique field #{unique_attr} with value '#{attr_value}' in issue #{@failed_count} has duplicate record"
      raise MultipleIssuesForUniqueValue, "Unique field #{unique_attr} with value '#{attr_value}' has duplicate record"
    else
      if issues.size == 0
        raise NoIssueForUniqueValue, "No issue with #{unique_attr} of '#{attr_value}' found"
      end
      issues.first
    end
  end
def issue_for_unique_attr ( unique_attr , attr_value , row_data ) if @issue_by_unique_attr . has_key? ( attr_value ) return @issue_by_unique_attr [ attr_value ] end if unique_attr == "id" issues = [ Issue . find_by_id ( attr_value ) ] else begin if Module . const_get ( 'IssueQuery' ) && IssueQuery . is_a? ( Class ) query_class = IssueQuery end rescue NameError query_class = Query end query = query_class . new ( :name => "_importer" , :project => @project ) query . add_filter ( "status_id" , "*" , [ 1 ] ) query . add_filter ( unique_attr , "=" , [ attr_value ] ) issues = Issue . find :all , :conditions => query . statement , :limit => 2 , :include => [ :assigned_to , :status , :tracker , :project , :priority , :category , :fixed_version ] end if issues . size > 1 @failed_count += 1 @failed_issues [ @failed_count ] = row_data @messages << "Warning: Unique field #{unique_attr} with value '#{attr_value}' in issue #{@failed_count} has duplicate record" raise MultipleIssuesForUniqueValue , "Unique field #{unique_attr} with value '#{attr_value}' has duplicate record" else if issues . size == 0 raise NoIssueForUniqueValue , "No issue with #{unique_attr} of '#{attr_value}' found" end issues . first end end
Returns the issue object associated with the given value of the given attribute.
Returns the issue object associated with the given value of the given attribute .
# Use IssueQuery class Redmine >= 2.3.0
unique_attr
<not_specific>
attr_value
<not_specific>
row_data
<not_specific>