[Piwik-svn] r492 - in trunk: . modules modules/Log modules/LogStats modules/LogStats/Generator

svnmaster at piwik.org svnmaster at piwik.org
Fri May 23 03:08:12 CEST 2008


Author: matt
Date: 2008-05-23 03:08:12 +0200 (Fri, 23 May 2008)
New Revision: 492

Modified:
   trunk/modules/Log/Message.php
   trunk/modules/LogStats.php
   trunk/modules/LogStats/Db.php
   trunk/modules/LogStats/Generator.php
   trunk/modules/LogStats/Generator/LogStats.php
   trunk/piwik.php
Log:
- fixing notice in Log message
- db object is now static in LogStats, boosting performance of the visits generator tool

Modified: trunk/modules/Log/Message.php
===================================================================
--- trunk/modules/Log/Message.php	2008-05-23 01:05:47 UTC (rev 491)
+++ trunk/modules/Log/Message.php	2008-05-23 01:08:12 UTC (rev 492)
@@ -51,7 +51,7 @@
  * @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.

Modified: trunk/modules/LogStats/Db.php
===================================================================
--- trunk/modules/LogStats/Db.php	2008-05-23 01:05:47 UTC (rev 491)
+++ trunk/modules/LogStats/Db.php	2008-05-23 01:08:12 UTC (rev 492)
@@ -80,9 +80,9 @@
 		{
 			$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 = '';
 		

Modified: trunk/modules/LogStats/Generator/LogStats.php
===================================================================
--- trunk/modules/LogStats/Generator/LogStats.php	2008-05-23 01:05:47 UTC (rev 491)
+++ trunk/modules/LogStats/Generator/LogStats.php	2008-05-23 01:08:12 UTC (rev 492)
@@ -38,7 +38,7 @@
 	 */
 	protected function endProcess()
 	{
-		$this->disconnectDb();
+		self::disconnectDb();
 	}
 	
 	/**
@@ -48,6 +48,11 @@
 	 */
 	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

Modified: trunk/modules/LogStats/Generator.php
===================================================================
--- trunk/modules/LogStats/Generator.php	2008-05-23 01:05:47 UTC (rev 491)
+++ trunk/modules/LogStats/Generator.php	2008-05-23 01:08:12 UTC (rev 492)
@@ -229,6 +229,7 @@
 	 */
 	public function end()
 	{
+		Piwik_LogStats::disconnectDb();
 		if($this->profiling)
 		{
 			Piwik::printSqlProfilingReportLogStats();

Modified: trunk/modules/LogStats.php
===================================================================
--- trunk/modules/LogStats.php	2008-05-23 01:05:47 UTC (rev 491)
+++ trunk/modules/LogStats.php	2008-05-23 01:08:12 UTC (rev 492)
@@ -54,7 +54,7 @@
 	 *
 	 * @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 @@
 	}
 	
 	// 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 @@
 	 */
 	protected function getNewVisitObject()
 	{
-		return new Piwik_LogStats_Visit($this->db);
+		return new Piwik_LogStats_Visit(self::$db);
 	}
 	
 	// main algorithm 
@@ -185,7 +198,7 @@
 		if( $this->processVisit() )
 		{
 			try {
-				$this->connectDatabase();
+				self::connectDatabase();
 				$visit = $this->getNewVisitObject();
 				$visit->handle();
 			} catch (PDOException $e) {
@@ -229,20 +242,12 @@
 		
 		if($GLOBALS['DEBUGPIWIK'] === true)
 		{
-			Piwik::printSqlProfilingReportLogStats($this->db);
+			Piwik::printSqlProfilingReportLogStats(self::$db);
 		}
 		
-		$this->disconnectDb();
+		self::disconnectDb();
 	}
 	
-	protected function disconnectDb() 
-	{
-		if(isset($this->db))
-		{
-			$this->db->disconnect();
-		}
-	}
-	
 	protected function outputTransparentGif()
 	{
 		if( !isset($GLOBALS['DEBUGPIWIK']) || !$GLOBALS['DEBUGPIWIK'] ) 

Modified: trunk/piwik.php
===================================================================
--- trunk/piwik.php	2008-05-23 01:05:47 UTC (rev 491)
+++ trunk/piwik.php	2008-05-23 01:08:12 UTC (rev 492)
@@ -29,7 +29,6 @@
 error_reporting(E_ALL|E_NOTICE);
 define('PIWIK_INCLUDE_PATH', '.');
 @ignore_user_abort(true);
- at set_time_limit(0);
 
 set_include_path(PIWIK_INCLUDE_PATH 
 					. PATH_SEPARATOR . PIWIK_INCLUDE_PATH . '/libs/'



More information about the Piwik-svn mailing list