Commit 3f3e30c2 authored by Eric Davis's avatar Eric Davis

Refactor: Moved the contents of #issue_update into Issue.

git-svn-id: svn+ssh://rubyforge.org/var/svn/redmine/trunk@3545 e93f8b46-1217-0410-a6f0-8f06a7374b81
parent 69769e1d
......@@ -199,13 +199,25 @@ class IssuesController < ApplicationController
def update
update_issue_from_params
if issue_update
if @issue.save_issue_with_child_records(params, @time_entry)
render_attachment_warning_if_needed(@issue)
if !@issue.current_journal.new_record?
# Only send notification if something was actually changed
flash[:notice] = l(:notice_successful_update)
end
respond_to do |format|
format.html { redirect_back_or_default({:action => 'show', :id => @issue}) }
format.xml { head :ok }
end
else
render_attachment_warning_if_needed(@issue)
if !@issue.current_journal.new_record?
# Only send notification if something was actually changed
flash[:notice] = l(:notice_successful_update)
end
@journal = @issue.current_journal
respond_to do |format|
format.html { render :action => 'edit' }
format.xml { render :xml => @issue.errors, :status => :unprocessable_entity }
......@@ -562,32 +574,4 @@ private
end
end
# TODO: Temporary utility method for #update. Should be split off
# and moved to the Issue model (accepts_nested_attributes_for maybe?)
def issue_update
if params[:time_entry] && params[:time_entry][:hours].present? && User.current.allowed_to?(:log_time, @project)
@time_entry = TimeEntry.new(:project => @project, :issue => @issue, :user => User.current, :spent_on => Date.today)
@time_entry.attributes = params[:time_entry]
@issue.time_entries << @time_entry
end
if @issue.valid?
attachments = Attachment.attach_files(@issue, params[:attachments])
render_attachment_warning_if_needed(@issue)
attachments[:files].each {|a| @issue.current_journal.details << JournalDetail.new(:property => 'attachment', :prop_key => a.id, :value => a.filename)}
call_hook(:controller_issues_edit_before_save, { :params => params, :issue => @issue, :time_entry => @time_entry, :journal => @issue.current_journal})
if @issue.save
if !@issue.current_journal.new_record?
# Only send notification if something was actually changed
flash[:notice] = l(:notice_successful_update)
end
call_hook(:controller_issues_edit_after_save, { :params => params, :issue => @issue, :time_entry => @time_entry, :journal => @issue.current_journal})
return true
end
end
# failure, returns false
end
end
......@@ -394,6 +394,34 @@ class Issue < ActiveRecord::Base
s
end
# Saves an issue, time_entry, attachments, and a journal from the parameters
def save_issue_with_child_records(params, existing_time_entry=nil)
if params[:time_entry] && params[:time_entry][:hours].present? && User.current.allowed_to?(:log_time, project)
@time_entry = existing_time_entry || TimeEntry.new
@time_entry.project = project
@time_entry.issue = self
@time_entry.user = User.current
@time_entry.spent_on = Date.today
@time_entry.attributes = params[:time_entry]
self.time_entries << @time_entry
end
if valid?
attachments = Attachment.attach_files(self, params[:attachments])
attachments[:files].each {|a| @current_journal.details << JournalDetail.new(:property => 'attachment', :prop_key => a.id, :value => a.filename)}
# TODO: Rename hook
Redmine::Hook.call_hook(:controller_issues_edit_before_save, { :params => params, :issue => self, :time_entry => @time_entry, :journal => @current_journal})
if save
# TODO: Rename hook
Redmine::Hook.call_hook(:controller_issues_edit_after_save, { :params => params, :issue => self, :time_entry => @time_entry, :journal => @current_journal})
return true
end
end
# failure, returns false
end
# Unassigns issues from +version+ if it's no longer shared with issue's project
def self.update_versions_from_sharing_change(version)
# Update issues assigned to the version
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment