From 31a22ac19a6cac0388d52dad4c745a4e9839bdfb Mon Sep 17 00:00:00 2001 From: nbm Date: Wed, 5 Jan 2005 08:56:10 +0000 Subject: [PATCH] Handle startup errors slightly better - at least show them and stop trying to continue on regardless. --- config/dmsDefaults.php | 23 +++++++++++++++++++++-- lib/Log.inc | 16 +++++++++++----- 2 files changed, 32 insertions(+), 7 deletions(-) diff --git a/config/dmsDefaults.php b/config/dmsDefaults.php index 9af0718..70f83a7 100644 --- a/config/dmsDefaults.php +++ b/config/dmsDefaults.php @@ -62,7 +62,14 @@ class KTInit { global $default; require_once("$default->fileSystemRoot/lib/Log.inc"); $default->log = new Log($default->fileSystemRoot . "/log", $default->logLevel); + $res = $default->log->initialiseLogFile(); + KTInit::handleInitError($res); + $default->queryLog = new Log($default->fileSystemRoot . "/log", $default->logLevel, "query"); + $res = $default->queryLog->initialiseLogFile(); + KTInit::handleInitError($res); $default->timerLog = new Log($default->fileSystemRoot . "/log", $default->logLevel, "timer"); + $res = $default->timerLog->initialiseLogFile(); + KTInit::handleInitError($res); } // }}} @@ -97,8 +104,8 @@ class KTInit { } // }}} - // {{{ setupDb() - function setupDb () { + // {{{ setupDB() + function setupDB () { global $default; require_once("DB.php"); @@ -118,6 +125,10 @@ class KTInit { ); $default->_db = &DB::connect($dsn, $options); + if (PEAR::isError($default->_db)) { + KTInit::handleInitError($default->_db); + // never returns + } $default->_db->setFetchMode(DB_FETCHMODE_ASSOC); // DBCompat allows phplib API compatibility @@ -160,6 +171,7 @@ class KTInit { KTInit::cleanMagicQuotesItem($var[$key]); } } else { + // XXX: Make it look pretty $var = stripslashes($var); } } @@ -181,6 +193,13 @@ class KTInit { mt_srand(hexdec(substr(md5(microtime()), -8)) & 0x7fffffff); } // }}} + + // {{{ handleInitError() + function handleInitError($oError) { + // XXX: Make it look pretty + die($oError->toString()); + } + // }}} } // }}} diff --git a/lib/Log.inc b/lib/Log.inc index 3276d23..6fc7d27 100644 --- a/lib/Log.inc +++ b/lib/Log.inc @@ -56,22 +56,28 @@ class Log { function Log($logDirectory, $logLevel = INFO, $sLogFilePrefix = "log") { $this->logDirectory = $logDirectory; $this->minimumLoggingLevel = $logLevel; - $this->initialiseLogFile($sLogFilePrefix); + $this->sLogFilePrefix = $sLogFilePrefix; } /** * Creates the log file from the current datetime */ - function initialiseLogFile($sLogFilePrefix) { + function initialiseLogFile() { global $default; if (!file_exists($this->logDirectory)) { - mkdir($this->logDirectory, 0755); + $res = @mkdir($this->logDirectory, 0755); + if ($res === false) { + return new PEAR_Error('Failed to create log directory (check permissions)'); + } } - $this->logFile = $this->logDirectory . "/$sLogFilePrefix-" . date("Y-m-d") . ".txt"; + $this->logFile = $this->logDirectory . "/" . $this->sLogFilePrefix . "-" . date("Y-m-d") . ".txt"; if (!file_exists($this->logFile)) { - touch($this->logFile); + $res = @touch($this->logFile); + if ($res === false) { + return new PEAR_Error('Failed to create log file (check permissions)'); + } } } -- libgit2 0.21.4