Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

OnDocFormSave Plugin to clear partition #5

Open
exside opened this issue May 6, 2013 · 3 comments
Open

OnDocFormSave Plugin to clear partition #5

exside opened this issue May 6, 2013 · 3 comments
Assignees

Comments

@exside
Copy link

exside commented May 6, 2013

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!

@janwidmer
Copy link

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

@opengeek opengeek self-assigned this Dec 2, 2015
@Jako
Copy link

Jako commented Jul 25, 2016

@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;

@hugopeek
Copy link

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?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants