upgrade all with dice compatible
This commit is contained in:
+18
-21
@@ -6,31 +6,28 @@
|
||||
Desc. : Class Check SQL / Repair Database
|
||||
Created By : Siau Pheng ([email protected]).
|
||||
Created Date : May 11th, 2011.
|
||||
Last Modified : August 13th, 2026.
|
||||
Last Modified : August 21st, 2026.
|
||||
|
||||
(c) 2011 - 2026, 3FONIA Software; WWW.3FONIA.COM.
|
||||
(c) 3FONIA Software; WWW.3FONIA.COM.
|
||||
|
||||
*******************************************************************/
|
||||
|
||||
//OK
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace siaupheng\webapp\DB;
|
||||
|
||||
use Exception;
|
||||
use flight\Engine;
|
||||
use flight\Session;
|
||||
use flight\database\SimplePdo;
|
||||
use \Exception;
|
||||
use \flight\Engine;
|
||||
use \flight\database\SimplePdo;
|
||||
|
||||
final class CheckSQL {
|
||||
private Array $__atabel = [];
|
||||
protected Engine $app;
|
||||
protected SimplePdo $db;
|
||||
|
||||
public function __construct(?Engine $app = null){
|
||||
$this->app = (empty($app) === true) ? \Flight::app() : $app;
|
||||
$this->db = $this->app->db();
|
||||
|
||||
public function __construct(Engine $app, SimplePdo $db) {
|
||||
$this->app = $app;
|
||||
$this->db = $db;
|
||||
$nama_db = $this->db->fetchField('SELECT DATABASE()');
|
||||
$arow = $this->db->fetchAll("SELECT TABLE_NAME,ENGINE,TABLE_ROWS FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_SCHEMA='".$nama_db."' AND TABLE_TYPE='BASE TABLE'");
|
||||
foreach ($arow as $row) {
|
||||
@@ -38,14 +35,14 @@ final class CheckSQL {
|
||||
}
|
||||
}
|
||||
|
||||
public function ignore_table() {
|
||||
public function ignore_table(): void {
|
||||
$tmp_arr = func_get_args();
|
||||
if (is_array($tmp_arr[0])) $tmp_arr = $tmp_arr[0];
|
||||
$farray = array_filter($this->__atabel, fn($child) => !in_array($child[0], $tmp_arr));
|
||||
$this->__atabel = array_values($farray);
|
||||
}
|
||||
|
||||
private function _check_db(array $atabel=[]) {
|
||||
private function _check_db(array $atabel=[]): string {
|
||||
$pesan = '<span style="color:blue;">OK</span>';
|
||||
$row = $this->db->runQuery('CHECK TABLE '.$atabel[0].' QUICK')->fetch(SimplePdo::FETCH_ASSOC);
|
||||
if (($row['Msg_text'] ?? '') !== 'OK') {
|
||||
@@ -57,24 +54,24 @@ final class CheckSQL {
|
||||
$pesan .= ' -> Auto Repair <span style="color:red;">' . $e->getMessage() . '</span>';
|
||||
}
|
||||
}
|
||||
return $atabel[0] . $atabel[3] ." ... ". $pesan ."<br>";
|
||||
return $atabel[0] . $atabel[3] ." ... ". $pesan;
|
||||
}
|
||||
|
||||
private function _opti_db(array $atabel=[]) {
|
||||
private function _opti_db(array $atabel=[]): string {
|
||||
$pesan = '<span style="color:orange;">SKIP</span>';
|
||||
if ($atabel[1] === 'MyISAM') {
|
||||
$pesan = '<span style="color:blue;">OK</span>';
|
||||
$row = $this->db->runQuery('OPTIMIZE TABLE '.$atabel[0])->fetch(SimplePdo::FETCH_ASSOC);
|
||||
if (!in_array(strtoupper($row['Msg_text'] ?? ''), ['OK','TABLE IS ALREADY UP TO DATE'])) $pesan = '<span style="color:red;">ERROR</span>';
|
||||
}
|
||||
return $atabel[0] . $atabel[2] ." ... ". $pesan ."<br>";
|
||||
return $atabel[0] . $atabel[2] ." ... ". $pesan;
|
||||
}
|
||||
|
||||
public function count_db() {
|
||||
public function count_db(): int {
|
||||
return count($this->__atabel);
|
||||
}
|
||||
|
||||
public function check_db() {
|
||||
public function check_db(): string {
|
||||
$hasil = "=== CEK DATABASE ===<br>";
|
||||
for ($n=0; $n<count($this->__atabel); $n++) {
|
||||
$hasil .= $this->_check_db($this->__atabel[$n]);
|
||||
@@ -82,11 +79,11 @@ final class CheckSQL {
|
||||
return $hasil;
|
||||
}
|
||||
|
||||
public function check_db_step($n) {
|
||||
public function check_db_step(int $n): string {
|
||||
return $this->_check_db($this->__atabel[$n]);
|
||||
}
|
||||
|
||||
public function optimize_db() {
|
||||
public function optimize_db(): string {
|
||||
$hasil = "=== OPTIMALISASI DATABASE ===<br>";
|
||||
for ($n=0;$n<count($this->__atabel);$n++) {
|
||||
$hasil .= $this->_opti_db($this->__atabel[$n]);
|
||||
@@ -94,7 +91,7 @@ final class CheckSQL {
|
||||
return $hasil;
|
||||
}
|
||||
|
||||
public function optimize_db_step($n) {
|
||||
public function optimize_db_step(int $n): string {
|
||||
return $this->_opti_db($this->__atabel[$n]);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user