]> git.immae.eu Git - github/shaarli/Shaarli.git/blobdiff - application/Cache.php
Merge pull request #1203 from ArthurHoaro/changelog
[github/shaarli/Shaarli.git] / application / Cache.php
index 9c7e818fe7a99c05b60e3419de4f9d048e0a1b08..e5d43e611656823eaef4b952219f9a7755198026 100644 (file)
@@ -7,26 +7,18 @@
  * Purges all cached pages
  *
  * @param string $pageCacheDir page cache directory
+ *
+ * @return mixed an error string if the directory is missing
  */
 function purgeCachedPages($pageCacheDir)
 {
     if (! is_dir($pageCacheDir)) {
-        return;
+        $error = sprintf(t('Cannot purge %s: no directory'), $pageCacheDir);
+        error_log($error);
+        return $error;
     }
 
-    // TODO: check write access to the cache directory
-
-    $handler = opendir($pageCacheDir);
-    if ($handler == false) {
-        return;
-    }
-
-    while (($filename = readdir($handler)) !== false) {
-        if (endsWith($filename, '.cache')) {
-                unlink($pageCacheDir.'/'.$filename);
-        }
-    }
-    closedir($handler);
+    array_map('unlink', glob($pageCacheDir.'/*.cache'));
 }
 
 /**