Skip to content

Commit

Permalink
Added a new capability to import parent tasks.
Browse files Browse the repository at this point in the history
If you provide a column that you map to "Parent Task",
you can import parent tasks.  There are several restrictions:
- If you want to import parent tasks, you must set the
  "Select unique field for identify issue" value in the upload.
- Obviously, that field must be unqiue.
- Finally, and most importantly, parent tasks must come before
  child tasks in the list.  Although this is kind of a pain,
  it makes this a one-pass rather than two-pass feature.
This has not yet been tested with using the ID as the unique
column.  Also, right now the "Select unique field for identify issue"
option is disabled by default; the second half of this update
will update the UI as well.
  • Loading branch information
Leo Hourvitz committed Mar 30, 2011
1 parent b2106a4 commit bbecb10
Showing 1 changed file with 41 additions and 6 deletions.
47 changes: 41 additions & 6 deletions app/controllers/importer_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 8,8 @@ class ImporterController < ApplicationController

ISSUE_ATTRS = [:id, :subject, :assigned_to, :fixed_version,
:author, :description, :category, :priority, :tracker, :status,
:start_date, :due_date, :done_ratio, :estimated_hours]
:start_date, :due_date, :done_ratio, :estimated_hours,
:parent_issue]

def index
end
Expand Down Expand Up @@ -93,15 94,16 @@ def result
ignore_non_exist = params[:ignore_non_exist]
fields_map = params[:fields_map]
unique_attr = fields_map[unique_field]

# attrs_map is fields_map's invert
attrs_map = fields_map.invert

# check params
if update_issue && unique_attr == nil
flash[:error] = "Unique field hasn't match an issue's field"
if (update_issue || attrs_map["parent_issue"] != nil) && unique_attr == nil
flash[:error] = "Unique field doesn't match an issue's field"
return
end

# attrs_map is fields_map's invert

attrs_map = fields_map.invert
FasterCSV.new(iip.csv_data, {:headers=>true, :encoding=>iip.encoding,
:quote_char=>iip.quote_char, :col_sep=>iip.col_sep}).each do |row|

Expand Down Expand Up @@ -203,6 205,39 @@ def result
issue.done_ratio = row[attrs_map["done_ratio"]] || issue.done_ratio
issue.estimated_hours = row[attrs_map["estimated_hours"]] || issue.estimated_hours

# parent issue
if row[attrs_map["parent_issue"]] != nil
if unique_attr == "id"
parent_issues = [Issue.find_by_id(row[unique_field])]
else
query = Query.new(:name => "_importer", :project => @project)
query.add_filter("status_id", "*", [1])
query.add_filter(unique_attr, "=", [row[attrs_map["parent_issue"]]])
logger.info("Querying for parent issue with #{unique_attr} = '#{row[unique_field]}")

parent_issues = Issue.find :all, :conditions => query.statement, :limit => 2, :include => [ :assigned_to, :status, :tracker, :project, :priority, :category, :fixed_version ]
end

if parent_issues.size > 1
flash[:warning] = "Unique field #{unique_field} has duplicate record"
@failed_count = 1
@failed_issues[@handle_count 1] = row
break
else
if parent_issues.size > 0
# found issue
issue.parent_issue_id = parent_issues.first.id

else
# ignore none exist issues
if ignore_non_exist
@skip_count = 1
next
end
end
end
end

# custom fields
issue.custom_field_values = issue.available_custom_fields.inject({}) do |h, c|
if value = row[attrs_map[c.name]]
Expand Down

6 comments on commit bbecb10

@markpennington
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

First, thank you for taking the time to put this together. Really great improvements. I tried to import some issues and associate them to an existing parent. I have that parent value as the first column in the csv so it precedes all other data, and I assigned a unique field that was not the issue ID. All the issues imported correctly (367 of them), but were not assigned to the parent. I followed your restrictions as explained as far as I know. Any thoughts? Again, thank you for the great work.

@leovitch
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi Mark, thanks for the note. Did you make sure to set the unique field pulldown in the UI? Right now, totally counter-intuitively, you have to turn on the "Update existing issues" checkbox. Also, I haven't tested whether the unique field can be a custom field or not (thinking about it, I kind of suspect it won't work yet).

I really want to write a manual for the plugin, but I'm not sure what the best way/place to document Redmine plugins is. Let me know if you've seen how other plugins do this well. I suppose I could just throw a link into the first upload page.

@markpennington
Copy link

@markpennington markpennington commented on bbecb10 Apr 2, 2011 via email

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@leovitch
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi Mark,

I started a new directory test/samples and put a sample .csv in it showing the simplest possible parent upload. There's also a screenshot in there of the needed UI setting to get parents to upload right now (until I can fix the UI).

I also tried to start documentation of the plugin on the Wiki for this repository (but I haven't figured out how to make the link to the screenshot image work yet).

Let me know if that helps!

@leovitch
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Mark -- Quite a few updates this weekend, most notably the user documentation on this Github's wiki and a whole directory full of examples with instructions on how to upload them. I also fixed the problem with not being able to use a custom field for relationships, and added the ability to import explicit issue relationships to a certain extent. Please take a look if you get a chance, hopefully it will help quite a bit!

@markpennington
Copy link

@markpennington markpennington commented on bbecb10 Apr 3, 2011 via email

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.