/** * Insert audit log * * @param string $actionType * @param int $objId * @param string $objName * @param array $objValues */ public function addAuditLog($actionType, $objId, $objName, $objValues = array()) { $objType = strtoupper($this->action); $objectTypes = array('HTPL' => 'host', 'STPL' => 'service', 'CONTACT' => 'contact', 'SG' => 'servicegroup', 'TP' => 'timeperiod', 'SERVICE' => 'service', 'CG' => 'contactgroup', 'CMD' => 'command', 'HOST' => 'host', 'HC' => 'hostcategories', 'HG' => 'hostgroup', 'SC' => 'servicecategories'); if (!isset($objectTypes[$objType])) { return null; } $objType = $objectTypes[$objType]; $contactObj = new Centreon_Object_Contact(); $contact = $contactObj->getIdByParameter('contact_alias', CentreonUtils::getUserName()); $userId = $contact[0]; $dbstorage = Centreon_Db_Manager::factory('storage'); $query = 'INSERT INTO log_action (action_log_date, object_type, object_id, object_name, action_type, log_contact_id) VALUES (?, ?, ?, ?, ?, ?)'; $time = time(); $dbstorage->query($query, array($time, $objType, $objId, $objName, $actionType, $userId)); $query = 'SELECT MAX(action_log_id) as action_log_id FROM log_action WHERE action_log_date = ?'; $stmt = $dbstorage->query($query, array($time)); $row = $stmt->fetch(); if (false === $row) { throw new CentreonClapiException("Error while inserting log action"); } $stmt->closeCursor(); $actionId = $row['action_log_id']; $query = 'INSERT INTO log_action_modification (field_name, field_value, action_log_id) VALUES (?, ?, ?)'; foreach ($objValues as $name => $value) { try { if (is_array($value)) { $value = implode(',', $value); } if (is_null($value)) { $value = ''; } $dbstorage->query($query, array($name, $value, $actionId)); } catch (Exception $e) { throw $e; } } }