Forums » Development »
Hook plugin help
Added by Pedro Braz about 11 years ago
Hello.
I need create a process what create one project for each issue that specific kind os track created.
I create a plugin and use the Hook controller_issues_new_after_save:
module GeradorProjetos
class Hooks < Redmine::Hook::ViewListener
def controller_issues_new_after_save(context={ })
tracker_id = issue[:tracker_id]
case tracker_id
when 2
params[:project] = {"name"=>issue[:subject],
"description"=>issue[:subject],
"homepage"=>issue[:subject],
"is_public"=>"0",
"parent_id"=>issue[:project_id],
"identifier"=>issue[:subject],
"tracker_ids"=>["2", "6"]}
ProjectsController.create
end
end
end
end
How i use the ProjectsController to create this project?
Replies (3)
RE: Hook plugin help - Added by Martin Denizet (redmine.org team member) about 11 years ago
Hello Pedro,
You could try:
new_project = Projet.new( :name => issue[:subject], :description => issue[:subject], :homepage => issue[:subject], :is_public => false, :parent_id => issue[:project_id], :identifier => issue[:subject], :tracker_ids => [ 2, 6 ] ) if new_project.save flash[:notice]= "Success" else flash[:error]= "Failure" end
Note that the identifier should be lower case without spaces. You should apply a slug function to it. There is one in Redmine but I didn't take the time to look for its name.
Cheers,
Martin
RE: Hook plugin help - Added by Martin Denizet (redmine.org team member) about 11 years ago
Glad I could help!
You could endorse me on CoderWall, that would be appreciated!
Cheers!