#12783 check if module is use by agent for safe mode before delete

This commit is contained in:
Daniel Cebrian 2024-02-07 15:39:23 +01:00
parent 4912a4051f
commit f2a15061f0
2 changed files with 31 additions and 0 deletions

View File

@ -2318,6 +2318,12 @@ if ($delete_module) {
exit;
}
// Check if module is used by agent for Safe mode.
$is_safe_mode_module = modules_check_safe_mode($id_borrar_modulo);
if ($is_safe_mode_module === true) {
db_process_sql_update('tagente', ['safe_mode_module' => '0'], ['id_agente' => $id_agente]);
}
// Before delete the main module, check and delete the childrens from the original module.
module_check_childrens_and_delete($id_borrar_modulo);

View File

@ -5074,3 +5074,28 @@ function modules_made_compatible($id_tipo_modulo)
return true;
}
}
/**
* Check if module is used by agent for Safe mode.
*
* @param integer $id_module Id for module to check
*
* @return boolean
*/
function modules_check_safe_mode($id_module)
{
$id_agent = modules_give_agent_id_from_module_id($id_module);
if ($id_agent === 0) {
// No exist agent with this id.
return false;
}
$agent = agents_get_agent($id_agent);
if (isset($agent['safe_mode_module']) === true && (int) $agent['safe_mode_module'] === (int) $id_module) {
return true;
} else {
return false;
}
}