Skip to content
Extraits de code Groupes Projets
Valider c6ee29c8 rédigé par BeezyT's avatar BeezyT
Parcourir les fichiers

refs #3332: Preparations for Transitions

 * advanced period factory
 * fake archive processing for live querying

git-svn-id: http://dev.piwik.org/svn/trunk@6811 59fd770c-687e-43c8-a1e3-f5a4ff64c105
parent 313e1b1e
Aucune branche associée trouvée
Aucune étiquette associée trouvée
Aucune requête de fusion associée trouvée
...@@ -322,22 +322,47 @@ abstract class Piwik_ArchiveProcessing ...@@ -322,22 +322,47 @@ abstract class Piwik_ArchiveProcessing
$this->idsite = $this->site->getId(); $this->idsite = $this->site->getId();
$this->periodId = $this->period->getId(); $this->periodId = $this->period->getId();
$dateStartLocalTimezone = $this->period->getDateStart(); $this->initDates();
$dateEndLocalTimezone = $this->period->getDateEnd();
$this->tableArchiveNumeric = self::makeNumericArchiveTable($this->period); $this->tableArchiveNumeric = self::makeNumericArchiveTable($this->period);
$this->tableArchiveBlob = self::makeBlobArchiveTable($this->period); $this->tableArchiveBlob = self::makeBlobArchiveTable($this->period);
$this->minDatetimeArchiveProcessedUTC = $this->getMinTimeArchivedProcessed();
$db = Zend_Registry::get('db');
$this->compressBlob = $db->hasBlobDataType();
}
/**
* The archive processing classes have features that might be useful for live querying;
* In particular, Piwik_ArchiveProcessing_Day::query*. In order to reuse those methods
* outside the actual archiving or to reuse archiving code for live querying, an instance
* of archive processing has to be faked.
*
* For example, this code can be used in an API method:
* $archiveProcessing = new Piwik_ArchiveProcessing_Day();
* $archiveProcessing->setSite(new Piwik_Site($idSite));
* $archiveProcessing->setPeriod(Piwik_Period::advancedFactory($period, $date));
* $archiveProcessing->setSegment(new Piwik_Segment($segment, $idSite));
* $archiveProcessing->initForLiveUsage();
* Then, either use $archiveProcessing->query* or pass the instance to the archiving
* code of the plugin. Note that even though we use Piwik_ArchiveProcessing_Day, this
* works for any $period and $date that has been passed to the API.
*/
public function initForLiveUsage() {
$this->idsite = $this->site->getId();
$this->initDates();
}
private function initDates() {
$dateStartLocalTimezone = $this->period->getDateStart();
$dateEndLocalTimezone = $this->period->getDateEnd();
$dateStartUTC = $dateStartLocalTimezone->setTimezone($this->site->getTimezone()); $dateStartUTC = $dateStartLocalTimezone->setTimezone($this->site->getTimezone());
$dateEndUTC = $dateEndLocalTimezone->setTimezone($this->site->getTimezone()); $dateEndUTC = $dateEndLocalTimezone->setTimezone($this->site->getTimezone());
$this->startDatetimeUTC = $dateStartUTC->getDateStartUTC(); $this->startDatetimeUTC = $dateStartUTC->getDateStartUTC();
$this->endDatetimeUTC = $dateEndUTC->getDateEndUTC(); $this->endDatetimeUTC = $dateEndUTC->getDateEndUTC();
$this->startTimestampUTC = $dateStartUTC->getTimestamp(); $this->startTimestampUTC = $dateStartUTC->getTimestamp();
$this->endTimestampUTC = strtotime($this->endDatetimeUTC); $this->endTimestampUTC = strtotime($this->endDatetimeUTC);
$this->minDatetimeArchiveProcessedUTC = $this->getMinTimeArchivedProcessed();
$db = Zend_Registry::get('db');
$this->compressBlob = $db->hasBlobDataType();
} }
/** /**
......
...@@ -72,6 +72,25 @@ abstract class Piwik_Period ...@@ -72,6 +72,25 @@ abstract class Piwik_Period
break; break;
} }
} }
/**
* The advanced factory method is easier to use from the API than the factory
* method above. It doesn't require an instance of Piwik_Date and works for
* period=range. Generally speaking, anything that can be passed as period
* and range to the API methods can directly be forwarded to this factory
* method in order to get a suitable instance of Piwik_Period.
*
* @param string $strPeriod "day", "week", "month", "year", "range"
* @param string $strDate
* @return Piwik_Period
*/
static public function advancedFactory($strPeriod, $strDate) {
if (Piwik_Archive::isMultiplePeriod($strDate, $strPeriod) || $strPeriod == 'range')
{
return new Piwik_Period_Range($strPeriod, $strDate);
}
return self::factory($strPeriod, Piwik_Date::factory($strDate));
}
/** /**
......
...@@ -716,23 +716,8 @@ class Piwik_API_API ...@@ -716,23 +716,8 @@ class Piwik_API_API
} }
$website = new Piwik_Site($idSite); $website = new Piwik_Site($idSite);
// $segment = new Piwik_Segment($segment, $idSite); // $segment = new Piwik_Segment($segment, $idSite);
if(Piwik_Archive::isMultiplePeriod($date, $period)) $period = Piwik_Period::advancedFactory($period, $date);
{
$period = new Piwik_Period_Range($period, $date);
}
else
{
if($period == 'range')
{
$period = new Piwik_Period_Range($period, $date);
}
else
{
$period = Piwik_Period::factory($period, Piwik_Date::factory($date));
}
}
$period = $period->getLocalizedLongString(); $period = $period->getLocalizedLongString();
$return = array( $return = array(
......
0% Chargement en cours ou .
You are about to add 0 people to the discussion. Proceed with caution.
Terminez d'abord l'édition de ce message.
Veuillez vous inscrire ou vous pour commenter