Skip to content

Commit

Permalink
Fix regression in MultiSites w/ regard to master, make sure orders_ev…
Browse files Browse the repository at this point in the history
…olution and ecommerce_revenue_evolution are not present if ecommerce is not enabled for the site.
  • Loading branch information
diosmosis committed Nov 26, 2014
1 parent 9c267a2 commit f56c92e
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 82 deletions.
7 changes: 5 additions & 2 deletions core/API/DataTablePostProcessor.php
Original file line number Diff line number Diff line change
Expand Up @@ -367,8 +367,11 @@ public function computeProcessedMetrics(DataTable $dataTable)
}

foreach ($dataTable->getRows() as $row) {
if ($row->getColumn($name) === false) { // do not compute the metric if it has been computed already
$row->addColumn($name, $processedMetric->compute($row));
if ($row->getColumn($name) === false) { // only compute the metric if it has not been computed already
$computedValue = $processedMetric->compute($row);
if ($computedValue !== false) {
$row->addColumn($name, $computedValue);
}

$subtable = $row->getSubtable();
if (!empty($subtable)) {
Expand Down
26 changes: 11 additions & 15 deletions plugins/MultiSites/API.php
Original file line number Diff line number Diff line change
Expand Up @@ -244,18 +244,6 @@ private function buildDataTable($idSitesOrIdSite, $period, $date, $segment, $_re
$this->calculateEvolutionPercentages($dataTable, $pastData, $apiMetrics);
}

// remove eCommerce related metrics on non eCommerce Piwik sites
// note: this is not optimal in terms of performance: those metrics should not be retrieved in the first place
if ($enhanced) {
if ($dataTable instanceof DataTable\Map) {
foreach ($dataTable->getDataTables() as $table) {
$this->removeEcommerceRelatedMetricsOnNonEcommercePiwikSites($table, $apiECommerceMetrics);
}
} else {
$this->removeEcommerceRelatedMetricsOnNonEcommercePiwikSites($dataTable, $apiECommerceMetrics);
}
}

// move the site id to a metadata column
$dataTable->filter('ColumnCallbackAddMetadata', array('label', 'group', array('\Piwik\Site', 'getGroupFor'), array()));
$dataTable->filter('ColumnCallbackAddMetadata', array('label', 'main_url', array('\Piwik\Site', 'getMainUrlFor'), array()));
Expand Down Expand Up @@ -330,8 +318,8 @@ private function calculateEvolutionPercentages($currentData, $pastData, $apiMetr
} else {
$extraProcessedMetrics = $currentData->getMetadata(DataTable::EXTRA_PROCESSED_METRICS_METADATA_NAME);
foreach ($apiMetrics as $metricSettings) {
$evolutionMetricClass = $metricSettings[self::METRIC_EVOLUTION_COL_NAME_KEY] == 'revenue_evolution'
? "Piwik\\Plugins\\MultiSites\\Columns\\Metrics\\RevenueEvolution"
$evolutionMetricClass = $this->isEcommerceEvolutionMetric($metricSettings)
? "Piwik\\Plugins\\MultiSites\\Columns\\Metrics\\EcommerceOnlyEvolutionMetric"
: "Piwik\\Plugins\\CoreHome\\Columns\\Metrics\\EvolutionMetric";

$extraProcessedMetrics[] = new $evolutionMetricClass(
Expand Down Expand Up @@ -508,5 +496,13 @@ private function mergeDataTableMapAndPopulateLabel($idSitesOrIdSite, $multipleWe

return $dataTable;
}
}

private function isEcommerceEvolutionMetric($metricSettings)
{
return in_array($metricSettings[self::METRIC_EVOLUTION_COL_NAME_KEY], array(
self::GOAL_REVENUE_METRIC . '_evolution',
self::ECOMMERCE_ORDERS_METRIC . '_evolution',
self::ECOMMERCE_REVENUE_METRIC . '_evolution'
));
}
}
37 changes: 0 additions & 37 deletions plugins/MultiSites/Columns/Metrics/RevenueEvolution.php

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,6 @@
<pageviews_evolution>100%</pageviews_evolution>
<revenue_evolution>100%</revenue_evolution>
<nb_conversions_evolution>100%</nb_conversions_evolution>
<orders_evolution>0%</orders_evolution>
<ecommerce_revenue_evolution>0%</ecommerce_revenue_evolution>
<group />
<main_url>http://piwik.net</main_url>
<idsite>1</idsite>
Expand All @@ -31,8 +29,6 @@
<pageviews_evolution>100%</pageviews_evolution>
<revenue_evolution>0%</revenue_evolution>
<nb_conversions_evolution>0%</nb_conversions_evolution>
<orders_evolution>0%</orders_evolution>
<ecommerce_revenue_evolution>0%</ecommerce_revenue_evolution>
<group />
<main_url>http://example-site-two.com</main_url>
<idsite>2</idsite>
Expand All @@ -51,8 +47,6 @@
<pageviews_evolution>-61.5%</pageviews_evolution>
<revenue_evolution>-96%</revenue_evolution>
<nb_conversions_evolution>-96%</nb_conversions_evolution>
<orders_evolution>0%</orders_evolution>
<ecommerce_revenue_evolution>0%</ecommerce_revenue_evolution>
<group />
<main_url>http://piwik.net</main_url>
<idsite>1</idsite>
Expand All @@ -69,8 +63,6 @@
<pageviews_evolution>-100%</pageviews_evolution>
<revenue_evolution>0%</revenue_evolution>
<nb_conversions_evolution>0%</nb_conversions_evolution>
<orders_evolution>0%</orders_evolution>
<ecommerce_revenue_evolution>0%</ecommerce_revenue_evolution>
<group />
<main_url>http://example-site-two.com</main_url>
<idsite>2</idsite>
Expand All @@ -89,8 +81,6 @@
<pageviews_evolution>-100%</pageviews_evolution>
<revenue_evolution>-100%</revenue_evolution>
<nb_conversions_evolution>-100%</nb_conversions_evolution>
<orders_evolution>0%</orders_evolution>
<ecommerce_revenue_evolution>0%</ecommerce_revenue_evolution>
<group />
<main_url>http://piwik.net</main_url>
<idsite>1</idsite>
Expand All @@ -107,8 +97,6 @@
<pageviews_evolution>0%</pageviews_evolution>
<revenue_evolution>0%</revenue_evolution>
<nb_conversions_evolution>0%</nb_conversions_evolution>
<orders_evolution>0%</orders_evolution>
<ecommerce_revenue_evolution>0%</ecommerce_revenue_evolution>
<group />
<main_url>http://example-site-two.com</main_url>
<idsite>2</idsite>
Expand All @@ -127,8 +115,6 @@
<pageviews_evolution>0%</pageviews_evolution>
<revenue_evolution>0%</revenue_evolution>
<nb_conversions_evolution>0%</nb_conversions_evolution>
<orders_evolution>0%</orders_evolution>
<ecommerce_revenue_evolution>0%</ecommerce_revenue_evolution>
<group />
<main_url>http://piwik.net</main_url>
<idsite>1</idsite>
Expand All @@ -145,8 +131,6 @@
<pageviews_evolution>0%</pageviews_evolution>
<revenue_evolution>0%</revenue_evolution>
<nb_conversions_evolution>0%</nb_conversions_evolution>
<orders_evolution>0%</orders_evolution>
<ecommerce_revenue_evolution>0%</ecommerce_revenue_evolution>
<group />
<main_url>http://example-site-two.com</main_url>
<idsite>2</idsite>
Expand All @@ -165,8 +149,6 @@
<pageviews_evolution>0%</pageviews_evolution>
<revenue_evolution>0%</revenue_evolution>
<nb_conversions_evolution>0%</nb_conversions_evolution>
<orders_evolution>0%</orders_evolution>
<ecommerce_revenue_evolution>0%</ecommerce_revenue_evolution>
<group />
<main_url>http://piwik.net</main_url>
<idsite>1</idsite>
Expand All @@ -183,8 +165,6 @@
<pageviews_evolution>0%</pageviews_evolution>
<revenue_evolution>0%</revenue_evolution>
<nb_conversions_evolution>0%</nb_conversions_evolution>
<orders_evolution>0%</orders_evolution>
<ecommerce_revenue_evolution>0%</ecommerce_revenue_evolution>
<group />
<main_url>http://example-site-two.com</main_url>
<idsite>2</idsite>
Expand All @@ -203,8 +183,6 @@
<pageviews_evolution>0%</pageviews_evolution>
<revenue_evolution>0%</revenue_evolution>
<nb_conversions_evolution>0%</nb_conversions_evolution>
<orders_evolution>0%</orders_evolution>
<ecommerce_revenue_evolution>0%</ecommerce_revenue_evolution>
<group />
<main_url>http://piwik.net</main_url>
<idsite>1</idsite>
Expand All @@ -221,8 +199,6 @@
<pageviews_evolution>0%</pageviews_evolution>
<revenue_evolution>0%</revenue_evolution>
<nb_conversions_evolution>0%</nb_conversions_evolution>
<orders_evolution>0%</orders_evolution>
<ecommerce_revenue_evolution>0%</ecommerce_revenue_evolution>
<group />
<main_url>http://example-site-two.com</main_url>
<idsite>2</idsite>
Expand All @@ -241,8 +217,6 @@
<pageviews_evolution>0%</pageviews_evolution>
<revenue_evolution>0%</revenue_evolution>
<nb_conversions_evolution>0%</nb_conversions_evolution>
<orders_evolution>0%</orders_evolution>
<ecommerce_revenue_evolution>0%</ecommerce_revenue_evolution>
<group />
<main_url>http://piwik.net</main_url>
<idsite>1</idsite>
Expand All @@ -259,8 +233,6 @@
<pageviews_evolution>0%</pageviews_evolution>
<revenue_evolution>0%</revenue_evolution>
<nb_conversions_evolution>0%</nb_conversions_evolution>
<orders_evolution>0%</orders_evolution>
<ecommerce_revenue_evolution>0%</ecommerce_revenue_evolution>
<group />
<main_url>http://example-site-two.com</main_url>
<idsite>2</idsite>
Expand Down

0 comments on commit f56c92e

Please sign in to comment.