Copied to clipboard

Flag this post as spam?

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


  • David Conlisk 432 posts 1008 karma points
    Jan 09, 2012 @ 13:25
    David Conlisk
    0

    Auto-update nodes after time has passed

    Hi all,

    Okay I asked this question on twitter earlier (I know, I should have posted here directly), so I'll try and reproduce the question and initial conversation, and make myself a little clearer.

    I have a news section on my site. Each news item has an archive checkbox that allows the content editor to archive the item. This means that the item does not appear in the regular news list. But it does appear when the user views the news archive. All of this runs using XSLT. The node does not move anywhere when archived - the content tree is fixed as news items are re-used in different parts of the site depending on other checkboxes (it's complicated!).

    What I want to happen is that my archive checkbox is checked for every news item once that item is over 30 days old. This needs to happen regardless of user input, so using the OnPublish event or similar won't work.

    @billywizz: Best way to do it would be to run a task on the server which hits a page that loops nodes on the server and changes them

    @drobar: just make it a shceduled task in Umbraco. No event needed. //@billywizz

    @billywizz: I've tried Doug and found it to be quite unreliable. I found the task on the server was much better

    @ismailmayat: take look at  http://our.umbraco.org/projects/backoffice-extensions/cogworks-cogpagereview im show list of items due for review its generated everytime someone logs in

    @rsoeteman: Check demo 2 http://www.richardsoeteman.net/2009/02/22/UmbracoV4EventsDemo.aspx

    @dconlisk: @rsoeteman Cheers I was having a look at your code but needs to happen without user interaction.

    @drobar: However you want to call the page that runs your code is cool. And tie in onPublish event for instant updates as well.

    @cultiv: Stating the obvious: why not just NOT show items older than 30 days?

    @dconlisk: @cultiv Because I need to allow editors the option of manually controlling the archive(using checkbox) without any confusion.

    @cultiv: @dconlisk Aaah, yeah, that's valid. Maybe make the checkbox say: If item is older than 30 days, show it in the overview anyway?

    So this is why you should never ask on twitter first! 140 characters just isn't enough to explain fully what's required when the problem is non-trivial.

    Anyway - any further ideas? I'd rather not update the xslt to check for dates as it's confusing for content editors ("why is this item appearing in the archive when the archived checkbox is not set?"). I'm thinking maybe run it as a dashboard control a la the Cogworks tool so that it runs every time someone logs into the admin area (depends on the client's requirements). Otherwise it'll probably be a scheduled task on the server that runs through all news items checking the dates and updating the checkbox if required.

    David

  • Tim 1193 posts 2675 karma points MVP 4x c-trib
    Jan 09, 2012 @ 13:36
    Tim
    2

    I think the best way to do this would be to have a page on the server that you can call from a commandline app. You won't be able to do it directly in the commandline app, as most of the Umbraco stuff requires the Umbraco context to work properly and get all the right DB settings etc.

    We did something where we had a feed of product prices that were fed in daily, and we created a simple page to run the update task. The command line app is dead simple, at it's most basic, you can just use something like this:

    using System;
    using System.Configuration;
    using System.Collections.Specialized;
    using System.Collections.Generic;
    using System.Text;
    using System.Web;
    using System.Net;
    
    namespace UmbracoTask
    {
        class Program
        {
            static void Main(string[] args)
            {
                using (WebClient client = new WebClient())
                {
                    client.Headers["User-Agent"] = "Mozilla/4.0 (Compatible; Windows NT 5.1; MSIE 6.0) (compatible; MSIE 6.0; Windows NT 5.1; .NET CLR 1.1.4322; .NET CLR 2.0.50727)";
    
                    byte[] arr = client.DownloadData("[FULL PAGE URL HERE]");
    
                    client.Dispose();
                }
            }
        }
    }
    

    You can easily password protect the page as well if you want to stop it being run by unauthorised users, which only requires that you set the WebClient Credentials to use a NetworkCredential object with the correct username and password. With minimal work you can create a generic umbraco task object that you can provide command line arguments to for the url, user and pass so that you can re-use it across multiple sites on a server!

  • Stefan Kip 1614 posts 4131 karma points c-trib
    Jan 09, 2012 @ 14:00
    Stefan Kip
    2

    I've used this in the past (.vbs - VBScript):

    Call LogEntry()
    
    Sub LogEntry()
    
            'Force the script to finish on an error.
            On Error Resume Next
    
            'Declare variables
            Dim objRequest
            Dim URL
    
            Set objRequest = CreateObject("Microsoft.XMLHTTP")
    
            'Put together the URL link appending the Variables.
            URL = "http://www.some-url.com"
    
            'Open the HTTP request and pass the URL to the objRequest object
            objRequest.open "GET", URL , false
    
            'Send the HTML Request
            objRequest.Send
    
            'Set the object to nothing
            Set objRequest = Nothing
    
    End Sub
  • David Conlisk 432 posts 1008 karma points
    Jan 09, 2012 @ 15:40
    David Conlisk
    0

    Hi guys,

    Thanks for your input! I've been in touch with the client and they are happy to simply filter the items by date when outputting them on the page using XSLT. This means that ALL items over 30 days old are archived, even if the archive checkbox is not checked in the content tree.

    Cheers,

    David

Please Sign in or register to post replies

Write your reply to:

Draft