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 <william.mead@manchenumerique.fr>
This commit is contained in:
parent
551e3f5994
commit
08f17dab0b
1 changed files with 74 additions and 78 deletions
|
|
@ -3,6 +3,7 @@
|
|||
* Copyright (C) 2009-2017 Regis Houssin <regis.houssin@inodbox.com>
|
||||
* Copyright (C) 2014 Marcos García <marcosgdf@gmail.com>
|
||||
* Copyright (C) 2023 Udo Tamm <dev@dolibit.de>
|
||||
* Copyright (C) 2023 William Mead <william.mead@manchenumerique.fr>
|
||||
*
|
||||
* 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
|
||||
|
|
|
|||
Loading…
Reference in a new issue