Skip to content

Commit a739c36

Browse files
committed
update column ids for table view
1 parent 89dd08b commit a739c36

File tree

2 files changed

+19
-11
lines changed

2 files changed

+19
-11
lines changed

lib/Service/ViewService.php

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -615,16 +615,16 @@ public function addColumnToView(View $view, Column $column, ?string $userId = nu
615615
}
616616

617617
/**
618-
* @param Table $table
618+
* @param int $tableId
619619
* @param array $view
620620
*
621-
* @return Table
621+
* @return void
622622
*
623623
* @throws InternalError
624624
*/
625-
public function importView(Table $table, array $view): View {
625+
public function importView(int $tableId, array $view): void {
626626
$item = new View();
627-
$item->setTableId($table->getId());
627+
$item->setTableId($tableId);
628628
$item->setTitle($view['title']);
629629
$item->setEmoji($view['emoji']);
630630
$item->setCreatedBy($view['createdBy']);
@@ -641,6 +641,5 @@ public function importView(Table $table, array $view): View {
641641
$this->logger->error('userMigrationImport insert error: ' . $e->getMessage());
642642
throw new InternalError('userMigrationImport insert error: ' . $e->getMessage());
643643
}
644-
return $newView;
645644
}
646645
}

lib/TablesMigrator.php

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -240,7 +240,6 @@ public function import(
240240
foreach ($tables as $table) {
241241
$newTable = $this->tableService->importTable($table);
242242

243-
$this->importViews($importSource, $newTable, $table, $this->viewService);
244243
$this->importFavorites($importSource, $newTable, $table, $this->favoritesService);
245244

246245
$columnIdMap = $this->importColumns($importSource, $newTable, $table, $this->columnService, $columnIdMap);
@@ -250,6 +249,7 @@ public function import(
250249
$tableIdMap[$table['id']] = $newTable->getId();
251250
}
252251

252+
$this->importViews($importSource, $tableIdMap, $columnIdMap, $this->viewService);
253253
$this->importShares($importSource, $tableIdMap, $contextIdMap);
254254

255255
$this->importRowCells(
@@ -353,18 +353,27 @@ private function importRowCells(array $data, array $rowIdMap, array $columnIdMap
353353

354354
/**
355355
* @param IImportSource $importSource
356-
* @param Table $newTable
357-
* @param array $table
356+
* @param array $tableIdMap
357+
* @param array $columnIdMap
358358
* @param ViewService $viewService
359359
*
360360
* @return void
361361
*/
362-
private function importViews($importSource, $newTable, $table, &$viewService): void
362+
private function importViews($importSource, array $tableIdMap, array $columnIdMap, &$viewService): void
363363
{
364364
$views = json_decode($importSource->getFileContents(self::FILE_VIEWS), true, self::JSON_DEPTH, self::JSON_OPTIONS);
365365
foreach ($views as $view) {
366-
if ($table['id'] === $view['tableId']) {
367-
$viewService->importView($newTable, $view);
366+
if (isset($tableIdMap[$view['tableId']])) {
367+
$newTableId = $tableIdMap[$view['tableId']];
368+
if (isset($view['columnSettings']) && is_array($view['columnSettings'])) {
369+
foreach ($view['columnSettings'] as &$setting) {
370+
if (isset($setting['columnId']) && isset($columnIdMap[$setting['columnId']])) {
371+
$setting['columnId'] = $columnIdMap[$setting['columnId']];
372+
}
373+
}
374+
unset($setting);
375+
}
376+
$viewService->importView($newTableId, $view);
368377
}
369378
}
370379
}

0 commit comments

Comments
 (0)