PluginProbe ʕ •ᴥ•ʔ
WP STAGING – WordPress Backups, Restore, Migration & Clone / 4.11.0
WP STAGING – WordPress Backups, Restore, Migration & Clone v4.11.0
4.11.0 4.10.0 4.9.5 4.9.4 4.9.3 4.9.2 4.9.1 4.9.0 4.8.1 trunk 3.0.0 3.0.1 3.0.2 3.0.3 3.0.4 3.0.5 3.0.6 3.1.0 3.1.1 3.1.2 3.1.3 3.1.4 3.10.0 3.2.0 3.3.1 3.3.2 3.3.3 3.4.1 3.4.3 3.5.0 3.6.0 3.7.1 3.8.0 3.8.1 3.8.2 3.8.3 3.8.4 3.8.5 3.8.6 3.8.7 3.9.0 3.9.1 3.9.2 3.9.3 3.9.4 4.0.0 4.1.0 4.1.1 4.1.2 4.1.3 4.1.4 4.2.0 4.2.1 4.3.0 4.3.1 4.3.2 4.4.0 4.5.0 4.6.0 4.7.0 4.7.1 4.7.2 4.7.3 4.8.0
wp-staging / Framework / Database / WpDbInfo.php
wp-staging / Framework / Database Last commit date
Exporter 1 day ago QueryBuilder 1 day ago CustomTable.php 1 day ago DbInfo.php 1 day ago ExcludedTables.php 1 day ago ExternalDatabaseConfiguration.php 1 day ago OptionPreservationHandler.php 1 day ago SearchReplace.php 1 day ago SelectedTables.php 1 day ago TableDto.php 1 day ago TableService.php 1 day ago TablesRenamer.php 1 day ago WpDbInfo.php 1 day ago WpOptionsInfo.php 1 day ago iDbInfo.php 2 years ago
WpDbInfo.php
135 lines
1 <?php
2
3 namespace WPStaging\Framework\Database;
4
5 use wpdb;
6
7 class WpDbInfo implements iDbInfo
8 {
9
10
11
12
13 const DEFAULT_VERSION = -1;
14
15
16
17
18 protected $wpdb;
19
20
21
22
23 public function __construct(wpdb $wpdb)
24 {
25 $this->wpdb = $wpdb;
26 }
27
28
29
30
31
32 public function getDbCollation(): string
33 {
34 return $this->getVariableByName('collation_database');
35 }
36
37
38
39
40 public function getDbEngine(): string
41 {
42 return $this->getVariableByName('default_storage_engine');
43 }
44
45
46
47
48 public function getMySqlServerVersion(): int
49 {
50 if (!is_null($this->wpdb->dbh)) {
51 return $this->wpdb->dbh->server_version;
52 }
53
54 $value = $this->wpdb->get_var("SELECT @@version");
55
56 return is_null($value) ? self::DEFAULT_VERSION : $this->versionToInt($value);
57 }
58
59
60
61
62 public function getMySqlClientVersion(): int
63 {
64 if (!is_null($this->wpdb->dbh)) {
65 return $this->wpdb->dbh->client_version;
66 }
67
68 return self::DEFAULT_VERSION;
69 }
70
71
72
73
74 public function getServerIp(): string
75 {
76 return $this->getVariableByName('hostname');
77 }
78
79
80
81
82 public function getServerPort(): int
83 {
84 return (int)$this->getVariableByName('port');
85 }
86
87
88
89
90
91 public function getServer(): string
92 {
93 return $this->getServerIp() . ':' . $this->getServerPort();
94 }
95
96
97
98
99 public function toArray(): array
100 {
101 return [
102 'db_engine' => $this->getDbEngine(),
103 'db_collation' => $this->getDbCollation(),
104 'db_server_ver' => $this->getMySqlServerVersion(),
105 'db_client_ver' => $this->getMySqlClientVersion(),
106 ];
107 }
108
109
110
111
112
113
114 protected function getVariableByName(string $varName): string
115 {
116 $query = "SHOW VARIABLES WHERE Variable_name = '" . $varName . "';";
117 $value = $this->wpdb->get_var($query, 1);
118
119 return is_null($value) ? '' : $value;
120 }
121
122
123
124
125
126
127
128 protected static function versionToInt(string $version): int
129 {
130 $match = explode('.', $version);
131
132 return (int)sprintf('%d%02d%02d', $match[0], $match[1], intval($match[2]));
133 }
134 }
135