Commit 31a22ac19a6cac0388d52dad4c745a4e9839bdfb
1 parent
1e905c35
Handle startup errors slightly better - at least show them and stop
trying to continue on regardless. git-svn-id: https://kt-dms.svn.sourceforge.net/svnroot/kt-dms/trunk@3107 c91229c3-7414-0410-bfa2-8a42b809f60b
Showing
2 changed files
with
32 additions
and
7 deletions
config/dmsDefaults.php
| @@ -62,7 +62,14 @@ class KTInit { | @@ -62,7 +62,14 @@ class KTInit { | ||
| 62 | global $default; | 62 | global $default; |
| 63 | require_once("$default->fileSystemRoot/lib/Log.inc"); | 63 | require_once("$default->fileSystemRoot/lib/Log.inc"); |
| 64 | $default->log = new Log($default->fileSystemRoot . "/log", $default->logLevel); | 64 | $default->log = new Log($default->fileSystemRoot . "/log", $default->logLevel); |
| 65 | + $res = $default->log->initialiseLogFile(); | ||
| 66 | + KTInit::handleInitError($res); | ||
| 67 | + $default->queryLog = new Log($default->fileSystemRoot . "/log", $default->logLevel, "query"); | ||
| 68 | + $res = $default->queryLog->initialiseLogFile(); | ||
| 69 | + KTInit::handleInitError($res); | ||
| 65 | $default->timerLog = new Log($default->fileSystemRoot . "/log", $default->logLevel, "timer"); | 70 | $default->timerLog = new Log($default->fileSystemRoot . "/log", $default->logLevel, "timer"); |
| 71 | + $res = $default->timerLog->initialiseLogFile(); | ||
| 72 | + KTInit::handleInitError($res); | ||
| 66 | } | 73 | } |
| 67 | // }}} | 74 | // }}} |
| 68 | 75 | ||
| @@ -97,8 +104,8 @@ class KTInit { | @@ -97,8 +104,8 @@ class KTInit { | ||
| 97 | } | 104 | } |
| 98 | // }}} | 105 | // }}} |
| 99 | 106 | ||
| 100 | - // {{{ setupDb() | ||
| 101 | - function setupDb () { | 107 | + // {{{ setupDB() |
| 108 | + function setupDB () { | ||
| 102 | global $default; | 109 | global $default; |
| 103 | 110 | ||
| 104 | require_once("DB.php"); | 111 | require_once("DB.php"); |
| @@ -118,6 +125,10 @@ class KTInit { | @@ -118,6 +125,10 @@ class KTInit { | ||
| 118 | ); | 125 | ); |
| 119 | 126 | ||
| 120 | $default->_db = &DB::connect($dsn, $options); | 127 | $default->_db = &DB::connect($dsn, $options); |
| 128 | + if (PEAR::isError($default->_db)) { | ||
| 129 | + KTInit::handleInitError($default->_db); | ||
| 130 | + // never returns | ||
| 131 | + } | ||
| 121 | $default->_db->setFetchMode(DB_FETCHMODE_ASSOC); | 132 | $default->_db->setFetchMode(DB_FETCHMODE_ASSOC); |
| 122 | 133 | ||
| 123 | // DBCompat allows phplib API compatibility | 134 | // DBCompat allows phplib API compatibility |
| @@ -160,6 +171,7 @@ class KTInit { | @@ -160,6 +171,7 @@ class KTInit { | ||
| 160 | KTInit::cleanMagicQuotesItem($var[$key]); | 171 | KTInit::cleanMagicQuotesItem($var[$key]); |
| 161 | } | 172 | } |
| 162 | } else { | 173 | } else { |
| 174 | + // XXX: Make it look pretty | ||
| 163 | $var = stripslashes($var); | 175 | $var = stripslashes($var); |
| 164 | } | 176 | } |
| 165 | } | 177 | } |
| @@ -181,6 +193,13 @@ class KTInit { | @@ -181,6 +193,13 @@ class KTInit { | ||
| 181 | mt_srand(hexdec(substr(md5(microtime()), -8)) & 0x7fffffff); | 193 | mt_srand(hexdec(substr(md5(microtime()), -8)) & 0x7fffffff); |
| 182 | } | 194 | } |
| 183 | // }}} | 195 | // }}} |
| 196 | + | ||
| 197 | + // {{{ handleInitError() | ||
| 198 | + function handleInitError($oError) { | ||
| 199 | + // XXX: Make it look pretty | ||
| 200 | + die($oError->toString()); | ||
| 201 | + } | ||
| 202 | + // }}} | ||
| 184 | } | 203 | } |
| 185 | // }}} | 204 | // }}} |
| 186 | 205 |
lib/Log.inc
| @@ -56,22 +56,28 @@ class Log { | @@ -56,22 +56,28 @@ class Log { | ||
| 56 | function Log($logDirectory, $logLevel = INFO, $sLogFilePrefix = "log") { | 56 | function Log($logDirectory, $logLevel = INFO, $sLogFilePrefix = "log") { |
| 57 | $this->logDirectory = $logDirectory; | 57 | $this->logDirectory = $logDirectory; |
| 58 | $this->minimumLoggingLevel = $logLevel; | 58 | $this->minimumLoggingLevel = $logLevel; |
| 59 | - $this->initialiseLogFile($sLogFilePrefix); | 59 | + $this->sLogFilePrefix = $sLogFilePrefix; |
| 60 | } | 60 | } |
| 61 | 61 | ||
| 62 | 62 | ||
| 63 | /** | 63 | /** |
| 64 | * Creates the log file from the current datetime | 64 | * Creates the log file from the current datetime |
| 65 | */ | 65 | */ |
| 66 | - function initialiseLogFile($sLogFilePrefix) { | 66 | + function initialiseLogFile() { |
| 67 | global $default; | 67 | global $default; |
| 68 | if (!file_exists($this->logDirectory)) { | 68 | if (!file_exists($this->logDirectory)) { |
| 69 | - mkdir($this->logDirectory, 0755); | 69 | + $res = @mkdir($this->logDirectory, 0755); |
| 70 | + if ($res === false) { | ||
| 71 | + return new PEAR_Error('Failed to create log directory (check permissions)'); | ||
| 72 | + } | ||
| 70 | } | 73 | } |
| 71 | 74 | ||
| 72 | - $this->logFile = $this->logDirectory . "/$sLogFilePrefix-" . date("Y-m-d") . ".txt"; | 75 | + $this->logFile = $this->logDirectory . "/" . $this->sLogFilePrefix . "-" . date("Y-m-d") . ".txt"; |
| 73 | if (!file_exists($this->logFile)) { | 76 | if (!file_exists($this->logFile)) { |
| 74 | - touch($this->logFile); | 77 | + $res = @touch($this->logFile); |
| 78 | + if ($res === false) { | ||
| 79 | + return new PEAR_Error('Failed to create log file (check permissions)'); | ||
| 80 | + } | ||
| 75 | } | 81 | } |
| 76 | } | 82 | } |
| 77 | 83 |