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:
authorStefan Giehl <stefan@matomo.org>2022-01-17 00:06:57 +0300
committerGitHub <noreply@github.com>2022-01-17 00:06:57 +0300
commitd1989fe093f6d8ab325cf24573479f280b7df928 (patch)
treef520f28c4463f024dd44017816deb2c7fca0e41a /plugins
parent7f77fdfd16f4e7d28aa5a3fc92e78469f7bc2fb2 (diff)
Fix possible error when generating reports for custom dimensions (#18614)
* handle an empty string as null for subtable ids * Adjust API definition * Adds test
Diffstat (limited to 'plugins')
-rw-r--r--plugins/CustomDimensions/API.php6
-rw-r--r--plugins/CustomDimensions/tests/Fixtures/TrackVisitsWithCustomDimensionsFixture.php23
-rw-r--r--plugins/CustomDimensions/tests/System/ApiTest.php22
-rw-r--r--plugins/CustomDimensions/tests/System/expected/test___ScheduledReports.generateReport_year.original.pdfbin0 -> 441798 bytes
4 files changed, 47 insertions, 4 deletions
diff --git a/plugins/CustomDimensions/API.php b/plugins/CustomDimensions/API.php
index 1b5f9ad455..d2ef2f4983 100644
--- a/plugins/CustomDimensions/API.php
+++ b/plugins/CustomDimensions/API.php
@@ -47,11 +47,11 @@ class API extends \Piwik\Plugin\API
* @param bool|false $segment
* @param bool|false $expanded
* @param bool|false $flat
- * @param int|null $idSubtable
+ * @param int|false $idSubtable
* @return DataTable|DataTable\Map
* @throws \Exception
*/
- public function getCustomDimension($idDimension, $idSite, $period, $date, $segment = false, $expanded = false, $flat = false, $idSubtable = null)
+ public function getCustomDimension($idDimension, $idSite, $period, $date, $segment = false, $expanded = false, $flat = false, $idSubtable = false)
{
Piwik::checkUserHasViewAccess($idSite);
@@ -62,7 +62,7 @@ class API extends \Piwik\Plugin\API
$dataTable = Archive::createDataTableFromArchive($record, $idSite, $period, $date, $segment, $expanded, $flat, $idSubtable);
- if (isset($idSubtable) && $dataTable->getRowsCount()) {
+ if (!empty($idSubtable) && $dataTable->getRowsCount()) {
$parentTable = Archive::createDataTableFromArchive($record, $idSite, $period, $date, $segment);
foreach ($parentTable->getRows() as $row) {
if ($row->getIdSubDataTable() == $idSubtable) {
diff --git a/plugins/CustomDimensions/tests/Fixtures/TrackVisitsWithCustomDimensionsFixture.php b/plugins/CustomDimensions/tests/Fixtures/TrackVisitsWithCustomDimensionsFixture.php
index 936c259251..a63e8255d7 100644
--- a/plugins/CustomDimensions/tests/Fixtures/TrackVisitsWithCustomDimensionsFixture.php
+++ b/plugins/CustomDimensions/tests/Fixtures/TrackVisitsWithCustomDimensionsFixture.php
@@ -7,13 +7,16 @@
*/
namespace Piwik\Plugins\CustomDimensions\tests\Fixtures;
+use Piwik\Context;
use Piwik\Date;
use Piwik\Plugins\CustomDimensions\CustomDimensions;
use Piwik\Plugins\CustomDimensions\Dao\Configuration;
use Piwik\Plugins\CustomDimensions\Dimension\Extraction;
use Piwik\Plugins\Goals;
+use Piwik\Plugins\ScheduledReports\API as APIScheduledReports;
+use Piwik\Plugins\ScheduledReports\ScheduledReports;
+use Piwik\ReportRenderer;
use Piwik\Tests\Framework\Fixture;
-use Piwik\Plugin;
use Piwik\Tracker\Cache;
/**
@@ -32,6 +35,7 @@ class TrackVisitsWithCustomDimensionsFixture extends Fixture
$this->setUpWebsites();
$this->addGoals();
$this->configureSomeDimensions();
+ $this->configureScheduledReport();
$this->trackFirstVisit();
$this->trackSecondVisit();
$this->trackThirdVisit();
@@ -77,6 +81,23 @@ class TrackVisitsWithCustomDimensionsFixture extends Fixture
Cache::clearCacheGeneral();
}
+ protected function configureScheduledReport()
+ {
+ // Context change is needed, as adding the custom dimensions reports looks for the idSite in the request params
+ Context::changeIdSite(1, function() {
+ APIScheduledReports::getInstance()->addReport(
+ $idSite = 1,
+ 'ScheduledReport',
+ 'month',
+ 0,
+ ScheduledReports::EMAIL_TYPE,
+ ReportRenderer::PDF_FORMAT,
+ ['VisitsSummary_get', 'CustomDimensions_getCustomDimension_idDimension--1', 'CustomDimensions_getCustomDimension_idDimension--2'],
+ [ScheduledReports::DISPLAY_FORMAT_PARAMETER => ScheduledReports::DISPLAY_FORMAT_TABLES_AND_GRAPHS]
+ );
+ });
+ }
+
protected function trackFirstVisit()
{
$t = self::getTracker($this->idSite, $this->dateTime, $defaultInit = true);
diff --git a/plugins/CustomDimensions/tests/System/ApiTest.php b/plugins/CustomDimensions/tests/System/ApiTest.php
index 5932490c81..5f136adc7b 100644
--- a/plugins/CustomDimensions/tests/System/ApiTest.php
+++ b/plugins/CustomDimensions/tests/System/ApiTest.php
@@ -8,7 +8,9 @@
namespace Piwik\Plugins\CustomDimensions\tests\System;
+use Piwik\Context;
use Piwik\Plugins\CustomDimensions\tests\Fixtures\TrackVisitsWithCustomDimensionsFixture;
+use Piwik\ReportRenderer;
use Piwik\Tests\Framework\TestCase\SystemTestCase;
/**
@@ -260,6 +262,26 @@ class ApiTest extends SystemTestCase
return $apiToTest;
}
+ public function testScheduledReport()
+ {
+ // Context change is needed, as otherwise the customdimension reports are not available
+ Context::changeIdSite(1, function(){
+ $this->runApiTests(['ScheduledReports.generateReport'], [
+ 'idSite' => 1,
+ 'date' => self::$fixture->dateTime,
+ 'periods' => ['year'],
+ 'format' => 'original',
+ 'fileExtension' => 'pdf',
+ 'otherRequestParameters' => [
+ 'idReport' => 1,
+ 'reportFormat' => ReportRenderer::PDF_FORMAT,
+ 'outputType' => \Piwik\Plugins\ScheduledReports\API::OUTPUT_RETURN,
+ 'serialize' => 0,
+ ],
+ ]);
+ });
+ }
+
public static function getOutputPrefix()
{
return '';
diff --git a/plugins/CustomDimensions/tests/System/expected/test___ScheduledReports.generateReport_year.original.pdf b/plugins/CustomDimensions/tests/System/expected/test___ScheduledReports.generateReport_year.original.pdf
new file mode 100644
index 0000000000..3f041bbae3
--- /dev/null
+++ b/plugins/CustomDimensions/tests/System/expected/test___ScheduledReports.generateReport_year.original.pdf
Binary files differ