From e9ec00f268f36e2ea5322fdd0dc3c9cb47c5be18 Mon Sep 17 00:00:00 2001 From: TheWitness Date: Sun, 29 Oct 2023 12:40:27 -0400 Subject: [PATCH] QA: Make sure on new installs hashes are updated - This is an interim issue not so much in production. --- automation_templates.php | 2 ++ lib/api_automation.php | 30 ++++++++++++++++++++++++++++++ 2 files changed, 32 insertions(+) diff --git a/automation_templates.php b/automation_templates.php index 40b262f5b..e8a9127cf 100644 --- a/automation_templates.php +++ b/automation_templates.php @@ -1315,6 +1315,8 @@ function template_edit() { function template() { global $at_actions, $item_rows, $availability_options; + automation_update_hashes(); + /* ================= input validation and session storage ================= */ $filters = array( 'rows' => array( diff --git a/lib/api_automation.php b/lib/api_automation.php index 8dbe8fb4b..cd15ee968 100644 --- a/lib/api_automation.php +++ b/lib/api_automation.php @@ -4661,6 +4661,36 @@ function automation_hash_to_id($type, $hash) { return false; } +function automation_update_hashes() { + $tables = array( + 'automation_templates', + 'automation_templates_rules', + 'automation_graph_rules', + 'automation_graph_rule_items', + 'automation_tree_rules', + 'automation_tree_rule_items', + 'automation_match_rule_items', + 'automation_snmp', + 'automation_snmp_items', + 'automation_networks' + ); + + foreach($tables as $table) { + $items = db_fetch_assoc("SELECT id FROM $table WHERE hash = ''"); + + if (cacti_sizeof($items)) { + foreach($items as $item) { + $hash = get_hash_automation(0, $table); + + db_execute_prepared("UPDATE $table + SET hash = ? + WHERE id = ?", + array($hash, $item['id'])); + } + } + } +} + function automation_network_export($network_ids) { if (!is_array($network_ids)) { $export_name = db_fetch_cell_prepared("SELECT CONCAT('automation_network_', name)