Wanting to re-save pages daily with cron manage

I have a few pages that need to be manually saved in order to make the site work. I installed Cron Manager thinking this would be the best path but am struggling to figure it out. Searched other forums but didn’t see the answer. Possibly there is a better way besides Cron. Open to any and all suggestions.

Essentially, I have event pages that I don’t want to unpublish, so instead I have made a TV for the date and time that the event ends. Unless I go in and save one page, that event still shows current. Essentially, I want modx to do whatever it needs to do to trigger this. Just once a day around midnight works fine.

Have you thought about using something like GetCache, which allows you to specify custom cache expirations for the parts that need to be dynamic? That could possibly prevent you from having to go in and re-save things like that.

It’s not clear to me how the TV is being used. If it’s in a tag with a conditional output modifier, is the tag called uncached (with the exclamation point)?

I would be tempted to use a custom snippet something like this (assuming that the TV’s rendered output is a human-readable date and time):

[[!CheckExpirationTV]]

/* CheckExpirationTV snippet */ 

$tvValue = $modx->resource->getTVValue('tvname');

$timestamp = strtotime($tvValue);

if ($timestamp <= time()) {
    return "Still Current";
} else {
    return "Event has ended";
}

Thanks Bob. Does your example refresh or check the time with every visit to the page? I have something like that sans “!” and have have multiple pages connected to these events. Can the page/s be autosaved, so that the “LastModified” is also updated? I believe that can also help with seo.

You need the exclamation mark to call it uncached; with it the result is cached until you save a resource or clear the cache manually. So, adding the exclamation mark would fix the issue you’re having, wouldn’t it?

Per @rthrash’s suggestion - if you do some more intensive logic, you could use the getCache snippet as a wrapper to cache the results for any period of time.

Thanks Bob. Does your example refresh or check the time with every visit to the page?

Yes, as Mark says, that’s the point of the !. Without it, MODX gets the results of the snippet code from the cache, where it never changes. The exclamation point basically says, “Run the snippet code right now and give me the fresh result.”

I’m guessing here, but I would think calling the snippet uncached would change the page causing the server to return an updated Last-modified header. You could probably check using the Network tab in Chrome or Firefox Dev. tools.

1 Like