fix: fallback site menu mt_idx when mapping is inconsistent

When site menu resolves to an id with no rows, retry with legacy site mt_idx=4 and surface fallback state in debug output.

Made-with: Cursor
This commit is contained in:
taekyoungc
2026-04-08 17:26:04 +09:00
parent f68f135446
commit b99c108aeb
2 changed files with 23 additions and 5 deletions

View File

@@ -33,7 +33,10 @@ class Menu extends BaseController
$requestedMtIdx = (int) ($this->request->getGet('mt_idx') ?? 0); $requestedMtIdx = (int) ($this->request->getGet('mt_idx') ?? 0);
$mtIdx = $this->resolveMtIdx($requestedMtIdx, $types); $mtIdx = $this->resolveMtIdx($requestedMtIdx, $types);
$debugMode = $this->request->getGet('debug') === '1'; $debugMode = $this->request->getGet('debug') === '1';
$fallbackApplied = false;
$list = $mtIdx > 0 ? $this->menuModel->getAllByType($mtIdx, $lgIdx) : []; $list = $mtIdx > 0 ? $this->menuModel->getAllByType($mtIdx, $lgIdx) : [];
$currentType = $mtIdx > 0 ? $this->typeModel->find($mtIdx) : null;
$currentTypeCode = (string) ($currentType->mt_code ?? '');
// 현재 지자체에 메뉴가 없으면, mt_idx별로 기본 지자체(lg_idx=1)의 메뉴를 한 번 복사한다. // 현재 지자체에 메뉴가 없으면, mt_idx별로 기본 지자체(lg_idx=1)의 메뉴를 한 번 복사한다.
if ($mtIdx > 0 && empty($list)) { if ($mtIdx > 0 && empty($list)) {
@@ -41,20 +44,33 @@ class Menu extends BaseController
$list = $this->menuModel->getAllByType($mtIdx, $lgIdx); $list = $this->menuModel->getAllByType($mtIdx, $lgIdx);
} }
// 운영 DB 불일치 대응: site 타입인데 mt_idx 매핑이 어긋난 경우(예: menu_type=2, menu는 4 사용)
if (empty($list) && $currentTypeCode === 'site' && $mtIdx !== 4) {
$fallbackMtIdx = 4;
$fallbackList = $this->menuModel->getAllByType($fallbackMtIdx, $lgIdx);
if (empty($fallbackList)) {
$this->menuModel->copyDefaultsFromLg($fallbackMtIdx, 1, $lgIdx);
$fallbackList = $this->menuModel->getAllByType($fallbackMtIdx, $lgIdx);
}
if (! empty($fallbackList)) {
$mtIdx = $fallbackMtIdx;
$list = $fallbackList;
$fallbackApplied = true;
}
}
// 트리 순서대로 상위 메뉴 바로 아래에 하위 메뉴가 오도록 평탄화 // 트리 순서대로 상위 메뉴 바로 아래에 하위 메뉴가 오도록 평탄화
if (! empty($list)) { if (! empty($list)) {
$tree = build_menu_tree($list); $tree = build_menu_tree($list);
$list = flatten_menu_tree($tree); $list = flatten_menu_tree($tree);
} }
$currentType = $mtIdx > 0 ? $this->typeModel->find($mtIdx) : null;
return view('admin/layout', [ return view('admin/layout', [
'title' => '메뉴 관리', 'title' => '메뉴 관리',
'content' => view('admin/menu/index', [ 'content' => view('admin/menu/index', [
'types' => $types, 'types' => $types,
'mtIdx' => $mtIdx, 'mtIdx' => $mtIdx,
'mtCode' => $currentType->mt_code ?? '', 'mtCode' => $currentTypeCode,
'list' => $list, 'list' => $list,
'levelNames' => config('Roles')->levelNames, 'levelNames' => config('Roles')->levelNames,
'debug_mode' => $debugMode, 'debug_mode' => $debugMode,
@@ -62,8 +78,9 @@ class Menu extends BaseController
'lg_idx' => $lgIdx, 'lg_idx' => $lgIdx,
'requested_mt_idx' => $requestedMtIdx, 'requested_mt_idx' => $requestedMtIdx,
'resolved_mt_idx' => $mtIdx, 'resolved_mt_idx' => $mtIdx,
'resolved_mt_code' => (string) ($currentType->mt_code ?? ''), 'resolved_mt_code' => $currentTypeCode,
'list_count' => count($list), 'list_count' => count($list),
'fallback_applied' => $fallbackApplied ? 'Y' : 'N',
], ],
]), ]),
]); ]);

View File

@@ -53,7 +53,8 @@ $adminMenuListResolveHref = static function (string $rawLink) use ($adminMenusNa
requested_mt_idx=<?= esc((string) ($debugInfo['requested_mt_idx'] ?? '')) ?>, requested_mt_idx=<?= esc((string) ($debugInfo['requested_mt_idx'] ?? '')) ?>,
resolved_mt_idx=<?= esc((string) ($debugInfo['resolved_mt_idx'] ?? '')) ?>, resolved_mt_idx=<?= esc((string) ($debugInfo['resolved_mt_idx'] ?? '')) ?>,
resolved_mt_code=<?= esc((string) ($debugInfo['resolved_mt_code'] ?? '')) ?>, resolved_mt_code=<?= esc((string) ($debugInfo['resolved_mt_code'] ?? '')) ?>,
list_count=<?= esc((string) ($debugInfo['list_count'] ?? '')) ?> list_count=<?= esc((string) ($debugInfo['list_count'] ?? '')) ?>,
fallback_applied=<?= esc((string) ($debugInfo['fallback_applied'] ?? 'N')) ?>
</section> </section>
<?php endif; ?> <?php endif; ?>