I'm implementing a mechanism where website visitors (not members, not admins) can ask to be sent an email when new node is published.
The correct time to send the email notification is I believe on the event:
umbraco.content.AfterClearDocumentCache += ...
Because the node must be published and updated in the document cache before I can call NiceUrl.
However I also want to update a flag to say I've sent the email, and the correct place to set that flag is I believe on the event:
Document.BeforePublish += ...
The reason I need to do it here, is if I do it AfterPublish the property in the UI admin form is not updated, and the user can hit publish again and it will send the email all over again.
I can think of a couple of ugly solutions I could try, such as:
putting the flag in the request.context.items
Do everything BeforePublish and send the nodeID in the email and having a redirect rule on the site to push them to the correct url.
But if anyone has a better idea, or input on which of the above will work better, let me know.
I do it simply like this: If an e-mail needs to be sent, the editor sets a checkbox to true, during afterpublish the e-mail gets sent AND the checkbox gets set to false again. This is a save event, not a publish event, therefore you don't get into a loop.
from my experience any property value you set in the AfterPublish Event will not show in the UI on postback. If you reload from the tree, you will see the change, but you will not see the change on postback, when you click save and publish from the tool bar.
Email Notification OnPublish Catch 22
Hi
I'm implementing a mechanism where website visitors (not members, not admins) can ask to be sent an email when new node is published.
The correct time to send the email notification is I believe on the event:
Because the node must be published and updated in the document cache before I can call NiceUrl.
However I also want to update a flag to say I've sent the email, and the correct place to set that flag is I believe on the event:
The reason I need to do it here, is if I do it AfterPublish the property in the UI admin form is not updated, and the user can hit publish again and it will send the email all over again.
I can think of a couple of ugly solutions I could try, such as:
But if anyone has a better idea, or input on which of the above will work better, let me know.
Cheers.
Murray.
I do it simply like this: If an e-mail needs to be sent, the editor sets a checkbox to true, during afterpublish the e-mail gets sent AND the checkbox gets set to false again. This is a save event, not a publish event, therefore you don't get into a loop.
from my experience any property value you set in the AfterPublish Event will not show in the UI on postback. If you reload from the tree, you will see the change, but you will not see the change on postback, when you click save and publish from the tool bar.
Yep, which is why I save the url in the context items and refresh the page afterwards, so all the way at the end of my eventhandler I do this:
And the in the PreRender handler I refresh the page:
Yes, this is an awkward little hack, but it has worked very well for me so far. :)
yep, I did an awkward hack too, so you may like it:-)
My requirements are slightly different in that sending an email is the default behaviour
For some reason AfterClearDocumentCache wasn't working for me, but this does the trick.
is working on a reply...