<![CDATA[ Running custom PHP via a Namespace in the Top Menu to clear core/cache folder - My Forums]]> https://forums.modx.com/thread/?thread=101854 <![CDATA[Re: Running custom PHP via a Namespace in the Top Menu to clear core/cache folder]]> https://forums.modx.com/thread/101854/running-custom-php-via-a-namespace-in-the-top-menu-to-clear-core-cache-folder#dis-post-549314
Thanks for the info, too.]]>
firebot6 Mar 11, 2017, 07:44 AM https://forums.modx.com/thread/101854/running-custom-php-via-a-namespace-in-the-top-menu-to-clear-core-cache-folder#dis-post-549314
<![CDATA[Re: Running custom PHP via a Namespace in the Top Menu to clear core/cache folder]]> https://forums.modx.com/thread/101854/running-custom-php-via-a-namespace-in-the-top-menu-to-clear-core-cache-folder#dis-post-549255 CacheClear extra, which does the same thing wink

And yes, the cache is refreshed when there's a new request.


]]>
BobRay Mar 08, 2017, 05:04 PM https://forums.modx.com/thread/101854/running-custom-php-via-a-namespace-in-the-top-menu-to-clear-core-cache-folder#dis-post-549255
<![CDATA[Running custom PHP via a Namespace in the Top Menu to clear core/cache folder]]> https://forums.modx.com/thread/101854/running-custom-php-via-a-namespace-in-the-top-menu-to-clear-core-cache-folder#dis-post-549245
<?php
$dir = "/host/site/core/cache";
$di = new RecursiveDirectoryIterator($dir, FilesystemIterator::SKIP_DOTS);
$ri = new RecursiveIteratorIterator($di, RecursiveIteratorIterator::CHILD_FIRST);
foreach ( $ri as $file ) {
    $file->isDir() ?  rmdir($file) : unlink($file);
}
return "Cache cleared.";
?>

(I've moved the core folder outside public_html, so the path is correct.)

If I put the PHP in a file and access it directly at www.site.com/clearcache.php, it works fine, and the core/cache folder is empty until a page or the manager is loaded.

To make it more accessible I:
- put the contents inside core/components/clearcache/index.php file
- created a new Namespace called "clearcache" with a Core path of "{core_path}components/clearcache/"
- created a new Top Menu item with an Action of "index" and a Namespace of "clearcache"

When I click on the new menu item, it returns "Cache cleared", however, the core/cache folder isn't empty. Is this because clicking on the menu item and loading the new page actively caches new content, or is there something in my PHP Modx doesn't like?

I'm running:
Modx Revolution 2.5.2-pl
PHP 5.5.38]]>
firebot6 Mar 08, 2017, 10:41 AM https://forums.modx.com/thread/101854/running-custom-php-via-a-namespace-in-the-top-menu-to-clear-core-cache-folder#dis-post-549245