From 08f17dab0b960f5fb3232e9ea693674cf0bcc29e Mon Sep 17 00:00:00 2001 From: William Mead Date: Mon, 23 Oct 2023 18:58:57 +0200 Subject: [PATCH] Qual logevents action switch (#26330) * QUAL use switch case instead of if elseif statements for actions * Deleted unnecessary action comments * Added default case * Added contributor details --------- Co-authored-by: William Mead --- .../interface_20_all_Logevents.class.php | 152 +++++++++--------- 1 file changed, 74 insertions(+), 78 deletions(-) diff --git a/htdocs/core/triggers/interface_20_all_Logevents.class.php b/htdocs/core/triggers/interface_20_all_Logevents.class.php index bd25fe4efad..acfb2318712 100644 --- a/htdocs/core/triggers/interface_20_all_Logevents.class.php +++ b/htdocs/core/triggers/interface_20_all_Logevents.class.php @@ -3,6 +3,7 @@ * Copyright (C) 2009-2017 Regis Houssin * Copyright (C) 2014 Marcos GarcĂ­a * Copyright (C) 2023 Udo Tamm + * Copyright (C) 2023 William Mead * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -84,84 +85,79 @@ class InterfaceLogevents extends DolibarrTriggers $langs->load("users"); // Actions - if ($action == 'USER_LOGIN') { - dol_syslog("Trigger '".$this->name."' for action '$action' launched by ".__FILE__.". id=".$object->id); - // Initialize data (date,duree,text,desc) - $text = "(UserLogged,".$object->login.")"; - $desc = "(UserLogged,".$object->login.")"; - - // USER_LOGIN_FAILED - } elseif ($action == 'USER_LOGIN_FAILED') { - dol_syslog("Trigger '".$this->name."' for action '$action' launched by ".__FILE__.". id=".$object->id); - - // USER_LOGOUT - } elseif ($action == 'USER_LOGOUT') { - dol_syslog("Trigger '".$this->name."' for action '$action' launched by ".__FILE__.". id=".$object->id); - // Initialize data (date,duree,text,desc) - $text = "(UserLogoff,".$object->login.")"; - $desc = "(UserLogoff,".$object->login.")"; - - // USER_CREATE - } elseif ($action == 'USER_CREATE') { - dol_syslog("Trigger '".$this->name."' for action '$action' launched by ".__FILE__.". id=".$object->id); - // Initialize data (date,duree,text,desc) - $text = $langs->transnoentities("NewUserCreated", $object->login); - $desc = $langs->transnoentities("NewUserCreated", $object->login); - - // USER_MODIFY - } elseif ($action == 'USER_MODIFY') { - dol_syslog("Trigger '".$this->name."' for action '$action' launched by ".__FILE__.". id=".$object->id); - // Initialize data (date,duree,text,desc) - $text = $langs->transnoentities("EventUserModified", $object->login); - $desc = $langs->transnoentities("EventUserModified", $object->login); - - // USER_NEW_PASSWORD - } elseif ($action == 'USER_NEW_PASSWORD') { - dol_syslog("Trigger '".$this->name."' for action '$action' launched by ".__FILE__.". id=".$object->id); - // Initialize data (date,duree,text,desc) - $text = $langs->transnoentities("NewUserPassword", $object->login); - $desc = $langs->transnoentities("NewUserPassword", $object->login); - - // USER ENABLED/DISABLED - } elseif ($action == 'USER_ENABLEDISABLE') { - dol_syslog("Trigger '".$this->name."' for action '$action' launched by ".__FILE__.". id=".$object->id); - // Initialize data (date,duree,text,desc) - if ($object->statut == 0) { - $text = $langs->transnoentities("UserEnabled", $object->login); - $desc = $langs->transnoentities("UserEnabled", $object->login); - } - if ($object->statut == 1) { - $text = $langs->transnoentities("UserDisabled", $object->login); - $desc = $langs->transnoentities("UserDisabled", $object->login); - } - - // USER_DELETE - } elseif ($action == 'USER_DELETE') { - dol_syslog("Trigger '".$this->name."' for action '$action' launched by ".__FILE__.". id=".$object->id); - // Initialize data (date,duree,text,desc) - $text = $langs->transnoentities("UserDeleted", $object->login); - $desc = $langs->transnoentities("UserDeleted", $object->login); - - // USERGROUP_CREATE - } elseif ($action == 'USERGROUP_CREATE') { - dol_syslog("Trigger '".$this->name."' for action '$action' launched by ".__FILE__.". id=".$object->id); - // Initialize data (date,duree,text,desc) - $text = $langs->transnoentities("NewGroupCreated", $object->name); - $desc = $langs->transnoentities("NewGroupCreated", $object->name); - - // USERGROUP_MODIFY - } elseif ($action == 'USERGROUP_MODIFY') { - dol_syslog("Trigger '".$this->name."' for action '$action' launched by ".__FILE__.". id=".$object->id); - // Initialize data (date,duree,text,desc) - $text = $langs->transnoentities("GroupModified", $object->name); - $desc = $langs->transnoentities("GroupModified", $object->name); - - // USERGROUP_DELETE - } elseif ($action == 'USERGROUP_DELETE') { - dol_syslog("Trigger '".$this->name."' for action '$action' launched by ".__FILE__.". id=".$object->id); - // Initialize data (date,duree,text,desc) - $text = $langs->transnoentities("GroupDeleted", $object->name); - $desc = $langs->transnoentities("GroupDeleted", $object->name); + switch ($action) { + case 'USER_LOGIN': + dol_syslog("Trigger '" . $this->name . "' for action '$action' launched by " . __FILE__ . ". id=" . $object->id); + // Initialize data (date,duree,text,desc) + $text = "(UserLogged," . $object->login . ")"; + $desc = "(UserLogged," . $object->login . ")"; + break; + case 'USER_LOGIN_FAILED': + dol_syslog("Trigger '" . $this->name . "' for action '$action' launched by " . __FILE__ . ". id=" . $object->id); + break; + case 'USER_LOGOUT': + dol_syslog("Trigger '" . $this->name . "' for action '$action' launched by " . __FILE__ . ". id=" . $object->id); + // Initialize data (date,duree,text,desc) + $text = "(UserLogoff," . $object->login . ")"; + $desc = "(UserLogoff," . $object->login . ")"; + break; + case 'USER_CREATE': + dol_syslog("Trigger '" . $this->name . "' for action '$action' launched by " . __FILE__ . ". id=" . $object->id); + // Initialize data (date,duree,text,desc) + $text = $langs->transnoentities("NewUserCreated", $object->login); + $desc = $langs->transnoentities("NewUserCreated", $object->login); + break; + case 'USER_MODIFY': + dol_syslog("Trigger '" . $this->name . "' for action '$action' launched by " . __FILE__ . ". id=" . $object->id); + // Initialize data (date,duree,text,desc) + $text = $langs->transnoentities("EventUserModified", $object->login); + $desc = $langs->transnoentities("EventUserModified", $object->login); + break; + case 'USER_NEW_PASSWORD': + dol_syslog("Trigger '" . $this->name . "' for action '$action' launched by " . __FILE__ . ". id=" . $object->id); + // Initialize data (date,duree,text,desc) + $text = $langs->transnoentities("NewUserPassword", $object->login); + $desc = $langs->transnoentities("NewUserPassword", $object->login); + break; + case 'USER_ENABLEDISABLE': + dol_syslog("Trigger '" . $this->name . "' for action '$action' launched by " . __FILE__ . ". id=" . $object->id); + // Initialize data (date,duree,text,desc) + if ($object->statut == 0) { + $text = $langs->transnoentities("UserEnabled", $object->login); + $desc = $langs->transnoentities("UserEnabled", $object->login); + } + if ($object->statut == 1) { + $text = $langs->transnoentities("UserDisabled", $object->login); + $desc = $langs->transnoentities("UserDisabled", $object->login); + } + break; + case 'USER_DELETE': + dol_syslog("Trigger '" . $this->name . "' for action '$action' launched by " . __FILE__ . ". id=" . $object->id); + // Initialize data (date,duree,text,desc) + $text = $langs->transnoentities("UserDeleted", $object->login); + $desc = $langs->transnoentities("UserDeleted", $object->login); + break; + case 'USERGROUP_CREATE': + dol_syslog("Trigger '" . $this->name . "' for action '$action' launched by " . __FILE__ . ". id=" . $object->id); + // Initialize data (date,duree,text,desc) + $text = $langs->transnoentities("NewGroupCreated", $object->name); + $desc = $langs->transnoentities("NewGroupCreated", $object->name); + break; + case 'USERGROUP_MODIFY': + dol_syslog("Trigger '" . $this->name . "' for action '$action' launched by " . __FILE__ . ". id=" . $object->id); + // Initialize data (date,duree,text,desc) + $text = $langs->transnoentities("GroupModified", $object->name); + $desc = $langs->transnoentities("GroupModified", $object->name); + break; + case 'USERGROUP_DELETE': + dol_syslog("Trigger '" . $this->name . "' for action '$action' launched by " . __FILE__ . ". id=" . $object->id); + // Initialize data (date,duree,text,desc) + $text = $langs->transnoentities("GroupDeleted", $object->name); + $desc = $langs->transnoentities("GroupDeleted", $object->name); + break; + default: + dol_syslog("Unknown action. Trigger '" . $this->name . "' for action '$action' launched by " . __FILE__ . ". id=" . $object->id); + break; } // Add more information into desc from the context property