Skip to content

Commit 9ebf499

Browse files
committed
Enhancement: Update rows via import (code review fixes)
Signed-off-by: Kostiantyn Miakshyn <[email protected]>
1 parent eb27c2f commit 9ebf499

File tree

4 files changed

+13
-11
lines changed

4 files changed

+13
-11
lines changed

lib/Controller/Api1Controller.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1282,7 +1282,7 @@ public function updateRow(int $rowId, ?int $viewId, $data): DataResponse {
12821282
}
12831283

12841284
try {
1285-
return new DataResponse($this->rowService->updateSet($rowId, $viewId, $dataNew, $this->userId)->jsonSerialize());
1285+
return new DataResponse($this->rowService->updateSet($rowId, $viewId, $dataNew, $this->userId, null)->jsonSerialize());
12861286
} catch (InternalError $e) {
12871287
$this->logger->error('An internal error or exception occurred: ' . $e->getMessage(), ['exception' => $e]);
12881288
$message = ['message' => $e->getMessage()];

lib/Controller/RowController.php

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ public function update(
7474
$columnId,
7575
$data
7676
) {
77-
return $this->service->updateSet($id, $viewId, ['columnId' => $columnId, 'value' => $data], $this->userId);
77+
return $this->service->updateSet($id, $viewId, ['columnId' => $columnId, 'value' => $data], $this->userId, null);
7878
});
7979
}
8080

@@ -83,18 +83,13 @@ public function updateSet(
8383
int $id,
8484
?int $viewId,
8585
array $data,
86-
8786
): DataResponse {
8887
return $this->handleError(function () use (
8988
$id,
9089
$viewId,
9190
$data
9291
) {
93-
return $this->service->updateSet(
94-
$id,
95-
$viewId,
96-
$data,
97-
$this->userId);
92+
return $this->service->updateSet($id, $viewId, $data, $this->userId, null);
9893
});
9994
}
10095

lib/Service/ImportService.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -462,7 +462,7 @@ private function upsertRow(Row $row): void {
462462

463463
if ($id) {
464464
try {
465-
$this->rowService->updateSet($id, $this->viewId, $data, $this->userId);
465+
$this->rowService->updateSet($id, $this->viewId, $data, $this->userId, $this->tableId);
466466
$this->countUpdatedRows++;
467467
return;
468468
} catch (\Throwable $e) {

lib/Service/RowService.php

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -383,6 +383,7 @@ public function updateSet(
383383
?int $viewId,
384384
array $data,
385385
string $userId,
386+
?int $tableId,
386387
): Row2 {
387388
try {
388389
$item = $this->getRowById($id);
@@ -432,8 +433,14 @@ public function updateSet(
432433
throw new InternalError(get_class($this) . ' - ' . __FUNCTION__ . ': ' . $e->getMessage());
433434
}
434435
} else {
435-
// if no view id is set, we assume a table and take the tableId from the row
436-
$tableId = $item->getTableId();
436+
if ($tableId === null) {
437+
$tableId = $item->getTableId();
438+
}
439+
if ($tableId !== $item->getTableId()) {
440+
$e = new \Exception('Row does not belong to table with id ' . $tableId);
441+
$this->logger->error($e->getMessage(), ['exception' => $e]);
442+
throw new InternalError(get_class($this) . ' - ' . __FUNCTION__ . ': ' . $e->getMessage());
443+
}
437444

438445
// security
439446
if (!$this->permissionsService->canReadRowsByElementId($item->getTableId(), 'table', $userId)) {

0 commit comments

Comments
 (0)