Defect #11315
open
When I copy a project it does not copy the issues custom fields' values
Added by Felipe Garcia over 12 years ago.
Updated over 7 years ago.
Description
We created a template project, but when we try to copy that project, the issues custom fields' values does not get copied.
Why this is happening? I am using Redmine 1.4
This happens when issues are bulk copied and the tracker and/or the project is changed. In these cases the custom field values just get deleted.
Here's a patch that will keep applicable custom field values instead of deleting them all:
diff --git a/app/models/issue.rb b/app/models/issue.rb
index 53d7823..9c71538 100644
--- a/app/models/issue.rb
+++ b/app/models/issue.rb
@@ -228,7 +228,7 @@ class Issue < ActiveRecord::Base
def tracker_id=(tid)
self.tracker = nil
result = write_attribute(:tracker_id, tid)
- @custom_field_values = nil
+ recalculate_custom_field_values!
result
end
@@ -257,7 +257,7 @@ class Issue < ActiveRecord::Base
if parent && parent.project_id != project_id
self.parent_issue_id = nil
end
- @custom_field_values = nil
+ recalculate_custom_field_values!
end
end
diff --git a/vendor/plugins/acts_as_customizable/lib/acts_as_customizable.rb b/vendor/plugins/acts_as_customizable/lib/acts_as_customizable.rb
index cfee2c5..d1db757 100644
--- a/vendor/plugins/acts_as_customizable/lib/acts_as_customizable.rb
+++ b/vendor/plugins/acts_as_customizable/lib/acts_as_customizable.rb
@@ -153,6 +153,16 @@ module Redmine
@custom_field_values_changed = true
end
+ # Recalculate custom_field_values based on current available_custom_fields.
+ # We need to make sure no extraneous custom_field_values are saved,
+ # #custom_field_values= will only save values for custom fields available
+ # to this object.
+ def recalculate_custom_field_values!
+ cfv_hash = custom_field_values.inject({}) {|h,cfv| h[cfv.custom_field.id] = cfv.value; h}
+ reset_custom_values!
+ self.custom_field_values = cfv_hash
+ end
+
module ClassMethods
end
end
- Category set to Custom fields
- Related to Defect #11481: Copying Projects (with Tickets) not working added
- Status changed from New to Needs feedback
I just came around this issue again and checked whether this issue still persists on current trunk (at r16339). AFAICS, this is fixed by r15318 for #22342. I did some quick tests and wasn't able to reproduce the issue any longer.
Can this be confirmed by somebody?
- Related to Defect #22342: When copying issues to a different project, subtasks /w custom fields not copied over added
Also available in: Atom
PDF