feat: 글로벌 메뉴 템플릿 복제 시스템 구현
- GlobalMenuTemplateSeeder 추가: 60개 메뉴 템플릿 생성 (tenant_id=NULL) - MenuBootstrapService.cloneGlobalMenusForTenant() 추가 - parent_id 매핑으로 계층 구조 유지 - DB 트랜잭션으로 원자성 보장 - RegisterService 업데이트: 신규 회원가입 시 메뉴 템플릿 복제 - 기존 225개 테넌트에 메뉴 일괄 복제 완료 - 테스트 완료: 회원가입 + 로그인 시 60개 메뉴 정상 반환
This commit is contained in:
@@ -11,11 +11,58 @@
|
||||
class MenuBootstrapService
|
||||
{
|
||||
/**
|
||||
* 테넌트를 위한 기본 메뉴 구조 생성
|
||||
* 글로벌 메뉴 템플릿을 테넌트에 복제
|
||||
*
|
||||
* @param int $tenantId 테넌트 ID
|
||||
* @return array 생성된 메뉴 ID 목록
|
||||
*/
|
||||
public static function cloneGlobalMenusForTenant(int $tenantId): array
|
||||
{
|
||||
return DB::transaction(function () use ($tenantId) {
|
||||
// 1. 글로벌 템플릿 메뉴 조회 (parent_id 순서대로 정렬)
|
||||
$templateMenus = Menu::withoutGlobalScopes()
|
||||
->whereNull('tenant_id')
|
||||
->orderByRaw('COALESCE(parent_id, 0)')
|
||||
->orderBy('sort_order')
|
||||
->get();
|
||||
|
||||
// 2. parent_id 매핑 테이블 생성
|
||||
$idMapping = [];
|
||||
$menuIds = [];
|
||||
|
||||
// 3. 계층 순서대로 복제 (parent → child)
|
||||
foreach ($templateMenus as $template) {
|
||||
$newMenu = Menu::create([
|
||||
'tenant_id' => $tenantId,
|
||||
'parent_id' => $template->parent_id
|
||||
? ($idMapping[$template->parent_id] ?? null)
|
||||
: null,
|
||||
'name' => $template->name,
|
||||
'url' => $template->url,
|
||||
'icon' => $template->icon,
|
||||
'sort_order' => $template->sort_order,
|
||||
'is_active' => $template->is_active,
|
||||
'hidden' => $template->hidden,
|
||||
'is_external' => $template->is_external,
|
||||
'external_url' => $template->external_url,
|
||||
]);
|
||||
|
||||
// 4. ID 매핑 저장
|
||||
$idMapping[$template->id] = $newMenu->id;
|
||||
$menuIds[] = $newMenu->id;
|
||||
}
|
||||
|
||||
return $menuIds;
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* 테넌트를 위한 기본 메뉴 구조 생성 (구버전 - 하위 호환성 유지)
|
||||
*
|
||||
* @deprecated Use cloneGlobalMenusForTenant() instead
|
||||
* @param int $tenantId 테넌트 ID
|
||||
* @return array 생성된 메뉴 ID 목록
|
||||
*/
|
||||
public static function createDefaultMenus(int $tenantId): array
|
||||
{
|
||||
return DB::transaction(function () use ($tenantId) {
|
||||
|
||||
Reference in New Issue
Block a user