Code cleanup.

git-svn-id: svn+ssh://rubyforge.org/var/svn/redmine/trunk@10939 e93f8b46-1217-0410-a6f0-8f06a7374b81
This commit is contained in:
Jean-Philippe Lang 2012-12-03 23:03:33 +00:00
parent 5dbefbc40d
commit 33549495c9
1 changed files with 10 additions and 20 deletions

View File

@ -695,27 +695,17 @@ class Project < ActiveRecord::Base
end end
end end
# Returns a new unsaved Project instance with attributes copied from +project+
# Copies +project+ and returns the new instance. This will not save
# the copy
def self.copy_from(project) def self.copy_from(project)
begin project = project.is_a?(Project) ? project : Project.find(project)
project = project.is_a?(Project) ? project : Project.find(project) # clear unique attributes
if project attributes = project.attributes.dup.except('id', 'name', 'identifier', 'status', 'parent_id', 'lft', 'rgt')
# clear unique attributes copy = Project.new(attributes)
attributes = project.attributes.dup.except('id', 'name', 'identifier', 'status', 'parent_id', 'lft', 'rgt') copy.enabled_modules = project.enabled_modules
copy = Project.new(attributes) copy.trackers = project.trackers
copy.enabled_modules = project.enabled_modules copy.custom_values = project.custom_values.collect {|v| v.clone}
copy.trackers = project.trackers copy.issue_custom_fields = project.issue_custom_fields
copy.custom_values = project.custom_values.collect {|v| v.clone} copy
copy.issue_custom_fields = project.issue_custom_fields
return copy
else
return nil
end
rescue ActiveRecord::RecordNotFound
return nil
end
end end
# Yields the given block for each project with its level in the tree # Yields the given block for each project with its level in the tree