Vote #64409
完了Hooks for IssuesController
100%
説明
I have been tasked with providing a plugin to allow Redmine to act as a controller for a 3rd party VCS system's built in issue tracker. In order to reduce situations where orphaned issue records could be created in the 3rd party tool, Hook events need to be called After issues have been saved in Redmine.
At present, I have modified my own Redmine installation's @issues_controller.rb@ file to provide hooks in the @new()@ and @edit()@ methods of the @IssuesController@ class, directly after the @redirect_to@ statements in those methods.
In the @add()@ method, I have done the following:
...
if @issue.save
attach_files(@issue, params[:attachments])
flash[:notice] = l(:notice_successful_create)
Mailer.deliver_issue_add(@issue) if Setting.notified_events.include?('issue_added')
redirect_to :controller => 'issues', :action => 'show', :id => @issue
#
call_hook(:controller_issues_new_after_save, { :issue => @issue })
#
return
end
...
... and in @edit()@:
...
if !journal.new_record?
# Only send notification if something was actually changed
flash[:notice] = l(:notice_successful_update)
Mailer.deliver_issue_edit(journal) if Setting.notified_events.include?('issue_updated')
end
redirect_to(params[:back_to] || {:action => 'show', :id => @issue})
#
call_hook(:controller_issues_edit_after_save, { :params => params, :issue => @issue, :time_entry => @time_entry, :journal => journal})
#
...
For my own most immediate requirements, this is the minimum I have needed to get the job done, and would very much appreciate if the feature could be added to future releases of Redmine, as this would save me needing to edit Redmine source whenever a new version is release.
I can however envisage situations where before and after events could be needed for issue creation, editing, deletion, or possibly anywhere that issue record changes are submitted.
Thanks.
Sean
journals
I'll add some hooks in there. I might move them a bit, I think they should run before any redirects.
--------------------------------------------------------------------------------
I've added the hooks in r2261. If you need any other hooks, go ahead and open a new issue for them and assign it to me.
--------------------------------------------------------------------------------
Eric, the revision @2261 associated with this issue (for the version 0.8.1) wasn't yet merged into 0.8-branche. I was using (:controller_issues_new_after_save, :controller_issues_edit_after_save) api hooks for issues controller using 0.8-branche and them simply did not work.
I make a svn diff to last revision of the 0.8-branche (@2900) and to revision @2261 showing that which was put in your revision wasnt find in 0.8-branche.
@@ -147,8 +147,8 @@
attach_files(@issue, params[:attachments])
flash[:notice] = l(:notice_successful_create)
Mailer.deliver_issue_add(@issue) if Setting.notified_events.include?('i
ssue_added')
- redirect_to(params[:continue] ? { :action => 'new', :tracker_id => @iss
ue.tracker } :
- { :action => 'show', :id => @issue })
+ call_hook(:controller_issues_new_after_save, { :params => params, :issu
e => @issue})
+ redirect_to :controller => 'issues', :action => 'show', :id => @issue
return
end
end
@@ -194,6 +194,7 @@
flash[:notice] = l(:notice_successful_update)
Mailer.deliver_issue_edit(journal) if Setting.notified_events.include
?('issue_updated')
end
+ call_hook(:controller_issues_edit_after_save, { :params => params, :iss
ue => @issue, :time_entry => @time_entry, :journal => journal})
redirect_to(params[:back_to] || {:action => 'show', :id => @issue})
end
end
--------------------------------------------------------------------------------
--------------------------------------------------------------------------------
Merged in 0.8-stable in r2997.
--------------------------------------------------------------------------------
related_issues
relates,Closed,3118,hook controller_issues_new_after_save is missing from issues_controller