Copied to clipboard

Flag this post as spam?

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


  • Sebastiaan Janssen 4899 posts 14655 karma points MVP admin hq
    Dec 17, 2009 @ 13:05
    Sebastiaan Janssen
    0

    Check if media upload is new or overwriting existing

    I have an aftersave handler in my media section that needs to be triggered only the first time an file gets uploaded. If someone opens up the media item and uploads a new file to the existing media item, then I don't want to execute the aftersave event. 

    Is there a good way to detect this?

  • Sebastiaan Janssen 4899 posts 14655 karma points MVP admin hq
    Dec 17, 2009 @ 16:10
    Sebastiaan Janssen
    0

    Well I've introduced a solution that is unfortunately very hacky, couldn't use BeforeSave or AfterNew at all because it's eiter too early or too late. Media items are also not versioned, so VersionDate vs CreateDate was useless.

    So I introduced a new property "preventAfterSaveAction" and I'm setting it immediately in my AfterSave handler:

    if (sender.ContentType.Alias != "Image") return;
    
    if (sender.getProperty("preventAfterSaveAction").Value.ToString() == "1") return;
    sender.getProperty("preventAfterSaveAction").Value = "1";

    I hate that i have to use an extra property for this though.

  • This forum is in read-only mode while we transition to the new forum.

    You can continue this topic on the new forum by tapping the "Continue discussion" link below.

Please Sign in or register to post replies