diff --git a/htdocs/core/class/utils.class.php b/htdocs/core/class/utils.class.php index 7be7e8f28cc..9534970a856 100644 --- a/htdocs/core/class/utils.class.php +++ b/htdocs/core/class/utils.class.php @@ -194,6 +194,7 @@ class Utils { global $db, $conf, $langs, $dolibarr_main_data_root; global $dolibarr_main_db_name, $dolibarr_main_db_host, $dolibarr_main_db_user, $dolibarr_main_db_port, $dolibarr_main_db_pass; + global $dolibarr_main_db_character_set; $langs->load("admin"); @@ -316,7 +317,12 @@ class Utils } else { $param .= " -d"; // No row information (no data) } - $param .= " --default-character-set=utf8"; // We always save output into utf8 charset + if ($dolibarr_main_db_character_set == 'utf8mb4') { + // We save output into utf8mb4 charset + $param .= " --default-character-set=utf8mb4"; + } else { + $param .= " --default-character-set=utf8"; // We always save output into utf8 charset + } $paramcrypted = $param; $paramclear = $param; if (!empty($dolibarr_main_db_pass)) { diff --git a/htdocs/install/repair.php b/htdocs/install/repair.php index 1f80d37efd8..ed4fb8dab13 100644 --- a/htdocs/install/repair.php +++ b/htdocs/install/repair.php @@ -3,6 +3,7 @@ * Copyright (C) 2004-2012 Laurent Destailleur * Copyright (C) 2005-2012 Regis Houssin * Copyright (C) 2015 Raphaël Doursenaud + * Copyright (C) 2021 Frédéric France * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -94,6 +95,7 @@ print 'Option repair_link_dispatch_lines_supplier_order_lines, (\'test\' or \'co print 'Option set_empty_time_spent_amount (\'test\' or \'confirmed\') is '.(GETPOST('set_empty_time_spent_amount', 'alpha') ?GETPOST('set_empty_time_spent_amount', 'alpha') : 'undefined').'
'."\n"; // Structure print 'Option force_utf8_on_tables, for mysql/mariadb only (\'test\' or \'confirmed\') is '.(GETPOST('force_utf8_on_tables', 'alpha') ?GETPOST('force_utf8_on_tables', 'alpha') : 'undefined').'
'."\n"; +print "Option force_utf8mb4_on_tables (EXPERIMENTAL!), for mysql/mariadb only ('test' or 'confirmed') is ".(GETPOST('force_utf8mb4_on_tables', 'alpha') ? GETPOST('force_utf8mb4_on_tables', 'alpha') : 'undefined')."
\n"; // Rebuild sequence print 'Option rebuild_sequences, for postgresql only (\'test\' or \'confirmed\') is '.(GETPOST('rebuild_sequences', 'alpha') ?GETPOST('rebuild_sequences', 'alpha') : 'undefined').'
'."\n"; print '
'; @@ -1256,6 +1258,60 @@ if ($ok && GETPOST('force_utf8_on_tables', 'alpha')) { } } +// force utf8mb4 on tables EXPERIMENTAL ! +if ($ok && GETPOST('force_utf8mb4_on_tables', 'alpha')) { + print '
*** Force page code and collation of tables into utf8mb4/utf8mb4_unicode_ci (for mysql/mariadb only)'; + + if ($db->type == "mysql" || $db->type == "mysqli") { + $force_utf8mb4_on_tables = GETPOST('force_utf8mb4_on_tables', 'alpha'); + + $listoftables = $db->DDLListTables($db->database_name); + + // Disable foreign key checking for avoid errors + if ($force_utf8mb4_on_tables == 'confirmed') { + $sql = 'SET FOREIGN_KEY_CHECKS=0'; + print ''; + $resql = $db->query($sql); + } + + foreach ($listoftables as $table) { + // do not convert llx_const if mysql encrypt/decrypt is used + if ($conf->db->dolibarr_main_db_encryption != 0 && preg_match('/\_const$/', $table)) { + continue; + } + + print ''; + print $table; + $sql1 = 'ALTER TABLE '.$table.' ROW_FORMAT=dynamic;'; + $sql2 = 'ALTER TABLE '.$table.' CONVERT TO CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci'; + print ''; + print ''; + if ($force_utf8mb4_on_tables == 'confirmed') { + $resql1 = $db->query($sql1); + if ($resql1) { + $resql2 = $db->query($sql2); + } else { + $resql2 = false; + } + print ' - Done ('.(($resql1 && $resql2) ? 'OK' : 'KO').')'; + } else { + print ' - Disabled'; + } + print ''; + flush(); + ob_flush(); + } + + // Enable foreign key checking + if ($force_utf8mb4_on_tables == 'confirmed') { + $sql = 'SET FOREIGN_KEY_CHECKS=1'; + print ''; + $resql = $db->query($sql); + } + } else { + print 'Not available with database type '.$db->type.''; + } +} // rebuild sequences for pgsql if ($ok && GETPOST('rebuild_sequences', 'alpha')) { @@ -1274,7 +1330,6 @@ if ($ok && GETPOST('rebuild_sequences', 'alpha')) { } } - // if ($ok && GETPOST('repair_link_dispatch_lines_supplier_order_lines')) { /*