mirror of
https://github.com/e107inc/e107.git
synced 2025-03-14 17:39:46 +01:00
Admin Log function fixes. Preference saving details stored correctly.
This commit is contained in:
parent
d47486d39f
commit
b859d1cf8d
13
class2.php
13
class2.php
@ -1492,21 +1492,28 @@ function get_user_data($uid, $extra = '')
|
||||
}
|
||||
|
||||
//------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------//
|
||||
//SO MUCH DEPRECATED - use e107::getConfig(alias)->save() instead
|
||||
//SO MUCH DEPRECATED
|
||||
/**
|
||||
* @deprecated
|
||||
* @example Use instead: e107::getConfig(alias)->->setPref($array)->save(); Not to be used for saving plugin or theme prefs!
|
||||
*/
|
||||
function save_prefs($table = 'core', $uid = USERID, $row_val = '')
|
||||
{
|
||||
global $pref, $user_pref, $tp, $PrefCache, $sql, $eArrayStorage, $theme_pref;
|
||||
|
||||
if(e107::getPref('developer'))
|
||||
{
|
||||
$backtrace = debug_backtrace(false);
|
||||
|
||||
e107::getAdminLog()->log_event(
|
||||
'Deprecated call - save_prefs()',
|
||||
'Call to deprecated function save_prefs() (class2.php)',
|
||||
"Call to deprecated function save_prefs() (class2.php). Backtrace:\n".print_r($backtrace, true),
|
||||
E_LOG_INFORMATIVE,
|
||||
'DEPRECATED'
|
||||
);
|
||||
// TODO - debug screen Deprecated Functions (e107)
|
||||
e107::getMessage()->addDebug('Deprecated save_prefs() backtrace:<pre>'."\n".print_r(debug_backtrace(), true).'</pre>');
|
||||
|
||||
e107::getMessage()->addDebug('Deprecated save_prefs() backtrace:<pre>'."\n".print_r($backtrace, true).'</pre>');
|
||||
}
|
||||
|
||||
switch($table)
|
||||
|
@ -539,11 +539,29 @@ class admin_log_form_ui extends e_admin_form_ui
|
||||
function dblog_remarks($curVal,$mode)
|
||||
{
|
||||
$frm = e107::getForm();
|
||||
$tp = e107::getParser();
|
||||
|
||||
switch($mode)
|
||||
{
|
||||
case 'read': // List Page
|
||||
return preg_replace_callback("#\[!(\w+?)(=.+?){0,1}!]#", 'log_process', $curVal);
|
||||
|
||||
$text = preg_replace_callback("#\[!(\w+?)(=.+?){0,1}!]#", 'log_process', $curVal);
|
||||
$text = $tp->toHtml($text);
|
||||
|
||||
if(strpos($text,'Array')!==false)
|
||||
{
|
||||
$id = $this->getController()->getListModel()->get('dblog_id');
|
||||
$ret ="<a class='e-expandit' href='#".$id."'>Details</a>";
|
||||
$ret .= "<div class='hide' id='".$id."'>";
|
||||
$text = str_replace("<br />","\n",$text);
|
||||
$text = str_replace("\","/",$text);
|
||||
$text = print_a($text,true);
|
||||
$ret .= $text;
|
||||
$ret .= "</div>";
|
||||
return $ret;
|
||||
}
|
||||
|
||||
return $text;
|
||||
break;
|
||||
|
||||
|
||||
|
@ -352,7 +352,7 @@ class notify_config
|
||||
e107::getConfig('notify')->updatePref($this->notify_prefs);
|
||||
if (e107::getConfig('notify')->save(FALSE))
|
||||
{
|
||||
e107::getAdminLog()->logArrayAll('NOTIFY_01',$this->changeList);
|
||||
// e107::getAdminLog()->logArrayAll('NOTIFY_01',$this->changeList);
|
||||
return TRUE;
|
||||
}
|
||||
else
|
||||
|
@ -1,5 +1,5 @@
|
||||
<?php
|
||||
/*
|
||||
/**
|
||||
* e107 website system
|
||||
*
|
||||
* Copyright (C) 2008-2010 e107 Inc (e107.org)
|
||||
@ -8,8 +8,12 @@
|
||||
*
|
||||
* Admin Log Handler
|
||||
*
|
||||
* $URL$
|
||||
* $Id$
|
||||
* USAGE:
|
||||
*
|
||||
* @example Log and Add to Message Handler: e107::getAdminLog()->addSuccess("Successfully executed")->save('PREF_01');
|
||||
* @example Log Only: e107::getAdminLog()->addSuccess("Successfully executed",false)->save('PREF_01');
|
||||
* @example Log Array Diff: e107::getAdminLog()->addArray($array1, $array2)->save('PREF_01');
|
||||
* @example Log Array Diff and Add to Message Handler: e107::getAdminLog()->addArray($array1, $array2, E_MESSAGE_ERROR )->save('PREF_01');
|
||||
*
|
||||
*/
|
||||
|
||||
@ -114,6 +118,23 @@ class e_admin_log
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Save all logs in the queue to the database and render any unhidden messages with the message handler.
|
||||
* @see alias flushMessages() method below.
|
||||
* @param string $logTitle - title for log entry eg. 'PREF_01'
|
||||
* @param int $logImportance [optional] default E_LOG_INFORMATIVE - passed directly to admin log
|
||||
* @param string $logEventCode [optional] - passed directly to admin log
|
||||
* @param string $mstack [optional] message stack passed to message handler
|
||||
*/
|
||||
public function save($logTitle, $logImportance = E_LOG_INFORMATIVE, $logEventCode = '', $mstack = false)
|
||||
{
|
||||
return $this->flushMessages($logTitle, $logImportance, $logEventCode, $mstack);
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Alternative admin log entry point - compatible with legacy calls, and a bit simpler to use than the generic entry point.
|
||||
* ($eventcode has been added - give it a reference to identify the source module, such as 'NEWS_12' or 'ECAL_03')
|
||||
@ -148,17 +169,22 @@ class e_admin_log
|
||||
//SecretR - now supports DB array as event_detail (see e.g. db::db_Insert())
|
||||
if (is_array($event_detail))
|
||||
{
|
||||
// handled inside e_log_event();
|
||||
|
||||
/*
|
||||
$tmp = array();
|
||||
if (isset($event_detail['data']))
|
||||
{
|
||||
$event_detail = $event_detail['data'];
|
||||
}
|
||||
foreach ($event_detail as $k => $v)
|
||||
{
|
||||
$tmp[] = $k.'=>'.$v;
|
||||
}
|
||||
$event_detail = implode("[!br!]\n", $tmp);
|
||||
unset($tmp);
|
||||
if (isset($event_detail['data']))
|
||||
{
|
||||
$event_detail = $event_detail['data'];
|
||||
}
|
||||
foreach ($event_detail as $k => $v)
|
||||
{
|
||||
$tmp[] = $k.'=>'.$v;
|
||||
}
|
||||
$event_detail = implode("[!br!]\n", $tmp);
|
||||
unset($tmp);
|
||||
*/
|
||||
|
||||
}
|
||||
else
|
||||
{
|
||||
@ -170,6 +196,8 @@ class e_admin_log
|
||||
{
|
||||
$event_detail .= "\n\n".debug_backtrace();
|
||||
}
|
||||
|
||||
|
||||
$this->e_log_event($event_type, -1, $event_code, $event_title, $event_detail, FALSE, LOG_TO_ADMIN);
|
||||
|
||||
return $this;
|
||||
@ -232,6 +260,7 @@ class e_admin_log
|
||||
|
||||
if (is_array($explain))
|
||||
{
|
||||
/*
|
||||
$line = '';
|
||||
$spacer = '';
|
||||
foreach ($explain as $k=>$v)
|
||||
@ -241,6 +270,9 @@ class e_admin_log
|
||||
}
|
||||
$explain = $line;
|
||||
unset($line);
|
||||
*/
|
||||
$explain = str_replace("\n",'[!br!]',print_r($explain,true));
|
||||
|
||||
}
|
||||
|
||||
|
||||
@ -425,31 +457,33 @@ class e_admin_log
|
||||
*
|
||||
* @return bool true if changes found and logged, false otherwise.
|
||||
*/
|
||||
function logArrayDiffs(&$new, &$old, $event, $logNow = true)
|
||||
function logArrayDiffs($new, $old, $event, $logNow = true)
|
||||
{
|
||||
$changes = array();
|
||||
foreach ($new as $k=>$v)
|
||||
{
|
||||
// FIXME - what about '' == '0'?
|
||||
if ($v != varset($old[$k], ''))
|
||||
{
|
||||
$old[$k] = $v;
|
||||
$changes[] = $k.'=>'.$v;
|
||||
}
|
||||
}
|
||||
// $changes = array();
|
||||
|
||||
$changes = array_diff_recursive($new,$old);
|
||||
|
||||
if (count($changes))
|
||||
{
|
||||
if($logNow) $this->add($event, implode('[!br!]', $changes), E_LOG_INFORMATIVE, '');
|
||||
else $this->logMessage(implode('[!br!]', $changes), LOG_MESSAGE_NODISPLAY, E_MESSAGE_INFO);
|
||||
if($logNow)
|
||||
{
|
||||
$this->add($event, print_r($changes,true), E_LOG_INFORMATIVE, '');
|
||||
}
|
||||
else
|
||||
{
|
||||
$this->logMessage($changes, LOG_MESSAGE_NODISPLAY, E_MESSAGE_INFO);
|
||||
}
|
||||
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Logs an entry with all the data from an array, one field per line.
|
||||
*
|
||||
* @deprecated
|
||||
* @param string $event - LAN define or string used as title in log
|
||||
* @param array $target - data to be logged
|
||||
* @param string $extra - if non-empty, it goes on the first line.
|
||||
@ -460,6 +494,14 @@ class e_admin_log
|
||||
*/
|
||||
public function logArrayAll($event, $target, $extra = '', $niceNames = NULL)
|
||||
{
|
||||
|
||||
if($extra == '' && $niceNames == null)
|
||||
{
|
||||
return $this->add($event, $target, E_LOG_INFORMATIVE, ''); // supports arrays
|
||||
|
||||
}
|
||||
|
||||
|
||||
$logString = '';
|
||||
if ($extra)
|
||||
{
|
||||
@ -504,6 +546,11 @@ class e_admin_log
|
||||
if(!$type) $type = E_MESSAGE_INFO;
|
||||
if($logLevel === TRUE) $logLevel = $type;
|
||||
|
||||
if(is_array($text))
|
||||
{
|
||||
$text = print_r($text,true);
|
||||
}
|
||||
|
||||
$logArray = array('message' => $text, 'dislevel' => $type, 'loglevel' => $logLevel, 'session' => $session, 'time'=>time());
|
||||
|
||||
$this->_messages[] = $logArray;
|
||||
@ -513,7 +560,6 @@ class e_admin_log
|
||||
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* @DEPRECATED
|
||||
* BC Alias for addSuccess();
|
||||
@ -536,7 +582,7 @@ class e_admin_log
|
||||
|
||||
|
||||
/**
|
||||
* Log success
|
||||
* Add a success message to the log queue
|
||||
*
|
||||
* @param string $text
|
||||
* @param boolean $message if true - register with eMessage handler
|
||||
@ -550,10 +596,10 @@ class e_admin_log
|
||||
|
||||
|
||||
/**
|
||||
* Log error
|
||||
* Add an error message to the log queue
|
||||
*
|
||||
* @param string $text
|
||||
* @param boolean $message if true - register with eMessage handler
|
||||
* @param boolean $message if true (default) - register with eMessage handler, set to false to hide.
|
||||
* @param boolean $session add session message
|
||||
* @return e_admin_log
|
||||
*/
|
||||
@ -564,10 +610,10 @@ class e_admin_log
|
||||
|
||||
|
||||
/**
|
||||
* Log Debug
|
||||
* Add an Debug message to the log queue
|
||||
*
|
||||
* @param string $text
|
||||
* @param boolean $message if true - register with eMessage handler
|
||||
* @param boolean $message if true (default) - register with eMessage handler, set to false to hide .
|
||||
* @param boolean $session add session message
|
||||
* @return e_admin_log
|
||||
*/
|
||||
@ -578,10 +624,10 @@ class e_admin_log
|
||||
|
||||
|
||||
/**
|
||||
* Log Warning
|
||||
* Add an Warning message to the log queue
|
||||
*
|
||||
* @param string $text
|
||||
* @param boolean $message if true - register with eMessage handler
|
||||
* @param boolean $message if true (default) - register with eMessage handler, set to false to hide.
|
||||
* @param boolean $session add session message
|
||||
* @return e_admin_log
|
||||
*/
|
||||
@ -590,6 +636,23 @@ class e_admin_log
|
||||
return $this->logMessage($text, ($message ? E_MESSAGE_WARNING : LOG_MESSAGE_NODISPLAY), E_MESSAGE_WARNING, $session);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Add an array to the log queue
|
||||
* @param $array
|
||||
* @param $oldArray (optional) - when included, only the changes between the arrays is saved.
|
||||
* @param $type (optional) default: LOG_MESSAGE_NODISPLAY. or E_MESSAGE_WARNING, E_MESSAGE_NOTICE, E_MESSAGE_SUCCESS
|
||||
*/
|
||||
public function addArray($array, $oldArray= null, $type = LOG_MESSAGE_NODISPLAY )
|
||||
{
|
||||
if(is_array($oldArray))
|
||||
{
|
||||
$text = array_diff_recursive($array,$oldArray); // Located in core_functions.php
|
||||
}
|
||||
|
||||
return $this->logMessage($text, $type, $type, $session);
|
||||
}
|
||||
|
||||
/**
|
||||
* Empty the messages - pass to both admin log and message handler
|
||||
*
|
||||
|
@ -190,6 +190,49 @@ function strip_if_magic($data)
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Return an array with changes between 2 arrays.
|
||||
*/
|
||||
function array_diff_recursive($array1, $array2)
|
||||
{
|
||||
$ret = array();
|
||||
|
||||
foreach($array1 as $key => $val)
|
||||
{
|
||||
if(array_key_exists($key, $array2))
|
||||
{
|
||||
if(is_array($val))
|
||||
{
|
||||
$diff = array_diff_recursive($val, $array2[$key]);
|
||||
|
||||
if(count($diff))
|
||||
{
|
||||
$ret[$key] = $diff;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if($val != $array2[$key])
|
||||
{
|
||||
$ret[$key] = $val;
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
$ret[$key] = $val;
|
||||
}
|
||||
}
|
||||
|
||||
return $ret;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Strips slashes from a string or an array
|
||||
*
|
||||
|
@ -502,6 +502,7 @@ class e_pref extends e_front_model
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
e107::getMessage()->setUnique($this->prefid); // attempt to fix
|
||||
|
||||
if($from_post)
|
||||
@ -520,7 +521,7 @@ class e_pref extends e_front_model
|
||||
return 0;
|
||||
}
|
||||
|
||||
$admin_log = e107::getAdminLog();
|
||||
$log = e107::getAdminLog();
|
||||
$disallow_logs = $this->getParam('nologs', false);
|
||||
|
||||
//Save to DB
|
||||
@ -535,11 +536,11 @@ class e_pref extends e_front_model
|
||||
$dbdata = $this->toString(false);
|
||||
}
|
||||
|
||||
if(e107::getDb()->db_Select_gen("REPLACE INTO `#core` (e107_name,e107_value) values ('{$this->prefid}', '".addslashes($dbdata)."') "))
|
||||
if(e107::getDb()->gen("REPLACE INTO `#core` (e107_name,e107_value) values ('{$this->prefid}', '".addslashes($dbdata)."') "))
|
||||
{
|
||||
$this->data_has_changed = false; //reset status
|
||||
|
||||
if($this->set_backup === true && !empty($this->pref_cache))
|
||||
if(!empty($this->pref_cache))
|
||||
{
|
||||
$old = e107::unserialize($this->pref_cache);
|
||||
if($this->serial_bc)
|
||||
@ -555,18 +556,42 @@ class e_pref extends e_front_model
|
||||
if(is_array($old) && !$disallow_logs) // fix install problems - no old prefs available
|
||||
{
|
||||
$new = $this->getPref();
|
||||
$admin_log->logArrayDiffs($new, $old, 'PREFS_02', false);
|
||||
// $log->logArrayDiffs($new, $old, 'PREFS_02', false);
|
||||
$log->addArray($new,$old);
|
||||
unset($new, $old);
|
||||
|
||||
}
|
||||
if(e107::getDb()->db_Select_gen("REPLACE INTO `#core` (e107_name,e107_value) values ('".$this->prefid."_Backup', '".addslashes($dbdata)."') "))
|
||||
|
||||
// Backup
|
||||
if($this->set_backup === true && e107::getDb()->gen("REPLACE INTO `#core` (e107_name,e107_value) values ('".$this->prefid."_Backup', '".addslashes($dbdata)."') "))
|
||||
{
|
||||
if(!$disallow_logs) $admin_log->logMessage('Backup of <strong>'.$this->alias.' ('.$this->prefid.')</strong> successfully created.', E_MESSAGE_DEBUG, E_MESSAGE_SUCCESS, $session_messages);
|
||||
if(!$disallow_logs) $log->logMessage('Backup of <strong>'.$this->alias.' ('.$this->prefid.')</strong> successfully created.', E_MESSAGE_DEBUG, E_MESSAGE_SUCCESS, $session_messages);
|
||||
e107::getCache()->clear_sys('Config_'.$this->alias.'_backup');
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
$this->setPrefCache($this->toString(false), true); //reset pref cache - runtime & file
|
||||
|
||||
if(!$disallow_logs) $admin_log->logSuccess('Settings successfully saved.', true, $session_messages)->flushMessages('PREFS_01', E_LOG_INFORMATIVE, '', $this->prefid);
|
||||
if($this->alias == 'search') // Quick Fix TODO Improve.
|
||||
{
|
||||
$logId = 'SEARCH_04';
|
||||
}
|
||||
elseif($this->alias == 'notify')
|
||||
{
|
||||
$logId = 'NOTIFY_01';
|
||||
}
|
||||
else
|
||||
{
|
||||
$logId = 'PREFS_01';
|
||||
}
|
||||
|
||||
$log->addSuccess('Settings successfully saved.',true);
|
||||
$log->save($logId);
|
||||
|
||||
// if(!$disallow_logs) $log->logSuccess('Settings successfully saved.', true, $session_messages)->flushMessages($logId, E_LOG_INFORMATIVE, '', $this->prefid);
|
||||
|
||||
|
||||
//BC
|
||||
if($this->alias === 'core')
|
||||
{
|
||||
@ -578,7 +603,7 @@ class e_pref extends e_front_model
|
||||
elseif(e107::getDb()->getLastErrorNumber())
|
||||
{
|
||||
if(!$disallow_logs)
|
||||
$admin_log->logError('mySQL error #'.e107::getDb()->getLastErrorNumber().': '.e107::getDb()->getLastErrorText(), true, $session_messages)
|
||||
$log->logError('mySQL error #'.e107::getDb()->getLastErrorNumber().': '.e107::getDb()->getLastErrorText(), true, $session_messages)
|
||||
->logError('Settings not saved.', true, $session_messages)
|
||||
->flushMessages('PREFS_03', E_LOG_INFORMATIVE, '', $this->prefid);
|
||||
|
||||
@ -592,7 +617,7 @@ class e_pref extends e_front_model
|
||||
//add errors to the eMessage stack
|
||||
//$this->setErrors(true, $session_messages); old - doesn't needed anymore
|
||||
if(!$disallow_logs)
|
||||
$admin_log->logError('Settings not saved.', true, $session_messages)
|
||||
$log->logError('Settings not saved.', true, $session_messages)
|
||||
->flushMessages('LAN_FIXME', E_LOG_INFORMATIVE, '', $this->prefid);
|
||||
|
||||
e107::getMessage()->moveStack($this->prefid);
|
||||
@ -601,7 +626,7 @@ class e_pref extends e_front_model
|
||||
else
|
||||
{
|
||||
e107::getMessage()->addInfo('Settings not saved as no changes were made.', $this->prefid, $session_messages);
|
||||
if(!$disallow_logs) $admin_log->flushMessages('LAN_FIXME', E_LOG_INFORMATIVE, '', $this->prefid);
|
||||
if(!$disallow_logs) $log->flushMessages('LAN_FIXME', E_LOG_INFORMATIVE, '', $this->prefid);
|
||||
e107::getMessage()->moveStack($this->prefid);
|
||||
return 0;
|
||||
}
|
||||
|
@ -58,7 +58,6 @@ class search extends e_shortcode
|
||||
{
|
||||
$this->search_prefs = e107::getConfig('search')->getPref();
|
||||
|
||||
|
||||
if (!e_QUERY)
|
||||
{
|
||||
$this->enhanced = true;
|
||||
@ -224,6 +223,10 @@ class search extends e_shortcode
|
||||
|
||||
if (check_class($this->search_prefs[$type.'_handlers'][$id]['class']))
|
||||
{
|
||||
echo "<br />type = ".$this->search_prefs[$type.'_handlers'][$id]['class'];
|
||||
|
||||
print_a($this->search_prefs);
|
||||
|
||||
if ($plug_require)
|
||||
{
|
||||
require_once($plug_require);
|
||||
|
Loading…
x
Reference in New Issue
Block a user