Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
- Fix PHP 8.4 deprecation warnings #534 @[robertoschwald](https://github.com/robertoschwald)
- date formatting on all rows
- fix double report execution after wizard close
- correct drilldown aggregation for numeric dimension indices

## 5.8.0 - 2025-07-29
### Added
Expand Down
4 changes: 2 additions & 2 deletions lib/Controller/DatasourceController.php
Original file line number Diff line number Diff line change
Expand Up @@ -302,8 +302,8 @@ private function aggregateData($data, $filter) {
$options = json_decode($filter, true);
if (isset($options['drilldown'])) {
// Sort the indices in descending order
$sortedIndices = array_keys($options['drilldown']);
rsort($sortedIndices);
$sortedIndices = array_keys($options['drilldown']);
rsort($sortedIndices, SORT_NUMERIC);

foreach ($sortedIndices as $removeIndex) {
$aggregatedData = [];
Expand Down
50 changes: 50 additions & 0 deletions tests/Controller/DatasourceControllerTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
<?php
namespace OCA\Analytics\Tests\Controller;

use OCA\Analytics\Controller\DatasourceController;
use OCA\Analytics\Tests\Stubs\FakeL10N;
use PHPUnit\Framework\TestCase;

class DatasourceControllerTest extends TestCase {
public function testAggregateDataRemovesColumnsUsingNumericSorting() {
$controller = new DatasourceController(
'analytics',
$this->createMock(\OCP\IRequest::class),
$this->createMock(\Psr\Log\LoggerInterface::class),
$this->createMock(\OCA\Analytics\Datasource\Github::class),
$this->createMock(\OCA\Analytics\Datasource\LocalCsv::class),
$this->createMock(\OCA\Analytics\Datasource\Regex::class),
$this->createMock(\OCA\Analytics\Datasource\ExternalJson::class),
$this->createMock(\OCA\Analytics\Datasource\LocalJson::class),
$this->createMock(\OCA\Analytics\Datasource\ExternalCsv::class),
$this->createMock(\OCA\Analytics\Datasource\LocalSpreadsheet::class),
new FakeL10N(),
$this->createMock(\OCP\EventDispatcher\IEventDispatcher::class),
$this->createMock(\OCP\IAppConfig::class)
);

$header = [];
$row1 = [];
$row2 = [];
for ($i = 0; $i <= 10; $i++) {
$header[] = 'col' . $i;
$row1[] = 'r1c' . $i;
$row2[] = 'r2c' . $i;
}
$header[] = 'Value';
$row1[] = 1;
$row2[] = 2;
$data = ['header' => $header, 'data' => [$row1, $row2]];

$filter = json_encode(['drilldown' => ['2' => true, '10' => true]]);
$reflection = new \ReflectionClass(DatasourceController::class);
$method = $reflection->getMethod('aggregateData');
$method->setAccessible(true);
$result = $method->invoke($controller, $data, $filter);

$this->assertSame('Value', end($result['header']));
$this->assertNotContains('col2', $result['header']);
$this->assertNotContains('col10', $result['header']);
$this->assertCount(10, $result['header']);
}
}