forked from Focuslinkstech/phpnuxbill-clear-cache
-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
clear_cache.php
executable file
·50 lines (44 loc) · 1.8 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
<?php
register_menu("Clear System Cache", true, "clear_cache", 'SETTINGS', '');
function clear_cache()
{
global $ui;
_admin();
$ui->assign('_title', 'Clear Cache');
$ui->assign('_system_menu', 'settings');
$admin = Admin::_info();
$ui->assign('_admin', $admin);
// Check user type for access
if ($admin['user_type'] != 'SuperAdmin' && $admin['user_type'] != 'Admin'){
r2(U . "dashboard", 'e', Lang::T("You Do Not Have Access"));
}
$compiledCacheDir = 'ui/compiled';
$templateCacheDir = 'system/cache';
try {
// Clear the compiled cache
$ui->setCacheDir($compiledCacheDir);
$CACHE_PATH = $ui->getCacheDir();
$files = scandir($CACHE_PATH);
foreach ($files as $file) {
$ext = pathinfo($file, PATHINFO_EXTENSION);
if (is_file($CACHE_PATH . DIRECTORY_SEPARATOR . $file) && $ext == 'temp') {
unlink($CACHE_PATH . DIRECTORY_SEPARATOR . $file);
}
}
// Clear the template cache
$ui->setCacheDir($templateCacheDir);
$templateCacheFiles = glob($ui->getCacheDir() . '/*');
foreach ($templateCacheFiles as $file) {
if (is_file($file)) {
unlink($file);
}
}
// Cache cleared successfully
_log('[' . $admin['fullname'] . ']: ' . Lang::T(' Cleared the system cache '), $admin['user_type']);
r2(U . 'dashboard', 's', Lang::T("Cache cleared successfully!"));
} catch (Exception $e) {
// Error occurred while clearing the cache
_log('[' . $admin['fullname'] . ']: ' . Lang::T(' Error occurred while clearing the cache: '. $e->getMessage()), $admin['user_type']);
r2(U . 'dashboard', 'e', Lang::T("Error occurred while clearing the cache: ") . $e->getMessage());
}
}