Merge branch 'ent-10053-No-existe-borrado-en-cascada-de-modulos-usando-CLI' into 'develop'

implemented module cascade deletion

See merge request artica/pandorafms!5641
This commit is contained in:
Daniel Rodriguez 2023-04-28 07:00:59 +00:00
commit 6570f0b98d
2 changed files with 16 additions and 4 deletions

View File

@ -3559,8 +3559,20 @@ 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);

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