theforeman / foreman_hooks

Run custom hook scripts on Foreman events
http://m0dlx.com/blog/Extending_Foreman_quickly_with_hook_scripts.html
GNU General Public License v3.0
56 stars 50 forks source link

hooks should be called before delete data #50

Closed pronix closed 6 years ago

pronix commented 6 years ago

before_destroy hooks will not receive parameters because they was deleted early. this patch call hook before delete parameters.

pronix commented 6 years ago

@domcleal please, check it.

sean797 commented 6 years ago

@pronix Sorry no one has picked this up already.

I'm not sure this is the correct solution, prepend: true will probably not be what is expected for after_create hooks, maybe others and might even cause problems in some cases.

I'm think prepend: true makes sense for any before_* hook. What do you think?

pronix commented 6 years ago

hello @sean797 quote from http://api.rubyonrails.org/classes/ActiveRecord/Callbacks.html

In this case, the problem is that when the before_destroy callback is executed, the children are not available because the ActiveRecord::Base#destroy callback gets executed first. You can use the prepend option on the before_destroy callback to avoid this.

so we can working with parameters before they will deleted.

sean797 commented 6 years ago

@pronix Yes, I get that, what I'm saying is if prepend: true is set for other hooks like after_create that could cause issues if a users hook depends on other callbacks within Foreman or plugins.

pronix commented 6 years ago

@sean797 got it. i will fix it. thanks

pronix commented 6 years ago

@sean797 check it please.

pronix commented 6 years ago

@sean797 fixed.check please.