OnDocFormSave Plugin to clear partition
First of all thank you very much for that nice snippet, helps a lot!
What I'm trying to do (according to the wiki here on github) is to clear a specific cache partition (set by getCache) with a plugin that is attached to the system event OnDocFormSave, but it seems that I'm just too stupid to get it right^^...never worked with processors before, so maybe that's the reason, but the RTFM about runProcessor didn't really help...I think it's something with passing the right path to the method, but I couldn't figure it out...what I tried was:
$response = $modx->runProcessor('/cache/partition/refresh', array(
'processors_path' => MODX_CORE_PATH . 'components/getcache/cache/partition/refresh',
'partitions' => 'partitionname'
));
if ($response->isError()) {
return; //$modx->log(modX::LOG_LEVEL_ERROR, 'There was an error refreshing cache partition' . $response->getMessage());
} else {
return;// $modx->log(modX::LOG_LEVEL_ERROR, 'Cache partition successfully cleared');
}
but what I get is just an endless saving loop =/, any tipps on that, would maybe also be helpful for others to include it more precisely into the wiki.
thanks in advance for any advice!
Hi Exside,
Did you ever make this work? I tried with the following code, it didn't give me exceptions but also the cache was not cleared afterwards..
$response = $modx->runProcessor('cache/partition/refresh.class',
array(
'partitions' => 'partitionname'
),
array(
'processors_path' => MODX_CORE_PATH . 'components/getcache',
)
);
if ($response->isError()) {
return; //$modx->log(modX::LOG_LEVEL_ERROR, 'There was an error refreshing cache partition' . $response->getMessage());
} else {
return;// $modx->log(modX::LOG_LEVEL_ERROR, 'Cache partition successfully cleared');
}
I used a second array for the processors_path because in the documentation, it says so (https://rtfm.modx.com/revolution/2.x/developing-in-modx/advanced-development/using-runprocessor#UsingrunProcessor-UsingrunProcessor)
"This directory can also be overridden in the 3rd parameter array with the param 'processors_path'"
@opengeek, maybe any Inputs from your side?
Best regards Jan
@janwidmer: The processors path should point to the processors folder and the action needs no .class suffix:
switch ($modx->event->name) {
case 'OnSiteRefresh':
$partition = 'partition';
$response = $modx->runProcessor('cache/partition/refresh', array(
'partitions' => $partition
), array(
'processors_path' => MODX_CORE_PATH . 'components/getcache/processors/'
));
if ($response->isError()) {
$modx->log(modX::LOG_LEVEL_ERROR, 'There was an error refreshing cache partition "' . $partition . '". ' . $response->getMessage(), '', 'Cache Refresh');
} else {
$oldLoglevel = $modx->getLogLevel();
$modx->setLogLevel(modX::LOG_LEVEL_INFO);
$modx->log(modX::LOG_LEVEL_INFO, 'Cache partition "' . $partition . '" successfully cleared.', '', 'Cache Refresh');
$modx->setLogLevel($oldLoglevel);
}
break;
}
return;
Above plugin works OnSiteRefresh, but somehow for me not OnCacheUpdate..
And is there a way to keep the original output of the Clear Cache process visible in the console?