Skip to content

The after_channel_entry_save event hook is called twice for every add-on using it #248

Closed

Description

@litzinger

Description of the problem
It appears the after_channel_entry_save hook is getting called twice for every add-on using it, even if there is only 1 row per add-on in the exp_extensions table for the hook.

How To Reproduce
Install an add-on using that hook, step debug, or log to file inside the add-on's method using the hook and you'll see it gets called twice every time an entry is saved. I tested this with 1 add-on installed, then a 2nd add-on, and they both have their after_channel_entry_save hook called twice. I also tested this in two different EE environments. One using 5.2.3, and another 5.2.4.

Environment Details:

  • Version: 5.2.3 & 5.2.4
  • PHP Version 7.2
  • MySQL Version 5.6
  • OS: macOS
  • Web Server: Apache (vagrant machine)

Activity

  1. derekjones commented on Jul 3, 2019

    @derekjones

    Curious. Are either of those add-ons calling a new save() on the model?

  2. added
    Bug: Unconfirmed
    on Jul 3, 2019
  3. litzinger commented on Jul 3, 2019

    @litzinger
    ContributorAuthor

    Nope, one of the is Reading Time Pro, and there are no instances of ->save in its codebase. Publisher does call save on some models, but I commented those calls out while testing and it didn't make a difference... the hook was still called twice.

  4. litzinger commented on Jul 3, 2019

    @litzinger
    ContributorAuthor

    Ok, I uninstalled Publisher and just tested RTP, and it wasn't called twice. So maybe it was a Publisher issue, but I can't pinpoint it yet.

  5. litzinger commented on Jul 3, 2019

    @litzinger
    ContributorAuthor

    I take that back. When creating a new entry, the hook in RTP is called twice. When editing it is called once. Publisher is not installed.

  6. derekjones commented on Jul 8, 2019

    @derekjones

    Is this occurring with the latest public release of Reading Time Pro so I can replicate or just in dev?

  7. litzinger commented on Jul 8, 2019

    @litzinger
    ContributorAuthor

    Yes it is.

  8. derekjones commented on Jul 8, 2019

    @derekjones

    Can you double check to see if you have two rows for that hook and method in your exp_extensions table? At the top of your method, I added:

    file_put_contents('/path/to/file/logit.txt', "\nHere at: ".ee()->localize->now, FILE_APPEND);
    

    Watching the file live while saving, it only adds a single line for each save.

  9. derekjones commented on Jul 8, 2019

    @derekjones

    Scratch that, reading comprehension. I'm also seeing the redundancy you are on new entries.

  10. added
    Bug: Accepted
    and removed
    Bug: Unconfirmed
    on Jul 8, 2019
  11. dougblackjr commented on Jan 16, 2020

    @dougblackjr
    Contributor

    Added PR #352 to address this one. I'm not sure it's the most elegant solution, so I invite feedback.

  12. added a commit that references this issue on Mar 24, 2020
    32e1744
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Bug: Accepted

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions