-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcheck-tables.php
81 lines (60 loc) · 2 KB
/
check-tables.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
#!/usr/bin/php
<?php
// Kutsutaanko CLI:stä
if (php_sapi_name() != 'cli') {
die ("Tätä scriptiä voi ajaa vain komentoriviltä!");
}
// Laitetaan Puperoot includepathiin
ini_set("include_path", ini_get("include_path").PATH_SEPARATOR.dirname(__FILE__));
error_reporting(E_ALL);
ini_set("display_errors", 1);
require "inc/connect.inc";
require "inc/functions.inc";
// Logitetaan ajo
cron_log();
function decho($string) {
echo date("d.m.Y @ G:i:s").": {$string}\n";
}
// Ollaanko annettu --verbose komentoriviltä
$verbose_mode = (in_array("--verbose", $argv) !== false) ? true : false;
$query = "SHOW FULL TABLES FROM `$dbkanta` WHERE Table_Type = 'BASE TABLE'";
$result = pupe_query($query);
decho("Check tables from $dbkanta.");
while ($row = mysqli_fetch_row($result)) {
$table = $row[0];
// check table for errors
$query = "check table $table";
$chkre = pupe_query($query);
$chkro = mysqli_fetch_assoc($chkre);
$_table_broken = ($chkro["Msg_text"] != "OK");
if ($_table_broken or $verbose_mode) {
//decho("$query -> $chkro[Msg_text]"); // MUOKKAUS: kommentoitu ulos
}
if ($_table_broken) {
// repair table for errors
$query = "repair table $table";
$chkre = pupe_query($query);
$chkro = mysqli_fetch_assoc($chkre);
decho("$query -> $chkro[Msg_text]");
}
// optimize table
$query = "optimize table $table";
$chkre = pupe_query($query);
$chkro = mysqli_fetch_assoc($chkre);
$_table_broken = ($chkro["Msg_text"] != "OK" and $chkro["Msg_text"] != "Table is already up to date");
if ($_table_broken or $verbose_mode) {
decho("$query -> $chkro[Msg_text]");
}
// varmistetaan vielä indexien käytössäolo
$query = "show index from $table";
$chkre = pupe_query($query);
while ($chkro = mysqli_fetch_assoc($chkre)) {
if (stripos($chkro["Comment"], "disabled") !== FALSE) {
$query = "alter table $table enable keys";
$chkre = pupe_query($query);
decho("$query -> $chkro[Comment]");
break;
}
}
}
decho("Check tables. Done.");