[Piwik-svn] r478 - in trunk: config modules modules/Archive

svnmaster at piwik.org svnmaster at piwik.org
Sun May 11 22:43:45 CEST 2008


Author: matt
Date: 2008-05-11 22:43:44 +0200 (Sun, 11 May 2008)
New Revision: 478

Modified:
   trunk/config/global.ini.php
   trunk/modules/Archive/Single.php
   trunk/modules/ArchiveProcessing.php
Log:
- new feature: you can now disable the automatic archiving triggering from the piwik UI. Useful when launching the archiving from the cron overnight.

Modified: trunk/config/global.ini.php
===================================================================
--- trunk/config/global.ini.php	2008-05-11 19:16:31 UTC (rev 477)
+++ trunk/config/global.ini.php	2008-05-11 20:43:44 UTC (rev 478)
@@ -75,6 +75,12 @@
 ; Possible values: yesterday, today, or any YYYY-MM-DD
 default_day = yesterday
 
+; When loading the piwik interface in the browser (as opposed to from the PHP-CLI client)
+; should we launch the archiving process if the archives have not yet been processed?
+; You want to set it to false when triggering the archiving through a crontab, 
+; so that your users do not trigger archiving in their browser when this is not expected
+enable_browser_archiving_triggering = true
+
 ; character used to automatically create categories in the "Action" "Downloads" reports
 ; for example a URL like "example.com/blog/development/first-post" will create 
 ; the page first-post in the subcategory development which belongs to the blog category
@@ -134,61 +140,38 @@
 
 [log]
 
+;possible values for log: screen, database, file
 ; normal messages
 logger_message[]		= screen
-;logger_message[]		= database
-;logger_message[]		= file
+logger_error[]			= screen
+logger_exception[]		= screen
 
 ; all calls to the API (method name, parameters, execution time, caller IP, etc.)
-;logger_api_call[]		= screen
-;logger_api_call[]		= database
 ;logger_api_call[]		= file
 
-; error intercepted
-logger_error[]			= screen
-;logger_error[]			= database
-;logger_error[]			= file
-
-; exception raised
-logger_exception[]		= screen
-;logger_exception[]		= database
-;logger_exception[]		= file
-
-; query profiling information (SQL, avg execution time, etc.)
-logger_query_profile[]	= screen
-;logger_query_profile[]	= database
-;logger_query_profile[]	= file
-
 [log_tests]
 logger_message[]		= screen
 logger_api_call[]		= screen
 logger_error[]			= screen
 logger_exception[]		= screen
-logger_query_profile[]	= screen
 
-
 [path]
 log				= tmp/logs/
 
-
 [smarty]
 ; the list of directories in which to look for templates
 template_dir[]	= plugins
 template_dir[]	= themes/default
 template_dir[]	= themes
 
-; smarty provided plugins
 plugins_dir[] 	= libs/Smarty/plugins
-; smarty plugins provided by piwik 
 plugins_dir[]	= modules/SmartyPlugins
 
-; where to store the compiled smarty templates
 compile_dir		= tmp/templates_c
-
 cache_dir		= tmp/cache
 
 ; error reporting inside Smarty
 error_reporting = E_ALL|E_NOTICE
 
-; should be set to false in a piwik release
+; allow smarty debugging using {debug}
 debugging		= true

Modified: trunk/modules/Archive/Single.php
===================================================================
--- trunk/modules/Archive/Single.php	2008-05-11 19:16:31 UTC (rev 477)
+++ trunk/modules/Archive/Single.php	2008-05-11 20:43:44 UTC (rev 478)
@@ -90,6 +90,10 @@
 	 */
 	public function getIdArchive()
 	{
+		if(is_null($this->idArchive))
+		{
+			throw new Exception("idArchive is null");
+		}
 		return $this->idArchive;
 	}
 	
@@ -131,21 +135,20 @@
 	{
 		if(!$this->alreadyChecked)
 		{
+			$this->isThereSomeVisits = false;
+			$this->alreadyChecked = true;
+			
 			// if the END of the period is BEFORE the website creation date
 			// we already know there are no stats for this period
 			// we add one day to make sure we don't miss the day of the website creation
 			if( $this->period->getDateEnd()->addDay(2)->isEarlier( $this->site->getCreationDate() ) )
 			{
-				$this->isThereSomeVisits = false;
-				$this->alreadyChecked = true;
 				return;				
 			}
 			
 			// if the starting date is in the future we know there is no visit
 			if( $this->period->getDateStart()->subDay(1)->isLater( Piwik_Date::today() ) )
 			{
-				$this->isThereSomeVisits = false;
-				$this->alreadyChecked = true;
 				return;
 			}
 			
@@ -155,12 +158,12 @@
 			$archiveProcessing->setSite($this->site);
 			$archiveProcessing->setPeriod($this->period);
 			
-			$IdArchive = $archiveProcessing->loadArchive();
+			$idArchive = $archiveProcessing->loadArchive();
 			$this->isThereSomeVisits = $archiveProcessing->isThereSomeVisits;
 			
 			$this->archiveProcessing = $archiveProcessing; 
 
-			$this->idArchive = $IdArchive;
+			$this->idArchive = $idArchive;
 			$this->alreadyChecked = true;
 		}
 	}
