Actions
Defect #11315
openWhen I copy a project it does not copy the issues custom fields' values
Status:
Needs feedback
Priority:
Normal
Assignee:
-
Category:
Custom fields
Target version:
-
Start date:
Due date:
% Done:
0%
Estimated time:
Resolution:
Affected version:
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
Related issues
Updated by Felix Schäfer about 12 years ago
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
Updated by Toshi MARUYAMA over 11 years ago
- Related to Defect #11481: Copying Projects (with Tickets) not working added
Updated by Mischa The Evil almost 8 years ago
- Status changed from New to Needs feedback
Updated by Mischa The Evil almost 8 years ago
- Related to Defect #22342: When copying issues to a different project, subtasks /w custom fields not copied over added
Actions