diff options
author | Eric Davis <edavis@littlestreamsoftware.com> | 2009-10-19 00:07:37 +0000 |
---|---|---|
committer | Eric Davis <edavis@littlestreamsoftware.com> | 2009-10-19 00:07:37 +0000 |
commit | a150689be9281f3a814cd5bdedd42f80f431fe41 (patch) | |
tree | dc9f10c027d2f985aa36f47272a6b49ba38bbcd5 /app | |
parent | 6531c3f88721c083f32c3e313efec6b40708382a (diff) | |
download | redmine-a150689be9281f3a814cd5bdedd42f80f431fe41.tar.gz redmine-a150689be9281f3a814cd5bdedd42f80f431fe41.zip |
Improved Project#copy to copy more data from the source Project. #3367
* Versions
* Associate the copied issues with the new versions
* Wiki
* WikiPages
* WikiContents
* IssueCategories
git-svn-id: svn+ssh://rubyforge.org/var/svn/redmine/trunk@2934 e93f8b46-1217-0410-a6f0-8f06a7374b81
Diffstat (limited to 'app')
-rw-r--r-- | app/models/project.rb | 34 |
1 files changed, 34 insertions, 0 deletions
diff --git a/app/models/project.rb b/app/models/project.rb index 74d8a32c2..33ed3b7fa 100644 --- a/app/models/project.rb +++ b/app/models/project.rb @@ -348,10 +348,44 @@ class Project < ActiveRecord::Base project = project.is_a?(Project) ? project : Project.find(project) Project.transaction do + # Wikis + self.wiki = Wiki.new(project.wiki.attributes.dup.except("project_id")) + project.wiki.pages.each do |page| + new_wiki_content = WikiContent.new(page.content.attributes.dup.except("page_id")) + new_wiki_page = WikiPage.new(page.attributes.dup.except("wiki_id")) + new_wiki_page.content = new_wiki_content + + self.wiki.pages << new_wiki_page + end + + # Versions + project.versions.each do |version| + new_version = Version.new + new_version.attributes = version.attributes.dup.except("project_id") + self.versions << new_version + end + + project.issue_categories.each do |issue_category| + new_issue_category = IssueCategory.new + new_issue_category.attributes = issue_category.attributes.dup.except("project_id") + self.issue_categories << new_issue_category + end + # Issues project.issues.each do |issue| new_issue = Issue.new new_issue.copy_from(issue) + # Reassign fixed_versions by name, since names are unique per + # project and the versions for self are not yet saved + if issue.fixed_version + new_issue.fixed_version = self.versions.select {|v| v.name == issue.fixed_version.name}.first + end + # Reassign the category by name, since names are unique per + # project and the categories for self are not yet saved + if issue.category + new_issue.category = self.issue_categories.select {|c| c.name == issue.category.name}.first + end + self.issues << new_issue end |