Skip to content

Commit

Permalink
fixes #5951 throw an exception in getRowEvolution if a report is requ…
Browse files Browse the repository at this point in the history
…est that does not have a dimension
  • Loading branch information
tsteur committed Aug 9, 2014
1 parent a2f3959 commit 3b962d9
Show file tree
Hide file tree
Showing 3 changed files with 49 additions and 0 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ This is a changelog for Piwik platform developers. All changes for our HTTP API'
* The [settings](http://developer.piwik.org/guides/piwik-configuration) API will receive the actual entered value and will no longer convert characters like `&` to `&`. If you still want this behavior - for instance to prevent XSS - you can define a filter by setting the `transform` property like this:
`$setting->transform = function ($value) { return Common::sanitizeInputValue($value); }`
* Config setting `disable_merged_assets` moved from `Debug` section to `Development`. The updater will automatically change the section for you.
* `API.getRowEvolution` will throw an exception if a report is requested that does not have a dimension, for instance `VisitsSummary.get`. This is a fix as an invalid format was returned before see [#5951](https://github.com/piwik/piwik/issues/5951)

### Deprecations
The following events are considered as deprecated and the new structure should be used in the future. We have not scheduled when those events will be removed but probably in Piwik 3.0 which is not scheduled yet and won't be soon. New features will be added only to the new classes.
Expand Down
4 changes: 4 additions & 0 deletions plugins/API/RowEvolution.php
Original file line number Diff line number Diff line change
Expand Up @@ -331,6 +331,10 @@ private function getRowEvolutionMetaData($idSite, $period, $date, $apiModule, $a
$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');
Expand Down
44 changes: 44 additions & 0 deletions plugins/API/tests/RowEvolutionTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
<?php
/**
* Piwik - free/libre analytics platform
*
* @link http://piwik.org
* @license http://www.gnu.org/licenses/gpl-3.0.html GPL v3 or later
*/

namespace Piwik\Plugins\API\tests;
use Piwik\Plugins\API\RowEvolution;
use Piwik\Tests\Fixture;

/**
* @group API
* @group RowEvolutionTest
* @group Database
*/
class RowEvolutionTest extends \DatabaseTestCase
{

public function setUp()
{
parent::setUp();
Fixture::createWebsite('2014-01-01 00:00:00');
}

/**
* @expectedException \Exception
* @expectedExceptionMessage Reports like VisitsSummary.get which do not have a dimension are not supported by row evolution
*/
public function test_getRowEvolution_shouldTriggerAnException_IfReportHasNoDimension()
{
$rowEvolution = new RowEvolution();
$rowEvolution->getRowEvolution(1, 'day', 'last7', 'VisitsSummary', 'get');
}

public function test_getRowEvolution_shouldNotTriggerAnException_IfReportHasADimension()
{
$rowEvolution = new RowEvolution();
$table = $rowEvolution->getRowEvolution(1, 'day', 'last7', 'Actions', 'getPageUrls');
$this->assertNotEmpty($table);
}

}

0 comments on commit 3b962d9

Please sign in to comment.