implemented module cascade deletion

This commit is contained in:
alejandro.campos@artica.es 2023-03-30 13:23:23 +02:00
parent 061c9f8750
commit 8718b2a9f5
2 changed files with 16 additions and 4 deletions

View File

@ -3553,9 +3553,21 @@ sub pandora_create_module ($$$$$$$$$$) {
##########################################################################
## Delete a module given its id.
##########################################################################
sub pandora_delete_module ($$;$) {
my ($dbh, $module_id, $conf) = @_;
sub pandora_delete_module {
my $dbh = shift;
my $module_id = shift;
my $conf = shift if @_;
my $cascade = shift if @_;
# Recursively delete descendants (delete in cascade)
if (defined($cascade) && $cascade eq 1) {
my @id_children_modules = get_db_rows($dbh, 'SELECT id_agente_modulo FROM tagente_modulo WHERE parent_module_id = ?', $module_id);
foreach my $id_child_module (@id_children_modules) {
pandora_delete_module($dbh, $id_child_module->{'id_agente_modulo'}, $conf, 1);
}
}
# Get module data
my $module = get_db_single_row ($dbh, 'SELECT * FROM tagente_modulo, tagente_estado WHERE tagente_modulo.id_agente_modulo = tagente_estado.id_agente_modulo AND tagente_modulo.id_agente_modulo=?', $module_id);
return unless defined ($module);

View File

@ -2933,7 +2933,7 @@ sub cli_delete_module() {
next;
}
pandora_delete_module($dbh,$id_module,$conf);
pandora_delete_module($dbh, $id_module, $conf, 1);
}
} else {
print_log "[INFO] Deleting module '$module_name' from agent '$agent_name' \n\n";
@ -2943,7 +2943,7 @@ sub cli_delete_module() {
my $id_module = get_agent_module_id($dbh,$module_name,$id_agent);
exist_check($id_module,'module',$module_name);
pandora_delete_module($dbh,$id_module,$conf);
pandora_delete_module($dbh, $id_module, $conf, 1);
}
}