update Piwik to version 2.16 (fixes #91)
This commit is contained in:
parent
296343bf3b
commit
d885a4baa9
5833 changed files with 418860 additions and 226988 deletions
|
|
@ -1,6 +1,6 @@
|
|||
<?php
|
||||
/**
|
||||
* Piwik - Open source web analytics
|
||||
* Piwik - free/libre analytics platform
|
||||
*
|
||||
* @link http://piwik.org
|
||||
* @license http://www.gnu.org/licenses/gpl-3.0.html GPL v3 or later
|
||||
|
|
@ -10,17 +10,17 @@ namespace Piwik\Plugins\API;
|
|||
|
||||
use Exception;
|
||||
use Piwik\API\DataTableManipulator\LabelFilter;
|
||||
use Piwik\API\DataTablePostProcessor;
|
||||
use Piwik\API\Request;
|
||||
use Piwik\API\ResponseBuilder;
|
||||
use Piwik\Common;
|
||||
use Piwik\DataTable;
|
||||
use Piwik\DataTable\Filter\CalculateEvolutionFilter;
|
||||
use Piwik\DataTable\Filter\SafeDecodeLabel;
|
||||
use Piwik\DataTable\Row;
|
||||
use Piwik\DataTable;
|
||||
use Piwik\Period;
|
||||
use Piwik\Piwik;
|
||||
use Piwik\Url;
|
||||
use Piwik\Site;
|
||||
use Piwik\Url;
|
||||
|
||||
/**
|
||||
* This class generates a Row evolution dataset, from input request
|
||||
|
|
@ -36,7 +36,7 @@ class RowEvolution
|
|||
'getPageUrl'
|
||||
);
|
||||
|
||||
public function getRowEvolution($idSite, $period, $date, $apiModule, $apiAction, $label = false, $segment = false, $column = false, $language = false, $idGoal = false, $legendAppendMetric = true, $labelUseAbsoluteUrl = true)
|
||||
public function getRowEvolution($idSite, $period, $date, $apiModule, $apiAction, $label = false, $segment = false, $column = false, $language = false, $idGoal = false, $legendAppendMetric = true, $labelUseAbsoluteUrl = true, $idDimension = false)
|
||||
{
|
||||
// validation of requested $period & $date
|
||||
if ($period == 'range') {
|
||||
|
|
@ -48,12 +48,12 @@ class RowEvolution
|
|||
throw new Exception("Row evolutions can not be processed with this combination of \'date\' and \'period\' parameters.");
|
||||
}
|
||||
|
||||
$label = ResponseBuilder::unsanitizeLabelParameter($label);
|
||||
$label = DataTablePostProcessor::unsanitizeLabelParameter($label);
|
||||
$labels = Piwik::getArrayFromApiParameter($label);
|
||||
|
||||
$metadata = $this->getRowEvolutionMetaData($idSite, $period, $date, $apiModule, $apiAction, $language, $idGoal);
|
||||
$metadata = $this->getRowEvolutionMetaData($idSite, $period, $date, $apiModule, $apiAction, $language, $idGoal, $idDimension);
|
||||
|
||||
$dataTable = $this->loadRowEvolutionDataFromAPI($metadata, $idSite, $period, $date, $apiModule, $apiAction, $labels, $segment, $idGoal);
|
||||
$dataTable = $this->loadRowEvolutionDataFromAPI($metadata, $idSite, $period, $date, $apiModule, $apiAction, $labels, $segment, $idGoal, $idDimension);
|
||||
|
||||
if (empty($labels)) {
|
||||
$labels = $this->getLabelsFromDataTable($dataTable, $labels);
|
||||
|
|
@ -144,7 +144,7 @@ class RowEvolution
|
|||
|
||||
$logo = $actualLabel = false;
|
||||
$urlFound = false;
|
||||
foreach ($dataTable->getDataTables() as $date => $subTable) {
|
||||
foreach ($dataTable->getDataTables() as $subTable) {
|
||||
/** @var $subTable DataTable */
|
||||
$subTable->applyQueuedFilters();
|
||||
if ($subTable->getRowsCount() > 0) {
|
||||
|
|
@ -204,10 +204,13 @@ class RowEvolution
|
|||
$replaceRegex = "/\\s*" . preg_quote(LabelFilter::SEPARATOR_RECURSIVE_LABEL) . "\\s*/";
|
||||
$cleanLabel = preg_replace($replaceRegex, '/', $label);
|
||||
|
||||
return $mainUrlHost . '/' . $cleanLabel . '/';
|
||||
$result = $mainUrlHost . '/' . $cleanLabel . '/';
|
||||
} else {
|
||||
return str_replace(LabelFilter::SEPARATOR_RECURSIVE_LABEL, ' - ', $label);
|
||||
$result = str_replace(LabelFilter::SEPARATOR_RECURSIVE_LABEL, ' - ', $label);
|
||||
}
|
||||
|
||||
// remove @ terminal operator occurances
|
||||
return str_replace(LabelFilter::TERMINAL_OPERATOR, '', $result);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -245,7 +248,7 @@ class RowEvolution
|
|||
* @throws Exception
|
||||
* @return DataTable\Map|DataTable
|
||||
*/
|
||||
private function loadRowEvolutionDataFromAPI($metadata, $idSite, $period, $date, $apiModule, $apiAction, $label = false, $segment = false, $idGoal = false)
|
||||
private function loadRowEvolutionDataFromAPI($metadata, $idSite, $period, $date, $apiModule, $apiAction, $label = false, $segment = false, $idGoal = false, $idDimension = false)
|
||||
{
|
||||
if (!is_array($label)) {
|
||||
$label = array($label);
|
||||
|
|
@ -262,6 +265,7 @@ class RowEvolution
|
|||
'serialize' => '0',
|
||||
'segment' => $segment,
|
||||
'idGoal' => $idGoal,
|
||||
'idDimension' => $idDimension,
|
||||
|
||||
// data for row evolution should NOT be limited
|
||||
'filter_limit' => -1,
|
||||
|
|
@ -276,9 +280,8 @@ class RowEvolution
|
|||
// note: some reports should not be filtered with AddColumnProcessedMetrics
|
||||
// specifically, reports without the Metrics::INDEX_NB_VISITS metric such as Goals.getVisitsUntilConversion & Goal.getDaysToConversion
|
||||
// this is because the AddColumnProcessedMetrics filter removes all datable rows lacking this metric
|
||||
if( isset($metadata['metrics']['nb_visits'])
|
||||
&& !empty($label)) {
|
||||
$parameters['filter_add_columns_when_show_all_columns'] = '1';
|
||||
if (isset($metadata['metrics']['nb_visits'])) {
|
||||
$parameters['filter_add_columns_when_show_all_columns'] = '0';
|
||||
}
|
||||
|
||||
$url = Url::getQueryStringFromParameters($parameters);
|
||||
|
|
@ -307,12 +310,15 @@ class RowEvolution
|
|||
* @throws Exception
|
||||
* @return array
|
||||
*/
|
||||
private function getRowEvolutionMetaData($idSite, $period, $date, $apiModule, $apiAction, $language, $idGoal = false)
|
||||
private function getRowEvolutionMetaData($idSite, $period, $date, $apiModule, $apiAction, $language, $idGoal = false, $idDimension = false)
|
||||
{
|
||||
$apiParameters = array();
|
||||
if (!empty($idGoal) && $idGoal > 0) {
|
||||
$apiParameters = array('idGoal' => $idGoal);
|
||||
}
|
||||
if (!empty($idDimension) && $idDimension > 0) {
|
||||
$apiParameters = array('idDimension' => (int) $idDimension);
|
||||
}
|
||||
$reportMetadata = API::getInstance()->getMetadata($idSite, $apiModule, $apiAction, $apiParameters, $language,
|
||||
$period, $date, $hideMetricsDoc = false, $showSubtableReports = true);
|
||||
|
||||
|
|
@ -328,6 +334,10 @@ class RowEvolution
|
|||
$metrics = $metrics + $reportMetadata['processedMetrics'];
|
||||
}
|
||||
|
||||
if (empty($reportMetadata['dimension'])) {
|
||||
throw new Exception(sprintf('Reports like %s.%s which do not have a dimension are not supported by row evolution', $apiModule, $apiAction));
|
||||
}
|
||||
|
||||
$dimension = $reportMetadata['dimension'];
|
||||
|
||||
return compact('metrics', 'dimension');
|
||||
|
|
@ -353,9 +363,16 @@ class RowEvolution
|
|||
unset($metadata['logos']);
|
||||
|
||||
$subDataTables = $dataTable->getDataTables();
|
||||
if (empty($subDataTables)) {
|
||||
throw new \Exception("Unexpected state: row evolution API call returned empty DataTable\\Map.");
|
||||
}
|
||||
|
||||
$firstDataTable = reset($subDataTables);
|
||||
$this->checkDataTableInstance($firstDataTable);
|
||||
$firstDataTableRow = $firstDataTable->getFirstRow();
|
||||
|
||||
$lastDataTable = end($subDataTables);
|
||||
$this->checkDataTableInstance($lastDataTable);
|
||||
$lastDataTableRow = $lastDataTable->getFirstRow();
|
||||
|
||||
// Process min/max values
|
||||
|
|
@ -423,7 +440,7 @@ class RowEvolution
|
|||
$labelRow, $apiModule, $apiAction, $labelUseAbsoluteUrl);
|
||||
|
||||
$prettyLabel = $labelRow->getColumn('label_html');
|
||||
if($prettyLabel !== false) {
|
||||
if ($prettyLabel !== false) {
|
||||
$actualLabels[$labelIdx] = $prettyLabel;
|
||||
}
|
||||
|
||||
|
|
@ -526,4 +543,11 @@ class RowEvolution
|
|||
$label = SafeDecodeLabel::decodeLabelSafe($label);
|
||||
return $label;
|
||||
}
|
||||
|
||||
private function checkDataTableInstance($lastDataTable)
|
||||
{
|
||||
if (!($lastDataTable instanceof DataTable)) {
|
||||
throw new \Exception("Unexpected state: row evolution returned DataTable\\Map w/ incorrect child table type: " . get_class($lastDataTable));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue