#8650 Option queryProfiles causes error in db connection
authorFlávio Gomes da Silva Lisboa <flavio.lisboa@serpro.gov.br>
Mon, 22 Jul 2013 11:33:51 +0000 (13:33 +0200)
committerPhilipp Schüle <p.schuele@metaways.de>
Tue, 23 Jul 2013 05:41:43 +0000 (07:41 +0200)
- moved db profiling options to 'profiler' section of config
- added doc for how to activate db profiling

https://forge.tine20.org/mantisbt/view.php?id=8650

Change-Id: I3e314ba8b2e05724e15975429e363e64246fe38e
Reviewed-on: https://gerrit.tine20.org/tine20/2190
Tested-by: jenkins user
Reviewed-by: Flávio Gomes da Silva Lisboa <flavio.lisboa@serpro.gov.br>
Reviewed-by: Philipp Schüle <p.schuele@metaways.de>
tine20/Tinebase/Core.php

index d55199a..c3d9725 100644 (file)
@@ -991,32 +991,49 @@ class Tinebase_Core
 
     /**
      * get db profiling
+     * 
+     * Enable db profiling like this (in config.inc.php):
+     * 
+     *   'database' => 
+     *      array(
+     *         [...] // db connection params  
+     *         'profiler' => TRUE
+     *      ),
+     *   'profiler' =>
+     *      array(
+     *         'queryProfiles' => TRUE,
+     *         'queryProfilesDetails' => TRUE,
+     *         //'profilerFilterElapsedSecs' => 1,
+     *      )
+     *    ),
+     * 
      */
     public static function getDbProfiling()
     {
-        if (! self::getConfig() || ! self::getConfig()->database) {
+        if (! self::getConfig() || ! self::getConfig()->database || ! (bool) self::getConfig()->database->profiler) {
             return;
         }
         
-        $config = self::getConfig()->database;
+        $config = self::getConfig()->profiler;
 
-        if ((bool) $config->profiler) {
-            $profiler = Zend_Db_Table::getDefaultAdapter()->getProfiler();
+        $profiler = Zend_Db_Table::getDefaultAdapter()->getProfiler();
 
-            if (! empty($config->profilerFilterElapsedSecs)) {
-                $profiler->setFilterElapsedSecs($config->profilerFilterElapsedSecs);
-            }
+        if (! empty($config->profilerFilterElapsedSecs)) {
+            $profiler->setFilterElapsedSecs($config->profilerFilterElapsedSecs);
+        }
 
-            $data = array(
-                'totalNumQueries' => $profiler->getTotalNumQueries(),
-                'totalElapsedSec' => $profiler->getTotalElapsedSecs(),
-                'longestTime'        => 0,
-                'longestQuery'       => ''
-            );
+        $data = array(
+            'totalNumQueries' => $profiler->getTotalNumQueries(),
+            'totalElapsedSec' => $profiler->getTotalElapsedSecs(),
+            'longestTime'        => 0,
+            'longestQuery'       => ''
+        );
 
-            if ((bool) $config->queryProfiles) {
+        if ($config && (bool) $config->queryProfiles) {
+            $queryProfiles = $profiler->getQueryProfiles();
+            if (is_array($queryProfiles)) {
                 $data['queryProfiles'] = array();
-                foreach($profiler->getQueryProfiles() as $profile) {
+                foreach ($queryProfiles as $profile) {
                     if ((bool) $config->queryProfilesDetails) {
                         $data['queryProfiles'][] = array(
                             'query'       => $profile->getQuery(),
@@ -1030,9 +1047,9 @@ class Tinebase_Core
                     }
                 }
             }
-
-            self::getLogger()->debug(__METHOD__ . ' (' . __LINE__ . ') value: ' . print_r($data, true));
         }
+
+        self::getLogger()->debug(__METHOD__ . ' (' . __LINE__ . ') value: ' . print_r($data, true));
     }
 
     /**