| 1 |
<?php |
| 2 |
|
| 3 |
if ( ! defined( 'ABSPATH' ) ) { |
| 4 |
exit; // Exit if accessed directly |
| 5 |
} |
| 6 |
|
| 7 |
/** |
| 8 |
* Class LP_Sessions_DB |
| 9 |
* |
| 10 |
* @since 4.1.1 |
| 11 |
*/ |
| 12 |
class LP_Sessions_DB extends LP_Database { |
| 13 |
private static $_instance; |
| 14 |
|
| 15 |
protected function __construct() { |
| 16 |
parent::__construct(); |
| 17 |
} |
| 18 |
|
| 19 |
public static function getInstance() { |
| 20 |
if ( is_null( self::$_instance ) ) { |
| 21 |
self::$_instance = new self(); |
| 22 |
} |
| 23 |
|
| 24 |
return self::$_instance; |
| 25 |
} |
| 26 |
|
| 27 |
/** |
| 28 |
* Get delete rows in session table |
| 29 |
* |
| 30 |
* @throws |
| 31 |
*/ |
| 32 |
public function delete_rows() { |
| 33 |
$now = current_time( 'timestamp' ); |
| 34 |
$adayago = $now - ( 24 * 60 * 60 ); |
| 35 |
$where = 'WHERE session_expiry < ' . $adayago . ''; |
| 36 |
$table = $this->tb_lp_sessions; |
| 37 |
$limit = 100; |
| 38 |
$result = $this->wpdb->query( |
| 39 |
" |
| 40 |
DELETE FROM {$table} |
| 41 |
{$where} |
| 42 |
LIMIT {$limit} |
| 43 |
" |
| 44 |
); |
| 45 |
|
| 46 |
$this->check_execute_has_error(); |
| 47 |
|
| 48 |
return $result; |
| 49 |
} |
| 50 |
public function count_row_db_sessions() { |
| 51 |
global $wpdb; |
| 52 |
$now = current_time( 'timestamp' ); |
| 53 |
$adayago = $now - ( 24 * 60 * 60 ); |
| 54 |
$where = 'WHERE session_expiry < ' . $adayago . ' AND 0=%d'; |
| 55 |
$query = $wpdb->prepare( |
| 56 |
" |
| 57 |
SELECT count(*) |
| 58 |
FROM $this->tb_lp_sessions |
| 59 |
{$where} |
| 60 |
", |
| 61 |
0 |
| 62 |
); |
| 63 |
|
| 64 |
$result = $wpdb->get_var( $query ); |
| 65 |
return $result; |
| 66 |
} |
| 67 |
} |
| 68 |
|
| 69 |
LP_Sessions_DB::getInstance(); |
| 70 |
|
| 71 |
|