Copied to clipboard

Flag this post as spam?

This post will be reported to the moderators as potential spam to be looked at


  • Rich Green 2246 posts 4008 karma points
    Nov 29, 2010 @ 18:50
    Rich Green
    1

    On first published event

    Hi,

    I'm looking to run some custom code when a node is first published.

    I can hook into the NewEventHandler but this isn't useful for me as there is no guarantee that the node will ever be published.

    So how can I check if this is the first time the node has been published?

    Cheers

    Rich

  • Jan Skovgaard 11280 posts 23678 karma points MVP 11x admin c-trib
    Nov 29, 2010 @ 20:48
    Jan Skovgaard
    0

    Hi Rich

    Maybe you can use the "afterPublish" event? Don't know if you have seen the complete reference of events in the wiki: http://our.umbraco.org/wiki/reference/api-cheatsheet/using-applicationbase-to-register-events/overview-of-all-events

    /Jan

  • Rich Green 2246 posts 4008 karma points
    Nov 29, 2010 @ 20:51
    Rich Green
    0

    Hey Jan,

    I'm pretty sure that runs everytime the node is published, I just want to run this piece of code once, the first time the node is published.

    Cheers

    Rich

     

  • Jan Skovgaard 11280 posts 23678 karma points MVP 11x admin c-trib
    Nov 29, 2010 @ 20:56
    Jan Skovgaard
    0

    Hmmm

    Wouldn't it be a possibility to check if there has been set a publication date? If it has not been set run the event otherwise don't?

    /Jan

  • Hendy Racher 863 posts 3849 karma points MVP 2x admin c-trib
    Nov 29, 2010 @ 20:57
    Hendy Racher
    1

    Hi Rich,

    Is there any other way you can check that the code you want to run on first publsh has already been run ? Can you use a marker property on the node ? otherwise I think you might have to look into the audit trail - just a guess.

    Cheers,
    Hendy

  • Hendy Racher 863 posts 3849 karma points MVP 2x admin c-trib
    Nov 29, 2010 @ 21:03
    Hendy Racher
    0

    arrh yes, how about the BeforePublish event and checking for a publication date (although what happens if item is published, unpublished, and then published again ?)

  • Jan Skovgaard 11280 posts 23678 karma points MVP 11x admin c-trib
    Nov 29, 2010 @ 21:05
    Jan Skovgaard
    1

    Yeah, I suppose it's more safe to follow your suggestions Hendy - setting a true/false property and check if it has been set seems more bulletproof :-)

    /Jan

  • Aaron Powell 1708 posts 3046 karma points c-trib
    Nov 29, 2010 @ 21:54
    Aaron Powell
    1

    Yeah there's no event that runs only once, and I think adding one would be be more overhead than benefit.

  • Richard Soeteman 4047 posts 12900 karma points MVP 2x
    Nov 29, 2010 @ 22:42
    Richard Soeteman
    1

    HI Rich,

    Versioning is based on publishing., So when the document has only one version you know it's the first document.

    Cheers,

    Richard

  • Rich Green 2246 posts 4008 karma points
    Nov 30, 2010 @ 19:04
    Rich Green
    0

    Hey,

    Thanks for the replies, you all rock :)

    The code that I run actually sets a value within the current node, so I can just check that every time.

    It just felt a little like a little bit of a hack but it works perfect and now I know that there's currently no better way.

    Cheers

    Rich

Please Sign in or register to post replies

Write your reply to:

Draft