diff --git a/pandora_console/include/functions_agents.php b/pandora_console/include/functions_agents.php index bb5b19a27e..3009671216 100644 --- a/pandora_console/include/functions_agents.php +++ b/pandora_console/include/functions_agents.php @@ -2766,13 +2766,6 @@ function agents_delete_agent($id_agents, $disableACL=false) ['id_agent' => $id_agent] ); - // Delete agent from visual dashboards. - db_process_sql( - 'UPDATE twidget_dashboard - SET options = NULL - WHERE options LIKE ("%\"agentid\":\"'.$id_agent.'\"%")' - ); - // Delete agent from treport. db_process_sql_delete( 'treport_content', @@ -2796,33 +2789,12 @@ function agents_delete_agent($id_agents, $disableACL=false) ] ); - // Delete from gis maps history - db_process_sql_delete( - 'tgis_data_history', - ['tagente_id_agente' => $id_agent] - ); - // Delete from policies. db_process_sql_delete( 'tpolicy_agents', ['id_agent' => $id_agent] ); - // Delete from tnetwork maps - db_process_sql_delete( - 'titem', - ['source_data' => $id_agent] - ); - - db_process_sql_delete( - 'trel_item', - [ - 'id_parent_source_data' => $id_agent, - 'id_child_source_data' => $id_agent, - ], - 'OR' - ); - // Delete agent from fav menu. db_process_sql_delete( 'tfavmenu_user', diff --git a/pandora_server/util/pandora_db.pl b/pandora_server/util/pandora_db.pl index d6ef5c4334..ce476d7154 100755 --- a/pandora_server/util/pandora_db.pl +++ b/pandora_server/util/pandora_db.pl @@ -772,47 +772,10 @@ sub pandora_checkdb_integrity { db_do ($dbh, 'DELETE FROM tlayout_data WHERE id_agent <> 0 AND id_agent NOT IN (SELECT id_agente FROM tagente)'); db_do ($dbh, 'DELETE FROM tlayout_data WHERE id_agente_modulo <> 0 AND id_agente_modulo NOT IN (SELECT id_agente_modulo FROM tagente_modulo)'); - # Delete orphan data form deleted agents. - # Clearl orphan data from dashboards - log_message ('INTEGRITY', "Deleting orphan dahsboard items."); - my @agents_ids = get_db_rows($dbh, 'SELECT id_agente FROM tagente'); - my $where_condition; - foreach my $agent_id (@agents_ids) { - $where_condition .= 'options NOT LIKE ("%\\"agentid\\":\\"'.$agent_id->{'id_agente'}.'\\"%")'; - if($agent_id == $agents_ids[-1]) { - last; - } - $where_condition .= ' AND '; - } - - db_do ($dbh, 'UPDATE twidget_dashboard set options = NULL WHERE '.$where_condition); - - $where_condition = ''; - my @modules = get_db_rows($dbh, 'SELECT id_agente_modulo FROM tagente_modulo'); - foreach my $id_agente_modulo (@modules) { - $where_condition .= 'options NOT LIKE ("%\\"moduleId\\":\\"'.$id_agente_modulo->{'id_agente_modulo'}.'\\"%")'; - if($id_agente_modulo == $modules[-1]) { - last; - } - $where_condition .= ' AND '; - } - - db_do ($dbh, 'UPDATE twidget_dashboard set options = NULL WHERE '.$where_condition); - # Delete orphan data from favorite agents log_message ('INTEGRITY', "Deleting orphan favories items."); db_do ($dbh, 'DELETE FROM tfavmenu_user WHERE section = "Agents" AND id_element NOT IN (SELECT id_agente FROM tagente)'); - # Delete orphan data from gis maps - log_message ('INTEGRITY', "Deleting orphan GIS data."); - db_do ($dbh, 'DELETE FROM tgis_data_history WHERE tagente_id_agente NOT IN (SELECT id_agente FROM tagente)'); - - # Delete orphan tnetwork maps data - log_message ('INTEGRITY', "Deleting orphan networkmaps data."); - db_do ($dbh, 'DELETE FROM titem WHERE source_data NOT IN (SELECT id_agente FROM tagente)'); - db_do ($dbh, 'DELETE FROM trel_item WHERE id_parent_source_data NOT IN (SELECT id_agente FROM tagente) OR id_child_source_data NOT IN (SELECT id_agente FROM tagente)'); - - # Check enterprise tables enterprise_hook ('pandora_checkdb_integrity_enterprise', [$conf, $dbh]); }