From b8e96be56c11a2bf30e2db90db021c41a00c55a9 Mon Sep 17 00:00:00 2001 From: hskwon Date: Tue, 2 Dec 2025 22:55:10 +0900 Subject: [PATCH] =?UTF-8?q?refactor:=20=ED=9A=8C=EC=9B=90=EA=B0=80?= =?UTF-8?q?=EC=9E=85=20=EB=A9=94=EB=89=B4=20=EB=B3=B5=EC=82=AC=20=EB=A1=9C?= =?UTF-8?q?=EC=A7=81=EC=9D=84=20global=5Fmenus=20=ED=85=8C=EC=9D=B4?= =?UTF-8?q?=EB=B8=94=20=EA=B8=B0=EB=B0=98=EC=9C=BC=EB=A1=9C=20=EB=B3=80?= =?UTF-8?q?=EA=B2=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - MenuBootstrapService: menus → global_menus 테이블에서 조회 - MenusStep: 신규 테넌트 부트스트랩 시 global_menus 사용 - GlobalMenuTemplateSeeder: GlobalMenu 모델 사용으로 변경 --- app/Services/MenuBootstrapService.php | 19 +++++-------- .../TenantBootstrap/Steps/MenusStep.php | 16 ++++++++--- database/seeders/GlobalMenuTemplateSeeder.php | 28 +++++++++---------- 3 files changed, 32 insertions(+), 31 deletions(-) diff --git a/app/Services/MenuBootstrapService.php b/app/Services/MenuBootstrapService.php index c6fb55f..642996c 100644 --- a/app/Services/MenuBootstrapService.php +++ b/app/Services/MenuBootstrapService.php @@ -2,6 +2,7 @@ namespace App\Services; +use App\Models\Commons\GlobalMenu; use App\Models\Commons\Menu; use Illuminate\Support\Facades\DB; @@ -23,10 +24,8 @@ class MenuBootstrapService public static function cloneGlobalMenusForTenant(int $tenantId): array { return DB::transaction(function () use ($tenantId) { - // 1. 활성화된 글로벌 템플릿 메뉴 조회 (parent_id 순서대로 정렬) - $templateMenus = Menu::withoutGlobalScopes() - ->whereNull('tenant_id') - ->where('is_active', true) // 활성화된 메뉴만 복사 + // 1. 활성화된 글로벌 템플릿 메뉴 조회 (global_menus 테이블에서) + $templateMenus = GlobalMenu::where('is_active', true) // 활성화된 메뉴만 복사 ->orderByRaw('COALESCE(parent_id, 0)') ->orderBy('sort_order') ->get(); @@ -88,10 +87,8 @@ public static function cloneSingleMenu(int $globalMenuId, int $tenantId, ?int $n return null; } - // 글로벌 메뉴 조회 - $globalMenu = Menu::withoutGlobalScopes() - ->whereNull('tenant_id') - ->find($globalMenuId); + // 글로벌 메뉴 조회 (global_menus 테이블에서) + $globalMenu = GlobalMenu::find($globalMenuId); if (! $globalMenu) { return null; @@ -134,10 +131,8 @@ public static function cloneMenuWithChildren(int $globalMenuId, int $tenantId, ? } $menuIds[] = $rootMenu->id; - // 2. 하위 메뉴 재귀 복제 - $children = Menu::withoutGlobalScopes() - ->whereNull('tenant_id') - ->where('parent_id', $globalMenuId) + // 2. 하위 메뉴 재귀 복제 (global_menus 테이블에서) + $children = GlobalMenu::where('parent_id', $globalMenuId) ->where('is_active', true) ->orderBy('sort_order') ->get(); diff --git a/app/Services/TenantBootstrap/Steps/MenusStep.php b/app/Services/TenantBootstrap/Steps/MenusStep.php index 235f748..ca1e022 100644 --- a/app/Services/TenantBootstrap/Steps/MenusStep.php +++ b/app/Services/TenantBootstrap/Steps/MenusStep.php @@ -24,10 +24,16 @@ public function run(int $tenantId): void return; } - // Get all global menus ordered by parent_id, sort_order + // Check if global_menus table exists + if (! DB::getSchemaBuilder()->hasTable('global_menus')) { + return; + } + + // Get all global menus from global_menus table ordered by parent_id, sort_order // Order by: root menus first (parent_id IS NULL), then by parent_id ASC, then sort_order ASC - $globalMenus = DB::table('menus') - ->whereNull('tenant_id') + $globalMenus = DB::table('global_menus') + ->whereNull('deleted_at') + ->where('is_active', true) ->orderByRaw('parent_id IS NULL DESC, parent_id ASC, sort_order ASC') ->get(); @@ -44,16 +50,18 @@ public function run(int $tenantId): void $newParentId = $parentIdMap[$menu->parent_id]; } - // Insert new menu for tenant + // Insert new menu for tenant with global_menu_id reference $newId = DB::table('menus')->insertGetId([ 'tenant_id' => $tenantId, 'parent_id' => $newParentId, + 'global_menu_id' => $menu->id, // global_menus 테이블의 ID 참조 'name' => $menu->name, 'icon' => $menu->icon ?? null, 'url' => $menu->url ?? null, 'sort_order' => $menu->sort_order ?? 0, 'is_active' => $menu->is_active ?? 1, 'hidden' => $menu->hidden ?? 0, + 'is_customized' => false, // 원본 상태 'is_external' => $menu->is_external ?? 0, 'external_url' => $menu->external_url ?? null, 'created_at' => now(), diff --git a/database/seeders/GlobalMenuTemplateSeeder.php b/database/seeders/GlobalMenuTemplateSeeder.php index 38ef304..fdfa609 100644 --- a/database/seeders/GlobalMenuTemplateSeeder.php +++ b/database/seeders/GlobalMenuTemplateSeeder.php @@ -2,14 +2,14 @@ namespace Database\Seeders; -use App\Models\Commons\Menu; +use App\Models\Commons\GlobalMenu; use Illuminate\Database\Seeder; use Illuminate\Support\Facades\DB; class GlobalMenuTemplateSeeder extends Seeder { /** - * 글로벌 메뉴 템플릿 시딩 (tenant_id = NULL) + * 글로벌 메뉴 템플릿 시딩 (global_menus 테이블) * mes_react App.tsx의 SystemAdmin 메뉴 구조 기반 */ public function run(): void @@ -227,38 +227,36 @@ public function run(): void ], ]; - // 메뉴 생성 + // 메뉴 생성 (global_menus 테이블에 저장) foreach ($menus as $menuData) { $children = $menuData['children'] ?? null; unset($menuData['children']); - // 최상위 메뉴 생성 (tenant_id = null) - $parentMenu = Menu::create([ - 'tenant_id' => null, + // 최상위 메뉴 생성 (global_menus 테이블) + $parentMenu = GlobalMenu::create([ 'parent_id' => null, 'name' => $menuData['name'], 'url' => $menuData['url'], 'icon' => $menuData['icon'], 'sort_order' => $menuData['sort_order'], - 'is_active' => 1, - 'hidden' => 0, - 'is_external' => 0, + 'is_active' => true, + 'hidden' => false, + 'is_external' => false, 'external_url' => null, ]); // 하위 메뉴 생성 if ($children) { foreach ($children as $index => $childData) { - Menu::create([ - 'tenant_id' => null, + GlobalMenu::create([ 'parent_id' => $parentMenu->id, 'name' => $childData['name'], 'url' => $childData['url'], 'icon' => $childData['icon'], 'sort_order' => $index + 1, - 'is_active' => 1, - 'hidden' => 0, - 'is_external' => 0, + 'is_active' => true, + 'hidden' => false, + 'is_external' => false, 'external_url' => null, ]); } @@ -266,6 +264,6 @@ public function run(): void } }); - $this->command->info('✅ 글로벌 메뉴 템플릿 생성 완료 (약 60개 메뉴 항목)'); + $this->command->info('✅ 글로벌 메뉴 템플릿 생성 완료 (global_menus 테이블, 약 60개 항목)'); } }