Skip to content

Instantly share code, notes, and snippets.

@gibbs
Last active November 13, 2018 17:18
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save gibbs/7182272 to your computer and use it in GitHub Desktop.
Save gibbs/7182272 to your computer and use it in GitHub Desktop.
Refresh / clear the MODX Revolution 2.1+ cache
<?php
// Dan Gibbs
// Clear MODx Revolution Cache (2.1 and later)
// Path to MODx Core Directory
define("MODX_CORE_PATH", "../core/");
define("MODX_CONFIG_KEY", "config");
// Include MODx main class
include(MODX_CORE_PATH . "model/modx/modx.class.php");
// Instantiate
$modx = new modX();
// Initialise xPDO
$modx->initialize("xPDO");
// refresh all the core partitions
$modx->cacheManager->refresh();
// refresh the web context_settings partitions
$modx->cacheManager->refresh(array(
'context_settings' => array('contexts' => array('web'))
));
$contexts = array();
$query = $modx->newQuery('modContext');
$query->select($modx->escape('key'));
if($query->prepare() && $query->stmt->execute())
{
$contexts = $query->stmt->fetchAll(PDO::FETCH_COLUMN);
}
// refresh the default partitions in the default order, excluding the mgr Context
$results = array();
$modx->cacheManager->refresh(array(
'auto_publish' => array('contexts' => array_diff($contexts, array('mgr'))),
'system_settings' => array(),
'context_settings' => array('contexts' => $contexts),
'db' => array(),
'scripts' => array(),
'default' => array(),
'resource' => array('contexts' => array_diff($contexts, array('mgr'))),
'menu' => array(),
'action_map' => array(),
'lexicon_topics' => array()
), $results);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment