@@ -17,90 +17,90 @@ |
||
17 | 17 | class TableAnalysis extends EE_Base |
18 | 18 | { |
19 | 19 | |
20 | - /** |
|
21 | - * The maximum number of characters that can be indexed on a column using utf8mb4 collation, |
|
22 | - * see https://events.codebasehq.com/redirect?https://make.wordpress.org/core/2015/04/02/the-utf8mb4-upgrade/ |
|
23 | - */ |
|
24 | - const INDEX_COLUMN_SIZE = 191; |
|
20 | + /** |
|
21 | + * The maximum number of characters that can be indexed on a column using utf8mb4 collation, |
|
22 | + * see https://events.codebasehq.com/redirect?https://make.wordpress.org/core/2015/04/02/the-utf8mb4-upgrade/ |
|
23 | + */ |
|
24 | + const INDEX_COLUMN_SIZE = 191; |
|
25 | 25 | |
26 | - /** |
|
27 | - * Returns the table name which will definitely have the wpdb prefix on the front, |
|
28 | - * except if it currently has the wpdb->base_prefix on the front, in which case |
|
29 | - * it will have the wpdb->base_prefix on it |
|
30 | - * |
|
31 | - * @global wpdb $wpdb |
|
32 | - * @param string $table_name |
|
33 | - * @return string $tableName, having ensured it has the wpdb prefix on the front |
|
34 | - */ |
|
35 | - public function ensureTableNameHasPrefix($table_name) |
|
36 | - { |
|
37 | - global $wpdb; |
|
38 | - return strpos($table_name, $wpdb->base_prefix) === 0 ? $table_name : $wpdb->prefix . $table_name; |
|
39 | - } |
|
26 | + /** |
|
27 | + * Returns the table name which will definitely have the wpdb prefix on the front, |
|
28 | + * except if it currently has the wpdb->base_prefix on the front, in which case |
|
29 | + * it will have the wpdb->base_prefix on it |
|
30 | + * |
|
31 | + * @global wpdb $wpdb |
|
32 | + * @param string $table_name |
|
33 | + * @return string $tableName, having ensured it has the wpdb prefix on the front |
|
34 | + */ |
|
35 | + public function ensureTableNameHasPrefix($table_name) |
|
36 | + { |
|
37 | + global $wpdb; |
|
38 | + return strpos($table_name, $wpdb->base_prefix) === 0 ? $table_name : $wpdb->prefix . $table_name; |
|
39 | + } |
|
40 | 40 | |
41 | 41 | |
42 | - /** |
|
43 | - * Indicates whether or not the table has any entries. $table_name can |
|
44 | - * optionally start with $wpdb->prefix or not |
|
45 | - * |
|
46 | - * @global wpdb $wpdb |
|
47 | - * @param string $table_name |
|
48 | - * @return bool |
|
49 | - */ |
|
50 | - public function tableIsEmpty($table_name) |
|
51 | - { |
|
52 | - global $wpdb; |
|
53 | - $table_name = $this->ensureTableNameHasPrefix($table_name); |
|
54 | - if ($this->tableExists($table_name)) { |
|
55 | - $count = $wpdb->get_var("SELECT COUNT(*) FROM $table_name"); |
|
56 | - return absint($count) === 0; |
|
57 | - } |
|
58 | - return false; |
|
59 | - } |
|
42 | + /** |
|
43 | + * Indicates whether or not the table has any entries. $table_name can |
|
44 | + * optionally start with $wpdb->prefix or not |
|
45 | + * |
|
46 | + * @global wpdb $wpdb |
|
47 | + * @param string $table_name |
|
48 | + * @return bool |
|
49 | + */ |
|
50 | + public function tableIsEmpty($table_name) |
|
51 | + { |
|
52 | + global $wpdb; |
|
53 | + $table_name = $this->ensureTableNameHasPrefix($table_name); |
|
54 | + if ($this->tableExists($table_name)) { |
|
55 | + $count = $wpdb->get_var("SELECT COUNT(*) FROM $table_name"); |
|
56 | + return absint($count) === 0; |
|
57 | + } |
|
58 | + return false; |
|
59 | + } |
|
60 | 60 | |
61 | 61 | |
62 | - /** |
|
63 | - * Indicates whether or not the table exists. $table_name can optionally |
|
64 | - * have the $wpdb->prefix on the beginning, or not. |
|
65 | - * |
|
66 | - * @global wpdb $wpdb |
|
67 | - * @param string $table_name |
|
68 | - * @return bool |
|
69 | - */ |
|
70 | - public function tableExists($table_name) |
|
71 | - { |
|
72 | - global $wpdb; |
|
73 | - $table_name = $this->ensureTableNameHasPrefix($table_name); |
|
74 | - $query = $wpdb->prepare( 'SHOW TABLES LIKE %s', $wpdb->esc_like( $table_name ) ); |
|
75 | - return $wpdb->get_var( $query ) === $table_name; |
|
76 | - } |
|
62 | + /** |
|
63 | + * Indicates whether or not the table exists. $table_name can optionally |
|
64 | + * have the $wpdb->prefix on the beginning, or not. |
|
65 | + * |
|
66 | + * @global wpdb $wpdb |
|
67 | + * @param string $table_name |
|
68 | + * @return bool |
|
69 | + */ |
|
70 | + public function tableExists($table_name) |
|
71 | + { |
|
72 | + global $wpdb; |
|
73 | + $table_name = $this->ensureTableNameHasPrefix($table_name); |
|
74 | + $query = $wpdb->prepare( 'SHOW TABLES LIKE %s', $wpdb->esc_like( $table_name ) ); |
|
75 | + return $wpdb->get_var( $query ) === $table_name; |
|
76 | + } |
|
77 | 77 | |
78 | 78 | |
79 | - /** |
|
80 | - * @param string $table_name |
|
81 | - * @param string $index_name |
|
82 | - * @return array of columns used on that index, Each entry is an object with the following properties { |
|
83 | - * @type string Table |
|
84 | - * @type string Non_unique "0" or "1" |
|
85 | - * @type string Key_name |
|
86 | - * @type string Seq_in_index |
|
87 | - * @type string Column_name |
|
88 | - * @type string Collation |
|
89 | - * @type string Cardinality |
|
90 | - * @type string Sub_part on a column, usually this is just the number of characters from this column to use in |
|
91 | - * indexing |
|
92 | - * @type string|null Packed |
|
93 | - * @type string Null |
|
94 | - * @type string Index_type |
|
95 | - * @type string Comment |
|
96 | - * @type string Index_comment |
|
97 | - * } |
|
98 | - */ |
|
99 | - public function showIndexes($table_name, $index_name) |
|
100 | - { |
|
101 | - global $wpdb; |
|
102 | - $table_name = $this->ensureTableNameHasPrefix($table_name); |
|
103 | - $index_exists_query = "SHOW INDEX FROM {$table_name} WHERE Key_name = '{$index_name}'"; |
|
104 | - return $wpdb->get_results($index_exists_query); |
|
105 | - } |
|
79 | + /** |
|
80 | + * @param string $table_name |
|
81 | + * @param string $index_name |
|
82 | + * @return array of columns used on that index, Each entry is an object with the following properties { |
|
83 | + * @type string Table |
|
84 | + * @type string Non_unique "0" or "1" |
|
85 | + * @type string Key_name |
|
86 | + * @type string Seq_in_index |
|
87 | + * @type string Column_name |
|
88 | + * @type string Collation |
|
89 | + * @type string Cardinality |
|
90 | + * @type string Sub_part on a column, usually this is just the number of characters from this column to use in |
|
91 | + * indexing |
|
92 | + * @type string|null Packed |
|
93 | + * @type string Null |
|
94 | + * @type string Index_type |
|
95 | + * @type string Comment |
|
96 | + * @type string Index_comment |
|
97 | + * } |
|
98 | + */ |
|
99 | + public function showIndexes($table_name, $index_name) |
|
100 | + { |
|
101 | + global $wpdb; |
|
102 | + $table_name = $this->ensureTableNameHasPrefix($table_name); |
|
103 | + $index_exists_query = "SHOW INDEX FROM {$table_name} WHERE Key_name = '{$index_name}'"; |
|
104 | + return $wpdb->get_results($index_exists_query); |
|
105 | + } |
|
106 | 106 | } |
@@ -35,7 +35,7 @@ discard block |
||
35 | 35 | public function ensureTableNameHasPrefix($table_name) |
36 | 36 | { |
37 | 37 | global $wpdb; |
38 | - return strpos($table_name, $wpdb->base_prefix) === 0 ? $table_name : $wpdb->prefix . $table_name; |
|
38 | + return strpos($table_name, $wpdb->base_prefix) === 0 ? $table_name : $wpdb->prefix.$table_name; |
|
39 | 39 | } |
40 | 40 | |
41 | 41 | |
@@ -71,8 +71,8 @@ discard block |
||
71 | 71 | { |
72 | 72 | global $wpdb; |
73 | 73 | $table_name = $this->ensureTableNameHasPrefix($table_name); |
74 | - $query = $wpdb->prepare( 'SHOW TABLES LIKE %s', $wpdb->esc_like( $table_name ) ); |
|
75 | - return $wpdb->get_var( $query ) === $table_name; |
|
74 | + $query = $wpdb->prepare('SHOW TABLES LIKE %s', $wpdb->esc_like($table_name)); |
|
75 | + return $wpdb->get_var($query) === $table_name; |
|
76 | 76 | } |
77 | 77 | |
78 | 78 |