1
0
mirror of https://github.com/e107inc/e107.git synced 2025-04-20 04:32:01 +02:00

Install routine fix - problem related mainly with our old enemy - global vars;

Everything should work fine now, notices also cleared.
This commit is contained in:
secretr 2010-05-16 11:14:19 +00:00
parent 8324bb12bb
commit cca1f3f8e0
5 changed files with 97 additions and 76 deletions

View File

@ -1,4 +1,4 @@
<?php
<?php
/*
* e107 website system
*
@ -44,7 +44,7 @@ class e_admin_log
* @var array
*/
protected $_messages;
/**
* Constructor. Sets up constants and overwrites default options where set.
*
@ -57,18 +57,18 @@ class e_admin_log
{
$this->_options[$key] = $val;
}
define("E_LOG_INFORMATIVE", 0); // Minimal Log Level, including really minor stuff
define("E_LOG_NOTICE", 1); // More important than informative, but less important than notice
define("E_LOG_WARNING", 2); // Not anything serious, but important information
define("E_LOG_FATAL", 3); // An event so bad your site ceased execution.
define("E_LOG_PLUGIN", 4); // Plugin information
// Logging actions
define("LOG_TO_ADMIN", 1);
define("LOG_TO_AUDIT", 2);
define("LOG_TO_ROLLING", 4);
// User audit logging (intentionally start at 10 - stick to 2 digits)
// The last two digits must match that for the corresponding log message
define('USER_AUDIT_ADMIN', 10); // User data changed by admin
@ -86,7 +86,7 @@ class e_admin_log
define('USER_AUDIT_BANNED', 22); // User banned
define('USER_AUDIT_BOUNCE_RESET', 23); // User bounce reset
define('USER_AUDIT_TEMP_ACCOUNT', 24); // User temporary account
// Init E_MESSAGE_* constants if not already done
e107::getMessage();
$this->_messages = array();
@ -139,16 +139,16 @@ class e_admin_log
$event_detail = implode("[!br!]\n", $tmp);
unset($tmp);
}
if ($this->_options['backtrace'] == true)
{
$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;
}
/**
Generic log entry point
-----------------------
@ -156,7 +156,7 @@ class e_admin_log
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()
@ -175,33 +175,35 @@ class e_admin_log
*
* @return none
* @todo - check microtime() call
* @todo - check microtime() call
*/
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;
$e107 = e107::getInstance();
$pref = e107::getPref();
$tp = e107::getParser();
list($time_usec, $time_sec) = explode(" ", microtime(FALSE)); // Log event time immediately to minimise uncertainty
$time_usec = $time_usec * 1000000;
if ($this->rldb == NULL)
$this->rldb = new db; // Better use our own db - don't know what else is going on
$this->rldb = e107::getDb('adminlog'); // Better use our own db - don't know what else is going on
if (is_bool($target_logs))
{ // Handle the legacy stuff for now - some old code used a boolean to select admin or rolling logs
$target_logs = $target_logs ? LOG_TO_ADMIN : LOG_TO_ROLLING;
}
//---------------------------------------
// Calculations common to all logs
//---------------------------------------
$userid = (USER === TRUE) ? USERID : 0;
$userstring = (USER === true ? USERNAME : "LAN_ANONYMOUS");
$userIP = $e107->getip();
$importance = $tp->toDB($importance, true, false, 'no_html');
$eventcode = $tp->toDB($eventcode, true, false, 'no_html');
if (is_array($explain))
{
$line = '';
@ -216,7 +218,7 @@ class e_admin_log
}
$explain = mysql_real_escape_string($tp->toDB($explain, true, false, 'no_html'));
$event_title = $tp->toDB($event_title, true, false, 'no_html');
//---------------------------------------
// Admin Log
//---------------------------------------
@ -225,18 +227,18 @@ class e_admin_log
$qry = " 0, ".intval($time_sec).','.intval($time_usec).", '{$importance}', '{$eventcode}', {$userid}, '{$userIP}', '{$event_title}', '{$explain}' ";
$this->rldb->db_Insert("admin_log", $qry);
}
//---------------------------------------
// Audit Log
//---------------------------------------
// Add in audit log here
//---------------------------------------
// Rolling Log
//---------------------------------------
if (($target_logs & LOG_TO_ROLLING) && varsettrue($pref['roll_log_active']))
{ // Rolling log
// Process source_call info
//---------------------------------------
if (is_numeric($source_call) && ($source_call >= 0))
@ -250,7 +252,7 @@ class e_admin_log
$i = 1; // Don't want to print the entry parameters to this function - we know all that!
}
}
if (is_array($source_call))
{ // Print the debug_backtrace() array
while ($i < $back_count)
@ -278,20 +280,20 @@ class e_admin_log
$source_call = $tp->toDB($source_call, true, false, 'no_html');
}
// else $source_call is a string
// Save new rolling log record
$this->rldb->db_Insert("dblog", "0, ".intval($time_sec).', '.intval($time_usec).", '{$importance}', '{$eventcode}', {$userid}, '{$userstring}', '{$userIP}', '{$source_call}', '{$event_title}', '{$explain}' ");
// Now delete any old stuff
$this->rldb->db_Delete("dblog", "dblog_datestamp < '".intval(time() - (varset($pref['roll_log_days'], 7) * 86400))."' ");
}
if ($finished)
exit; // Optional abort for all logs
}
/**--------------------------------------
* USER AUDIT ENTRY
*--------------------------------------
@ -299,7 +301,7 @@ class e_admin_log
* @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
* @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
@ -309,22 +311,22 @@ class e_admin_log
global $e107,$tp,$pref;
list($time_usec, $time_sec) = explode(" ", microtime()); // Log event time immediately to minimise uncertainty
$time_usec = $time_usec * 1000000;
// See whether we should log this
$user_logging_opts = array_flip(explode(',', varset($pref['user_audit_opts'], '')));
if (!isset($user_logging_opts[$event_type]))
return; // Finished if not set to log this event type
if ($this->rldb == NULL)
$this->rldb = new db; // Better use our own db - don't know what else is going on
if ($id) $userid = $id;
else $userid = (USER === TRUE) ? USERID : 0;
if ($u_name) $userstring = $u_name;
else $userstring = (USER === true ? USERNAME : "LAN_ANONYMOUS");
$userIP = $e107->getip();
$eventcode = 'USER_'.$event_type;
$title = 'LAN_AUDIT_LOG_0'.$event_type; // This creates a string which will be displayed as a constant
$spacer = '';
$detail = '';
@ -347,7 +349,7 @@ class e_admin_log
*/
/**
* Removes all events older than $days, or truncates the table if $days == false
*
@ -369,7 +371,7 @@ class e_admin_log
$sql->db_Delete("dblog", "WHERE `dblog_datestamp` < {$time}", true);
}
}
//--------------------------------------
// HELPER ROUTINES
//--------------------------------------
@ -438,7 +440,7 @@ class e_admin_log
}
$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
*/
@ -449,10 +451,10 @@ class e_admin_log
* @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.
* @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)
@ -463,10 +465,10 @@ class e_admin_log
$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
@ -479,7 +481,7 @@ class e_admin_log
/**
* Log error
*
*
* @param string $text
* @param boolean $message if true - register with eMessage handler
* @param boolean $session add session message

View File

@ -2,7 +2,7 @@
/*
* e107 website system
*
* Copyright (C) 2008-2009 e107 Inc (e107.org)
* Copyright (C) 2008-2010 e107 Inc (e107.org)
* Released under the terms and conditions of the
* GNU General Public License (http://www.gnu.org/licenses/gpl.txt)
*
@ -34,11 +34,10 @@ class ecache {
const CACHE_PREFIX = '<?php exit;';
function ecache()
function __construct()
{
global $pref;
$this->UserCacheActive = varsettrue($pref['cachestatus']);
$this->SystemCacheActive = varsettrue($pref['syscachestatus']);
$this->UserCacheActive = e107::getPref('cachestatus');
$this->SystemCacheActive = e107::getPref('syscachestatus');
}
/**
@ -104,8 +103,7 @@ class ecache {
*/
function retrieve($CacheTag, $MaximumAge = false, $ForcedCheck = false, $syscache = false)
{
global $pref, $tp;
if(($ForcedCheck != false ) || ($syscache == false && varsettrue($pref['cachestatus'])) || ($syscache == true && varsettrue($pref['syscachestatus'])) && !$tp->checkHighlighting())
if(($ForcedCheck != false ) || ($syscache == false && $this->UserCacheActive) || ($syscache == true && $this->SystemCacheActive) && !e107::getParser()->checkHighlighting())
{
$cache_file = (isset($this) && $this instanceof ecache ? $this->cache_fname($CacheTag, $syscache) : ecache::cache_fname($CacheTag, $syscache));
if (file_exists($cache_file))
@ -165,8 +163,7 @@ class ecache {
*/
public function set($CacheTag, $Data, $ForceCache = false, $bRaw=0, $syscache = false)
{
global $pref, $FILES_DIRECTORY, $tp;
if(($ForceCache != false ) || ($syscache == false && varsettrue($pref['cachestatus'])) || ($syscache == true && varsettrue($pref['syscachestatus'])) && !$tp->checkHighlighting())
if(($ForceCache != false ) || ($syscache == false && $this->UserCacheActive) || ($syscache == true && $this->SystemCacheActive) && !e107::getParser()->checkHighlighting())
{
$cache_file = (isset($this) && $this instanceof ecache ? $this->cache_fname($CacheTag, $syscache) : ecache::cache_fname($CacheTag, $syscache));
file_put_contents($cache_file, ($bRaw? $Data : self::CACHE_PREFIX.$Data) );
@ -268,5 +265,3 @@ class ecache {
}
}
}
?>

View File

@ -504,6 +504,7 @@ class e_pref extends e_front_model
}
$admin_log = e107::getAdminLog();
$disallow_logs = $this->getParam('nologs', false);
//Save to DB
if(!$this->hasError())
@ -534,7 +535,7 @@ class e_pref extends e_front_model
}
// auto admin log
if(is_array($old)) // fix install problems - no old prefs available
if(is_array($old) && !$disallow_logs) // fix install problems - no old prefs available
{
$new = $this->getPref();
$admin_log->logArrayDiffs($new, $old, 'PREFS_02', false);
@ -542,13 +543,13 @@ class e_pref extends e_front_model
}
if(e107::getDb()->db_Select_gen("REPLACE INTO `#core` (e107_name,e107_value) values ('".$this->prefid."_Backup', '".addslashes($dbdata)."') "))
{
$admin_log->logMessage('Backup of <strong>'.$this->alias.' ('.$this->prefid.')</strong> successfully created.', E_MESSAGE_DEBUG, E_MESSAGE_SUCCESS, $session_messages);
if(!$disallow_logs) $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');
}
}
$this->setPrefCache($this->toString(false), true); //reset pref cache - runtime & file
$admin_log->logSuccess('Settings successfully saved.', true, $session_messages)->flushMessages('PREFS_01');
if(!$disallow_logs) $admin_log->logSuccess('Settings successfully saved.', true, $session_messages)->flushMessages('PREFS_01');
//BC
if($this->alias === 'core')
{
@ -558,7 +559,8 @@ class e_pref extends e_front_model
}
elseif(e107::getDb()->getLastErrorNumber())
{
$admin_log->logError('mySQL error #'.e107::getDb()->getLastErrorNumber().': '.e107::getDb()->getLastErrorText(), true, $session_messages)
if(!$disallow_logs)
$admin_log->logError('mySQL error #'.e107::getDb()->getLastErrorNumber().': '.e107::getDb()->getLastErrorText(), true, $session_messages)
->logError('Settings not saved.', true, $session_messages)
->flushMessages('PREFS_03');
return false;
@ -569,14 +571,15 @@ class e_pref extends e_front_model
{
//add errors to the eMessage stack
//$this->setErrors(true, $session_messages); old - doesn't needed anymore
$admin_log->logError('Settings not saved.', true, $session_messages)
if(!$disallow_logs)
$admin_log->logError('Settings not saved.', true, $session_messages)
->flushMessages('LAN_FIXME');
return false;
}
else
{
e107::getMessage()->add('Settings not saved as no changes were made.', E_MESSAGE_INFO, $session_messages);
$admin_log->flushMessages('LAN_FIXME');
if(!$disallow_logs) $admin_log->flushMessages('LAN_FIXME');
return 0;
}
}

