[Piwik-svn] r493 - trunk/modules

svnmaster at piwik.org svnmaster at piwik.org
Thu May 29 03:32:34 CEST 2008


Author: matt
Date: 2008-05-29 03:32:32 +0200 (Thu, 29 May 2008)
New Revision: 493

Modified:
   trunk/modules/ArchiveProcessing.php
Log:
- fixing bug when concurrent archiving, the primary key wasn't always honored and we could end up with 2 archiving having the same idarchive

Modified: trunk/modules/ArchiveProcessing.php
===================================================================
--- trunk/modules/ArchiveProcessing.php	2008-05-23 01:08:12 UTC (rev 492)
+++ trunk/modules/ArchiveProcessing.php	2008-05-29 01:32:32 UTC (rev 493)
@@ -31,7 +31,6 @@
  * 
  * @package Piwik_ArchiveProcessing
  */
-
 abstract class Piwik_ArchiveProcessing
 {
 	/**
@@ -76,6 +75,7 @@
 	 * @var Piwik_Date
 	 */
 	protected $dateStart;
+	
 	/**
 	 * Ending date of the archive
 	 * 
@@ -89,6 +89,7 @@
 	 * @var Piwik_TablePartitioning
 	 */
 	protected $tableArchiveNumeric;
+	
 	/**
 	 * Object used to generate (depending on the $dateStart)  the name of the DB table to use to store numeric values
 	 * 
@@ -127,7 +128,6 @@
 	 */
 	public $site 	= null;
 	
-	
 	/**
 	 * Starting date @see Piwik_Date::toString()
 	 *
@@ -181,7 +181,6 @@
 		$this->debugAlwaysArchive = Zend_Registry::get('config')->Debug->always_archive_data;
 	}
 	
-	
 	/**
 	 * Returns the Piwik_ArchiveProcessing_Day or Piwik_ArchiveProcessing_Period object
 	 * depending on $name period string
@@ -300,8 +299,8 @@
 	 */
 	protected function launchArchiving()
 	{
-		$this->archivesSubperiods = $this->loadSubperiodsArchive();
 		$this->initCompute();
+		$this->archivesSubperiods = $this->loadSubperiodsArchive();
 		$this->compute();
 		$this->postCompute();
 		// we execute again the isArchived that does some initialization work
@@ -324,7 +323,7 @@
 		$this->loadNextIdarchive();
 		
 		$record = new Piwik_ArchiveProcessing_Record_Numeric('done', Piwik_ArchiveProcessing::DONE_ERROR);
-		$this->insertRecord( $record);
+		$this->insertRecord($record);
 		$record->delete();
 		
 		$this->logTable 			= Piwik::prefixTable('log_visit');
@@ -342,8 +341,6 @@
 	 */
 	protected function postCompute()
 	{
-//		echo "<br>".Piwik_ArchiveProcessing_Record_Manager::getInstance()->toString();
-		
 		// delete the first done = ERROR 
 		Zend_Registry::get('db')->query("
 							DELETE FROM ".$this->tableArchiveNumeric->getTableName()." 
@@ -370,8 +367,6 @@
 		
 		// we delete all tables from the table register
 		Piwik_ArchiveProcessing_Record_Manager::getInstance()->deleteAll();
-		
-		
 	} 
 	
 	/**
@@ -394,7 +389,6 @@
 		return $this->tableArchiveBlob->getTableName();
 	}
 	
-	
 	/**
 	 * Set the period
 	 *
@@ -448,9 +442,9 @@
 	}
 	
 	/**
-	 * Inserts a record in the good table (either NUMERIC or BLOB)
+	 * Inserts a record in the right table (either NUMERIC or BLOB)
 	 *
-	 * @param unknown_type $record
+	 * @param Piwik_ArchiveProcessing_Record $record
 	 */
 	protected function insertRecord($record)
 	{
@@ -498,7 +492,6 @@
 			
 			$periods[] = $archivePeriod;
 		}
-		
 		return $periods;
 	}
 	
@@ -515,14 +508,11 @@
 	 */
 	protected function isArchived()
 	{
-//		Piwik::log("Is archive site=$idsite for period = ".$this->period->getLabel()." for date_start = $strDateStart ?");
 		$bindSQL = array(	$this->idsite, 
 								$this->strDateStart, 
 								$this->strDateEnd, 
 								$this->periodId, 
 								);
-//		echo " p = ".$this->periodId." d = ".$this->strDateStart ."," . $this->strDateEnd;		
-		
 		$timeStampWhere = " AND UNIX_TIMESTAMP(ts_archived) >= ? ";
 		$bindSQL[] = $this->maxTimestampArchive;
 			
@@ -538,14 +528,13 @@
 						ORDER BY ts_archived DESC";
 		
 		$results = Zend_Registry::get('db')->fetchAll($sqlQuery, $bindSQL );
-		// the archive exists in the table
 		if(empty($results))
 		{
 			return false;
 		}
 		
 		$idarchive = false;
-		// let's look for the more recent idarchive
+		// we look for the more recent idarchive
 		foreach($results as $result)
 		{
 			if($result['name'] == 'done')
@@ -561,7 +550,7 @@
 			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
+		// we look for the nb_visits result for this more recent archive
 		foreach($results as $result)
 		{
 			if($result['name'] == 'nb_visits' 
@@ -575,7 +564,7 @@
 	}
 	
 	/**
-	 * Returns true if, for various reasons, archiving is disabled.
+	 * Returns true if, for some reasons, triggering the archiving is disabled.
 	 *
 	 * @return bool
 	 */
@@ -600,4 +589,3 @@
 		return $archivingIsDisabled;
 	}
 }
-



More information about the Piwik-svn mailing list