Skip to content

Commit

Permalink
Fixing #5581 - Colors table upgrade failure causing upgrade failure
Browse files Browse the repository at this point in the history
Due to previously never completed upgrade, future upgrades fail due to missing color table keys
  • Loading branch information
TheWitness committed Nov 18, 2023
1 parent 308835b commit 24a7a46
Show file tree
Hide file tree
Showing 2 changed files with 47 additions and 0 deletions.
1 change: 1 addition & 0 deletions CHANGELOG
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ Cacti CHANGELOG
-issue#5565: Incorrect variable name in change_device cli script
-issue#5572: RRD Checker timeouts to low
-issue#5573: Incorrect URL for editing graph template
-issue#5581: Due to previously never completed upgrade, future upgrades fail due to missing color table keys
-feature#5577: Provide new templates for ArubaOS switch, Aruba wifi controller and HPE iLO to be available during install

1.2.25
Expand Down
46 changes: 46 additions & 0 deletions install/upgrades/1_2_26.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,5 +25,51 @@
function upgrade_to_1_2_26() {
db_install_execute("ALTER TABLE `settings` MODIFY `value` varchar(4096) not null default ''");
db_install_execute("ALTER TABLE `settings_user` MODIFY `value` varchar(4096) not null default ''");

/* rerun this function just in case for some reason it was missed */
$duplicates = db_install_fetch_assoc('SELECT hex, COUNT(*) AS totals
FROM colors
GROUP BY hex
HAVING totals > 1');

if (cacti_sizeof($duplicates['data'])) {
$duplicates = $duplicates['data'];

foreach($duplicates as $duplicate) {
$hexes_results = db_install_fetch_assoc('SELECT id, hex
FROM colors
WHERE hex = ?
ORDER BY id ASC',
array($duplicate['hex']), true);
$hexes = $hexes_results['data'];

$first = true;

foreach($hexes as $hex) {
if ($first) {
$keephex = $hex['id'];
$first = false;
} else {
db_install_execute('UPDATE graph_templates_item
SET color_id = ?
WHERE color_id = ?',
array($keephex, $hex['id']));

if (db_table_exists('color_template_items')) {
db_install_execute('UPDATE color_template_items
SET color_id = ?
WHERE color_id = ?',
array($keephex, $hex['id']));
}

db_install_execute('DELETE FROM colors WHERE id = ?', array($hex['id']));
}
}
}

if (!db_index_exists('colors', 'hex')) {
db_install_add_key('colors', 'UNIQUE INDEX', 'hex', array('hex'));
}
}
}

0 comments on commit 24a7a46

Please sign in to comment.