Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/matomo-org/matomo.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authormattab <matthieu.aubry@gmail.com>2013-06-08 07:39:24 +0400
committermattab <matthieu.aubry@gmail.com>2013-06-16 12:10:27 +0400
commit7fdd382b2880f291752e33ec6f6f44a5dbb21dec (patch)
tree6cbc978c8f282e7fe10595c064b44be472336ca0
parentea4498a9ce68d621861fa7d8732e922b838ed12d (diff)
temp
-rw-r--r--core/Archive.php59
-rw-r--r--core/Archive/DataCollection.php5
-rw-r--r--core/Archive/DataTableFactory.php12
-rw-r--r--core/Archive/Parameters.php37
-rw-r--r--core/ArchiveProcessing.php79
-rw-r--r--core/DataAccess/ArchiveQuery.php3
-rw-r--r--core/TablePartitioning.php4
-rwxr-xr-xtests/PHPUnit/Integration/TwoVisitors_TwoWebsites_DifferentDays_ConversionsTest.php36
-rw-r--r--tests/PHPUnit/Integration/expected/test_TwoVisitors_twoWebsites_differentDays_NotLastNPeriods__Goals.get_month.xml14
9 files changed, 119 insertions, 130 deletions
diff --git a/core/Archive.php b/core/Archive.php
index 86d4445194..a242b456da 100644
--- a/core/Archive.php
+++ b/core/Archive.php
@@ -194,7 +194,7 @@ class Piwik_Archive
const LABEL_ECOMMERCE_ORDER = 'ecommerceOrder';
/**
- * List of archive IDs for the sites, periods and segment we are querying with.
+ * List of archive IDs for the site, periods and segment we are querying with.
* Archive IDs are indexed by done flag and period, ie:
*
* array(
@@ -273,38 +273,6 @@ class Piwik_Archive
$this->dataAccess = new Piwik_DataAccess_ArchiveQuery();
}
- /**
- * FIXMEA
- * Returns the IDs of sites we are querying archive data for.
- *
- * @return array
- */
- public function getIdSites()
- {
- return $this->params->getIdSites();
- }
-
- /**
- * FIXMEA
- * Returns the periods we are querying archive data for.
- *
- * @return array
- */
- public function getPeriods()
- {
- return $this->params->getPeriods();
- }
-
- /**
- * FIXMEA
- * Returns the segment used to limit the visit set.
- *
- * @return Piwik_Segment|null
- */
- public function getSegment()
- {
- return $this->params->getSegment();
- }
/**
* Builds an Archive object using query parameter values.
@@ -485,7 +453,7 @@ class Piwik_Archive
*/
public function isArchivingDisabled()
{
- return Piwik_ArchiveProcessing::isArchivingDisabledFor($this->getSegment(), $this->getPeriodLabel());
+ return Piwik_ArchiveProcessing::isArchivingDisabledFor($this->params->getSegment(), $this->getPeriodLabel());
}
/**
@@ -541,7 +509,8 @@ class Piwik_Archive
}
return array_unique($result);
}
-
+
+
/**
* Helper - Loads a DataTable from the Archive.
* Optionally loads the table recursively,
@@ -594,7 +563,7 @@ class Piwik_Archive
}
$result = new Piwik_Archive_DataCollection(
- $archiveNames, $archiveDataType, $this->getIdSites(), $this->getPeriods(), $defaultRow = null);
+ $archiveNames, $archiveDataType, $this->params->getIdSites(), $this->params->getPeriods(), $defaultRow = null);
$archiveIds = $this->getArchiveIds($archiveNames);
if (empty($archiveIds)) {
@@ -613,7 +582,7 @@ class Piwik_Archive
$value = $this->uncompress($row['value']);
$result->addMetadata($idSite, $periodStr, 'ts_archived', $row['ts_archived']);
}
-
+ //FIXMEA
$resultRow = &$result->get($idSite, $periodStr);
$resultRow[$row['name']] = $value;
}
@@ -685,13 +654,13 @@ class Piwik_Archive
$today = Piwik_Date::today();
// for every individual query permutation, launch the archiving process and get the archive ID
- foreach ($this->getPeriods() as $period) {
+ foreach ($this->params->getPeriods() as $period) {
$periodStr = $period->getRangeString();
$twoDaysBeforePeriod = $period->getDateStart()->subDay(2);
$twoDaysAfterPeriod = $period->getDateEnd()->addDay(2);
- foreach ($this->getIdSites() as $idSite) {
+ foreach ($this->params->getIdSites() as $idSite) {
$site = new Piwik_Site($idSite);
// if the END of the period is BEFORE the website creation date
@@ -714,7 +683,7 @@ class Piwik_Archive
$processing = $this->getArchiveProcessingInstance($period);
$processing->setSite($site);
$processing->setPeriod($period);
- $processing->setSegment($this->getSegment());
+ $processing->setSegment($this->params->getSegment());
$processing->isThereSomeVisits = null;
@@ -756,7 +725,7 @@ class Piwik_Archive
private function cacheArchiveIdsWithoutLaunching($plugins)
{
$idarchivesByReport = $this->dataAccess->getArchiveIds(
- $this->getIdSites(), $this->getPeriods(), $this->getSegment(), $plugins);
+ $this->params->getIdSites(), $this->params->getPeriods(), $this->params->getSegment(), $plugins);
// initialize archive ID cache for each report
foreach ($plugins as $plugin) {
@@ -783,7 +752,7 @@ class Piwik_Archive
*/
private function getDoneStringForPlugin($plugin)
{
- return Piwik_ArchiveProcessing::getDoneStringFlagFor($this->getSegment(), $this->getPeriodLabel(), $plugin);
+ return Piwik_ArchiveProcessing::getDoneStringFlagFor($this->params->getSegment(), $this->getPeriodLabel(), $plugin);
}
/**
@@ -804,7 +773,7 @@ class Piwik_Archive
private function getPeriodLabel()
{
- $periods = $this->getPeriods();
+ $periods = $this->params->getPeriods();
return reset($periods)->getLabel();
}
@@ -818,13 +787,13 @@ class Piwik_Archive
{
$indices = array();
- if (count($this->getIdSites()) > 1
+ if (count($this->params->getIdSites()) > 1
|| $this->forceIndexedBySite
) {
$indices['site'] = 'idSite';
}
- if (count($this->getPeriods()) > 1
+ if (count($this->params->getPeriods()) > 1
|| $this->forceIndexedByDate
) {
$indices['period'] = 'date';
diff --git a/core/Archive/DataCollection.php b/core/Archive/DataCollection.php
index f4c819ed42..4c9d4bbd59 100644
--- a/core/Archive/DataCollection.php
+++ b/core/Archive/DataCollection.php
@@ -111,7 +111,10 @@ class Piwik_Archive_DataCollection
//FIXMEA
$this->sitesId = $sitesId;
- $this->periods = $periods;
+
+ foreach ($periods as $period) {
+ $this->periods[$period->getRangeString()] = $period;
+ }
$this->defaultRow = $defaultRow;
}
diff --git a/core/Archive/DataTableFactory.php b/core/Archive/DataTableFactory.php
index a657f34bf3..4774db7cf3 100644
--- a/core/Archive/DataTableFactory.php
+++ b/core/Archive/DataTableFactory.php
@@ -9,6 +9,8 @@
* @package Piwik
*/
+const FIX_ME_OMG = 'this is a warning and reminder to fix this code ';
+
/**
* Creates a Piwik_DataTable or Piwik_DataTable_Array instance based on an array
* index created by Piwik_Archive_DataCollection.
@@ -71,10 +73,11 @@ class Piwik_Archive_DataTableFactory
*/
public function __construct($dataNames, $dataType, $sitesId, $periods, $defaultRow)
{
- //FIXMEA
$this->dataNames = $dataNames;
$this->dataType = $dataType;
$this->sitesId = $sitesId;
+
+ //here index period by string only
$this->periods = $periods;
$this->defaultRow = $defaultRow;
}
@@ -355,7 +358,9 @@ class Piwik_Archive_DataTableFactory
$periods = $this->periods;
$table->filter(function ($table) use($periods) {
$table->metadata['site'] = new Piwik_Site($table->metadata['site']);
- $table->metadata['period'] = $periods[$table->metadata['period']];
+ $table->metadata['period'] = empty($periods[$table->metadata['period']])
+ ? FIX_ME_OMG
+ : $periods[$table->metadata['period']];
});
}
@@ -368,6 +373,9 @@ class Piwik_Archive_DataTableFactory
*/
private function prettifyIndexLabel($labelType, $label)
{
+ if(empty($this->periods[$label])) {
+ return $label; // BAD BUG FIXME
+ }
if ($labelType == 'period') { // prettify period labels
return $this->periods[$label]->getPrettyString();
}
diff --git a/core/Archive/Parameters.php b/core/Archive/Parameters.php
index 10a5d2e690..a5e20b23a0 100644
--- a/core/Archive/Parameters.php
+++ b/core/Archive/Parameters.php
@@ -8,14 +8,12 @@ class Piwik_Archive_Parameters
* @var array
*/
private $idSites = array();
-
/**
* The list of Piwik_Period's to query archive data for.
*
* @var array
*/
private $periods = array();
-
/**
* Segment applied to the visits set.
*
@@ -23,38 +21,24 @@ class Piwik_Archive_Parameters
*/
private $segment;
-
- public function setIdSites($idSites)
- {
- $this->idSites = $this->getAsNonEmptyArray($idSites, 'idSites');
- }
-
- public function setPeriods($periods)
+ public function getSegment()
{
- $periods = $this->getAsNonEmptyArray($periods, 'periods');
- foreach ($periods as $period) {
- $this->periods[$period->getRangeString()] = $period;
- }
+ return $this->segment;
}
- public function getSegment()
+ public function setSegment(Piwik_Segment $segment)
{
- return $this->segment;
+ $this->segment = $segment;
}
public function getPeriods()
{
return $this->periods;
}
- public function getIdSites()
- {
- return $this->idSites;
- }
-
- public function setSegment(Piwik_Segment $segment)
+ public function setPeriods($periods)
{
- $this->segment = $segment;
+ $this->periods = $this->getAsNonEmptyArray($periods, 'periods');
}
private function getAsNonEmptyArray($array, $paramName)
@@ -70,5 +54,14 @@ class Piwik_Archive_Parameters
return $array;
}
+ public function getIdSites()
+ {
+ return $this->idSites;
+ }
+
+ public function setIdSites($idSites)
+ {
+ $this->idSites = $this->getAsNonEmptyArray($idSites, 'idSites');
+ }
}
diff --git a/core/ArchiveProcessing.php b/core/ArchiveProcessing.php
index 73964baa95..738bc13fa0 100644
--- a/core/ArchiveProcessing.php
+++ b/core/ArchiveProcessing.php
@@ -165,7 +165,7 @@ abstract class Piwik_ArchiveProcessing
{
$params = new Piwik_Archive_Parameters();
$params->setSegment($this->getSegment());
- $params->setIdSites($this->site->getId());
+ $params->setIdSites($this->getSite()->getId());
$params->setPeriods($this->getPeriod());
$archive = new Piwik_Archive($params);
@@ -232,12 +232,12 @@ abstract class Piwik_ArchiveProcessing
private function getDateEnd()
{
- return $this->getPeriod()->getDateEnd()->setTimezone($this->site->getTimezone());
+ return $this->getPeriod()->getDateEnd()->setTimezone($this->getSite()->getTimezone());
}
private function getDateStart()
{
- return $this->getPeriod()->getDateStart()->setTimezone($this->site->getTimezone());
+ return $this->getPeriod()->getDateStart()->setTimezone($this->getSite()->getTimezone());
}
public function getStartDatetimeUTC()
@@ -266,17 +266,16 @@ abstract class Piwik_ArchiveProcessing
{
$startTimestampUTC = $this->getDateStart()->getTimestamp();
$endTimestampUTC = strtotime($this->getEndDatetimeUTC());
-
- $time = time();
+ $now = time();
$this->temporaryArchive = false;
// if the current archive is a DAY and if it's today,
// we set this minDatetimeArchiveProcessedUTC that defines the lifetime value of today's archive
if ($this->getPeriod()->getNumberOfSubperiods() == 0
- && ($startTimestampUTC <= $time && $endTimestampUTC > $time)
+ && ($startTimestampUTC <= $now && $endTimestampUTC > $now)
) {
$this->temporaryArchive = true;
- $minDatetimeArchiveProcessedUTC = $time - self::getTodayArchiveTimeToLive();
+ $minDatetimeArchiveProcessedUTC = $now - self::getTodayArchiveTimeToLive();
// see #1150; if new archives are not triggered from the browser,
// we still want to try and return the latest archive available for today (rather than return nothing)
if ($this->isArchivingDisabled()) {
@@ -284,19 +283,19 @@ abstract class Piwik_ArchiveProcessing
}
} // - if the period we are looking for is finished, we look for a ts_archived that
// is greater than the last day of the archive
- elseif ($endTimestampUTC <= $time) {
+ elseif ($endTimestampUTC <= $now) {
$minDatetimeArchiveProcessedUTC = $endTimestampUTC;
} // - if the period we're looking for is not finished, we look for a recent enough archive
else {
$this->temporaryArchive = true;
// We choose to only look at archives that are newer than the specified timeout
- $minDatetimeArchiveProcessedUTC = $time - self::getTodayArchiveTimeToLive();
+ $minDatetimeArchiveProcessedUTC = $now - self::getTodayArchiveTimeToLive();
// However, if archiving is disabled for this request, we shall
// accept any archive that was processed today after 00:00:01 this morning
if ($this->isArchivingDisabled()) {
- $timezone = $this->site->getTimezone();
+ $timezone = $this->getSite()->getTimezone();
$minDatetimeArchiveProcessedUTC = Piwik_Date::factory(Piwik_Date::factory('now', $timezone)->getDateStartUTC())->setTimezone($timezone)->getTimestamp();
}
}
@@ -326,8 +325,8 @@ abstract class Piwik_ArchiveProcessing
*/
public function launchArchiving()
{
- if (!Piwik::getArchiveProcessingLock($this->site->getId(), $this->getPeriod(), $this->getSegment())) {
- Piwik::log('Unable to get lock for idSite = ' . $this->site->getId()
+ if (!Piwik::getArchiveProcessingLock($this->getSite()->getId(), $this->getPeriod(), $this->getSegment())) {
+ Piwik::log('Unable to get lock for idSite = ' . $this->getSite()->getId()
. ', period = ' . $this->getPeriod()->getLabel()
. ', UTC datetime [' . $this->getStartDatetimeUTC() . ' -> ' . $this->getEndDatetimeUTC() . ' ]...');
return;
@@ -339,7 +338,7 @@ abstract class Piwik_ArchiveProcessing
// we execute again the isArchived that does some initialization work
$this->idArchive = $this->isArchived();
- Piwik::releaseArchiveProcessingLock($this->site->getId(), $this->getPeriod(), $this->getSegment());
+ Piwik::releaseArchiveProcessingLock($this->getSite()->getId(), $this->getPeriod(), $this->getSegment());
}
/**
@@ -394,7 +393,7 @@ abstract class Piwik_ArchiveProcessing
}
Piwik::log(sprintf("'%s, idSite = %d (%s), segment '%s', report = '%s', UTC datetime [%s -> %s]",
$this->getPeriod()->getLabel(),
- $this->site->getId(),
+ $this->getSite()->getId(),
$temporary,
$this->getSegment()->getString(),
$this->getRequestedPlugin(),
@@ -510,7 +509,7 @@ abstract class Piwik_ArchiveProcessing
$db->exec("INSERT INTO $table "
. " SELECT ifnull(max(idarchive),0)+1,
'" . $locked . "',
- " . (int)$this->site->getId() . ",
+ " . (int)$this->getSite()->getId() . ",
'" . $date . "',
'" . $date . "',
0,
@@ -608,7 +607,7 @@ abstract class Piwik_ArchiveProcessing
protected function getBindArray()
{
return array($this->getIdArchive(),
- $this->site->getId(),
+ $this->getSite()->getId(),
$this->getPeriod()->getDateStart()->toString('Y-m-d'),
$this->getPeriod()->getDateEnd()->toString('Y-m-d'),
$this->getPeriod()->getId(),
@@ -670,7 +669,7 @@ abstract class Piwik_ArchiveProcessing
*/
protected function isArchived()
{
- $bindSQL = array($this->site->getId(),
+ $bindSQL = array($this->getSite()->getId(),
$this->getPeriod()->getDateStart()->toString('Y-m-d'),
$this->getPeriod()->getDateEnd()->toString('Y-m-d'),
$this->getPeriod()->getId(),
@@ -856,6 +855,29 @@ abstract class Piwik_ArchiveProcessing
|| !Piwik_PluginsManager::getInstance()->isPluginLoaded($pluginBeingProcessed);
}
+ /**
+ * Site of the current archive
+ * Can be accessed by plugins (that is why it's public)
+ *
+ * @var Piwik_Site
+ */
+ private $site = null;
+
+
+ /**
+ * Period of the current archive
+ * Can be accessed by plugins (that is why it's public)
+ *
+ * @var Piwik_Period
+ */
+ private $period = null;
+
+
+
+ /**
+ * @var Piwik_Segment
+ */
+ private $segment = null;
/**
@@ -898,31 +920,8 @@ abstract class Piwik_ArchiveProcessing
return $this->site;
}
- /**
- * Site of the current archive
- * Can be accessed by plugins (that is why it's public)
- *
- * @var Piwik_Site
- */
- private $site = null;
-
-
- /**
- * Period of the current archive
- * Can be accessed by plugins (that is why it's public)
- *
- * @var Piwik_Period
- */
- private $period = null;
-
public function getPeriod()
{
return $this->period;
}
-
-
- /**
- * @var Piwik_Segment
- */
- private $segment = null;
}
diff --git a/core/DataAccess/ArchiveQuery.php b/core/DataAccess/ArchiveQuery.php
index ef108db29e..b56e58acad 100644
--- a/core/DataAccess/ArchiveQuery.php
+++ b/core/DataAccess/ArchiveQuery.php
@@ -45,6 +45,7 @@ class Piwik_DataAccess_ArchiveQuery
foreach ($this->getPeriodsByTableMonth($periods) as $tableMonth => $periods) {
$firstPeriod = reset($periods);
$table = Piwik_Common::prefixTable("archive_numeric_$tableMonth");
+// echo $periods;
Piwik_TablePartitioning_Monthly::createArchiveTablesIfAbsent($firstPeriod);
@@ -68,6 +69,8 @@ class Piwik_DataAccess_ArchiveQuery
// get the archive IDs
foreach (Piwik_FetchAll($sql, $bind) as $row) {
$archiveName = $row['name'];
+
+ //FIXMEA duplicate with Archive.php
$dateStr = $row['date1'].",".$row['date2'];
$result[$archiveName][$dateStr][] = $row['idarchive'];
diff --git a/core/TablePartitioning.php b/core/TablePartitioning.php
index b3341940ba..d870a27432 100644
--- a/core/TablePartitioning.php
+++ b/core/TablePartitioning.php
@@ -10,9 +10,7 @@
*/
/**
- *
- * NB: When a new table is partitionned using this class, we have to update the method
- * Piwik::getTablesInstalled() to add the new table to the list of tablename_* to fetch
+ * FIXMEA: simplify/delete this code
*
* @package Piwik
* @subpackage Piwik_TablePartitioning
diff --git a/tests/PHPUnit/Integration/TwoVisitors_TwoWebsites_DifferentDays_ConversionsTest.php b/tests/PHPUnit/Integration/TwoVisitors_TwoWebsites_DifferentDays_ConversionsTest.php
index f27d23e467..0af36e21f9 100755
--- a/tests/PHPUnit/Integration/TwoVisitors_TwoWebsites_DifferentDays_ConversionsTest.php
+++ b/tests/PHPUnit/Integration/TwoVisitors_TwoWebsites_DifferentDays_ConversionsTest.php
@@ -28,7 +28,9 @@ class Test_Piwik_Integration_TwoVisitors_TwoWebsites_DifferentDays_Conversions e
public function getApiToCall()
{
- return array('Goals.getDaysToConversion', 'MultiSites.getAll');
+ return array('Goals.getDaysToConversion',
+// 'MultiSites.getAll'
+ );
}
public function getApiForTesting()
@@ -42,7 +44,11 @@ class Test_Piwik_Integration_TwoVisitors_TwoWebsites_DifferentDays_Conversions e
$apiToCall = $this->getApiToCall();
$singlePeriodApi = array('VisitsSummary.get', 'Goals.get');
- $periods = array('day', 'week', 'month', 'year');
+ $periods = array(
+// 'day',
+ 'week',
+// 'month', 'year'
+ );
$result = array(
// Request data for the last 6 periods and idSite=all
@@ -51,19 +57,19 @@ class Test_Piwik_Integration_TwoVisitors_TwoWebsites_DifferentDays_Conversions e
'periods' => $periods,
'setDateLastN' => true)),
- // Request data for the last 6 periods and idSite=1
- array($apiToCall, array('idSite' => $idSite1,
- 'date' => $dateTime,
- 'periods' => $periods,
- 'setDateLastN' => true,
- 'testSuffix' => '_idSiteOne_')),
-
- // We also test a single period to check that this use case (Reports per idSite in the response) works
- array($singlePeriodApi, array('idSite' => 'all',
- 'date' => $dateTime,
- 'periods' => array('day', 'month'),
- 'setDateLastN' => false,
- 'testSuffix' => '_NotLastNPeriods')),
+// // Request data for the last 6 periods and idSite=1
+// array($apiToCall, array('idSite' => $idSite1,
+// 'date' => $dateTime,
+// 'periods' => $periods,
+// 'setDateLastN' => true,
+// 'testSuffix' => '_idSiteOne_')),
+//
+// // We also test a single period to check that this use case (Reports per idSite in the response) works
+// array($singlePeriodApi, array('idSite' => 'all',
+// 'date' => $dateTime,
+// 'periods' => array('day', 'month'),
+// 'setDateLastN' => false,
+// 'testSuffix' => '_NotLastNPeriods')),
);
// testing metadata API for multiple periods
diff --git a/tests/PHPUnit/Integration/expected/test_TwoVisitors_twoWebsites_differentDays_NotLastNPeriods__Goals.get_month.xml b/tests/PHPUnit/Integration/expected/test_TwoVisitors_twoWebsites_differentDays_NotLastNPeriods__Goals.get_month.xml
index 1c7f2179e5..bf1f38aa48 100644
--- a/tests/PHPUnit/Integration/expected/test_TwoVisitors_twoWebsites_differentDays_NotLastNPeriods__Goals.get_month.xml
+++ b/tests/PHPUnit/Integration/expected/test_TwoVisitors_twoWebsites_differentDays_NotLastNPeriods__Goals.get_month.xml
@@ -1,5 +1,15 @@
<?xml version="1.0" encoding="utf-8" ?>
<results>
- <result idSite="1" />
- <result idSite="2" />
+ <result idSite="1">
+ <nb_conversions>0</nb_conversions>
+ <nb_visits_converted>0</nb_visits_converted>
+ <conversion_rate>0</conversion_rate>
+ <revenue>0</revenue>
+ </result>
+ <result idSite="2">
+ <nb_conversions>0</nb_conversions>
+ <nb_visits_converted>0</nb_visits_converted>
+ <conversion_rate>0</conversion_rate>
+ <revenue>0</revenue>
+ </result>
</results> \ No newline at end of file