-
Notifications
You must be signed in to change notification settings - Fork 24
/
clear_cache.php
76 lines (68 loc) · 2.04 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
<?php
##################################################
#
# Copyright (c) 2007-2008 OIC Group, Inc.
# Written and Designed by Adam Kessler
#
# 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.
#
# GPL: http://www.gnu.org/licenses/gpl.txt
#
##################################################
class clear_cache extends upgradescript {
protected $from_version = '1.99.0';
// protected $to_version = '1.99.2';
function name() { return "Clear the Caches"; }
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/cache',
// BASE.'tmp/css', // css cache??
BASE.'tmp/mail',
BASE.'tmp/minify', // minify cache
BASE.'tmp/pods',
BASE.'tmp/rsscache',
BASE.'tmp/views_c', // 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']);
}
// delete the entire img_cache and recreate the folder
if (file_exists(BASE.'tmp/img_cache')) $this->cleardir_recursive(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)) {
cleardir_recursive($file);
rmdir($file);
} else {
unlink($file);
}
}
}
// rmdir($dir);
}
}
?>