How to show value of auto_publish.cache.php on a page

Hello,

I have limited ModX/php skills and I haven’ been able to find the correct information.

I’m running a website dedicated to the cantatas by JS Bach (https://whichbachcantata.be). I’m importing the records from a personal system using ImportX, with a scheduled publication date. There is a bug whereby the value in /core/cache/auto_publish/auto_publish.cache.php is not updated, but I haven’t been able to pinpoint it yet.

In order to verify if the scheduled publication is correct, I would like to expose the value within auto_publish.cache.php on a page on the site (in a readable time stamp, something like "next publication: DD/MM/YYYY MM:SS), but I haven’t been able to figure out how to do it. Could someone please help?

Thanks & cheers --Mike

Hey Mike,

The contents of that file are a unix timestamp when something is set to publish in the future.

<?php  return '1609256700';

As soon as the date passes, the resource is set to published and the timestamp is cleared.

<?php  return 0;

From what I can tell, the cache only stores the next publish timestamp. I have two test resources set to future publish dates. You can do this within MODX, but something simple like Epochconverter.com also works well to double check. Just paste in the timestamp from the file to see when the next publish time is.

The one thing to make sure of is your server date settings. Go to your MODX settings and search for “time”. There are two settings, “date_timezone” and “server_offset_time”. In my case MODX is using UTC, and I’m in Denver, so I set my offset to “-7”. That way, when I set a future publish date, it uses the correct time.

There are a couple ways to check your server time, but an easy way is to create a new Snippet and call it whatever you want: “date”, “DateSnippet”, etc.

In my case I have “date”, and within that snippet, I return the date with a format applied.

<?php
return date('Y-m-d H:i:s');

Then you can just drop this in one of your pages, or create a test page and put the snippet in there.

Which will output your server date-time:

Hopefully that helps!

Thanks,
Jared

Maybe this snippet code works:

<?php
//read auto_publish value from the cache
$partKey = $modx->getOption('cache_auto_publish_key', null, 'auto_publish');
$partHandler = $modx->getOption('cache_auto_publish_handler', null, $modx->getOption(xPDO::OPT_CACHE_HANDLER));

$cacheRefreshTime = (integer) $modx->cacheManager->get('auto_publish', array(
    xPDO::OPT_CACHE_KEY => $partKey,
    xPDO::OPT_CACHE_HANDLER => $partHandler
));
if ($cacheRefreshTime > 0) {
   //convert timestamp to readable form
   return date('Y-m-d H:i:s',$cacheRefreshTime);
} else {
    return "nothing scheduled";
}

Most of the code is copied from the class modRequest.

Hello @halftrainedharry, that is exactly what I needed, works like a charm! Thanks!

And thanks to you too @jaredfhealy for the extensive answer!

Have a great New Year and on to a better 2021!

Cheers --Mike