fix: use Joomla native CacheControllerFactory for cache clearing
Generic: Repo Health / Site Health (push) Has been cancelled
Generic: Repo Health / Access control (push) Has been cancelled
Universal: Auto Version Bump / Version Bump (push) Has been cancelled
Platform: moko-platform CI / Gate 1: Code Quality (push) Has been cancelled
Platform: moko-platform CI / Gate 2: Unit Tests (8.1) (push) Has been cancelled
Platform: moko-platform CI / Gate 2: Unit Tests (8.2) (push) Has been cancelled
Platform: moko-platform CI / Gate 2: Unit Tests (8.3) (push) Has been cancelled
Platform: moko-platform CI / Gate 3: Self-Health Check (push) Has been cancelled
Platform: moko-platform CI / Gate 4: Governance (push) Has been cancelled
Platform: moko-platform CI / Gate 5: Template Integrity (push) Has been cancelled
Platform: moko-platform CI / CI Summary (push) Has been cancelled
Generic: Repo Health / Scripts governance (push) Has been cancelled
Generic: Repo Health / Repository health (push) Has been cancelled
Generic: Repo Health / Report Issues (push) Has been cancelled

Replace manual file deletion with Joomla's built-in cache API
(CacheControllerFactoryInterface::createCacheController->clean).
Same approach as com_cache uses. Cleans both site and admin cache.

Authored-by: Moko Consulting
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
Jonathan Miller
2026-06-04 17:22:28 -05:00
parent 3db14d29ef
commit 0d096acfa8
@@ -267,44 +267,18 @@ class DashboardModel extends BaseDatabaseModel
{
try
{
// Purge all file-based cache directories
$root = JPATH_ROOT;
$dirs = [
$root . '/cache',
$root . '/administrator/cache',
// Use Joomla's native cache API — same as com_cache
$cache = Factory::getContainer()->get(\Joomla\CMS\Cache\CacheControllerFactoryInterface::class);
$cache->createCacheController('', ['defaultgroup' => ''])->cache->clean('');
// Also clean admin cache
$conf = Factory::getApplication()->get('cache_handler', 'file');
$options = [
'defaultgroup' => '',
'cachebase' => JPATH_ADMINISTRATOR . '/cache',
'storage' => $conf,
];
foreach ($dirs as $dir)
{
if (!is_dir($dir))
{
continue;
}
$it = new \RecursiveIteratorIterator(
new \RecursiveDirectoryIterator($dir, \RecursiveDirectoryIterator::SKIP_DOTS),
\RecursiveIteratorIterator::CHILD_FIRST
);
foreach ($it as $file)
{
$name = $file->getFilename();
if ($name === 'index.html' || $name === '.htaccess')
{
continue;
}
if ($file->isDir())
{
@rmdir($file->getPathname());
}
else
{
@unlink($file->getPathname());
}
}
}
$cache->createCacheController('', $options)->cache->clean('');
// Clear opcache if available
if (\function_exists('opcache_reset'))