QueryBuilder
2 years ago
DbInfo.php
2 years ago
ExcludedTables.php
4 years ago
OptionPreservationHandler.php
2 years ago
SearchReplace.php
2 years ago
SelectedTables.php
2 years ago
TableDto.php
5 years ago
TableService.php
2 years ago
TablesRenamer.php
2 years ago
WpDbInfo.php
2 years ago
iDbInfo.php
2 years ago
WpDbInfo.php
107 lines
| 1 | <?php |
| 2 | |
| 3 | namespace WPStaging\Framework\Database; |
| 4 | |
| 5 | class WpDbInfo implements iDbInfo |
| 6 | { |
| 7 | /** |
| 8 | * @var \wpdb |
| 9 | */ |
| 10 | protected $wpdb; |
| 11 | |
| 12 | /** |
| 13 | * @param \wpdb $wpdb |
| 14 | */ |
| 15 | public function __construct($wpdb) |
| 16 | { |
| 17 | $this->wpdb = $wpdb; |
| 18 | } |
| 19 | |
| 20 | /** |
| 21 | * Get the database default collation: collation_database |
| 22 | * @return string |
| 23 | */ |
| 24 | public function getDbCollation(): string |
| 25 | { |
| 26 | $result = $this->wpdb->dbh->query("SHOW VARIABLES LIKE 'collation_database'"); |
| 27 | |
| 28 | $output = ''; |
| 29 | if ($obj = $result->fetch_object()) { |
| 30 | $output = $obj->Value; |
| 31 | } |
| 32 | |
| 33 | return $output; |
| 34 | } |
| 35 | |
| 36 | /** |
| 37 | * @return string |
| 38 | */ |
| 39 | public function getDbEngine(): string |
| 40 | { |
| 41 | $result = $this->wpdb->dbh->query("SHOW VARIABLES LIKE 'default_storage_engine'"); |
| 42 | |
| 43 | $output = ''; |
| 44 | if ($obj = $result->fetch_object()) { |
| 45 | $output = $obj->Value; |
| 46 | } |
| 47 | |
| 48 | return $output; |
| 49 | } |
| 50 | |
| 51 | /** |
| 52 | * @return int |
| 53 | */ |
| 54 | public function getMySqlServerVersion(): int |
| 55 | { |
| 56 | return $this->wpdb->dbh->server_version; |
| 57 | } |
| 58 | |
| 59 | /** |
| 60 | * @return int |
| 61 | */ |
| 62 | public function getMySqlClientVersion(): int |
| 63 | { |
| 64 | return $this->wpdb->dbh->client_version; |
| 65 | } |
| 66 | |
| 67 | /** |
| 68 | * @return string |
| 69 | */ |
| 70 | public function getServerIp(): string |
| 71 | { |
| 72 | $queryToFindHost = "SHOW VARIABLES WHERE Variable_name = 'hostname';"; |
| 73 | return $this->wpdb->get_var($queryToFindHost, 1); |
| 74 | } |
| 75 | |
| 76 | /** |
| 77 | * @return int |
| 78 | */ |
| 79 | public function getServerPort(): int |
| 80 | { |
| 81 | $queryToFindPort = "SHOW VARIABLES WHERE Variable_name = 'port';"; |
| 82 | return (int)$this->wpdb->get_var($queryToFindPort, 1); |
| 83 | } |
| 84 | |
| 85 | /** |
| 86 | * Return the server name and port as server:port |
| 87 | * @return string |
| 88 | */ |
| 89 | public function getServer(): string |
| 90 | { |
| 91 | return $this->getServerIp() . ':' . $this->getServerPort(); |
| 92 | } |
| 93 | |
| 94 | /** |
| 95 | * @return array |
| 96 | */ |
| 97 | public function toArray(): array |
| 98 | { |
| 99 | return [ |
| 100 | 'db_engine' => $this->getDbEngine(), |
| 101 | 'db_collation' => $this->getDbCollation(), |
| 102 | 'db_server_ver' => $this->getMySqlServerVersion(), |
| 103 | 'db_client_ver' => $this->getMySqlClientVersion() |
| 104 | ]; |
| 105 | } |
| 106 | } |
| 107 |