We use cookies to improve your experience. No personal information is gathered and we don't serve ads. Cookies Policy.

ExpressionEngine Logo ExpressionEngine
Features Pricing Support Find A Developer
Partners Upgrades
Blog Add-Ons Learn
Docs Forums University
Log In or Sign Up
Log In Sign Up
ExpressionEngine Logo
Features Pro new Support Find A Developer
Partners Upgrades
Blog Add-Ons Learn
Docs Forums University Blog
  • Home
  • Forums

Easy to create infinite loops with new channel hooks

Developer Preview

Low's avatar
Low
407 posts
10 years ago
Low's avatar Low

They way the hooks are triggered, it’s quite easy to create an infinite loop.

For example, say you use the after_channel_entry_save hook to update another entry’s data. If, in your extension, you use a Model to change the data of that entry, that entry’s hook will fire.

This can also occur if you change an entry in a field type’s post_save method.

I’m sure you could work around the issue, but I reckon it’s fairly easy (maybe too easy) to create infinite loops like this.

       
Pascal Kriete's avatar
Pascal Kriete
2,589 posts
10 years ago
Pascal Kriete's avatar Pascal Kriete

We discussed it while building them, but there is no good way around it. If it fires on all data manipulations, which is what we want, people will find bad ways to manipulate that data and cause loops.

Both the extensions library and the models themselves try to mitigate those problems, but at the end of the day you could do it with the old hooks as well.

The easiest way to avoid them is to prefer the before* hooks. Modifications in there will get saved automatically.

       
Low's avatar
Low
407 posts
10 years ago
Low's avatar Low

I’m currently seeing this in a custom field type, where I want to change the entry’s entry/expiration dates based on the field type’s value. Right now, I’m doing this in the post_save method. I would do this in the save method instead, but I don’t have access to the parent entry then. So…

FR: a way to manipulate the Entry model in the save method of a field type.

For now, I’ll just continue using Active Record to change those values.

       

Reply

Sign In To Reply

ExpressionEngine Home Features Pro Contact Version Support
Learn Docs University Forums
Resources Support Add-Ons Partners Blog
Privacy Terms Trademark Use License

Packet Tide owns and develops ExpressionEngine. © Packet Tide, All Rights Reserved.