From adfab8b55fb00a393281a5a7b3039504675f904e Mon Sep 17 00:00:00 2001 From: Sam Minnee Date: Wed, 13 Jan 2010 00:06:38 +0000 Subject: [PATCH] API CHANGE: Added FilesystemPublisher::getExistingStaticCacheFiles(), to help build caching logic methods. (from r91354) git-svn-id: svn://svn.silverstripe.com/silverstripe/open/modules/cms/branches/2.4@96810 467b73ca-7a2a-4603-9d3b-597d59a354a9 --- code/staticpublisher/FilesystemPublisher.php | 26 ++++++++++++++++++++ 1 file changed, 26 insertions(+) diff --git a/code/staticpublisher/FilesystemPublisher.php b/code/staticpublisher/FilesystemPublisher.php index c6af352c..fe8c7f5f 100644 --- a/code/staticpublisher/FilesystemPublisher.php +++ b/code/staticpublisher/FilesystemPublisher.php @@ -221,6 +221,32 @@ class FilesystemPublisher extends StaticPublisher { public function getDestDir() { return '../'.$this->destFolder; } + + /** + * Return an array of all the existing static cache files, as a map of URL => file. + * Only returns cache files that will actually map to a URL, based on urlsToPaths. + */ + public function getExistingStaticCacheFiles() { + $cacheDir = '../'.$this->destFolder; + + $urlMapper = array_flip($this->urlsToPaths($this->owner->allPagesToCache())); + + $output = array(); + + // Glob each dir, then glob each one of those + foreach(glob("$cacheDir/*", GLOB_ONLYDIR) as $cacheDir) { + foreach(glob($cacheDir.'/*') as $cacheFile) { + $mapKey = str_replace("../cache/","",$cacheFile); + if(isset($urlMapper[$mapKey])) { + $url = $urlMapper[$mapKey]; + $output[$url] = $cacheFile; + } + } + } + + return $output; + } + } ?>