Skip to content

Commit

Permalink
Issue #5450 - Bulk convert to latin1
Browse files Browse the repository at this point in the history
* Unable to bulk convert to latin1 if desired
* Minor paranoa on audit_database.php
  • Loading branch information
TheWitness committed Aug 12, 2023
1 parent 8ec64bd commit ea05cd5
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 6 deletions.
1 change: 1 addition & 0 deletions CHANGELOG
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ Cacti CHANGELOG
-issue#5440: Device class not saved when importing a template during a new installation
-issue#5446: Duplication functions for Graph/Template and Data Source/Template do not return an id
-issue#5447: Duplication of Device Templates happens in the base Cacti file and not in an API file
-issue#5450: Unable to bulk convert to latin1 if desired
-feature#5375: Add template for Fortinet firewall and Aruba Instant cluster
-feature#5393: Add template for SNMP printer
-feature#5418: Display device class before package import
Expand Down
10 changes: 8 additions & 2 deletions cli/audit_database.php
Original file line number Diff line number Diff line change
Expand Up @@ -325,10 +325,16 @@ function repair_database($run = true) {
AND TABLE_NAME = ?',
array($database_default, $table));

if (isset($tblinfo['COLLATION'])) {
$collation = $tblinfo['COLLATION'];
} else {
$collation = 'utf8mb4';
}

if ($tblinfo['ENGINE'] == 'MyISAM') {
$suffix = ",\n ENGINE=InnoDB ROW_FORMAT=Dynamic CHARSET=" . $tblinfo['COLLATION'];
$suffix = ",\n ENGINE=InnoDB ROW_FORMAT=Dynamic CHARSET=" . $collation;
} else {
$suffix = ",\n ROW_FORMAT=Dynamic CHARSET=" . $tblinfo['COLLATION'];
$suffix = ",\n ROW_FORMAT=Dynamic CHARSET=" . $collation;
}

$sql = 'ALTER TABLE `' . $table . "`\n " . implode(",\n ", $changes) . $suffix . ';';
Expand Down
20 changes: 16 additions & 4 deletions cli/convert_tables.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@

$innodb = false;
$utf8 = false;
$latin = false;
$debug = false;
$size = 1000000;
$force = false;
Expand Down Expand Up @@ -79,6 +80,10 @@
case '--innodb':
$innodb = true;
break;
case '-l':
case '--latin1':
$latin = true;
break;
case '-n':
case '--skip-innodb':
$skip_tables = explode(' ', $value);
Expand Down Expand Up @@ -119,8 +124,8 @@
exit;
}

if (!($innodb || $utf8)) {
print_or_log($installer, "ERROR: Must select either UTF8 or InnoDB conversion.\n\n");
if (!($innodb || $utf8 || $latin)) {
print_or_log($installer, "ERROR: Must select either UTF8, LATIN1 or InnoDB conversion.\n\n");
display_help();
exit;
}
Expand Down Expand Up @@ -191,6 +196,10 @@
$canConvert = $table['Collation'] != 'utf8mb4_unicode_ci';
}

if (!$canConvert && $latin) {
$canConvert = $table['Collation'] != 'latin1';
}

if ($dynamic && $table['Row_format'] == 'Compact') {
$canConvert = true;
}
Expand All @@ -202,6 +211,8 @@
$sql = '';
if ($utf8) {
$sql .= ' CONVERT TO CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci';
} elseif ($latin) {
$sql .= ' CONVERT TO CHARACTER SET latin1';
}

if ($innodb && $canInnoDB) {
Expand Down Expand Up @@ -252,12 +263,13 @@ function display_version() {
function display_help () {
display_version();

print "\nusage: convert_tables.php [--debug] [--innodb] [--utf8] [--table=N] [--size=N] [--rebuild] [--dynamic]\n\n";
print "\nusage: convert_tables.php [--debug] [--innodb] [--utf8] [--latin1] [--table=N] [--size=N] [--rebuild] [--dynamic]\n\n";
print "A utility to convert a Cacti Database from MyISAM to the InnoDB table format.\n";
print "MEMORY tables are not converted to InnoDB in this process.\n\n";
print "Required (one or more):\n";
print "-i | --innodb - Convert any MyISAM tables to InnoDB\n";
print "-u | --utf8 - Convert any non-UTF8 tables to utf8mb4_unicode_ci\n\n";
print "-u | --utf8 - Convert any non-UTF8 tables to utf8mb4_unicode_ci\n";
print "-l | --latin1 - Convert any non-latin1 tables to latin1\n\n";
print "Optional:\n";
print "-t | --table=S - The name of a single table to change\n";
print "-n | --skip-innodb=\"table1 table2 ...\" - Skip converting tables to InnoDB\n";
Expand Down

0 comments on commit ea05cd5

Please sign in to comment.