| 1777 |
1777 |
|
| 1778 |
1778 |
unless @copied_from.leaf? || @copy_options[:subtasks] == false
|
| 1779 |
1779 |
copy_options = (@copy_options || {}).merge(:subtasks => false)
|
| 1780 |
|
copied_issue_ids = {@copied_from.id => self.id}
|
|
1780 |
copied_issues = {@copied_from.id => self}
|
| 1781 |
1781 |
@copied_from.reload.descendants.reorder("#{Issue.table_name}.lft").each do |child|
|
| 1782 |
1782 |
# Do not copy self when copying an issue as a descendant of the copied issue
|
| 1783 |
1783 |
next if child == self
|
| 1784 |
1784 |
# Do not copy subtasks of issues that were not copied
|
| 1785 |
|
next unless copied_issue_ids[child.parent_id]
|
|
1785 |
next unless copied_issues[child.parent_id]
|
| 1786 |
1786 |
|
| 1787 |
1787 |
# Do not copy subtasks that are not visible to avoid potential disclosure of private data
|
| 1788 |
1788 |
unless child.visible?
|
| ... | ... | |
| 1800 |
1800 |
end
|
| 1801 |
1801 |
copy.author = author
|
| 1802 |
1802 |
copy.project = project
|
| 1803 |
|
copy.parent_issue_id = copied_issue_ids[child.parent_id]
|
|
1803 |
copy.parent_issue_id = copied_issues[child.parent_id].id
|
| 1804 |
1804 |
unless child.fixed_version.present? && child.fixed_version.status == 'open'
|
| 1805 |
1805 |
copy.fixed_version_id = nil
|
| 1806 |
1806 |
end
|
| ... | ... | |
| 1818 |
1818 |
end
|
| 1819 |
1819 |
next
|
| 1820 |
1820 |
end
|
| 1821 |
|
copied_issue_ids[child.id] = copy.id
|
|
1821 |
copied_issues[child.id] = copy
|
|
1822 |
end
|
|
1823 |
|
|
1824 |
# Replicate dependencies between copied children
|
|
1825 |
@copied_from.reload.descendants.reorder("#{Issue.table_name}.lft").each do |child|
|
|
1826 |
copy = copied_issues[child.id]
|
|
1827 |
next unless copy
|
|
1828 |
child.relations_to.each do |rel|
|
|
1829 |
next unless copied_issues.key?(rel.issue_from.id)
|
|
1830 |
from = Issue.find_by_id(copied_issues[rel.issue_from.id].id)
|
|
1831 |
next unless from
|
|
1832 |
relation = IssueRelation.new(:issue_from => from, :issue_to => copy, :relation_type => rel.relation_type)
|
|
1833 |
unless relation.save
|
|
1834 |
logger.error "Could not create relation while copying ##{child.id} to ##{copy.id} due to validation errors: #{relation.errors.full_messages.join(', ')}" if logger
|
|
1835 |
end
|
|
1836 |
end
|
| 1822 |
1837 |
end
|
| 1823 |
1838 |
end
|
| 1824 |
1839 |
@after_create_from_copy_handled = true
|