Project

General

Profile

Feature #3055 » duplicate_issues_attachment.diff

Preethi Sriram, 2012-01-17 01:14

View differences:

app/models/journal.rb (working copy)
def notify=(arg)
@notify = arg
end
# copies a set of journal notes from one object to another
def self.copy_notes(objToId, objFromId)
transaction do
connection.insert "INSERT INTO #{Journal.table_name} (journalized_id,journalized_type,user_id,notes,created_on)" +
" SELECT #{objToId}, journalized_type,user_id,notes,created_on" +
" FROM #{Journal.table_name}" +
" WHERE journalized_id = #{objFromId}"
end
true
end
end
app/models/issue.rb (working copy)
self.attributes = issue.attributes.dup.except("id", "root_id", "parent_id", "lft", "rgt", "created_on", "updated_on")
self.custom_field_values = issue.custom_field_values.inject({}) {|h,v| h[v.custom_field_id] = v.value; h}
self.status = issue.status
self
end
# copies attachments from one issue to another
def copy_attachment(arg)
issue = arg.is_a?(Issue) ? arg : Issue.visible.find(arg)
if issue.attachments.any?
Attachment.copy_files(id,issue.id)
end
end
def copy_notes(arg)
issue = arg.is_a?(Issue) ? arg : Issue.visible.find(arg)
if issue.journals.present?
Journal.copy_notes(id,issue.id)
end
end
# Moves/copies an issue to a new project and tracker
# Returns the moved/copied issue on success, false on failure
def move_to_project(*args)
app/models/attachment.rb (working copy)
end
{:files => attached, :unsaved => obj.unsaved_attachments}
end
# copies a set of files attached from one object to another
def self.copy_files(objToId, objFromId)
transaction do
connection.insert "INSERT INTO #{Attachment.table_name} (container_id,container_type,filename,disk_filename,filesize,content_type,digest,downloads,author_id,created_on,description)" +
" SELECT #{objToId}, container_type,filename,disk_filename,filesize,content_type,digest,downloads,author_id,created_on,description" +
" FROM #{Attachment.table_name}" +
" WHERE container_id = #{objFromId}"
end
true
end
private
def sanitize_filename(value)
app/controllers/issues_controller.rb (working copy)
# Add a new issue
# The new issue will be created from an existing one if copy_from parameter is given
def new
respond_to do |format|
format.html { render :action => 'new', :layout => !request.xhr? }
format.js { render :partial => 'attributes' }
if params[:copy_from]
respond_to do |format|
format.html { render :action => 'new',:copy_from => params[:copy_from], :layout => !request.xhr? }
format.js { render :partial => 'attributes' }
end
else
respond_to do |format|
format.html { render :action => 'new', :layout => !request.xhr? }
format.js { render :partial => 'attributes' }
end
end
end
def create
call_hook(:controller_issues_new_before_save, { :params => params, :issue => @issue })
if @issue.save
@issue.copy_attachment(params[:copy_from]) if params[:copy_from]
@issue.copy_notes(params[:copy_from]) if params[:copy_from]
attachments = Attachment.attach_files(@issue, params[:attachments])
render_attachment_warning_if_needed(@issue)
flash[:notice] = l(:notice_successful_create)
app/views/issues/new.rhtml (working copy)
<h2><%=l(:label_issue_new)%></h2>
<% labelled_tabular_form_for :issue, @issue, :url => {:controller => 'issues', :action => 'create', :project_id => @project},
<% labelled_tabular_form_for :issue, @issue, :url => {:controller => 'issues', :action => 'create',:copy_from => params[:copy_from], :project_id => @project},
:html => {:multipart => true, :id => 'issue-form', :class => 'tabular new-issue-form'} do |f| %>
<%= error_messages_for 'issue' %>
<div class="box">
(1-1/4)