Copied to clipboard

Flag this post as spam?

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


  • BEWD 90 posts 302 karma points
    Aug 07, 2016 @ 11:53
    BEWD
    0

    Set unpublish date from the front end

    Hi All

    I am currently developing a corporate Intranet in Umbraco and a requirement is news and Fore Sale / Wanted board.

    We do not want all the corporate users logging in to Umbraco to add something for sale or a news article so that functionality has been dealt with via Umbraco Forms. We have set an expiry date for when the item is no longer required on the site which I filter out in the partial view.

    My question is, is there any way to use this expiry date as the unpublish date as well so then it at least gives the site admins a bit of a clue as to what they can delete?

    An even better solution would be delete the item maybe 7 days later than the expiry/Unpublish date including the relevant media item (photo) that they upload.

    Am I asking the impossible or is it quite easy? I am using Umbraco 7.4.3 and can share any code on here that would be need to help find a possible solution or workaround.

    Cheers

    Ben

  • Cimplex 113 posts 576 karma points
    Aug 07, 2016 @ 14:27
    Cimplex
    0

    Hi Ben,

    It sure is possible! I would create a date property on the document type with the expire date. In your partial view i would get all items where the current date is less than the expire date.

    On the intra where you create items post them to a controller and create the items. To set a property value u use the ContentService class.

    var node = Services.ContentService.GetById(123);
    var expireDate = node.SetValue("expireDate", "the date");
    

    More info here. https://our.umbraco.org/documentation/Reference/Management/Services/ContentService

    Then you use the built in task scheduler and run it once a day and check the expire date on your nodes.

    https://our.umbraco.org/wiki/install-and-setup/scheduled-tasks/

    If the current date is > than the expire date unpublish the node or if the current date is > 7 days delete the node.

    // Herman

  • BEWD 90 posts 302 karma points
    Aug 07, 2016 @ 16:31
    BEWD
    0

    Cheers Herman

    That sounds slightly more complicated that I had hoped but hey, I'll give it a go :)

    Ben

Please Sign in or register to post replies

Write your reply to:

Draft