We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 24374
    • 322 Posts
    I have a client who was setting resources to be published at a certain date and time, and they wouldn't go live when the time came. After doing some research, I found out that the list of resources that are being "watched" for upcoming publish dates and times is kept in the cache somewhere, so since I have CacheMaster set to uncheck the clear cache checkbox by default, when someone addes a publish date/time and saves the resource, the cache is not cleared, and that list is of resources to watch doesn't get recreated.

    I see that there is a folder called "auto_publish" in the cache, with a single file inside, "auto_publish.cache.php". I did a test and set two resources to be published in the future, and this file just contains a single line:
    return '1392066017';
    How does this work? Is this the file I need to reset?

    1. I could make a plugin that, if something is entered in the pub_date field, always clears the cached file that tracks "watched" resources (or recreates it, if that's what's needed), but does anyone know exactly how this information gets saved? How would I know what to put in the file? Or is there a MODX command that does this?

    2. It would be better if CacheMaster would reset this watched-resource file, or provide an option to do that. Is there an easy place to make this happen in the code? (Bob?) [ed. note: rainbowtiger last edited this post 10 years, 2 months ago.]
      • 3749
      • 24,544 Posts
      I think that number in auto_publish.cache.php is a unix timestamp with the publication date/time of the next resource due to be published or unpublished. During every request, that number is checked against the current time. If the number there is less than the current time, the whole cache is refreshed and any documents due to be published or unpublished are processed. During the cache refresh, that number is reset to the pub_date of the next document after that due to be published or unpublished.

      As far as I can tell, the only time that number in the auto_publish cache is updated is during a total cache refresh.

      $modx->cacheManager->autoPublish() is the public method that resets it, but its argument is a fairly complex array. However, you can call $cacheManager->refresh() with an argument that I think would solve the problem with a minimum of overhead.

      If you feel daring, you could try putting this code at line 219 of the CacheMaster plugin. It goes in the OnBeforeDocFormSave section, just below the complex $cacheManager->delete call and just above the break statement:

      /* If pub_date or unpub_date are set, update the auto_publish cache */
         if ($resource->get('pub_date') || $resource->get('unpub_date')) {
             $providers = array(
                 'auto_publish' => array('contexts' => $ctx),
             );
            $cm->refresh($providers);
      
         }
      


      [ed. note: BobRay last edited this post 10 years, 1 month ago.]
        Did I help you? Buy me a beer
        Get my Book: MODX:The Official Guide
        MODX info for everyone: http://bobsguides.com/modx.html
        My MODX Extras
        Bob's Guides is now hosted at A2 MODX Hosting