fix:메뉴 동기화 동명 메뉴 중복 import 및 자기참조 방지
- filterMenusByName에서 children 제거하여 동명 메뉴 중복 import 방지 - importMenu에서 name+parent_id로 매칭하여 다른 계층 동명 메뉴 자기참조 방지 Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -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,
|
||||
|
||||
Reference in New Issue
Block a user