Last active
November 13, 2018 17:18
-
-
Save gibbs/7182272 to your computer and use it in GitHub Desktop.
Refresh / clear the MODX Revolution 2.1+ cache
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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