diff options
author | mattpiwik <matthieu.aubry@gmail.com> | 2008-05-23 05:08:12 +0400 |
---|---|---|
committer | mattpiwik <matthieu.aubry@gmail.com> | 2008-05-23 05:08:12 +0400 |
commit | 3ee758618315c185aae84bbd71ca358b0c6023dd (patch) | |
tree | f37de2de376090fc4f44b524c7a5fba17b10e256 | |
parent | bf196060692597ca9658758d68109afd4382c672 (diff) |
- fixing notice in Log message
- db object is now static in LogStats, boosting performance of the visits generator tool
git-svn-id: http://dev.piwik.org/svn/trunk@492 59fd770c-687e-43c8-a1e3-f5a4ff64c105
-rw-r--r-- | modules/Log/Message.php | 2 | ||||
-rw-r--r-- | modules/LogStats.php | 37 | ||||
-rw-r--r-- | modules/LogStats/Db.php | 6 | ||||
-rw-r--r-- | modules/LogStats/Generator.php | 1 | ||||
-rw-r--r-- | modules/LogStats/Generator/LogStats.php | 9 | ||||
-rw-r--r-- | piwik.php | 1 |
6 files changed, 33 insertions, 23 deletions
diff --git a/modules/Log/Message.php b/modules/Log/Message.php index 847b11ad54..62d6fa4b1a 100644 --- a/modules/Log/Message.php +++ b/modules/Log/Message.php @@ -51,7 +51,7 @@ class Piwik_Log_Message extends Piwik_Log * @package Piwik_Log * @subpackage Piwik_Log_Message */ -class Piwik_Log_Formatter_Message_ScreenFormatter implements Zend_Log_Formatter_Interface +class Piwik_Log_Formatter_Message_ScreenFormatter extends Piwik_Log_Formatter_ScreenFormatter { /** * Formats data into a single line to be written by the writer. diff --git a/modules/LogStats.php b/modules/LogStats.php index b16b9d6b07..c121fea3ef 100644 --- a/modules/LogStats.php +++ b/modules/LogStats.php @@ -54,7 +54,7 @@ class Piwik_LogStats * * @var Piwik_LogStats_Db */ - protected $db = null; + static protected $db = null; const STATE_NOTHING_TO_NOTICE = 1; const STATE_TO_REDIRECT_URL = 2; @@ -75,22 +75,35 @@ class Piwik_LogStats } // create the database object - function connectDatabase() + static function connectDatabase() { + if( !is_null(self::$db)) + { + return; + } + $configDb = Piwik_LogStats_Config::getInstance()->database; // we decode the password. Password is html encoded because it's enclosed between " double quotes $configDb['password'] = htmlspecialchars_decode($configDb['password']); - $this->db = new Piwik_LogStats_Db( $configDb['host'], + self::$db = new Piwik_LogStats_Db( $configDb['host'], $configDb['username'], $configDb['password'], $configDb['dbname'] ); - $this->db->connect(); + self::$db->connect(); } + static function disconnectDb() + { + if(isset(self::$db)) + { + self::$db->disconnect(); + } + } + private function initProcess() { try{ @@ -172,7 +185,7 @@ class Piwik_LogStats */ protected function getNewVisitObject() { - return new Piwik_LogStats_Visit($this->db); + return new Piwik_LogStats_Visit(self::$db); } // main algorithm @@ -185,7 +198,7 @@ class Piwik_LogStats if( $this->processVisit() ) { try { - $this->connectDatabase(); + self::connectDatabase(); $visit = $this->getNewVisitObject(); $visit->handle(); } catch (PDOException $e) { @@ -229,18 +242,10 @@ class Piwik_LogStats if($GLOBALS['DEBUGPIWIK'] === true) { - Piwik::printSqlProfilingReportLogStats($this->db); + Piwik::printSqlProfilingReportLogStats(self::$db); } - $this->disconnectDb(); - } - - protected function disconnectDb() - { - if(isset($this->db)) - { - $this->db->disconnect(); - } + self::disconnectDb(); } protected function outputTransparentGif() diff --git a/modules/LogStats/Db.php b/modules/LogStats/Db.php index be33107302..c49fcd9151 100644 --- a/modules/LogStats/Db.php +++ b/modules/LogStats/Db.php @@ -80,9 +80,9 @@ class Piwik_LogStats_Db { $timer = $this->initProfiler(); } - $pdoConnect = new PDO($this->dsn, $this->username, $this->password); - $pdoConnect->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION); - $this->connection = $pdoConnect; + + $this->connection = new PDO($this->dsn, $this->username, $this->password); + $this->connection->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION); // we delete the password from this object "just in case" it could be printed $this->password = ''; diff --git a/modules/LogStats/Generator.php b/modules/LogStats/Generator.php index 046b79f6e7..4700c20617 100644 --- a/modules/LogStats/Generator.php +++ b/modules/LogStats/Generator.php @@ -229,6 +229,7 @@ class Piwik_LogStats_Generator */ public function end() { + Piwik_LogStats::disconnectDb(); if($this->profiling) { Piwik::printSqlProfilingReportLogStats(); diff --git a/modules/LogStats/Generator/LogStats.php b/modules/LogStats/Generator/LogStats.php index 2b01f41d44..e4f741ab7e 100644 --- a/modules/LogStats/Generator/LogStats.php +++ b/modules/LogStats/Generator/LogStats.php @@ -38,7 +38,7 @@ class Piwik_LogStats_Generator_LogStats extends Piwik_LogStats */ protected function endProcess() { - $this->disconnectDb(); + self::disconnectDb(); } /** @@ -48,6 +48,11 @@ class Piwik_LogStats_Generator_LogStats extends Piwik_LogStats */ protected function getNewVisitObject() { - return new Piwik_LogStats_Generator_Visit($this->db); + return new Piwik_LogStats_Generator_Visit(self::$db); } + + static function disconnectDb() + { + return; + } }
\ No newline at end of file @@ -29,7 +29,6 @@ error_reporting(E_ALL|E_NOTICE); define('PIWIK_INCLUDE_PATH', '.'); @ignore_user_abort(true); -@set_time_limit(0); set_include_path(PIWIK_INCLUDE_PATH . PATH_SEPARATOR . PIWIK_INCLUDE_PATH . '/libs/' |