Project

General

Profile

Actions

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.

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

Related to Redmine - Defect #13518: To copy project doesn't copy the issues' custom fields in version 2.2.3Needs feedback

Actions
Related to Redmine - Defect #13540: To copy project doesn't copy the issues' custom fields in version 2.3.0Closed

Actions
Related to Redmine - Defect #11481: Copying Projects (with Tickets) not workingNeeds feedback

Actions
Related to Redmine - Defect #22342: When copying issues to a different project, subtasks /w custom fields not copied overClosedJean-Philippe Lang

Actions
Actions #1

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

Actions #2

Updated by Toshi MARUYAMA about 12 years ago

  • Category set to Custom fields
Actions #3

Updated by Toshi MARUYAMA over 11 years ago

  • Related to Defect #11481: Copying Projects (with Tickets) not working added
Actions #4

Updated by Mischa The Evil over 7 years ago

  • 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?

Actions #5

Updated by Mischa The Evil over 7 years ago

  • Related to Defect #22342: When copying issues to a different project, subtasks /w custom fields not copied over added
Actions

Also available in: Atom PDF