1 | <?php |
---|
2 | options::cat('Maintenance', 'Database', 'Table checks'); |
---|
3 | options::fadd('This checks automatically your database', 'none', 'custom', array('admin_db', 'checkDatabase'), array('admin_db', 'none')); |
---|
4 | options::fadd('Current SQL cache size', 'none', 'custom', array('admin_db', 'checkCache'), array('admin_db', 'killCache')); |
---|
5 | |
---|
6 | class admin_db |
---|
7 | { |
---|
8 | function checkDatabase() |
---|
9 | { |
---|
10 | // nothing to do currently |
---|
11 | } |
---|
12 | |
---|
13 | function none() |
---|
14 | { |
---|
15 | // do nothing on submit |
---|
16 | } |
---|
17 | |
---|
18 | function checkCache() |
---|
19 | { |
---|
20 | $size = 0; |
---|
21 | $dir = opendir(KB_CACHEDIR); |
---|
22 | while ($line = readdir($dir)) |
---|
23 | { |
---|
24 | if (strstr($line, 'qcache_qry') !== false) |
---|
25 | { |
---|
26 | $size += filesize(KB_CACHEDIR.'/'.$line); |
---|
27 | } |
---|
28 | } |
---|
29 | |
---|
30 | // GB |
---|
31 | if (($size / 1073741824) > 1){ |
---|
32 | return round($size/1073741824, 4).' GB <input type="checkbox" name="option[sql_clearcache]">Clear cache ?'; |
---|
33 | // MB |
---|
34 | }elseif (($size / 1048576) > 1){ |
---|
35 | return round($size/1048576, 4).' MB <input type="checkbox" name="option[sql_clearcache]">Clear cache ?'; |
---|
36 | // KB |
---|
37 | }else{ |
---|
38 | return round($size/1024, 2).' KB <input type="checkbox" name="option[sql_clearcache]">Clear cache ?'; |
---|
39 | } |
---|
40 | } |
---|
41 | |
---|
42 | function killCache() |
---|
43 | { |
---|
44 | if ($_POST['option']['sql_clearcache'] != 'on') |
---|
45 | { |
---|
46 | return; |
---|
47 | } |
---|
48 | |
---|
49 | $dir = opendir(KB_CACHEDIR); |
---|
50 | while ($line = readdir($dir)) |
---|
51 | { |
---|
52 | if (strstr($line, 'qcache_qry') !== false) |
---|
53 | { |
---|
54 | @unlink(KB_CACHEDIR.'/'.$line); |
---|
55 | } |
---|
56 | elseif (strstr($line, 'qcache_tbl') !== false) |
---|
57 | { |
---|
58 | @unlink(KB_CACHEDIR.'/'.$line); |
---|
59 | } |
---|
60 | } |
---|
61 | } |
---|
62 | } |
---|
63 | ?> |
---|