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,9 +3559,21 @@ sub pandora_create_module ($$$$$$$$$$) {
########################################################################## ##########################################################################
## Delete a module given its id. ## Delete a module given its id.
########################################################################## ##########################################################################
sub pandora_delete_module ($$;$) { sub pandora_delete_module {
my ($dbh, $module_id, $conf) = @_; 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 # 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); 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); return unless defined ($module);

View File

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