@@ -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