Skip to content

Commit

Permalink
Clear SSI files if all or (all) pages cache clear triggers
Browse files Browse the repository at this point in the history
  • Loading branch information
weakbit committed Jun 13, 2024
1 parent dfd6b39 commit b462b18
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 0 deletions.
39 changes: 39 additions & 0 deletions Classes/Cache/ClearCache.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
<?php

declare(strict_types=1);

namespace AUS\SsiInclude\Cache;

use AUS\SsiInclude\ViewHelpers\RenderIncludeViewHelper;
use TYPO3\CMS\Core\Core\Environment;

class ClearCache
{
/** @param array<mixed> $parameters */
public function clearCache(array $parameters): void
{
if (isset($parameters['cacheCmd']) && ($parameters['cacheCmd'] === 'pages' || $parameters['cacheCmd'] === 'all')) {
$path = Environment::getPublicPath() . RenderIncludeViewHelper::SSI_INCLUDE_DIR;
$this->removeFiles($path);
}
}

protected function removeFiles(string $dir): void
{
if (is_dir($dir)) {
$objects = scandir($dir);
if (!$objects) {
return;
}

foreach ($objects as $object) {
if ($object !== '.' && $object !== '..') {
$filePath = $dir . DIRECTORY_SEPARATOR . $object;
if (is_file($filePath) && is_writable($filePath)) {
unlink($filePath);
}
}
}
}
}
}
4 changes: 4 additions & 0 deletions ext_localconf.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
<?php

use AUS\SsiInclude\Cache\ClearCache;

if (!defined('TYPO3_COMPOSER_MODE')) {
// include autoload if this is the TER version
require __DIR__ . '/vendor/autoload.php';
}

$GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['t3lib/class.t3lib_tcemain.php']['clearCachePostProc'][] = ClearCache::class . '->clearCache';

0 comments on commit b462b18

Please sign in to comment.