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 | require_once('common/includes/autoupgrade.php'); |
---|
11 | |
---|
12 | // todo: write functions to take care of this |
---|
13 | // based on a database description file |
---|
14 | check_cap_industrial(); |
---|
15 | check_pilots(); |
---|
16 | check_invdetail(); |
---|
17 | check_contracts(); |
---|
18 | check_index(); |
---|
19 | check_tblstrct1(); |
---|
20 | check_tblstrct2(); |
---|
21 | check_tblstrct3(); |
---|
22 | check_tblstrct4(); |
---|
23 | check_tblstrct5(); |
---|
24 | chk_kb3_items(); |
---|
25 | chk_kb3_items2(); |
---|
26 | check_tblstrct6(); |
---|
27 | check_navigationtable(); |
---|
28 | return 'Maintenance complete.<br/>'; |
---|
29 | } |
---|
30 | |
---|
31 | function none() |
---|
32 | { |
---|
33 | // do nothing on submit |
---|
34 | } |
---|
35 | |
---|
36 | function checkCache() |
---|
37 | { |
---|
38 | $size = 0; |
---|
39 | $dir = opendir(KB_CACHEDIR); |
---|
40 | while ($line = readdir($dir)) |
---|
41 | { |
---|
42 | if (strstr($line, 'qcache_qry') !== false) |
---|
43 | { |
---|
44 | $size += filesize(KB_CACHEDIR.'/'.$line); |
---|
45 | } |
---|
46 | } |
---|
47 | |
---|
48 | // GB |
---|
49 | if (($size / 1073741824) > 1){ |
---|
50 | return round($size/1073741824, 4).' GB <input type="checkbox" name="option[sql_clearcache]">Clear cache ?'; |
---|
51 | // MB |
---|
52 | }elseif (($size / 1048576) > 1){ |
---|
53 | return round($size/1048576, 4).' MB <input type="checkbox" name="option[sql_clearcache]">Clear cache ?'; |
---|
54 | // KB |
---|
55 | }else{ |
---|
56 | return round($size/1024, 2).' KB <input type="checkbox" name="option[sql_clearcache]">Clear cache ?'; |
---|
57 | } |
---|
58 | } |
---|
59 | |
---|
60 | function killCache() |
---|
61 | { |
---|
62 | if ($_POST['option']['sql_clearcache'] != 'on') |
---|
63 | { |
---|
64 | return; |
---|
65 | } |
---|
66 | |
---|
67 | $dir = opendir(KB_CACHEDIR); |
---|
68 | while ($line = readdir($dir)) |
---|
69 | { |
---|
70 | if (strstr($line, 'qcache_qry') !== false) |
---|
71 | { |
---|
72 | @unlink(KB_CACHEDIR.'/'.$line); |
---|
73 | } |
---|
74 | elseif (strstr($line, 'qcache_tbl') !== false) |
---|
75 | { |
---|
76 | @unlink(KB_CACHEDIR.'/'.$line); |
---|
77 | } |
---|
78 | } |
---|
79 | } |
---|
80 | } |
---|
81 | ?> |
---|