We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 29861
    • 59 Posts
    Hi,

    Modx Revolution 2.0.0pl
    Anyone knows how to write an external php script (not accessible from the web) that would clear the cache (I guess $modx->clearCache()) and set the site unavailable?

    I saw this Modx Evo Doc: http://wiki.modxcms.com/index.php/MODx_site_menu_in_external_PHP_app
    But it doesn’t seem to be applicable to Modx Revo. Is it?

    Thanks a lot,

    Thierry.
      • 29861
      • 59 Posts
      huh
      No one has even a small hint to start creating that script.
      I’d like to write that script only accessible by the cron table.
      How do I load the $modx global variable to be able to read the database?
      Thank you!
      Thierry.
        • 26903
        • 1,336 Posts
        Bit rough but,

        What you need to do is to write a script that basically does what index.php does at its top end, so take this as your base, get rid of the micro time cruft and set IN_PARSER_MODE to false and IN_API_MODE to true, get rid of the ob_start, you should now have an initialized modx object, get rid of the handle request at the bottom and put your code here. To clear the cache use the code from \core\model\modx\processors\system\clearcache.php i.e do this :-
        $paths = array(
            'config.cache.php',
            'sitePublishing.idx.php',
            'registry/mgr/workspace/',
            'lexicon/',
        );
        $contexts = $modx->getCollection('modContext');
        foreach ($contexts as $context) {
            $paths[] = $context->get('key') . '/';
        }
        
        $options = array(
            'publishing' => 1,
            'extensions' => array('.cache.php', '.msg.php', '.tpl.php'),
        );
        if ($modx->getOption('cache_db')) $options['objects'] = '*';
        $results= $modx->cacheManager->clearCache($paths, $options);
        
        


        then to set the site unavailable you need to set the system setting site_status to 0, do this by updating this setting something like :-
        $setting = $modx->getObject('modSystemSetting',
                        array ('key' => 'site_status',
                        'namespace' => 'core'));
                    $setting->set('value', 0);
                    $setting->save();
                }


        and see how it goes.
          Use MODx, or the cat gets it!
          • 29861
          • 59 Posts
          grin
          Wow lot’s of info smiley Thanks for the index.php and clearcache.php hints.
          I’ll dive into it soon.

          Thierry.
            • 26903
            • 1,336 Posts
            Having re-read my post just done a few quick edits on it, may be better now.
              Use MODx, or the cat gets it!