Feature #3055 » duplicate_issues_attachment.diff
| app/models/journal.rb (working copy) | ||
|---|---|---|
| 85 | 85 |
def notify=(arg) |
| 86 | 86 |
@notify = arg |
| 87 | 87 |
end |
| 88 |
|
|
| 89 |
# copies a set of journal notes from one object to another |
|
| 90 |
def self.copy_notes(objToId, objFromId) |
|
| 91 |
transaction do |
|
| 92 |
connection.insert "INSERT INTO #{Journal.table_name} (journalized_id,journalized_type,user_id,notes,created_on)" +
|
|
| 93 |
" SELECT #{objToId}, journalized_type,user_id,notes,created_on" +
|
|
| 94 |
" FROM #{Journal.table_name}" +
|
|
| 95 |
" WHERE journalized_id = #{objFromId}"
|
|
| 96 |
|
|
| 97 |
|
|
| 98 |
end |
|
| 99 |
true |
|
| 100 |
end |
|
| 88 | 101 |
end |
| app/models/issue.rb (working copy) | ||
|---|---|---|
| 136 | 136 |
self.attributes = issue.attributes.dup.except("id", "root_id", "parent_id", "lft", "rgt", "created_on", "updated_on")
|
| 137 | 137 |
self.custom_field_values = issue.custom_field_values.inject({}) {|h,v| h[v.custom_field_id] = v.value; h}
|
| 138 | 138 |
self.status = issue.status |
| 139 |
|
|
| 139 | 140 |
self |
| 140 | 141 |
end |
| 141 | ||
| 142 |
# copies attachments from one issue to another |
|
| 143 |
def copy_attachment(arg) |
|
| 144 |
|
|
| 145 |
issue = arg.is_a?(Issue) ? arg : Issue.visible.find(arg) |
|
| 146 |
|
|
| 147 |
if issue.attachments.any? |
|
| 148 |
Attachment.copy_files(id,issue.id) |
|
| 149 |
end |
|
| 150 |
|
|
| 151 |
end |
|
| 152 |
|
|
| 153 |
def copy_notes(arg) |
|
| 154 |
issue = arg.is_a?(Issue) ? arg : Issue.visible.find(arg) |
|
| 155 |
|
|
| 156 |
if issue.journals.present? |
|
| 157 |
Journal.copy_notes(id,issue.id) |
|
| 158 |
end |
|
| 159 |
|
|
| 160 |
end |
|
| 142 | 161 |
# Moves/copies an issue to a new project and tracker |
| 143 | 162 |
# Returns the moved/copied issue on success, false on failure |
| 144 | 163 |
def move_to_project(*args) |
| app/models/attachment.rb (working copy) | ||
|---|---|---|
| 160 | 160 |
end |
| 161 | 161 |
{:files => attached, :unsaved => obj.unsaved_attachments}
|
| 162 | 162 |
end |
| 163 |
|
|
| 164 |
# copies a set of files attached from one object to another |
|
| 165 |
def self.copy_files(objToId, objFromId) |
|
| 166 |
transaction do |
|
| 167 |
connection.insert "INSERT INTO #{Attachment.table_name} (container_id,container_type,filename,disk_filename,filesize,content_type,digest,downloads,author_id,created_on,description)" +
|
|
| 168 |
" SELECT #{objToId}, container_type,filename,disk_filename,filesize,content_type,digest,downloads,author_id,created_on,description" +
|
|
| 169 |
" FROM #{Attachment.table_name}" +
|
|
| 170 |
" WHERE container_id = #{objFromId}"
|
|
| 171 |
end |
|
| 172 |
true |
|
| 173 |
end |
|
| 163 | 174 | |
| 164 | 175 |
private |
| 165 | 176 |
def sanitize_filename(value) |
| app/controllers/issues_controller.rb (working copy) | ||
|---|---|---|
| 129 | 129 |
# Add a new issue |
| 130 | 130 |
# The new issue will be created from an existing one if copy_from parameter is given |
| 131 | 131 |
def new |
| 132 |
respond_to do |format| |
|
| 133 |
format.html { render :action => 'new', :layout => !request.xhr? }
|
|
| 134 |
format.js { render :partial => 'attributes' }
|
|
| 132 |
if params[:copy_from] |
|
| 133 |
respond_to do |format| |
|
| 134 |
format.html { render :action => 'new',:copy_from => params[:copy_from], :layout => !request.xhr? }
|
|
| 135 |
format.js { render :partial => 'attributes' }
|
|
| 136 |
end |
|
| 137 |
|
|
| 138 |
else |
|
| 139 |
respond_to do |format| |
|
| 140 |
format.html { render :action => 'new', :layout => !request.xhr? }
|
|
| 141 |
format.js { render :partial => 'attributes' }
|
|
| 142 |
end |
|
| 135 | 143 |
end |
| 136 | 144 |
end |
| 137 | 145 | |
| 138 | 146 |
def create |
| 147 |
|
|
| 139 | 148 |
call_hook(:controller_issues_new_before_save, { :params => params, :issue => @issue })
|
| 140 | 149 |
if @issue.save |
| 150 |
@issue.copy_attachment(params[:copy_from]) if params[:copy_from] |
|
| 151 |
@issue.copy_notes(params[:copy_from]) if params[:copy_from] |
|
| 141 | 152 |
attachments = Attachment.attach_files(@issue, params[:attachments]) |
| 142 | 153 |
render_attachment_warning_if_needed(@issue) |
| 143 | 154 |
flash[:notice] = l(:notice_successful_create) |
| app/views/issues/new.rhtml (working copy) | ||
|---|---|---|
| 1 | 1 |
<h2><%=l(:label_issue_new)%></h2> |
| 2 | 2 | |
| 3 |
<% labelled_tabular_form_for :issue, @issue, :url => {:controller => 'issues', :action => 'create', :project_id => @project},
|
|
| 3 |
<% labelled_tabular_form_for :issue, @issue, :url => {:controller => 'issues', :action => 'create',:copy_from => params[:copy_from], :project_id => @project},
|
|
| 4 | 4 |
:html => {:multipart => true, :id => 'issue-form', :class => 'tabular new-issue-form'} do |f| %>
|
| 5 | 5 |
<%= error_messages_for 'issue' %> |
| 6 | 6 |
<div class="box"> |
| 7 | 7 | |