mirror of
https://github.com/e107inc/e107.git
synced 2025-08-09 16:17:14 +02:00
EONE-29 (issue): logMessage(), logSuccess(), logError(), flushMessages() methods added (admin_log handler)
admin log is called on preferences save now
This commit is contained in:
@@ -1,33 +1,32 @@
|
|||||||
<?php
|
<?php
|
||||||
/*
|
/*
|
||||||
+ ----------------------------------------------------------------------------+
|
* e107 website system
|
||||||
| e107 website system
|
*
|
||||||
|
|
* Copyright (C) 2008-2010 e107 Inc (e107.org)
|
||||||
| ?Copyright (C) 2008-2010 e107 Inc (e107.org)
|
* Released under the terms and conditions of the
|
||||||
| http://e107.org
|
* GNU General Public License (http://www.gnu.org/licenses/gpl.txt)
|
||||||
|
|
*
|
||||||
|
|
* Admin Log Handler
|
||||||
| Released under the terms and conditions of the
|
*
|
||||||
| GNU General Public License (http://gnu.org).
|
* $URL$
|
||||||
|
|
* $Id$
|
||||||
| $Source: /cvs_backup/e107_0.8/e107_handlers/admin_log_class.php,v $
|
*
|
||||||
| $Revision$
|
*/
|
||||||
| $Date$
|
|
||||||
| $Author$
|
|
||||||
+----------------------------------------------------------------------------+
|
|
||||||
*/
|
|
||||||
|
|
||||||
if (!defined('e107_INIT'))
|
if (!defined('e107_INIT'))
|
||||||
{
|
{
|
||||||
exit;
|
exit;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
define('LOG_MESSAGE_NODISPLAY', 'nodisplay');
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Admin logging class.
|
* Admin logging class.
|
||||||
*
|
*
|
||||||
* @package e107
|
* @package e107
|
||||||
* @subpackage e107_handlers
|
* @subpackage e107_handlers
|
||||||
* @version $Id$;
|
* @version $Id$;
|
||||||
|
* @author e107steved
|
||||||
*/
|
*/
|
||||||
class e_admin_log
|
class e_admin_log
|
||||||
{
|
{
|
||||||
@@ -37,8 +36,14 @@ class e_admin_log
|
|||||||
*
|
*
|
||||||
* @var array
|
* @var array
|
||||||
*/
|
*/
|
||||||
var $_options = array('log_level'=>2, 'backtrace'=>false, );
|
protected $_options = array('log_level'=>2, 'backtrace'=>false, );
|
||||||
var $rldb = NULL; // Database used by logging routine
|
public $rldb = NULL; // Database used by logging routine
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Log messages
|
||||||
|
* @var array
|
||||||
|
*/
|
||||||
|
protected $_messages;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Constructor. Sets up constants and overwrites default options where set.
|
* Constructor. Sets up constants and overwrites default options where set.
|
||||||
@@ -81,6 +86,10 @@ class e_admin_log
|
|||||||
define('USER_AUDIT_BANNED', 22); // User banned
|
define('USER_AUDIT_BANNED', 22); // User banned
|
||||||
define('USER_AUDIT_BOUNCE_RESET', 23); // User bounce reset
|
define('USER_AUDIT_BOUNCE_RESET', 23); // User bounce reset
|
||||||
define('USER_AUDIT_TEMP_ACCOUNT', 24); // User temporary account
|
define('USER_AUDIT_TEMP_ACCOUNT', 24); // User temporary account
|
||||||
|
|
||||||
|
// Init E_MESSAGE_* constants if not already done
|
||||||
|
e107::getMessage();
|
||||||
|
$this->_messages = array();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -350,7 +359,8 @@ class e_admin_log
|
|||||||
$changes = array();
|
$changes = array();
|
||||||
foreach ($new as $k=>$v)
|
foreach ($new as $k=>$v)
|
||||||
{
|
{
|
||||||
if ($v != varset($old[$k],''))
|
// FIXME - what about '' == '0'?
|
||||||
|
if ($v != varset($old[$k], ''))
|
||||||
{
|
{
|
||||||
$old[$k] = $v;
|
$old[$k] = $v;
|
||||||
$changes[] = $k.'=>'.$v;
|
$changes[] = $k.'=>'.$v;
|
||||||
@@ -392,4 +402,93 @@ class e_admin_log
|
|||||||
$this->log_event($event, $logString, E_LOG_INFORMATIVE, '');
|
$this->log_event($event, $logString, E_LOG_INFORMATIVE, '');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The next two routines accept and buffers messages which are destined for both admin log and message handler
|
||||||
|
*/
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Add a message to the queue
|
||||||
|
*
|
||||||
|
* @param string $text - the message text for logging/display
|
||||||
|
* @param int $type - the 'importance' of the message. E_MESSAGE_SUCCESS|E_MESSAGE_ERROR|E_MESSAGE_INFO|E_MESSAGE_DEBUG|E_MESSAGE_NODISPLAY
|
||||||
|
* (Values as used in message handler, apart from the last, which causes the message to not be passed to the message handler
|
||||||
|
* @param boolean|int $logLevel - TRUE to give same importance as for message display. FALSE to not log.
|
||||||
|
* one of the values specified for $mesLevel to determine the prefix attached to the log message
|
||||||
|
* @param boolean $session add session message
|
||||||
|
*
|
||||||
|
* @return e_admin_log
|
||||||
|
*/
|
||||||
|
public function logMessage($text, $type = '', $logLevel = TRUE, $session = FALSE)
|
||||||
|
{
|
||||||
|
if(empty($text)) return;
|
||||||
|
if(!$type) $type = E_MESSAGE_INFO;
|
||||||
|
if($logLevel === TRUE) $logLevel = $type;
|
||||||
|
$this->_messages[] = array('message' => $text, 'dislevel' => $type, 'loglevel' => $logLevel, 'session' => $session);
|
||||||
|
return $this;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Log success
|
||||||
|
*
|
||||||
|
* @param string $text
|
||||||
|
* @param boolean $message if true - register with eMessage handler
|
||||||
|
* @param boolean $session add session message
|
||||||
|
* @return e_admin_log
|
||||||
|
*/
|
||||||
|
public function logSuccess($text, $message = true, $session = false)
|
||||||
|
{
|
||||||
|
return $this->logMessage($text, ($message ? E_MESSAGE_SUCCESS : LOG_MESSAGE_NODISPLAY), E_MESSAGE_SUCCESS, $session);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Log error
|
||||||
|
*
|
||||||
|
* @param string $text
|
||||||
|
* @param boolean $message if true - register with eMessage handler
|
||||||
|
* @param boolean $session add session message
|
||||||
|
* @return e_admin_log
|
||||||
|
*/
|
||||||
|
public function logError($text, $message = true, $session = false)
|
||||||
|
{
|
||||||
|
return $this->logMessage($text, ($message ? E_MESSAGE_ERROR : LOG_MESSAGE_NODISPLAY), E_MESSAGE_ERROR, $session);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Empty the messages - pass to both admin log and message handler
|
||||||
|
*
|
||||||
|
* @param string $logTitle - title for log entry
|
||||||
|
* @param int $logImportance - passed directly to admin log
|
||||||
|
* @param string $logEventCode - passed directly to admin log
|
||||||
|
*
|
||||||
|
* @return e_admin_log
|
||||||
|
*/
|
||||||
|
public function flushMessages($logTitle, $logImportance = E_LOG_INFORMATIVE, $logEventCode = '')
|
||||||
|
{
|
||||||
|
$mes = e107::getMessage();
|
||||||
|
|
||||||
|
$resultTypes = array(E_MESSAGE_SUCCESS - 'Success', E_MESSAGE_ERROR => 'Fail'); // Add LANS here. Could add other codes
|
||||||
|
$separator = '';
|
||||||
|
$logString = '';
|
||||||
|
foreach ($this->_messages as $m)
|
||||||
|
{
|
||||||
|
if ($m['loglevel'] !== FALSE)
|
||||||
|
{
|
||||||
|
$logString .= $separator;
|
||||||
|
if ($m['loglevel'] == LOG_MESSAGE_NODISPLAY) { $logString .= ' '; } // Indent supplementary messages
|
||||||
|
$logString .= $m['message'];
|
||||||
|
if (isset($resultTypes[$m['loglevel']]))
|
||||||
|
{
|
||||||
|
$logString .= ' - '.$resultTypes[$m['loglevel']];
|
||||||
|
}
|
||||||
|
$separator = '[!br!]';
|
||||||
|
}
|
||||||
|
if ($m['dislevel'] != LOG_MESSAGE_NODISPLAY)
|
||||||
|
{
|
||||||
|
$mes->add($m['message'], $m['dislevel'], $m['session']);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
e107::getAdminLog()->log_event($logTitle, $logString, $logImportance, $logEventCode);
|
||||||
|
$this->_messages = array(); // Clear the memory for reuse
|
||||||
|
return $this;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@@ -18,11 +18,11 @@ if (!defined('e107_INIT')) { exit; }
|
|||||||
/*
|
/*
|
||||||
* Type defines
|
* Type defines
|
||||||
*/
|
*/
|
||||||
define('E_MESSAGE_INFO', 'info');
|
define('E_MESSAGE_INFO', 'info');
|
||||||
define('E_MESSAGE_SUCCESS', 'success');
|
define('E_MESSAGE_SUCCESS', 'success');
|
||||||
define('E_MESSAGE_WARNING', 'warning');
|
define('E_MESSAGE_WARNING', 'warning');
|
||||||
define('E_MESSAGE_ERROR', 'error');
|
define('E_MESSAGE_ERROR', 'error');
|
||||||
define('E_MESSAGE_DEBUG', 'debug');
|
define('E_MESSAGE_DEBUG', 'debug');
|
||||||
|
|
||||||
//FIXME - language file! new?
|
//FIXME - language file! new?
|
||||||
|
|
||||||
|
@@ -499,14 +499,13 @@ class e_pref extends e_admin_model
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
//FIXME - switch to new model system messages (separate eMessage namespaces)
|
|
||||||
$emessage = e107::getMessage();
|
|
||||||
|
|
||||||
if(!$this->data_has_changed && !$force)
|
if(!$this->data_has_changed && !$force)
|
||||||
{
|
{
|
||||||
$emessage->add('Settings not saved as no changes were made.', E_MESSAGE_INFO, $session_messages);
|
e107::getMessage()->addInfo('Settings not saved as no changes were made.', 'default', $session_messages);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
$admin_log = e107::getAdminLog();
|
||||||
|
|
||||||
//Save to DB
|
//Save to DB
|
||||||
if(!$this->hasError())
|
if(!$this->hasError())
|
||||||
@@ -528,32 +527,40 @@ class e_pref extends e_admin_model
|
|||||||
{
|
{
|
||||||
if($this->serial_bc)
|
if($this->serial_bc)
|
||||||
{
|
{
|
||||||
$dbdata = serialize(e107::getArrayStorage()->ReadArray($this->pref_cache));
|
$old = e107::getArrayStorage()->ReadArray($this->pref_cache);
|
||||||
|
$dbdata = serialize($old);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
$dbdata = $this->pref_cache;
|
$old = $dbdata = $this->pref_cache;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// auto admin log
|
||||||
|
$new = $this->getPref();
|
||||||
|
$admin_log->logArrayDiffs($new, $old, 'LAN_FIXME');
|
||||||
|
unset($new, $old);
|
||||||
|
|
||||||
if(e107::getDb()->db_Select_gen("REPLACE INTO `#core` (e107_name,e107_value) values ('".$this->prefid."_Backup', '".addslashes($dbdata)."') "))
|
if(e107::getDb()->db_Select_gen("REPLACE INTO `#core` (e107_name,e107_value) values ('".$this->prefid."_Backup', '".addslashes($dbdata)."') "))
|
||||||
{
|
{
|
||||||
$emessage->add('Backup of <strong>'.$this->alias.' ('.$this->prefid.')</strong> successfully created.', E_MESSAGE_DEBUG, $session_messages);
|
$admin_log->logMessage('Backup of <strong>'.$this->alias.' ('.$this->prefid.')</strong> successfully created.', E_MESSAGE_DEBUG, E_MESSAGE_SUCCESS, $session_messages);
|
||||||
ecache::clear_sys('Config_'.$this->alias.'_backup');
|
ecache::clear_sys('Config_'.$this->alias.'_backup');
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
$this->setPrefCache($this->toString(false), true); //reset pref cache - runtime & file
|
$this->setPrefCache($this->toString(false), true); //reset pref cache - runtime & file
|
||||||
|
|
||||||
$emessage->add('Settings successfully saved.', E_MESSAGE_SUCCESS, $session_messages);
|
$admin_log->logSuccess('Settings successfully saved.', true, $session_messages);
|
||||||
//BC
|
//BC
|
||||||
if($this->alias === 'core')
|
if($this->alias === 'core')
|
||||||
{
|
{
|
||||||
$pref = $this->getData();
|
$pref = $this->getPref();
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
elseif(e107::getDb()->getLastErrorNumber())
|
elseif(e107::getDb()->getLastErrorNumber())
|
||||||
{
|
{
|
||||||
$emessage->add('mySQL error #'.e107::getDb()->getLastErrorNumber().': '.e107::getDb()->getLastErrorText(), E_MESSAGE_ERROR, $session_messages);
|
$admin_log->logError('mySQL error #'.e107::getDb()->getLastErrorNumber().': '.e107::getDb()->getLastErrorText(), true, $session_messages)
|
||||||
$emessage->add('Settings not saved.', E_MESSAGE_ERROR, $session_messages);
|
->logError('Settings not saved.', true, $session_messages)
|
||||||
|
->flushMessages('LAN_FIXME');
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -562,12 +569,14 @@ class e_pref extends e_admin_model
|
|||||||
{
|
{
|
||||||
//add errors to the eMessage stack
|
//add errors to the eMessage stack
|
||||||
//$this->setErrors(true, $session_messages); old - doesn't needed anymore
|
//$this->setErrors(true, $session_messages); old - doesn't needed anymore
|
||||||
$emessage->add('Settings not saved.', E_MESSAGE_ERROR, $session_messages);
|
$admin_log->logError('Settings not saved.', true, $session_messages)
|
||||||
|
->flushMessages('LAN_FIXME');
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
$emessage->add('Settings not saved as no changes were made.', E_MESSAGE_INFO, $session_messages);
|
e107::getMessage()->add('Settings not saved as no changes were made.', E_MESSAGE_INFO, $session_messages);
|
||||||
|
$admin_log->flushMessages('LAN_FIXME');
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user