wpml-st-translations-file-scan-db-charset-validation.php
1.29 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
<?php
class WPML_ST_Translations_File_Scan_Db_Charset_Validation implements WPML_ST_Translations_File_Scan_Charset_Validation {
/** @var wpdb */
private $wpdb;
/** @var WPML_ST_Translations_File_Scan_Db_Table_List */
private $table_list;
/**
* @param wpdb $wpdb
* @param WPML_ST_Translations_File_Scan_Db_Table_List $table_list
*/
public function __construct( wpdb $wpdb, WPML_ST_Translations_File_Scan_Db_Table_List $table_list ) {
$this->wpdb = $wpdb;
$this->table_list = $table_list;
}
/**
* @return bool
*/
public function is_valid() {
if ( ! $this->wpdb->has_cap( 'utf8mb4' ) ) {
return false;
}
$chunks = array();
foreach ( $this->table_list->get_tables() as $table ) {
$chunks[] = $this->get_unique_collation_list_from_table( $table );
}
$collations = call_user_func_array( 'array_merge', $chunks );
$collations = array_unique( $collations );
return count( $collations ) < 2;
}
/**
* @param string $table
*
* @return array
*/
private function get_unique_collation_list_from_table( $table ) {
/** @var array $columns */
$columns = $this->wpdb->get_results( "SHOW FULL COLUMNS FROM `{$table}` WHERE Collation LIKE 'utf8mb4%'" );
return array_unique( wp_list_pluck( $columns, 'Collation' ) );
}
}