11930-Remove in pandora_db.pl integrity & functions_agents.php

This commit is contained in:
Pablo Aragon 2023-08-23 14:00:35 +02:00
parent e08c4508b7
commit 120298e6a3
2 changed files with 0 additions and 65 deletions

View File

@ -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',

View File

@ -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]);
}