Skip to content

Commit

Permalink
Slight backflip, queries are logged by the core but only if there is …
Browse files Browse the repository at this point in the history
…an authenticated user
  • Loading branch information
brendo committed Dec 16, 2011
1 parent 4ac641b commit 87f935d
Show file tree
Hide file tree
Showing 5 changed files with 51 additions and 6 deletions.
21 changes: 20 additions & 1 deletion symphony/lib/core/class.errorhandler.php
Expand Up @@ -223,14 +223,33 @@ public static function render(Exception $e){
=======
>>>>>>> Symphony no longer logs queries in the core, this can be done with an extension. Remove getLastError(), there is no need as DatabaseExceptions contain all necessary information.
<<<<<<< HEAD
return sprintf(file_get_contents(self::getTemplate('fatalerror.generic')),
=======
if(is_object(Symphony::Database())){
$debug = Symphony::Database()->debug();

if(!empty($debug) foreach($debug as $query){
$queries .= sprintf(
'<li%s><code>%s;</code> <small>[%01.4f]</small></li>',
($odd == true ? ' class="odd"' : NULL),
htmlspecialchars($query['query']),
(isset($query['execution_time']) ? $query['execution_time'] : NULL)
);
$odd = !$odd;
}
}

return sprintf(file_get_contents(TEMPLATE . '/fatalerror.generic.tpl'),
>>>>>>> Slight backflip, queries are logged by the core but only if there is an authenticated user
($e instanceof ErrorException ? GenericErrorHandler::$errorTypeStrings[$e->getSeverity()] : 'Fatal Error'),
$e->getMessage(),
$e->getFile(),
$e->getLine(),
$markdown,
$lines,
$trace
$trace,
$queries
);

}
Expand Down
14 changes: 12 additions & 2 deletions symphony/lib/core/class.symphony.php
Expand Up @@ -117,8 +117,7 @@ protected function __construct(){
$this->initialiseExtensionManager();
$this->initialiseCookie();

// If the user is not a logged in Author, turn off the verbose error
// messages.
// If the user is not a logged in Author, turn off the verbose error messages.
if(!self::isLoggedIn() && is_null($this->Author)){
GenericExceptionHandler::$enabled = false;
}
Expand Down Expand Up @@ -788,6 +787,7 @@ public static function render(Exception $e){
if(is_object(Symphony::Database())){
$debug = Symphony::Database()->debug();

<<<<<<< HEAD
if(count($debug['query']) > 0){
foreach($debug['query'] as $query){
$queries .= sprintf(
Expand All @@ -798,6 +798,16 @@ public static function render(Exception $e){
);
$odd = !$odd;
}
=======
if(!empty($debug) foreach($debug as $query){
$queries .= sprintf(
'<li%s><code>%s;</code> <small>[%01.4f]</small></li>',
($odd == true ? ' class="odd"' : NULL),
htmlspecialchars($query['query']),
(isset($query['execution_time']) ? $query['execution_time'] : NULL)
);
$odd = !$odd;
>>>>>>> Slight backflip, queries are logged by the core but only if there is an authenticated user
}
}

Expand Down
16 changes: 13 additions & 3 deletions symphony/lib/toolkit/class.mysql.php
Expand Up @@ -497,7 +497,19 @@ public function query($query, $type = "OBJECT"){
'query_hash' => $query_hash,
'execution_time' => precision_timer('stop', $start)
));

// If the ExceptionHandler is enabled, then the user is authenticated
// or we have a serious issue, so log the query.
if(GenericExceptionHandler::$enabled) {
self::$_log[$query_hash] = array(
'query' => $query,
'query_hash' => $query_hash,
'execution_time' => precision_timer('stop', $start)
);
}
}

// Symphony isn't ready yet. Log internally
else {
self::$_log[$query_hash] = array(
'query' => $query,
Expand Down Expand Up @@ -826,9 +838,7 @@ public function getStatistics() {
$query_timer = 0.0;
$slow_queries = array();

$query_log = $this->debug();

foreach($query_log as $key => $val) {
foreach(self::$_log as $key => $val) {
$query_timer += $val['execution_time'];
if($val['execution_time'] > 0.0999) $slow_queries[] = $val;
}
Expand Down
3 changes: 3 additions & 0 deletions symphony/template/fatalerror.database.tpl
Expand Up @@ -83,6 +83,9 @@
<h3>Backtrace:</h3>
<ul>%s</ul>
<h3>Database Query Log:</h3>
<ul>%s</ul>
</div>
</body>
</html>
3 changes: 3 additions & 0 deletions symphony/template/fatalerror.generic.tpl
Expand Up @@ -98,6 +98,9 @@
<h3>Backtrace:</h3>
<ul>%s</ul>
<h3>Database Query Log:</h3>
<ul>%s</ul>
</div>
</body>
</html>

0 comments on commit 87f935d

Please sign in to comment.