| 1 |
<?php |
| 2 |
|
| 3 |
namespace Dev4Press\Plugin\SweepPress\Basic; |
| 4 |
|
| 5 |
use Dev4Press\Plugin\SweepPress\Base\DB as CoreDB; |
| 6 |
|
| 7 |
if ( ! defined( 'ABSPATH' ) ) { |
| 8 |
exit; |
| 9 |
} |
| 10 |
|
| 11 |
class DB extends CoreDB { |
| 12 |
protected $plugin_instance = 'db'; |
| 13 |
|
| 14 |
public function get_table_rows_count( string $table ) : int { |
| 15 |
$sql = "SELECT COUNT(*) FROM " . $table; |
| 16 |
|
| 17 |
return absint( $this->get_var( $sql ) ); |
| 18 |
} |
| 19 |
|
| 20 |
public function get_actionscheduler_groups() : array { |
| 21 |
$sql = "SELECT * FROM " . $this->actionscheduler_groups; |
| 22 |
$raw = $this->get_results( $sql ); |
| 23 |
|
| 24 |
return $this->pluck( $raw, 'slug', 'group_id' ); |
| 25 |
} |
| 26 |
|
| 27 |
public function repair_table( $name ) : array { |
| 28 |
$info = $this->get_results( "REPAIR TABLE `" . $name . "`" ); |
| 29 |
|
| 30 |
$data = array( |
| 31 |
'note' => '', |
| 32 |
'status' => '', |
| 33 |
'error' => '' |
| 34 |
); |
| 35 |
|
| 36 |
foreach ( $info as $row ) { |
| 37 |
$data[ strtolower( $row->Msg_type ) ] = $row->Msg_text; |
| 38 |
} |
| 39 |
|
| 40 |
if ( empty( $data[ 'status' ] ) ) { |
| 41 |
$data[ 'status' ] = empty( $data[ 'error' ] ) ? __( "Nothing Done", "sweeppress" ) : __( "Operation Failed", "sweeppress" ); |
| 42 |
} |
| 43 |
|
| 44 |
return $data; |
| 45 |
} |
| 46 |
|
| 47 |
public function optimize_table( $name ) : array { |
| 48 |
$info = $this->get_results( "OPTIMIZE TABLE `" . $name . "`" ); |
| 49 |
|
| 50 |
$data = array( |
| 51 |
'note' => '', |
| 52 |
'status' => '', |
| 53 |
'error' => '' |
| 54 |
); |
| 55 |
|
| 56 |
foreach ( $info as $row ) { |
| 57 |
$data[ strtolower( $row->Msg_type ) ] = $row->Msg_text; |
| 58 |
} |
| 59 |
|
| 60 |
return $data; |
| 61 |
} |
| 62 |
} |
| 63 |
|