Project

General

Profile

Actions

Defect #13540

closed

To copy project doesn't copy the issues' custom fields in version 2.3.0

Added by Guillem TanyĆ  Palacios over 11 years ago. Updated almost 8 years ago.

Status:
Closed
Priority:
Normal
Assignee:
-
Category:
Custom fields
Target version:
-
Start date:
Due date:
% Done:

0%

Estimated time:
Resolution:
Duplicate
Affected version:

Description

In Redmine version 2.3.0, when you copy a project that the issues have custom fields, this fields aren't copied.

In a previous release of Redmine (2.1.2) this problem is resolved.
The solution could be the same that is explained in the issue #11315.
This issue is the same that issue #13518, but in redmine 2.3.0

This solution consist in:

  • Modify the file app/models/issue.rb to add a call to a function to recalculate the custom fields
    • In tracker_id function:
      def tracker_id=(tid)
           self.tracker = nil
           result = write_attribute(:tracker_id, tid)
      -    @custom_field_values = nil
      +    recalculate_custom_field_values!
           result
      end
      
    • In project function
      def project=(project, keep_tracker=false)
          project_was = self.project
          write_attribute(:project_id, project ? project.id : nil)
          association_instance_set('project', project)
          if project_was && project && project_was != project
            (...)
      -      @custom_field_values = nil
      +      recalculate_custom_field_values!  
          end
      end
      
  • Finally, add the new method in lib/plugins/acts_as_customizable/lib/acts_as_customizable.rb
    # 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
    

==========================

My Environment

Ruby version 2.0.0 (x86_64-linux)
RubyGems version 2.0.3
Rack version 1.4
Rails version 3.2.13
Active Record version 3.2.13
Action Pack version 3.2.13
Active Resource version 3.2.13
Action Mailer version 3.2.13
Active Support version 3.2.13
Environment production
Database adapter mysql2


Related issues

Related to Redmine - Defect #11315: When I copy a project it does not copy the issues custom fields' valuesNeeds feedback

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

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

Actions
Actions

Also available in: Atom PDF