/
clear_cache.php
100 lines (91 loc) · 2.67 KB
/
clear_cache.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
<?php
/**
* This file is part of Exponent
* Exponent is free software; you can redistribute
* it and/or modify it under the terms of the GNU
* General Public License as published by the Free
* Software Foundation; either version 2 of the
* License, or (at your option) any later version.
*
* The file that holds the clear_cache class
*
* @link http://www.gnu.org/licenses/gpl.txt GPL http://www.gnu.org/licenses/gpl.txt
* @package Exponent-CMS
* @copyright 2004-2011 OIC Group, Inc.
* @author Adam Kessler <adam@oicgroup.net>
* @version 2.0.0
*/
/**
* This is the class clear_cache
*
* @subpackage Upgrade
* @package Installation
*/
class clear_cache extends upgradescript {
protected $from_version = '1.99.0';
// protected $to_version = '1.99.2';
/**
* name/title of upgrade script
* @return string
*/
function name() { return "Clear the Caches"; }
/**
* additional test(s) to see if upgrade script should be run
* @return bool
*/
function needed() {
return true;
}
/**
* cleans out all the cache folders
* @return bool
*/
function upgrade() {
// work our way through all the tmp files and remove them
if (!defined('SYS_FILES')) include_once(BASE.'subsystems/files.php');
$files = array(
BASE.'tmp/mail', // not used?? FIXME
BASE.'tmp/pods', // not used?? FIXME
BASE.'tmp/css', // exponent minified css cache
BASE.'tmp/minify', // minify cache
BASE.'tmp/pixidou', // (new) pixidou cache
BASE.'tmp/rsscache', // magpierss cache
BASE.'tmp/views_c', // smarty cache
BASE.'tmp/cache', // alternate smarty cache
);
// delete the files.
$removed = 0;
$errors = 0;
foreach ($files as $file) {
$files = exponent_files_remove_files_in_directory($file);
$removed += count($files['removed']);
$errors += count($files['not_removed']);
}
// phpThumb cache includes subfolders
// if (file_exists(BASE.'tmp/img_cache')) $this->cleardir_recursive(BASE.'tmp/img_cache');
if (file_exists(BASE.'tmp/img_cache')) exponent_files_remove_files_in_directory(BASE.'tmp/img_cache');
return "Caches were cleared.<br>".$errors." files could not be removed.";
}
/**
* recursively clear a directories contents, but leave the directory
* @param $dir
*/
function cleardir_recursive($dir) {
$files = scandir($dir);
array_shift($files); // remove '.' from array
array_shift($files); // remove '..' from array
foreach ($files as $file) {
if (substr($file, 0, 1) != '.') { // don't remove dot files
$file = $dir . '/' . $file;
if (is_dir($file)) {
$this->cleardir_recursive($file);
rmdir($file);
} else {
unlink($file);
}
}
}
// rmdir($dir);
}
}
?>