fix:서버 메뉴 이름 불일치 보정 시더 추가
서버 DB의 메뉴 이름(미수금 관리, 미지급금 관리, 환불/해지 관리)이 로컬과 달라 이동되지 않은 3개 메뉴를 고객/거래처/채권관리로 이동 Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
107
database/seeders/FixServerMenuSeeder.php
Normal file
107
database/seeders/FixServerMenuSeeder.php
Normal file
@@ -0,0 +1,107 @@
|
||||
<?php
|
||||
|
||||
namespace Database\Seeders;
|
||||
|
||||
use App\Models\Commons\Menu;
|
||||
use Illuminate\Database\Seeder;
|
||||
|
||||
class FixServerMenuSeeder extends Seeder
|
||||
{
|
||||
public function run(): void
|
||||
{
|
||||
$tenantId = 1;
|
||||
|
||||
// 고객/거래처/채권관리 그룹 찾기
|
||||
$targetGroup = Menu::withoutGlobalScopes()
|
||||
->where('tenant_id', $tenantId)
|
||||
->where('name', '고객/거래처/채권관리')
|
||||
->whereNull('parent_id')
|
||||
->first();
|
||||
|
||||
if (!$targetGroup) {
|
||||
$this->command->error('고객/거래처/채권관리 그룹을 찾을 수 없습니다.');
|
||||
return;
|
||||
}
|
||||
|
||||
$this->command->info("대상 그룹: 고객/거래처/채권관리 (id: {$targetGroup->id})");
|
||||
|
||||
// 서버에서 실제 메뉴 이름으로 이동 (로컬과 서버 모두 대응)
|
||||
$menuMoves = [
|
||||
// [검색 이름들, 새 이름, sort_order]
|
||||
[['채권관리', '미수금 관리', '미수금관리'], '미수금관리', 3],
|
||||
[['채무관리', '미지급금 관리', '미지급금관리'], '미지급금관리', 4],
|
||||
[['환불관리', '환불/해지 관리', '환불/해지관리'], '환불/해지관리', 5],
|
||||
];
|
||||
|
||||
foreach ($menuMoves as [$searchNames, $newName, $sortOrder]) {
|
||||
$menu = null;
|
||||
foreach ($searchNames as $name) {
|
||||
$menu = Menu::withoutGlobalScopes()
|
||||
->where('tenant_id', $tenantId)
|
||||
->where('name', $name)
|
||||
->where('is_active', true)
|
||||
->first();
|
||||
if ($menu) break;
|
||||
}
|
||||
|
||||
if (!$menu) {
|
||||
// 이미 이동된 경우 확인
|
||||
$existing = Menu::withoutGlobalScopes()
|
||||
->where('tenant_id', $tenantId)
|
||||
->where('parent_id', $targetGroup->id)
|
||||
->where('name', $newName)
|
||||
->first();
|
||||
|
||||
if ($existing) {
|
||||
$this->command->info(" 이미 이동됨: {$newName} (id: {$existing->id})");
|
||||
} else {
|
||||
$this->command->warn(" 메뉴 없음: " . implode(' / ', $searchNames));
|
||||
}
|
||||
continue;
|
||||
}
|
||||
|
||||
$menu->update([
|
||||
'parent_id' => $targetGroup->id,
|
||||
'sort_order' => $sortOrder,
|
||||
'name' => $newName,
|
||||
]);
|
||||
$this->command->info(" 이동: {$menu->getOriginal('name')} → 고객/거래처/채권관리/{$newName} (sort: {$sortOrder})");
|
||||
}
|
||||
|
||||
// 재무관리 부모 비활성화 (자식 없으면)
|
||||
$financeParent = Menu::withoutGlobalScopes()
|
||||
->where('tenant_id', $tenantId)
|
||||
->where('name', '재무관리')
|
||||
->whereNull('parent_id')
|
||||
->first();
|
||||
|
||||
if ($financeParent) {
|
||||
$remaining = Menu::withoutGlobalScopes()
|
||||
->where('tenant_id', $tenantId)
|
||||
->where('parent_id', $financeParent->id)
|
||||
->where('is_active', true)
|
||||
->count();
|
||||
|
||||
if ($remaining === 0) {
|
||||
$financeParent->update(['is_active' => false]);
|
||||
$this->command->info(" 비활성화: 재무관리 (id: {$financeParent->id})");
|
||||
} else {
|
||||
$this->command->warn(" 재무관리 자식 {$remaining}개 남음 - 비활성화 안 함");
|
||||
}
|
||||
}
|
||||
|
||||
// 결과 확인
|
||||
$this->command->info('');
|
||||
$this->command->info('=== 고객/거래처/채권관리 최종 구성 ===');
|
||||
$children = Menu::withoutGlobalScopes()
|
||||
->where('tenant_id', $tenantId)
|
||||
->where('parent_id', $targetGroup->id)
|
||||
->where('is_active', true)
|
||||
->orderBy('sort_order')
|
||||
->get(['name', 'url', 'sort_order']);
|
||||
|
||||
foreach ($children as $child) {
|
||||
$this->command->info(" {$child->sort_order}. {$child->name} → {$child->url}");
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user