@@ -316,8 +319,6 @@
 	 */
 	public function preFetchBlob( $name )
 	{
-//		Piwik::log("-- prefetch blob ".$name."_*");
-		
 		if(!$this->isThereSomeVisits)
 		{
 			return false;

Modified: trunk/modules/ArchiveProcessing.php
===================================================================
--- trunk/modules/ArchiveProcessing.php	2008-05-11 19:16:31 UTC (rev 477)
+++ trunk/modules/ArchiveProcessing.php	2008-05-11 20:43:44 UTC (rev 478)
@@ -275,17 +275,16 @@
 	{
 		$this->loadArchiveProperties();
 		$this->idArchive = $this->isArchived();
-		
-		if($this->idArchive === false
-			|| $this->debugAlwaysArchive)
+	
+		if($this->isArchivingDisabled())
 		{
-			$this->archivesSubperiods = $this->loadSubperiodsArchive();
-			$this->initCompute();
-			$this->compute();
-			$this->postCompute();
-			// we execute again the isArchived that does some initialization work
-			$this->idArchive = $this->isArchived();
+			$this->isThereSomeVisits = false;
 		}
+		elseif($this->idArchive === false
+				||	$this->debugAlwaysArchive)
+		{
+			$this->launchArchiving();
+		}
 		else
 		{
 			$this->isThereSomeVisits = true;
@@ -295,6 +294,20 @@
 	}
 	
 	/**
+	 * @see loadArchive()
+	 *
+	 */
+	protected function launchArchiving()
+	{
+		$this->archivesSubperiods = $this->loadSubperiodsArchive();
+		$this->initCompute();
+		$this->compute();
+		$this->postCompute();
+		// we execute again the isArchived that does some initialization work
+		$this->idArchive = $this->isArchived();
+	}
+	
+	/**
 	 * This methods reads the subperiods if necessary, 
 	 * and computes the archive of the current period.
 	 */
@@ -525,46 +538,66 @@
 		
 		$results = Zend_Registry::get('db')->fetchAll($sqlQuery, $bindSQL );
 		// the archive exists in the table
-		if(!empty($results))
+		if(empty($results))
 		{
-//			echo $this->strDateStart . " " . $this->strDateEnd;
-//			var_dump($results);
-			
-			$idarchive = false;
-			// let's look for the more recent idarchive
-			foreach($results as $result)
+			return false;
+		}
+		
+		$idarchive = false;
+		// let's look for the more recent idarchive
+		foreach($results as $result)
+		{
+			if($result['name'] == 'done')
 			{
-				if($result['name'] == 'done')
-				{
-					$idarchive = $result['idarchive'];
-					$this->timestampDateStart = $result['timestamp'];
-					break;
-				}
+				$idarchive = $result['idarchive'];
+				$this->timestampDateStart = $result['timestamp'];
+				break;
 			}
-			
-			if($idarchive === false)
+		}
+		
+		if($idarchive === false)
+		{
+			throw new Exception("Error during the archiving process: ". var_export($results,true));
+		}
+		
+		// let's look for the nb_visits result for this more recent archive
+		foreach($results as $result)
+		{
+			if($result['name'] == 'nb_visits' 
+				&& $result['idarchive'] == $idarchive)
 			{
-				throw new Exception("Error during the archiving process: ". var_export($results,true));
+				$this->isThereSomeVisits = ($result['value'] != 0);
+				break;
 			}
+		}
+		return $idarchive;
+	}
+	
+	/**
+	 * Returns true if, for various reasons, archiving is disabled.
+	 *
+	 * @return bool
+	 */
+	protected function isArchivingDisabled()
+	{
+		static $archivingIsDisabled = null;
+		
+		if(is_null($archivingIsDisabled))
+		{
+			$archivingIsDisabled = false;
 			
-			// let's look for the nb_visits result for this more recent archive
-			foreach($results as $result)
+			$enableBrowserArchivingTriggering = (bool)Zend_Registry::get('config')->General->enable_browser_archiving_triggering;
+			if($enableBrowserArchivingTriggering == false)
 			{
-				if($result['name'] == 'nb_visits' 
-					&& $result['idarchive'] == $idarchive)
+				$sapi_type = php_sapi_name();
+				if( !in_array(substr($sapi_type, 0, 3), array('cgi', 'cli')))
 				{
-					$this->isThereSomeVisits = ($result['value'] != 0);
-					break;
+					$archivingIsDisabled = true;
 				}
 			}
-			return $idarchive;
 		}
-		else
-		{
-//			echo "no archive for ".$this->strDateStart . " " . $this->strDateEnd; exit;
-			return false;
-		}
+		
+		return $archivingIsDisabled;
 	}
-	
 }
 



More information about the Piwik-svn mailing list