View File

@ -2,16 +2,14 @@
/*
* e107 website system
*
* Copyright (C) 2008-2009 e107 Inc (e107.org)
* Copyright (C) 2008-2010 e107 Inc (e107.org)
* Released under the terms and conditions of the
* GNU General Public License (http://www.gnu.org/licenses/gpl.txt)
*
* Simple XML Parser
*
* $Source: /cvs_backup/e107_0.8/e107_handlers/xml_class.php,v $
* $Revision$
* $Date$
* $Author$
* $URL $
* $Id$
*/
if (!defined('e107_INIT')) { exit; }
@ -828,10 +826,11 @@ class xmlClass
*
* @param path $file - e107 XML file path
* @param string $mode[optional] - add|replace
* @param boolean $noLogs [optional] tells pref handler to disable admin logs when true (install issues)
* @param boolean $debug [optional]
* @return array with keys 'success' and 'failed' - DB table entry status.
*/
public function e107Import($file,$mode='replace',$debug=FALSE)
public function e107Import($file, $mode='replace', $noLogs = false, $debug=FALSE)
{
$xmlArray = $this->loadXMLfile($file, 'advanced');
@ -850,27 +849,29 @@ class xmlClass
foreach($xmlArray['prefs'] as $type=>$array)
{
$pArray = $this->e107ImportPrefs($xmlArray,$type);
if($mode == 'replace')
{
e107::getConfig($type)->setPref($pArray);
}
else // 'add'
{
foreach ($pArray as $pname => $pval)
foreach ($pArray as $pname => $pval)
{
e107::getConfig($type)->add($pname, $pval); // don't parse x/y/z
}
// e107::getConfig($type)->addPref($pArray);
// e107::getConfig($type)->addPref($pArray);
}
if($debug == FALSE)
{
e107::getConfig($type)->save(FALSE,TRUE);
e107::getConfig($type)
->setParam('nologs', $noLogs)
->save(FALSE,TRUE);
}
}
}
if(vartrue($xmlArray['database']))
{
foreach($xmlArray['database']['dbTable'] as $val)

View File

@ -204,6 +204,11 @@ class e_install
// public function __construct()
function e_install()
{
// notice removal, required from various core routines
define('USERID', 1);
define('USER', true);
define('ADMIN', true);
$this->logFile = '';
if (MAKE_INSTALL_LOG)
{
@ -791,6 +796,10 @@ class e_install
return $this->stage_5();
}
// required for various core routines
define('USERNAME', $this->previous_steps['admin']['user']);
define('USEREMAIL', $this->previous_steps['admin']['email']);
// ------------- Step 6 Form --------------------------------
@ -873,6 +882,10 @@ class e_install
$this->stage = 7;
$this->logLine('Stage 7 started');
// required for various core routines
define('USERNAME', $this->previous_steps['admin']['user']);
define('USEREMAIL', $this->previous_steps['admin']['email']);
if(varset($_POST['sitename']))
{
$this->previous_steps['prefs']['sitename'] = $_POST['sitename'];
@ -940,6 +953,11 @@ class e_install
{
global $e_forms;
// required for various core routines
define('USERNAME', $this->previous_steps['admin']['user']);
define('USEREMAIL', $this->previous_steps['admin']['email']);
$this->stage = 8;
$this->logLine('Stage 8 started');
@ -1029,6 +1047,7 @@ class e_install
{
$this->logLine('Starting configuration import');
// Basic stuff to get the handlers/classes to work.
@ -1066,7 +1085,6 @@ class e_install
$tp = e107::getParser();
define('PREVIEWTHEMENAME',""); // Notice Removal.
define('USERID', 1); // notice removal, required from media import routine
include_lan($this->e107->e107_dirs['LANGUAGES_DIRECTORY'].$this->previous_steps['language']."/lan_prefs.php");
include_lan($this->e107->e107_dirs['LANGUAGES_DIRECTORY'].$this->previous_steps['language']."/admin/lan_theme.php");
@ -1077,10 +1095,10 @@ class e_install
$this->logLine('Plugins table updated');
//should be 'add' not 'replace' - but 'add' doesn't insert arrays correctly.
// [SecretR] should work now
e107::getXml()->e107Import($XMLImportfile, 'add'); // Add missing core pref values
// [SecretR] should work now - fixed log errors (argument noLogs = true) change to false to enable log
e107::getXml()->e107Import($XMLImportfile, 'add', true); // Add missing core pref values
$this->logLine('Core prefs written');
// Install Theme-required plugins
if(vartrue($this->previous_steps['install_plugins']))
{
@ -1096,7 +1114,7 @@ class e_install
}
}
}
// Media import
e107::getMedia()->import('news',e_IMAGE.'newspost_images/') //TODO remove when news are pluginized
->import('page',e_IMAGE.'custom/') //TODO remove when pages are pluginized
@ -1105,14 +1123,16 @@ class e_install
->importIcons(e_THEME.$this->previous_steps['prefs']['sitetheme']."/images/")
->importIcons(e_THEME.$this->previous_steps['prefs']['sitetheme']."/icons/");
$this->logLine('Media imported to media manager');
e107::getSingleton('e107plugin')->save_addon_prefs(); // save plugin addon pref-lists. eg. e_latest_list.
$this->logLine('Addon prefs saved');
$tm = e107::getSingleton('themeHandler');
$tm->noLog = TRUE;
$tm->noLog = true; // false to enable log
$tm->setTheme($this->previous_steps['prefs']['sitetheme']);
// Admin log fix - don't allow logs to be called inside pref handler
e107::getConfig('core')->setParam('nologs', false); // change to true to enable log
$pref = e107::getConfig('core')->getPref();
// Set Preferences defined during install - overwriting those that may exist in the XML.