Merge branch 'ent-5138-9245-Metaconsola-Sincronizacion-de-grupos-cuando-se-eliminan' into 'develop'

Ent 5138 9245 metaconsola sincronizacion de grupos cuando se eliminan

See merge request artica/pandorafms!3112
This commit is contained in:
Daniel Rodriguez 2020-03-23 13:04:16 +01:00
commit ce249275e4
1 changed files with 132 additions and 24 deletions

View File

@ -443,6 +443,108 @@ if (($delete_group) && (check_acl($config['id_user'], 0, 'PM'))) {
$usedGroup = groups_check_used($id_group);
if (!$usedGroup['return']) {
$errors_meta = false;
if (is_metaconsole()) {
$group_name = groups_get_name($id_group);
$servers = metaconsole_get_servers();
$error_counter = 0;
$success_counter = 0;
$success_nodes = [];
$error_nodes = [];
// Check if the group can be deleted or not.
foreach ($servers as $server) {
if (metaconsole_connect($server) == NOERR) {
$result_exist_group = db_get_row_filter('tgrupo', ['nombre' => $group_name, 'id_grupo' => $id_group]);
if ($result_exist_group !== false) {
$used_group = groups_check_used($id_group);
// Save the names of the nodes that are empty and can be deleted, and those that cannot.
if (!$used_group['return']) {
$success_nodes[] .= $server['server_name'];
$success_counter++;
} else {
$error_nodes[] .= $server['server_name'];
$error_counter++;
}
}
}
metaconsole_restore_db();
}
if ($error_counter > 0) {
ui_print_error_message(
__('The group %s could not be deleted because it is not empty in the nodes', $group_name).': '.implode(', ', $error_nodes)
);
$errors_meta = true;
} else {
if ($success_counter > 0) {
$error_deleting_counter = 0;
$success_deleting_counter = 0;
$error_deleting = [];
$success_deleting = [];
$error_connecting_node = [];
// Delete the group in the nodes.
foreach ($servers as $server) {
if (metaconsole_connect($server) == NOERR) {
$group = db_get_row_filter(
'tgrupo',
['id_grupo' => $id_group]
);
db_process_sql_update(
'tgrupo',
['parent' => $group['parent']],
['parent' => $id_group]
);
db_process_sql_delete(
'tgroup_stat',
['id_group' => $id_group]
);
$result = db_process_sql_delete(
'tgrupo',
['id_grupo' => $id_group]
);
if ($result === false) {
$error_deleting[] .= $server['server_name'];
$error_deleting_counter++;
} else {
$success_deleting[] .= $server['server_name'];
$success_deleting_counter++;
}
} else {
$error_deleting_counter++;
$error_connecting_node[] .= $server['server_name'];
}
metaconsole_restore_db();
}
// If the group could not be deleted in any node, do not delete it in meta.
if ($error_deleting_counter > 0) {
$errors_meta = true;
if (!empty($error_connecting_node)) {
ui_print_error_message(__('Error connecting to %s', implode(', ', $error_connecting_node).'. The group has not been deleted in the metaconsole.'));
}
if (!empty($error_deleting)) {
ui_print_error_message(
__('The group has not been deleted in the metaconsole due to an error in the node database').': '.implode(', ', $error_deleting)
);
}
}
if ($success_deleting_counter > 0) {
ui_print_success_message(__('The group %s has been deleted in the nodes', $group_name).': '.implode(', ', $success_deleting));
}
}
}
}
if ($errors_meta === false) {
$group = db_get_row_filter(
'tgrupo',
['id_grupo' => $id_group]
@ -463,11 +565,6 @@ if (($delete_group) && (check_acl($config['id_user'], 0, 'PM'))) {
'tgrupo',
['id_grupo' => $id_group]
);
} else {
ui_print_error_message(
sprintf(__('The group is not empty. It is use in %s.'), implode(', ', $usedGroup['tables']))
);
}
if ($result && (!$usedGroup['return'])) {
ui_print_success_message(__('Group successfully deleted'));
@ -475,6 +572,12 @@ if (($delete_group) && (check_acl($config['id_user'], 0, 'PM'))) {
ui_print_error_message(__('There was a problem deleting group'));
}
}
} else {
ui_print_error_message(
sprintf(__('The group is not empty. It is use in %s.'), implode(', ', $usedGroup['tables']))
);
}
}
// Credential store is loaded previously in this document to avoid
@ -636,7 +739,12 @@ if ($tab == 'tree') {
]
).'</a>';
if (is_metaconsole()) {
$confirm_message = __('Are you sure? This group will also be deleted in all the nodes.');
} else {
$confirm_message = __('Are you sure?');
}
if ($group['has_child']) {
$confirm_message = __('The child groups will be updated to use the parent id of the deleted group').'. '.$confirm_message;
}