| 1 |
<?php |
| 2 |
|
| 3 |
// Exit if accessed directly. |
| 4 |
if (!defined('ABSPATH')) { |
| 5 |
exit; |
| 6 |
} |
| 7 |
|
| 8 |
class Easy_Quotes_Fonts_Database |
| 9 |
{ |
| 10 |
private $tablenames = []; |
| 11 |
|
| 12 |
public function __construct() |
| 13 |
{ |
| 14 |
global $wpdb; |
| 15 |
$this->tablenames[0] = $wpdb->prefix . 'easy-quotes-categories'; |
| 16 |
$this->tablenames[1] = $wpdb->prefix . 'easy-quotes-families'; |
| 17 |
$this->tablenames[2] = $wpdb->prefix . 'easy-quotes-variants'; |
| 18 |
$this->tablenames[3] = $wpdb->prefix . 'easy-quotes-files'; |
| 19 |
$this->tablenames[4] = $wpdb->prefix . 'easy-quotes-subsets'; |
| 20 |
$this->tablenames[5] = $wpdb->prefix . 'easy-quotes-family-subsets'; |
| 21 |
} |
| 22 |
|
| 23 |
/** |
| 24 |
* Drop all font tables (cleanup method) |
| 25 |
* |
| 26 |
* @return void |
| 27 |
*/ |
| 28 |
public function dropTables() |
| 29 |
{ |
| 30 |
global $wpdb; |
| 31 |
// Drop in reverse order due to foreign key constraints |
| 32 |
for ($i = 5; $i >= 0; $i--) { |
| 33 |
$wpdb->query("DROP TABLE IF EXISTS `" . $this->tablenames[$i] . "`;"); |
| 34 |
} |
| 35 |
|
| 36 |
// Also remove the database version option |
| 37 |
delete_option('easy-quotes-db-version'); |
| 38 |
} |
| 39 |
|
| 40 |
/** |
| 41 |
* Check if legacy tables exist (helper method) |
| 42 |
* |
| 43 |
* @return bool true if any legacy tables exist |
| 44 |
*/ |
| 45 |
public function legacyTablesExist() |
| 46 |
{ |
| 47 |
global $wpdb; |
| 48 |
|
| 49 |
foreach ($this->tablenames as $tablename) { |
| 50 |
$table_exists = $wpdb->get_var("SHOW TABLES LIKE '$tablename'"); |
| 51 |
if ($table_exists) { |
| 52 |
return true; |
| 53 |
} |
| 54 |
} |
| 55 |
|
| 56 |
return false; |
| 57 |
} |
| 58 |
} |
| 59 |
|