Skip to content

Commit

Permalink
Add self recovery for database if corrupted (reliability)
Browse files Browse the repository at this point in the history
  • Loading branch information
hendrowicaksono committed Sep 12, 2012
1 parent 04d4173 commit cc8e795
Showing 1 changed file with 32 additions and 0 deletions.
32 changes: 32 additions & 0 deletions admin/default/home.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*
* some patches by hendro
*/

// key to authenticate
Expand Down Expand Up @@ -72,6 +73,37 @@
$warnings[] = __('The PATH for <strong>mysqldump</strong> program is not right! Please check configuration file or you won\'t be able to do any database backups.');
}

// check need to be repaired mysql database
$query_of_tables = $dbs->query('SHOW TABLES');
$num_of_tables = $query_of_tables->num_rows;
$prevtable = '';
$is_repaired = false;

if (isset ($_POST['do_repair'])) {
if ($_POST['do_repair'] == 1) {
while ($row = $query_of_tables->fetch_row()) {
$sql_of_repair = 'REPAIR TABLE '.$row[0];
$query_of_repair = $dbs->query ($sql_of_repair);
}
}
}

while ($row = $query_of_tables->fetch_row()) {
$query_of_check = $dbs->query('CHECK TABLE '.$row[0]);
while ($rowcheck = $query_of_check->fetch_assoc()) {
if (!(($rowcheck['Msg_type'] == "status") && ($rowcheck['Msg_text'] == "OK"))) {
if ($row[0] != $prevtable) {
echo '<li class="warning">Table '.$row[0].' might need to be repaired.</li>';
}
$prevtable = $row[0];
$is_repaired = true;
}
}
}
if (($is_repaired) && !isset($_POST['do_repair'])) {
echo '<li class="warning"><form method="POST"><input type="hidden" name="do_repair" value="1"><input value="Repaire Tables" type="submit"></form></li>';
}

// if there any warnings
if ($warnings) {
echo '<div class="message">';
Expand Down

0 comments on commit cc8e795

Please sign in to comment.