Fixed that controller_issues_edit_before/after_save hooks have no controller context (#15044).
Patch by Jordan Hollinger. git-svn-id: svn+ssh://rubyforge.org/var/svn/redmine/trunk@12219 e93f8b46-1217-0410-a6f0-8f06a7374b81
This commit is contained in:
parent
58c69b8123
commit
94e7df78ca
|
@ -181,7 +181,7 @@ class IssuesController < ApplicationController
|
||||||
@issue.save_attachments(params[:attachments] || (params[:issue] && params[:issue][:uploads]))
|
@issue.save_attachments(params[:attachments] || (params[:issue] && params[:issue][:uploads]))
|
||||||
saved = false
|
saved = false
|
||||||
begin
|
begin
|
||||||
saved = @issue.save_issue_with_child_records(params, @time_entry)
|
saved = save_issue_with_child_records
|
||||||
rescue ActiveRecord::StaleObjectError
|
rescue ActiveRecord::StaleObjectError
|
||||||
@conflict = true
|
@conflict = true
|
||||||
if params[:last_journal_id]
|
if params[:last_journal_id]
|
||||||
|
@ -452,4 +452,26 @@ class IssuesController < ApplicationController
|
||||||
end
|
end
|
||||||
attributes
|
attributes
|
||||||
end
|
end
|
||||||
|
|
||||||
|
# Saves @issue and a time_entry from the parameters
|
||||||
|
def save_issue_with_child_records
|
||||||
|
Issue.transaction do
|
||||||
|
if params[:time_entry] && (params[:time_entry][:hours].present? || params[:time_entry][:comments].present?) && User.current.allowed_to?(:log_time, @issue.project)
|
||||||
|
time_entry = @time_entry || TimeEntry.new
|
||||||
|
time_entry.project = @issue.project
|
||||||
|
time_entry.issue = @issue
|
||||||
|
time_entry.user = User.current
|
||||||
|
time_entry.spent_on = User.current.today
|
||||||
|
time_entry.attributes = params[:time_entry]
|
||||||
|
@issue.time_entries << time_entry
|
||||||
|
end
|
||||||
|
|
||||||
|
call_hook(:controller_issues_edit_before_save, { :params => params, :issue => @issue, :time_entry => time_entry, :journal => @issue.current_journal})
|
||||||
|
if @issue.save
|
||||||
|
call_hook(:controller_issues_edit_after_save, { :params => params, :issue => @issue, :time_entry => time_entry, :journal => @issue.current_journal})
|
||||||
|
else
|
||||||
|
raise ActiveRecord::Rollback
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -1087,30 +1087,6 @@ class Issue < ActiveRecord::Base
|
||||||
s
|
s
|
||||||
end
|
end
|
||||||
|
|
||||||
# Saves an issue and a time_entry from the parameters
|
|
||||||
def save_issue_with_child_records(params, existing_time_entry=nil)
|
|
||||||
Issue.transaction do
|
|
||||||
if params[:time_entry] && (params[:time_entry][:hours].present? || params[:time_entry][:comments].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 = User.current.today
|
|
||||||
@time_entry.attributes = params[:time_entry]
|
|
||||||
self.time_entries << @time_entry
|
|
||||||
end
|
|
||||||
|
|
||||||
# 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})
|
|
||||||
else
|
|
||||||
raise ActiveRecord::Rollback
|
|
||||||
end
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
# Unassigns issues from +version+ if it's no longer shared with issue's project
|
# Unassigns issues from +version+ if it's no longer shared with issue's project
|
||||||
def self.update_versions_from_sharing_change(version)
|
def self.update_versions_from_sharing_change(version)
|
||||||
# Update issues assigned to the version
|
# Update issues assigned to the version
|
||||||
|
|
Loading…
Reference in New Issue