How to Create Issue with Hook "controller_issues_new_after_save"
Added by Tobias Turschner over 2 years ago
Hi, I'm trying to create an Issue with changes after an Issue is created.
No new Issue is created and no error is in the log.
My code so far:
def controller_issues_new_before_save(context={})
$IssueProject = context[:issue].project
$IssueAuthor = context[:issue].author
$IssueTracker = context[:issue].tracker
$IssueDescription = context[:issue].description
end
def controller_issues_new_after_save(context={})
Issue.new(
:author => $IssueAuthor,
:project => $IssueProject,
:tracker => $IssueTracker,
:description => $IssueDescription + "Change"
)
end
I read https://www.rubydoc.info/github/redmine/redmine/Issue but I can't figure out the problem.
I hope someone can enlighten me.
Replies (3)
RE: How to Create Issue with Hook "controller_issues_new_after_save" - Added by Mischa The Evil over 2 years ago
- why do you use global variables here?
new
method only creates the object but doesn't save it1.
I've also fixed some formatting in your post btw...
1 https://stackoverflow.com/questions/9791386/differences-in-rails-between-new-save-and-create
RE: How to Create Issue with Hook "controller_issues_new_after_save" - Added by Tobias Turschner over 2 years ago
Thank you for the formatting and response.
I used global variables, because I had some issue with the instance variables together with the constructor call .new.
I see makes sense.
I will write my solution here, if I have figured it out.
RE: How to Create Issue with Hook "controller_issues_new_after_save" - Added by Tobias Turschner over 2 years ago
I'm wondering how I can create serveral Issues within the hook.
Because context[:issue].save()
is executed serveral times but only the end result is in the database and shown.
Can someone help me to figure out how I can create a .save
put it in the database then change some variables and store it again?
Basically clone the Issue just with a different ID.