From 81e0859041cd181c142a87a5fc78640f92aa5ce0 Mon Sep 17 00:00:00 2001 From: Vjacheslav Trushkin Date: Sun, 14 Jul 2013 12:11:57 -0400 Subject: [PATCH 1/4] [ticket/11688] Purge TWIG cache Purge directories Replace opendir() with DirectoryIterator PHPBB3-11688 --- phpBB/phpbb/cache/driver/file.php | 67 +++++++++++++++++++++++++------ 1 file 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); @@ -241,6 +249,39 @@ class phpbb_cache_driver_file extends phpbb_cache_driver_base $this->is_modified = false; } + /** + * 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 */ From a68aed51190e10535d364db056de97098cd56019 Mon Sep 17 00:00:00 2001 From: Vjacheslav Trushkin Date: Sun, 14 Jul 2013 13:20:41 -0400 Subject: [PATCH 2/4] [ticket/11688] tpl_ files are no longer used Remove tpl_ and ctpl_ from cache->purge() because those prefixes are no longer used. PHPBB3-11688 --- phpBB/phpbb/cache/driver/file.php | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/phpBB/phpbb/cache/driver/file.php b/phpBB/phpbb/cache/driver/file.php index 7f8c646a11..19596f5205 100644 --- a/phpBB/phpbb/cache/driver/file.php +++ b/phpBB/phpbb/cache/driver/file.php @@ -228,9 +228,7 @@ class phpbb_cache_driver_file extends phpbb_cache_driver_base 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) + strpos($filename, 'data_') === 0) { $this->remove_file($fileInfo->getPathname()); } From 212294382d2626012bb1caf0dde1392e59b1ca31 Mon Sep 17 00:00:00 2001 From: Vjacheslav Trushkin Date: Tue, 30 Jul 2013 12:32:14 +0300 Subject: [PATCH 3/4] [ticket/11688] Rename purge_dir to remove_dir PHPBB3-11688 --- phpBB/phpbb/cache/driver/file.php | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/phpBB/phpbb/cache/driver/file.php b/phpBB/phpbb/cache/driver/file.php index 19596f5205..66a74ea4eb 100644 --- a/phpBB/phpbb/cache/driver/file.php +++ b/phpBB/phpbb/cache/driver/file.php @@ -223,7 +223,7 @@ class phpbb_cache_driver_file extends phpbb_cache_driver_base $filename = $fileInfo->getFilename(); if ($fileInfo->isDir()) { - $this->purge_dir($fileInfo->getPathname()); + $this->remove_dir($fileInfo->getPathname()); } elseif (strpos($filename, 'container_') === 0 || strpos($filename, 'url_matcher') === 0 || @@ -250,7 +250,7 @@ class phpbb_cache_driver_file extends phpbb_cache_driver_base /** * Remove directory */ - protected function purge_dir($dir) + protected function remove_dir($dir) { try { @@ -269,7 +269,7 @@ class phpbb_cache_driver_file extends phpbb_cache_driver_base } if ($fileInfo->isDir()) { - $this->purge_dir($fileInfo->getPathname()); + $this->remove_dir($fileInfo->getPathname()); } else { From 5eb321d3113136f5e6cbc1f0ad911636f93f94df Mon Sep 17 00:00:00 2001 From: Vjacheslav Trushkin Date: Tue, 30 Jul 2013 21:02:40 +0300 Subject: [PATCH 4/4] [ticket/11688] Fix docblock PHPBB3-11688 --- phpBB/phpbb/cache/driver/file.php | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/phpBB/phpbb/cache/driver/file.php b/phpBB/phpbb/cache/driver/file.php index 66a74ea4eb..944dfd6541 100644 --- a/phpBB/phpbb/cache/driver/file.php +++ b/phpBB/phpbb/cache/driver/file.php @@ -249,6 +249,10 @@ class phpbb_cache_driver_file extends phpbb_cache_driver_base /** * Remove directory + * + * @param string $dir Directory to remove + * + * @return null */ protected function remove_dir($dir) { @@ -267,6 +271,7 @@ class phpbb_cache_driver_file extends phpbb_cache_driver_base { continue; } + if ($fileInfo->isDir()) { $this->remove_dir($fileInfo->getPathname());