Skip to content

Commit

Permalink
Merge pull request #744 from nextcloud/fix/743
Browse files Browse the repository at this point in the history
fix: only return values that belong to a view after updating a row fr…
  • Loading branch information
Florian authored Dec 18, 2023
2 parents f95d83e + 7e90043 commit f055fd2
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 1 deletion.
22 changes: 22 additions & 0 deletions lib/Db/RowMapper.php
Original file line number Diff line number Diff line change
Expand Up @@ -402,4 +402,26 @@ public function countRows(int $tableId): int {
return 0;
}
}

/**
* @param int $id
* @param View $view
* @return Row
* @throws DoesNotExistException
* @throws Exception
* @throws MultipleObjectsReturnedException
*/
public function findByView(int $id, View $view): Row {
$qb = $this->db->getQueryBuilder();
$qb->select('t1.*')
->from($this->table, 't1')
->where($qb->expr()->eq('id', $qb->createNamedParameter($id, IQueryBuilder::PARAM_INT)));
$row = $this->findEntity($qb);

$row->setDataArray(array_filter($row->getDataArray(), function ($item) use ($view) {
return in_array($item['columnId'], $view->getColumnsArray());
}));

return $row;
}
}
13 changes: 12 additions & 1 deletion lib/Service/RowService.php
Original file line number Diff line number Diff line change
Expand Up @@ -345,11 +345,22 @@ public function updateSet(
$item->setLastEditBy($userId);
$item->setLastEditAt($time->format('Y-m-d H:i:s'));
try {
return $this->mapper->update($item);
$row = $this->mapper->update($item);
} catch (Exception $e) {
$this->logger->error($e->getMessage(), ['exception' => $e]);
throw new InternalError(get_class($this) . ' - ' . __FUNCTION__ . ': '.$e->getMessage());
}

if ($viewId) {
try {
$row = $this->mapper->findByView($row->getId(), $view);
} catch (DoesNotExistException|MultipleObjectsReturnedException|Exception $e) {
$this->logger->error($e->getMessage(), ['exception' => $e]);
throw new InternalError(get_class($this) . ' - ' . __FUNCTION__ . ': '.$e->getMessage());
}
}

return $row;
}

private function replaceOrAddData(array $dataArray, array $newDataObject): array {
Expand Down

0 comments on commit f055fd2

Please sign in to comment.