Skip to content

Commit

Permalink
empty columns (e.g. manual input) need to be handled as null during d…
Browse files Browse the repository at this point in the history
…atabase update
  • Loading branch information
Rello committed Jan 10, 2025
1 parent c41f172 commit ec8e605
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 5 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
### Fixed
- calculated columns: correct percentage formula in total row
- report copy is not taking over all properties
- empty columns (e.g. manual input) need to be handled as null during database update

## 5.2.2 - 2025-01-05
### Added
Expand Down
13 changes: 9 additions & 4 deletions lib/Db/StorageMapper.php
Original file line number Diff line number Diff line change
Expand Up @@ -84,11 +84,16 @@ public function create(int $datasetId, $dimension1, $dimension2, $value, string
$sql->update(self::TABLE_NAME)
->set('timestamp', $sql->createNamedParameter($timestamp))
->where($sql->expr()->eq('user_id', $sql->createNamedParameter($this->userId)))
->andWhere($sql->expr()->eq('dataset', $sql->createNamedParameter($datasetId)))
->andWhere($sql->expr()->eq('dimension1', $sql->createNamedParameter($dimension1)))
->andWhere($sql->expr()->eq('dimension2', $sql->createNamedParameter($dimension2)));
->andWhere($sql->expr()->eq('dataset', $sql->createNamedParameter($datasetId)));

// if the dimension value is null, a different where clause is required
$expression1 = $dimension1 === null ? $sql->expr()->isNull('dimension1') : $sql->expr()->eq('dimension1', $sql->createNamedParameter($dimension1));
$expression2 = $dimension2 === null ? $sql->expr()->isNull('dimension2') : $sql->expr()->eq('dimension2', $sql->createNamedParameter($dimension2));

$sql->andWhere($expression1)
->andWhere($expression2);

if ($aggregation === 'xxsummation') {
if ($aggregation === 'xxsummation') {
// Feature not yet available
// $this->logger->error('old value: ' . $result['value']);
// $this->logger->error('new value: ' . $value + $result['value']);
Expand Down
4 changes: 3 additions & 1 deletion lib/Service/DataloadService.php
Original file line number Diff line number Diff line change
Expand Up @@ -232,7 +232,9 @@ public function execute(int $dataloadId)
$error = $error + 1;
continue;
}
// if data source only delivers 2 columns, the value needs to be in the last one
$this->logger->info('before: ' .$row[0]. '_' . $row[1]. '_' . $row[2]);
// if data source only delivers 2 columns, the value is moved to the last one
// resulting in xxx, null , 123
if (count($row) === 2) {
$row[2] = $row[1];
$row[1] = null;
Expand Down
4 changes: 4 additions & 0 deletions lib/Service/StorageService.php
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,10 @@ public function update(
$dimension1 = $this->VariableService->replaceTextVariablesSingle($dimension1);
$dimension2 = $this->VariableService->replaceTextVariablesSingle($dimension2);

// in case a dimension is empty (e.g. manual data input), we properly null it as also null is coming from data loads
$dimension1 = $dimension1 === '' ? null : $dimension1;
$dimension2 = $dimension2 === '' ? null : $dimension2;

if ($value !== false) {
try {
$action = $this->StorageMapper->create($datasetId, $dimension1, $dimension2, $value, $user_id, null, $bulkInsert, $aggregation);
Expand Down

0 comments on commit ec8e605

Please sign in to comment.