1
0
mirror of https://github.com/e107inc/e107.git synced 2025-08-07 23:26:41 +02:00

Update routine uses new combined admin logging and messaging API

This commit is contained in:
e107steved
2010-04-20 21:35:20 +00:00
parent 321adb9dc0
commit ee3e6ed9d9
4 changed files with 1629 additions and 1520 deletions

View File

@@ -200,10 +200,10 @@ require_once(e_HANDLER.'e_upgrade_class.php');
//--------------------------------------------
function update_core_prefs($type='')
{
global $pref, $admin_log, $e107info;
global $pref, $e107info;
$admin_log = e107::getAdminLog();
$do_save = FALSE;
$should = get_default_prefs();
$accum = array();
$just_check = $type == 'do' ? FALSE : TRUE; // TRUE if we're just seeing if an update is needed
@@ -213,14 +213,16 @@ function update_core_prefs($type='')
{
if ($just_check) return update_needed('Missing pref: '.$k);
$pref[$k] = $v;
$accum[] = $k;
$admin_log->logMessage($k.' => '.$v, E_MESSAGE_NODISPLAY, E_MESSAGE_INFO);
$do_save = TRUE;
}
}
if ($do_save)
{
save_prefs();
$admin_log->log_event('UPDATE_03',LAN_UPDATE_14.$e107info['e107_version'].'[!br!]'.implode(', ',$accum),E_LOG_INFORMATIVE,''); // Log result of actual update
$admin_log->logMessage(LAN_UPDATE_14.$e107info['e107_version'], E_MESSAGE_NODISPLAY, E_MESSAGE_INFO);
$admin_log->flushMessages('UPDATE_03',E_LOG_INFORMATIVE);
//$admin_log->log_event('UPDATE_03',LAN_UPDATE_14.$e107info['e107_version'].'[!br!]'.implode(', ',$accum),E_LOG_INFORMATIVE,''); // Log result of actual update
}
return $just_check;
}
@@ -255,8 +257,10 @@ if (defined('TEST_UPDATE'))
//--------------------------------------------
function update_706_to_800($type='')
{
global $sql,$ns, $pref, $admin_log, $e107info;
$mes = e107::getMessage();
global $sql,$ns, $pref, $e107info;
//$mes = new messageLog; // Combined logging and message displaying handler
//$mes = e107::getMessage();
$mes = e107::getAdminLog(); // Used for combined logging and message displaying
// List of unwanted $pref values which can go
$obs_prefs = array('frontpage_type','rss_feeds', 'log_lvcount', 'zone', 'upload_allowedfiletype', 'real', 'forum_user_customtitle',
@@ -335,11 +339,15 @@ function update_706_to_800($type='')
$db_parser = new db_table_admin; // Class to read table defs and process them
$do_save = FALSE; // Set TRUE to update prefs when update complete
$updateMessages = array(); // Used to log actions for the admin log
$updateMessages = array(); // Used to log actions for the admin log - TODO: will go once all converted to new class
$just_check = $type == 'do' ? FALSE : TRUE; // TRUE if we're just seeing whether an update is needed
if (!$just_check)
{
$mes->logMessage(LAN_UPDATE_14.$e107info['e107_version'], E_MESSAGE_NODISPLAY);
}
// Check that custompages have been imported from current theme.php file
if(!array_key_exists('sitetheme_custompages',$pref))
@@ -395,7 +403,7 @@ function update_706_to_800($type='')
// Could we use $sysprefs->set($s_prefs,'notify_prefs') instead - avoids caching problems ????
$status = ($sql -> db_Update("core", "e107_value='".$s_prefs."' WHERE e107_name='notify_prefs'") === FALSE) ? E_MESSAGE_SUCCESS : E_MESSAGE_ERROR;
$message = str_replace('--COUNT--',$nt_changed,LAN_UPDATE_20);
$mes->add($message, $status);
$mes->logMessage($message, $status);
}
@@ -406,7 +414,7 @@ function update_706_to_800($type='')
if ($just_check) return update_needed();
$pref['signup_option_customtitle'] = $pref['forum_user_customtitle'];
unset($pref['forum_user_customtitle']);
$mes->add(LAN_UPDATE_20.'customtitle', E_MESSAGE_SUCCESS);
$mes->logMessage(LAN_UPDATE_20.'customtitle', E_MESSAGE_SUCCESS);
$do_save = TRUE;
}
@@ -419,7 +427,7 @@ function update_706_to_800($type='')
while ($row = e107::getDb()->db_Fetch(MYSQL_ASSOC))
{
$status = e107::getDb('sql2')->db_Update('core',"e107_value=\"".convert_serialized($row['e107_value'])."\" WHERE e107_name='".$row['e107_name']."'");
$mes->add(LAN_UPDATE_22.$row['e107_name'], $status);
$mes->logMessage(LAN_UPDATE_22.$row['e107_name'], $status);
}
}
@@ -465,8 +473,8 @@ function update_706_to_800($type='')
$status = E_MESSAGE_INFO;
}
$result = $menuConfig->save(false, true, false); // Save updated menuprefs - without the counts
$updateMessages[] = $statusTexts[$status].': '.$resultMessage; // Admin log message
$mes->add($resultMessage,$status); // User message
//$updateMessages[] = $statusTexts[$status].': '.$resultMessage; // Admin log message
$mes->logMessage($resultMessage,$status); // User message
}
@@ -482,7 +490,7 @@ function update_706_to_800($type='')
if ($just_check) return update_needed('Menu path changed required: '.$val['menu'].' ');
$updqry = "menu_path='".$val['newpath']."/' WHERE menu_name = '".$val['menu']."' AND (menu_path='".$val['oldpath']."' || menu_path='".$val['oldpath']."/' ) ";
$status = $sql->db_Update('menus', $updqry) ? E_MESSAGE_SUCCESS : E_MESSAGE_ERROR;
$mes->add(LAN_UPDATE_23.'<b>'.$val['menu'].'</b> : '.$val['oldpath'].' => '.$val['newpath'], $status); // LAN_UPDATE_25;
$mes->logMessage(LAN_UPDATE_23.'<b>'.$val['menu'].'</b> : '.$val['oldpath'].' => '.$val['newpath'], $status); // LAN_UPDATE_25;
// catch_error($sql);
}
}
@@ -500,13 +508,13 @@ function update_706_to_800($type='')
if($row['menu_location']!=0)
{
$status = $sql->db_Update('menus', "menu_name='online_menu', menu_path='online/' WHERE menu_path='online_extended_menu' || menu_path='online_extended_menu/' ") ? E_MESSAGE_SUCCESS : E_MESSAGE_ERROR;
$mes->add(LAN_UPDATE_23."<b>online_menu</b> : online/", $status);
$mes->logMessage(LAN_UPDATE_23."<b>online_menu</b> : online/", $status);
}
else
{ //else if the menu is not active
//we need to delete the online_extended menu row, and change the online_menu to online
$sql->db_Delete('menus', " menu_path='online_extended_menu' || menu_path='online_extended_menu/' ");
// $updateMessages[] = LAN_UPXXDATE_31;
$mes->logMessage(LAN_UPDATE_31, E_MESSAGE_SUCCESS);
}
catch_error($sql);
}
@@ -517,7 +525,7 @@ function update_706_to_800($type='')
if ($just_check) return update_needed();
$status = $sql->db_Update('menus', "menu_path='online/' WHERE menu_path='online_menu' || menu_path='online_menu/' ") ? E_MESSAGE_SUCCESS : E_MESSAGE_ERROR;
$mes->add(LAN_UPDATE_23."<b>online_menu</b> : online/", $status);
$mes->logMessage(LAN_UPDATE_23."<b>online_menu</b> : online/", $status);
catch_error($sql);
}
@@ -536,26 +544,26 @@ function update_706_to_800($type='')
{
// Flag error
// $commentMessage = LAN_UPDAXXTE_34;
$mes->add(LAN_UPDATE_21."comments", E_MESSAGE_ERROR);
$mes->logMessage(LAN_UPDATE_21."comments", E_MESSAGE_ERROR);
}
else
{
if (FALSE ===$sql->db_Update('comments',"comment_author_id=SUBSTRING_INDEX(`comment_author`,'.',1), comment_author_name=SUBSTRING(`comment_author` FROM POSITION('.' IN `comment_author`)+1)"))
{
// Flag error
$mes->add(LAN_UPDATE_21.'comments', E_MESSAGE_ERROR);
$mes->logMessage(LAN_UPDATE_21.'comments', E_MESSAGE_ERROR);
}
else
{ // Delete superceded field - comment_author
if (!$sql->db_Select_gen("ALTER TABLE `#comments` DROP COLUMN `comment_author`"))
{
// Flag error
$mes->add(LAN_UPDATE_24.'comments - comment_author', E_MESSAGE_ERROR);
$mes->logMessage(LAN_UPDATE_24.'comments - comment_author', E_MESSAGE_ERROR);
}
}
}
$mes->add(LAN_UPDATE_21.'comments', E_MESSAGE_SUCCESS);
$mes->logMessage(LAN_UPDATE_21.'comments', E_MESSAGE_SUCCESS);
}
@@ -594,7 +602,7 @@ function update_706_to_800($type='')
$pref['frontpage_force'] = array(e_UC_PUBLIC => '');
$pref['frontpage'] = array(e_UC_PUBLIC => 'news.php');
// $_pdateMessages[] = LAN_UPDATE_38; //FIXME
$mes->add(LAN_UPDATE_20."frontpage",E_MESSAGE_SUCCESS);
$mes->logMessage(LAN_UPDATE_20."frontpage",E_MESSAGE_SUCCESS);
$do_save = TRUE;
}
@@ -608,8 +616,8 @@ function update_706_to_800($type='')
{
if ($just_check) return update_needed('Update newsfeed field definition');
$status = $sql->db_Select_gen("ALTER TABLE `".MPREFIX."newsfeed` MODIFY `newsfeed_url` VARCHAR(250) NOT NULL DEFAULT '' ") ? E_MESSAGE_SUCCESS : E_MESSAGE_ERROR;
$updateMessages[] = LAN_UPDATE_40;
$mes->add(LAN_UPDATE_21."newsfeed",$status);
//$updateMessages[] = LAN_UPDATE_40;
$mes->logMessage(LAN_UPDATE_21."newsfeed",$status);
// catch_error($sql);
}
}
@@ -626,7 +634,8 @@ function update_706_to_800($type='')
{
if ($just_check) return update_needed('Update download table field definition');
$sql->db_Select_gen("ALTER TABLE `#download` MODIFY `download_url` VARCHAR(255) NOT NULL DEFAULT '' ");
$updateMessages[] = LAN_UPDATE_52; //FIXME
//$updateMessages[] = LAN_UPDATE_52; //FIXME
$mes->logMessage(LAN_UPDATE_52, E_MESSAGE_SUCCESS);
catch_error($sql);
}
}
@@ -642,7 +651,8 @@ function update_706_to_800($type='')
{
if ($just_check) return update_needed('Update download mirror table field definition');
$sql->db_Select_gen("ALTER TABLE `".MPREFIX."download_mirror` MODIFY `mirror_url` VARCHAR(255) NOT NULL DEFAULT '' ");
$updateMessages[] = LAN_UPDATE_53; //FIXME
$mes->logMessage(LAN_UPDATE_53, E_MESSAGE_SUCCESS);
catch_error($sql);
}
}
@@ -657,10 +667,12 @@ function update_706_to_800($type='')
if ($just_check) return update_needed('Move user timezone info');
if (!copy_user_timezone())
{ // Error doing the transfer
$updateMessages[] = LAN_UPDATE_42; //FIXME
//$updateMessages[] = LAN_UPDATE_42;
$mes->logMessage(LAN_UPDATE_42, E_MESSAGE_ERROR);
return FALSE;
}
$updateMessages[] = LAN_UPDATE_41;
//$updateMessages[] = LAN_UPDATE_41;
$mes->logMessage(LAN_UPDATE_41);
}
}
@@ -672,7 +684,8 @@ function update_706_to_800($type='')
if ($just_check) return update_needed('Rename dblog to admin_log');
$sql->db_Select_gen('ALTER TABLE `'.MPREFIX.'dblog` RENAME `'.MPREFIX.'admin_log`');
catch_error($sql);
$updateMessages[] = LAN_UPDATE_43; //FIXME
//$updateMessages[] = LAN_UPDATE_43;
$mes->logMessage(LAN_UPDATE_43, E_MESSAGE_SUCCESS);
}
@@ -681,7 +694,8 @@ function update_706_to_800($type='')
{
if ($just_check) return update_needed('Rename rl_history to dblog');
$sql->db_Select_gen('ALTER TABLE `'.MPREFIX.'rl_history` RENAME `'.MPREFIX.'dblog`');
$updateMessages[] = LAN_UPDATE_44; //FIXME
//$updateMessages[] = LAN_UPDATE_44;
$mes->logMessage(LAN_UPDATE_44, E_MESSAGE_SUCCESS);
catch_error($sql);
}
@@ -697,12 +711,12 @@ function update_706_to_800($type='')
{
$status = $sql->db_Select_gen('CREATE TABLE `'.MPREFIX.$defs[0][1].'` ('.$defs[0][2].') TYPE='.$defs[0][3]) ? E_MESSAGE_SUCCESS : E_MESSAGE_ERROR;
// $updateMessages[] = LAN_UPDATE_45.$defs[0][1];
$mes->add(LAN_UPDATE_27.$defs[0][1], $status); //TODO - all update messages should work like this. But also need $updateMessages[] for admin log
$mes->logMessage(LAN_UPDATE_27.$defs[0][1], $status);
// catch_error($sql);
}
else
{ // error parsing defs file
$mes->add(LAN_UPDATE_46.$defs[0][1], E_MESSAGE_ERROR);
$mes->logMessage(LAN_UPDATE_46.$defs[0][1], E_MESSAGE_ERROR);
}
unset($defs);
}
@@ -718,12 +732,12 @@ function update_706_to_800($type='')
$req_fields = $db_parser->parse_field_defs($req_defs[0][2]); // Required definitions
if ($debugLevel)
{
$mes->add("Required table structure: <br />".$db_parser->make_field_list($req_fields), E_MESSAGE_DEBUG);
$mes->logMessage("Required table structure: <br />".$db_parser->make_field_list($req_fields), E_MESSAGE_DEBUG);
}
if ((($actual_defs = $db_parser->get_current_table($ct)) === FALSE) || !is_array($actual_defs)) // Adds current default prefix
{
$mes->add("Couldn't get table structure: ".$ct, E_MESSAGE_DEBUG);
$mes->logMessage("Couldn't get table structure: ".$ct, E_MESSAGE_DEBUG);
}
else
{
@@ -731,7 +745,7 @@ function update_706_to_800($type='')
$actual_fields = $db_parser->parse_field_defs($actual_defs[0][2]);
if ($debugLevel)
{
$mes->add("Actual table structure: <br />".$db_parser->make_field_list($actual_fields), E_MESSAGE_DEBUG);
$mes->logMessage("Actual table structure: <br />".$db_parser->make_field_list($actual_fields), E_MESSAGE_DEBUG);
}
$diffs = $db_parser->compare_field_lists($req_fields,$actual_fields);
@@ -742,18 +756,18 @@ function update_706_to_800($type='')
// Do the changes here
if ($debugLevel)
{
$mes->add("List of changes found:<br />".$db_parser->make_changes_list($diffs), E_MESSAGE_DEBUG);
$mes->logMessage("List of changes found:<br />".$db_parser->make_changes_list($diffs), E_MESSAGE_DEBUG);
}
$qry = 'ALTER TABLE '.MPREFIX.$ct.' '.implode(', ',$diffs[1]);
if ($debugLevel)
{
$mes->add("Update Query used: ".$qry, E_MESSAGE_DEBUG);
$mes->logMessage("Update Query used: ".$qry, E_MESSAGE_DEBUG);
}
$status = $sql->db_Select_gen($qry) ? E_MESSAGE_SUCCESS : E_MESSAGE_ERROR;
$mes->add(LAN_UPDATE_21.$ct, $status);
$mes->logMessage(LAN_UPDATE_21.$ct, $status);
catch_error($sql);
}
}
@@ -766,7 +780,6 @@ function update_706_to_800($type='')
if (plugInstalled($plugName))
{
$ttc = explode(',',$plugList);
$mes = e107::getMessage();
foreach ($ttc as $ct)
{
$sqlDefs = e_PLUGIN.$plugName.'/'.str_replace('_menu','',$plugName).'_sql.php'; // Filename containing definitions
@@ -782,7 +795,7 @@ function update_706_to_800($type='')
{
$message = "Required plugin table structure: <br />".$db_parser->make_field_list($req_fields);
$mes->add($message, E_MESSAGE_DEBUG);
$mes->logMessage($message, E_MESSAGE_DEBUG);
}
@@ -797,7 +810,7 @@ function update_706_to_800($type='')
if (E107_DBG_SQLDETAILS)
{
$message= "Actual table structure: <br />".$db_parser->make_field_list($actual_fields);
$mes->add($message, E_MESSAGE_DEBUG);
$mes->logMessage($message, E_MESSAGE_DEBUG);
}
$diffs = $db_parser->compare_field_lists($req_fields,$actual_fields);
@@ -806,7 +819,7 @@ function update_706_to_800($type='')
if (E107_DBG_SQLDETAILS)
{
$message = "List of changes found:<br />".$db_parser->make_changes_list($diffs);
$mes->add($message, E_MESSAGE_DEBUG);
$mes->logMessage($message, E_MESSAGE_DEBUG);
}
if ($just_check) return update_needed("Field changes rqd; plugin table: ".$ct);
// Do the changes here
@@ -814,10 +827,11 @@ function update_706_to_800($type='')
if (E107_DBG_SQLDETAILS)
{
$message = "Update Query used: ".$qry."<br />";
$mes->add($message, E_MESSAGE_DEBUG);
$mes->logMessage($message, E_MESSAGE_DEBUG);
}
$sql->db_Select_gen($qry);
$updateMessages[] = LAN_UPDATE_51.$ct; //FIXME
$updateMessages[] = LAN_UPDATE_51.$ct;
$mes->logMessage(LAN_UPDATE_51.$ct, E_MESSAGE_SUCCESS);
catch_error($sql);
}
}
@@ -844,7 +858,7 @@ function update_706_to_800($type='')
{
if ($just_check) return update_needed("Delete table: ".$ot);
$status = $sql->db_Select_gen('DROP TABLE `'.MPREFIX.$ot.'`') ? E_MESSAGE_SUCCESS : E_MESSAGE_ERROR;
$mes->add(LAN_UPDATE_25.$ot, $status);
$mes->logMessage(LAN_UPDATE_25.$ot, $status);
}
}
@@ -861,7 +875,7 @@ function update_706_to_800($type='')
{
if ($just_check) return update_needed('Update IP address field '.$f.' in table '.$t);
$status = $sql->db_Select_gen("ALTER TABLE `".MPREFIX.$t."` MODIFY `{$f}` VARCHAR(45) NOT NULL DEFAULT '';") ? E_MESSAGE_SUCCESS : E_MESSAGE_ERROR;
$mes->add(LAN_UPDATE_26.$t.' - '.$f, $status);
$mes->logMessage(LAN_UPDATE_26.$t.' - '.$f, $status);
// catch_error($sql);
}
}
@@ -944,17 +958,68 @@ function update_706_to_800($type='')
if ($do_save)
{
save_prefs();
$mes->add(LAN_UPDATE_50);
$updateMessages[] = LAN_UPDATE_50.implode(', ',$accum); // Note for admin log
$mes->logMessage(LAN_UPDATE_50);
$mes->logMessage(implode(', ', $accum), E_MESSAGE_NODISPLAY);
//$updateMessages[] = LAN_UPDATE_50.implode(', ',$accum); // Note for admin log
}
//FIXME grab message-stack from $mes for the log.
if ($just_check) return TRUE;
$admin_log->log_event('UPDATE_01',LAN_UPDATE_14.$e107info['e107_version'].'[!br!]'.implode('[!br!]',$updateMessages),E_LOG_INFORMATIVE,''); // Log result of actual update
$mes->flushMessages('UPDATE_01'); // Write admin log entry, update message handler
//$admin_log->log_event('UPDATE_01',LAN_UPDATE_14.$e107info['e107_version'].'[!br!]'.implode('[!br!]',$updateMessages),E_LOG_INFORMATIVE,''); // Log result of actual update
return $just_check;
}
function core_media_import($cat,$epath)
{
if(!vartrue($cat)){ return;}
if(!is_readable($epath))
{
return;
}
$fl = e107::getFile();
$tp = e107::getParser();
$sql = e107::getDb();
$mes = e107::getMessage();
$fl->setFileInfo('all');
$img_array = $fl->get_files($epath,'','',2);
if(!count($img_array)){ return;}
foreach($img_array as $f)
{
$fullpath = $tp->createConstants($f['path'].$f['fname'],1);
$insert = array(
'media_caption' => $f['fname'],
'media_description' => '',
'media_category' => $cat,
'media_datestamp' => $f['modified'],
'media_url' => $fullpath,
'media_userclass' => 0,
'media_name' => $f['fname'],
'media_author' => USERID,
'media_size' => $f['fsize'],
'media_dimensions' => $f['img-width']." x ".$f['img-height'],
'media_usedby' => '',
'media_tags' => '',
'media_type' => $f['mime']
);
if(!$sql->db_Select('core_media','media_url',"media_url = '".$fullpath."' LIMIT 1"))
{
if($sql->db_Insert("core_media",$insert))
{
$mes->add("Importing Media: ".$f['fname'], E_MESSAGE_SUCCESS);
}
}
}
}
function update_70x_to_706($type='')
{
@@ -1095,7 +1160,12 @@ function mysql_table_exists($table)
*/
// Add index to a table. Returns FALSE if not required. Returns a message if required and just checking
/**
* Add index to a table. Returns FALSE if not required. Returns a message if required and just checking
*
* @todo - get rid of $updateMessages parameter once log/message display method finalised, call the relevant method
*/
function addIndexToTable($target, $indexSpec, $just_check, &$updateMessages, $optionalTable=FALSE)
{
global $sql;

View File

@@ -37,8 +37,8 @@ class e_admin_log
* @var array
*/
protected $_options = array('log_level'=>2, 'backtrace'=>false, );
public $rldb = NULL; // Database used by logging routine
protected $rldb = NULL; // Database used by logging routine
/**
* Log messages
* @var array
@@ -49,9 +49,9 @@ class e_admin_log
* Constructor. Sets up constants and overwrites default options where set.
*
* @param array $options
* @return e_admin_log
* @return none
*/
function __construct($options = array())
public function __construct($options = array())
{
foreach ($options as $key=>$val)
{
@@ -92,18 +92,25 @@ class e_admin_log
$this->_messages = array();
}
/**
* 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')
* We also log everything (unlike 0.7, where admin log and debug stuff were all mixed up together)
*
* For multi-lingual logging (where the event title is shown in the language of the current user), LAN defines may be used in the title
*
* For generic calls, leave $event_code as empty, and specify a constant string STRING_nn of less than 10 characters for the event title
* Typically the 'STRING' part of the name defines the area originating the log event, and the 'nn' is a numeric code
* This is stored as 'LAN_AL_STRING_NN', and must be defined in a language file which is loaded during log display.
*
* @param string $event_title
* @param mixed $event_detail
* @param integer $event_type [optional] Log level
* @param unknown $event_code [optional]
* @return e_admin_log
*/
function log_event($event_title, $event_detail, $event_type = E_LOG_INFORMATIVE , $event_code = '')
public function log_event($event_title, $event_detail, $event_type = E_LOG_INFORMATIVE , $event_code = '')
{
if ($event_code == '')
{
@@ -142,36 +149,39 @@ class e_admin_log
return $this;
}
/*
/**
Generic log entry point
-----------------------
Example call: (Deliberately pick separators that shouldn't be in file names)
e_log_event(E_LOG_NOTICE,__FILE__."|".__FUNCTION__."@".__LINE__,"ECODE","Event Title","explanatory message",FALSE,LOG_TO_ADMIN);
or:
e_log_event(E_LOG_NOTICE,debug_backtrace(),"ECODE","Event Title","explanatory message",TRUE,LOG_TO_ROLLING);
*
* @param int $importance - importance of event - 0..4 or so
* @param mixed $source_call - either: string identifying calling file/routine
* or: a number 0..9 identifying info to log from debug_backtrace()
* or: empty string, in which case first entry from debug_backtrace() logged
* or: an array, assumed to be from passing debug_backtrace() as a parameter, in which case relevant
* information is extracted and the argument list from the first entry logged
* or: -1, in which case no information logged
* @param string $eventcode - abbreviation listing event type
* @param string $event_title - title of event - pass standard 'LAN_ERROR_nn' defines to allow language translation
* @param string $explain - detail of event
* @param bool $finished - if TRUE, aborts execution
* @param int $target_logs - flags indicating which logs to update - if entry to be posted in several logs, add (or 'OR') their defines:
* LOG_TO_ADMIN - admin log
* LOG_TO_AUDIT - audit log
* LOG_TO_ROLLING - rolling log
*
* @return none
Parameters:
$importance - importance of event - 0..4 or so
$source_call - either: string identifying calling file/routine
or: a number 0..9 identifying info to log from debug_backtrace()
or: empty string, in which case first entry from debug_backtrace() logged
or: an array, assumed to be from passing debug_backtrace() as a parameter, in which case relevant
information is extracted and the argument list from the first entry logged
or: -1, in which case no information logged
$eventcode - abbreviation listing event type
$event_title - title of event - pass standard 'LAN_ERROR_nn' defines to allow language translation
$explain - detail of event
$finished - if TRUE, aborts execution
$target_logs - flags indicating which logs to update - if entry to be posted in several logs, add (or 'OR') their defines:
LOG_TO_ADMIN - admin log
LOG_TO_AUDIT - audit log
LOG_TO_ROLLING - rolling log
* @todo - check microtime() call
*/
function e_log_event($importance, $source_call, $eventcode = "GEN", $event_title = "Untitled", $explain = "", $finished = FALSE, $target_logs = LOG_TO_AUDIT )
public function e_log_event($importance, $source_call, $eventcode = "GEN", $event_title = "Untitled", $explain = "", $finished = FALSE, $target_logs = LOG_TO_AUDIT )
{
global $pref,$e107,$tp;
list($time_usec, $time_sec) = explode(" ", microtime()); // Log event time immediately to minimise uncertainty
list($time_usec, $time_sec) = explode(" ", microtime(FALSE)); // Log event time immediately to minimise uncertainty
$time_usec = $time_usec * 1000000;
if ($this->rldb == NULL)
@@ -280,12 +290,20 @@ class e_admin_log
exit; // Optional abort for all logs
}
//--------------------------------------
// USER AUDIT ENTRY
//--------------------------------------
// $event_code is a defined constant (see above) which specifies the event
// $event_data is an array of data fields whose keys and values are logged (usually user data, but doesn't have to be - can add messages here)
// $id and $u_name are left blank except for admin edits and user login, where they specify the id and login name of the 'target' user
/**--------------------------------------
* USER AUDIT ENTRY
*--------------------------------------
* Log user-related events
* @param int $event_code is a defined constant (see above) which specifies the event
* @param array $event_data is an array of data fields whose keys and values are logged (usually user data, but doesn't have to be - can add messages here)
* @param int $id
* @param string $u_name
* both $id and $u_name are left blank except for admin edits and user login, where they specify the id and login name of the 'target' user
*
* @return none
*/
function user_audit($event_type, $event_data, $id = '', $u_name = '')
{
global $e107,$tp,$pref;
@@ -318,12 +336,17 @@ class e_admin_log
$this->rldb->db_Insert("audit_log", "0, ".intval($time_sec).', '.intval($time_usec).", '{$eventcode}', {$userid}, '{$userstring}', '{$userIP}', '{$title}', '{$detail}' ");
}
/* Legacy function probably not needed
function get_log_events($count = 15, $offset)
{
global $sql;
$count = intval($count);
return "Not implemented yet";
}
*/
/**
* Removes all events older than $days, or truncates the table if $days == false
@@ -331,7 +354,7 @@ class e_admin_log
* @param integer|false $days
* @return void
*/
function purge_log_events($days)
public function purge_log_events($days)
{
global $sql;
if ($days == false)
@@ -350,10 +373,15 @@ class e_admin_log
//--------------------------------------
// HELPER ROUTINES
//--------------------------------------
// Generic routine to log changes to an array. Only elements in $new are checked
// Returns true if changes, false otherwise.
// Only makes log entry if changes detected.
// The $old array is updated with changes, but not saved anywhere
/**
* Generic routine to log changes to an array. Only elements in $new are checked
*
* @param array $new - most recent data being saved
* @param array $old existing data - array is updated with changes, but not saved anywhere
* @param string $event - LAN define or string used as title in log
*
* @return bool true if changes found and logged, false otherwise.
*/
function logArrayDiffs(&$new, &$old, $event, $logNow = true)
{
$changes = array();
@@ -375,11 +403,19 @@ class e_admin_log
return FALSE;
}
// Logs an entry with all the data from an array, one field per line.
// If $extra is non-empty, it goes on the first line.
// Normally data is in the format keyname=>value, one per line.
// If the $niceName array exists and has a definition, the 'nice Name' is displayed instead of the key name
function logArrayAll($event, $target, $extra = '', $niceNames = NULL)
/**
* Logs an entry with all the data from an array, one field per line.
*
* @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.
* @param array $niceNames - Normally data is logged in the format keyname=>value, one per line.
* If the $niceName array exists and has a definition, the 'nice Name' is displayed instead of the key name
*
* @return none
*/
public function logArrayAll($event, $target, $extra = '', $niceNames = NULL)
{
$logString = '';
if ($extra)
@@ -476,6 +512,7 @@ class e_admin_log
{
$logString .= $separator;
if ($m['loglevel'] == LOG_MESSAGE_NODISPLAY) { $logString .= ' '; } // Indent supplementary messages
// Not sure about next line - might want to log the <br /> as text, rather than it forcing a newline
$logString .= strip_tags(str_replace(array('<br>', '<br/>', '<br />'), '[!br!]', $m['message']));
if (isset($resultTypes[$m['loglevel']]))
{

View File

@@ -539,7 +539,7 @@ class e_pref extends e_admin_model
if(is_array($old)) // fix install problems - no old prefs available
{
$new = $this->getPref();
$admin_log->logArrayDiffs($new, $old, 'LAN_FIXME', false);
$admin_log->logArrayDiffs($new, $old, 'PREFS_02', false);
unset($new, $old);
}
if(e107::getDb()->db_Select_gen("REPLACE INTO `#core` (e107_name,e107_value) values ('".$this->prefid."_Backup', '".addslashes($dbdata)."') "))
@@ -550,7 +550,7 @@ class e_pref extends e_admin_model
}
$this->setPrefCache($this->toString(false), true); //reset pref cache - runtime & file
$admin_log->logSuccess('Settings successfully saved.', true, $session_messages)->flushMessages('LAN_FIXME');
$admin_log->logSuccess('Settings successfully saved.', true, $session_messages)->flushMessages('PREFS_01');
//BC
if($this->alias === 'core')
{
@@ -562,7 +562,7 @@ class e_pref extends e_admin_model
{
$admin_log->logError('mySQL error #'.e107::getDb()->getLastErrorNumber().': '.e107::getDb()->getLastErrorText(), true, $session_messages)
->logError('Settings not saved.', true, $session_messages)
->flushMessages('LAN_FIXME');
->flushMessages('PREFS_03');
return false;
}
}

View File

@@ -110,6 +110,8 @@ define('LAN_ROLL_LOG_11','Admin login fail');
// Prefs events
//-------------
define('LAN_AL_PREFS_01', 'Preferences changed');
define('LAN_AL_PREFS_02', 'New Preferences created');
define('LAN_AL_PREFS_03', 'Error saving prefs');
// Front Page events