diff options
author | Vjacheslav Trushkin <cyberalien@gmail.com> | 2013-07-14 12:11:57 -0400 |
---|---|---|
committer | Vjacheslav Trushkin <cyberalien@gmail.com> | 2013-07-14 12:11:57 -0400 |
commit | 81e0859041cd181c142a87a5fc78640f92aa5ce0 (patch) | |
tree | 46ab2b9bd5ba3fbf5078637627c1aded1fe151a4 | |
parent | c15bde161a93fc2abc48cacd7e5a71c682880e52 (diff) | |
download | forums-81e0859041cd181c142a87a5fc78640f92aa5ce0.tar forums-81e0859041cd181c142a87a5fc78640f92aa5ce0.tar.gz forums-81e0859041cd181c142a87a5fc78640f92aa5ce0.tar.bz2 forums-81e0859041cd181c142a87a5fc78640f92aa5ce0.tar.xz forums-81e0859041cd181c142a87a5fc78640f92aa5ce0.zip |
[ticket/11688] Purge TWIG cache
Purge directories
Replace opendir() with DirectoryIterator
PHPBB3-11688
-rw-r--r-- | phpBB/phpbb/cache/driver/file.php | 67 |
1 files changed, 54 insertions, 13 deletions
diff --git a/phpBB/phpbb/cache/driver/file.php b/phpBB/phpbb/cache/driver/file.php index 85decbe3e8..7f8c646a11 100644 --- a/phpBB/phpbb/cache/driver/file.php +++ b/phpBB/phpbb/cache/driver/file.php @@ -205,28 +205,36 @@ class phpbb_cache_driver_file extends phpbb_cache_driver_base function purge() { // Purge all phpbb cache files - $dir = @opendir($this->cache_dir); - - if (!$dir) + try + { + $iterator = new DirectoryIterator($this->cache_dir); + } + catch (Exception $e) { return; } - while (($entry = readdir($dir)) !== false) + foreach ($iterator as $fileInfo) { - if (strpos($entry, 'container_') !== 0 && - strpos($entry, 'url_matcher') !== 0 && - strpos($entry, 'sql_') !== 0 && - strpos($entry, 'data_') !== 0 && - strpos($entry, 'ctpl_') !== 0 && - strpos($entry, 'tpl_') !== 0) + if ($fileInfo->isDot()) { continue; } - - $this->remove_file($this->cache_dir . $entry); + $filename = $fileInfo->getFilename(); + if ($fileInfo->isDir()) + { + $this->purge_dir($fileInfo->getPathname()); + } + elseif (strpos($filename, 'container_') === 0 || + strpos($filename, 'url_matcher') === 0 || + strpos($filename, 'sql_') === 0 || + strpos($filename, 'data_') === 0 || + strpos($filename, 'ctpl_') === 0 || + strpos($filename, 'tpl_') === 0) + { + $this->remove_file($fileInfo->getPathname()); + } } - closedir($dir); unset($this->vars); unset($this->var_expires); @@ -242,6 +250,39 @@ class phpbb_cache_driver_file extends phpbb_cache_driver_base } /** + * Remove directory + */ + protected function purge_dir($dir) + { + try + { + $iterator = new DirectoryIterator($dir); + } + catch (Exception $e) + { + return; + } + + foreach ($iterator as $fileInfo) + { + if ($fileInfo->isDot()) + { + continue; + } + if ($fileInfo->isDir()) + { + $this->purge_dir($fileInfo->getPathname()); + } + else + { + $this->remove_file($fileInfo->getPathname()); + } + } + + @rmdir($dir); + } + + /** * Destroy cache data */ function destroy($var_name, $table = '') |