From 1ed2b3d91a2285290436fd0220c9e9ea7b1885a3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EA=B6=8C=ED=98=81=EC=84=B1?= Date: Fri, 13 Feb 2026 03:41:19 +0900 Subject: [PATCH] =?UTF-8?q?fix:=EB=A9=94=EB=89=B4=20=EB=8F=99=EA=B8=B0?= =?UTF-8?q?=ED=99=94=20=EB=8F=99=EB=AA=85=20=EB=A9=94=EB=89=B4=20=EC=A4=91?= =?UTF-8?q?=EB=B3=B5=20import=20=EB=B0=8F=20=EC=9E=90=EA=B8=B0=EC=B0=B8?= =?UTF-8?q?=EC=A1=B0=20=EB=B0=A9=EC=A7=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - filterMenusByName에서 children 제거하여 동명 메뉴 중복 import 방지 - importMenu에서 name+parent_id로 매칭하여 다른 계층 동명 메뉴 자기참조 방지 Co-Authored-By: Claude Opus 4.6 --- app/Http/Controllers/MenuSyncController.php | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/app/Http/Controllers/MenuSyncController.php b/app/Http/Controllers/MenuSyncController.php index fcdbb680..389fa1ea 100644 --- a/app/Http/Controllers/MenuSyncController.php +++ b/app/Http/Controllers/MenuSyncController.php @@ -450,16 +450,20 @@ private function filterMenusByName(array $menus, array $names, ?string $parentNa { $result = []; foreach ($menus as $menu) { + $originalChildren = $menu['children'] ?? []; + if (in_array($menu['name'], $names)) { - // 부모 이름 추가 $menu['parent_name'] = $parentName; + // children은 flat list에서 개별 처리되므로 제거 (동명 메뉴 중복 import 방지) + $menu['children'] = []; $result[] = $menu; } - if (! empty($menu['children'])) { - // 현재 메뉴를 부모로 전달 - $result = array_merge($result, $this->filterMenusByName($menu['children'], $names, $menu['name'])); + + if (! empty($originalChildren)) { + $result = array_merge($result, $this->filterMenusByName($originalChildren, $names, $menu['name'])); } } + return $result; } @@ -477,14 +481,14 @@ private function importMenu(array $data, ?int $parentId = null): void $parentId = $parent?->id; } - // 기존 메뉴 찾기 또는 생성 + // name + parent_id로 매칭 (동명 메뉴가 다른 계층에 있을 때 자기참조 방지) $menu = Menu::withoutGlobalScopes()->updateOrCreate( [ 'tenant_id' => $this->getTenantId(), 'name' => $data['name'], + 'parent_id' => $parentId, ], [ - 'parent_id' => $parentId, 'url' => $data['url'], 'icon' => $data['icon'] ?? null, 'sort_order' => $data['sort_order'] ?? 0,