Archived Support Site

This support site is archived. You can view the old support discussions but you cannot post new discussions.

Add hook or ability to send email when entry goes live/published.

Tim Kelty's Avatar

Tim Kelty

30 Jul, 2013 06:39 PM

I have clients that want to send internal emails when entries in specific channels are first made live.

It would be great to add this option, or add a hook so I could make an extension!

  1. Support Staff 1 Posted by Malcolm Elswort... on 05 Aug, 2013 05:12 PM

    Malcolm Elsworth's Avatar

    Hi Tim,

    As BWF uses the standard EE Publishing process for an entry before it is set live, it would be possible to use a standard EE hook to achieve this.

    For example, if you used the entry_submission_absolute_end hook you could check for a status of 'open', and then check that there wasn't a BWF draft for that entry. These two pieces of data would tell you this was a first time publish and you could trigger your custom event.

    Hope that's helpful.

    Best wishes,
    Malcolm

  2. 2 Posted by Tim Kelty on 05 Aug, 2013 05:30 PM

    Tim Kelty's Avatar

    Helpful indeed, thanks!

  3. 3 Posted by Tim Kelty on 06 Aug, 2013 07:38 PM

    Tim Kelty's Avatar

    Using entry_submission_absolute_end, it would seem $meta['status'] always comes through as an empty string with BWF installed.

    I see the status in $data['epBwfEntry_create_open'], should I use that?

  4. Support Staff 4 Posted by Malcolm Elswort... on 07 Aug, 2013 12:53 PM

    Malcolm Elsworth's Avatar

    Hi Tim,

    Yes, 'epBwfEntry_create_open' is a reliable way to determine a first time publish.

    Thanks,
    Malcolm

  5. 5 Posted by Tim on 07 Aug, 2013 09:02 PM

    Tim's Avatar

    Unless I'm missing something, it doesn't appear that I have what I need to achieve this.

    While I can test against epBwfEntry_create_open for a first-time publish, I also need to look for epBwfEntry_update_open, in the event that an entry was first saved as a draft, and then published.

    Checking that there isn't a draft in exp_ep_entry_drafts as well works, but that only happens if something was published, and then saved as a draft. With that check, a subsequent publish wouldn't trigger this, but that's all.

    That leaves me with no way to determine if this is a "first-time" Publish in these scenarios:

    * Entry is Published, edited, and published again
    * Entry is saved as a draft, published, and published again.

  6. Support Staff 6 Posted by Malcolm Elswort... on 08 Aug, 2013 10:08 AM

    Malcolm Elsworth's Avatar

    Hi Tim,

    Strictly speaking, both the scenarios you have described do not constitute 'first-time' publishes. Unless you start comparing dates there would be no way to know whether the second publish occurred moments after the fist or months later.

    If you can be very specific about what you want to achieve we can probably fine a way to help you.

    Best wishes,
    Malcolm

  7. 7 Posted by Tim Kelty on 08 Aug, 2013 12:55 PM

    Tim Kelty's Avatar

    Sorry, let me try to clarify.

    I know the scenarios I listed don't constitute "first-time" publishes. The problem I'm having now is NOT triggering my functionality in those cases.

    The client wants an internal promotional email to go out when something is published for the first time.

    The trouble I'm having is determining whether or not it is the first time or not. If I just check for epBwfEntry_create_open, subsequent Publishes (which would use epBwfEntry_update_open) would be correctly ignored. However, this would also incorrectly ignore entries that were initially saved as a draft (epBwfEntry_create_open = draft), and then Published (epBwfEntry_update_open = open).

    I can check that there "wasn't a BWF draft for that entry", as you suggested, but it appears a draft is only created when a published entry get a draft saved. So the only situation that would account for is: entry is published, draft is saved, entry is published again...and my extension would correctly not send the email because a draft existed.

    I think if I knew the incoming ee status of an entry I could figure it out, but I don't see an easy way to access that before it's changed. That way, if the initial ee status was draft, I would know this was a unpublished draft. And if it was open, I'd know it was already published before.

    I hope that all makes sense,
    Thanks again for all your help!

  8. 8 Posted by Tim Kelty on 08 Aug, 2013 09:38 PM

    Tim Kelty's Avatar

    So I ended up achieving what I needed to this way:

    To capture the incoming/initial status, I had to set a static property in a `entry_submission_ready` hook.

    Then, in my `entry_submission_absolute_end` hook, my check looks like:
    @@@
    $first_publish = ($bwf_status == 'open' && self::$incoming_status != 'open' && !$this->draft_exists($entry_id)) ? true : false;
    @@@
    Works, but seems like a lot of hoops to jump through. Let me know if you know a better way.

  9. Support Staff 9 Posted by Malcolm Elswort... on 13 Aug, 2013 04:02 PM

    Malcolm Elsworth's Avatar

    Hi Tim,

    Glad you found a way to get this to work, this looks like a good solution.

    Going to close this ticket out but do re-open if you need any further help with this.

    Best wishes,
    Malcolm

  10. Malcolm Elsworth closed this discussion on 13 Aug, 2013 04:02 PM.

Comments are currently closed for this discussion. You can start a new one.

Keyboard shortcuts

Generic

? Show this help
ESC Blurs the current field

Comment Form

r Focus the comment reply box
^ + ↩ Submit the comment

You can use Command ⌘ instead of Control ^ on Mac