Method: Project#copy

Defined in:
app/models/project.rb

#copy(project, options = {}) ⇒ Object

Copies and saves the Project instance based on the project. Duplicates the source project’s:

  • Wiki

  • Versions

  • Categories

  • Issues

  • Members

  • Queries

Accepts an options argument to specify what to copy

Examples:

project.copy(1)                                    # => copies everything
project.copy(1, :only => 'members')                # => copies members only
project.copy(1, :only => ['members', 'versions'])  # => copies members and versions


931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
# File 'app/models/project.rb', line 931

def copy(project, options={})
  project = Project.find(project) unless project.is_a?(Project)

  to_be_copied = %w(members wiki versions issue_categories issues queries boards documents)
  to_be_copied = to_be_copied & Array.wrap(options[:only]) unless options[:only].nil?

  Project.transaction do
    if save
      reload

      self.attachments = project.attachments.map do |attachment|
        attachment.copy(:container => self)
      end

      to_be_copied.each do |name|
        send :"copy_#{name}", project
      end
      Redmine::Hook.call_hook(:model_project_copy_before_save,
                              :source_project => project,
                              :destination_project => self)
      save
    else
      false
    end
  end
end