first commit

This commit is contained in:
2023-09-12 21:41:04 +02:00
commit 3361a7f053
13284 changed files with 2116755 additions and 0 deletions

View File

@@ -0,0 +1,8 @@
<?php
interface WPML_ST_Translations_File_Scan_Charset_Validation {
/**
* @return bool
*/
public function is_valid();
}

View File

@@ -0,0 +1,18 @@
<?php
class WPML_ST_Translations_File_Scan_Db_Charset_Filter_Factory {
/** @var wpdb $wpdb */
private $wpdb;
public function __construct( wpdb $wpdb ) {
$this->wpdb = $wpdb;
}
public function create() {
$charset_validator = new WPML_ST_Translations_File_Scan_Db_Charset_Validation( $this->wpdb, new WPML_ST_Translations_File_Scan_Db_Table_List( $this->wpdb ) );
return $charset_validator->is_valid() ? null : new WPML_ST_Translations_File_Unicode_Characters_Filter();
}
}

View File

@@ -0,0 +1,51 @@
<?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 ) {
$columns = $this->wpdb->get_results( "SHOW FULL COLUMNS FROM `{$table}` WHERE Collation LIKE 'utf8mb4%'" );
return array_unique( wp_list_pluck( $columns, 'Collation' ) );
}
}

View File

@@ -0,0 +1,23 @@
<?php
class WPML_ST_Translations_File_Scan_Db_Table_List {
/** @var wpdb */
private $wpdb;
/**
* @param wpdb $wpdb
*/
public function __construct( wpdb $wpdb ) {
$this->wpdb = $wpdb;
}
/**
* @return array
*/
public function get_tables() {
return array(
$this->wpdb->prefix . 'icl_strings',
$this->wpdb->prefix . 'icl_string_translations',
);
}
}