Untick Empty Cache Checkbox for Unpublished Resources in MODX Revolution Plugin
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 | |
/** | |
* cacheguard plugin for cacheguard extra | |
* | |
* Copyright 2013 by JP DeVries jp@modx.com | |
* Created on 06-21-2013 | |
* | |
* cacheguard is free software; you can redistribute it and/or modify it under the | |
* terms of the GNU General Public License as published by the Free Software | |
* Foundation; either version 2 of the License, or (at your option) any later | |
* version. | |
* | |
* cacheguard is distributed in the hope that it will be useful, but WITHOUT ANY | |
* WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR | |
* A PARTICULAR PURPOSE. See the GNU General Public License for more details. | |
* | |
* You should have received a copy of the GNU General Public License along with | |
* cacheguard; if not, write to the Free Software Foundation, Inc., 59 Temple | |
* Place, Suite 330, Boston, MA 02111-1307 USA | |
* | |
* @package cacheguard | |
*/ | |
/** | |
* Description | |
* ----------- | |
* Sets Clear Cache tickbox to false for unpublished Resources | |
* | |
* Variables | |
* --------- | |
* @var $modx modX | |
* @var $scriptProperties array | |
* | |
* @package cacheguard | |
**/ | |
$eventName = $modx->event->name; | |
switch($eventName) { | |
case 'OnDocFormRender': | |
if($resource->get('published') != '1') { | |
$selector = ($resource->get('class_key') == 'Article') ? 'modx-resource-clearcache' : 'modx-resource-syncsite'; | |
$modx->regClientStartupHTMLBlock("<script> | |
var cacheguard_protected = false; | |
Ext.onReady(function(){ | |
if(!cacheguard_protected)Ext.getCmp('$selector').setValue(0); | |
cacheguard_protected = true; | |
});</script> | |
"); | |
} | |
break; | |
case 'OnDocFormSave': | |
if($resource->get('published') != '1') { | |
$resourceCache = $modx->getCacheManager()->getCacheProvider( | |
$modx->getOption('cache_resource_key', null, 'resource'), | |
array( | |
xPDO::OPT_CACHE_HANDLER => $modx->getOption('cache_resource_handler', null, $modx->getOption(xPDO::OPT_CACHE_HANDLER)), | |
xPDO::OPT_CACHE_EXPIRES => $modx->getOption('cache_resource_expires', null, $modx->getOption(xPDO::OPT_CACHE_EXPIRES)), | |
) | |
); | |
$resourceCache->delete("{$resource->context_key}/resources/{$resource->id}"); | |
} | |
break; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
I've forked this and updated it so that auto_publish works as expected: https://gist.github.com/Jsewill/d66be704f0ab2478e2f0a04e33ad3d6c
Have a look, and if you like it, feel free to incorporate it into your MODX package.