Compare commits

..

9 Commits

Author SHA1 Message Date
taekyoungc
8753b1aa68 chore: add db diagnostic mode on packaging units page
Expose a temporary db_diag=1 view for /bag/packaging-units so we can verify runtime DB connectivity and required table counts directly on production.
2026-04-09 12:39:09 +09:00
taekyoungc
aa50eb72ee fix: add runtime logging for code-kind lookup failures
Capture detailed runtime context when /bag/code-kinds and /bag/code-details fail so production logs reveal the exact exception source and request/session scope.
2026-04-09 12:20:35 +09:00
taekyoungc
7580c31ab0 fix: restore site nav rendering with menu type fallback
Fallback to legacy site mt_idx=4 when site menu type mapping is inconsistent or missing so top navigation renders on trash.wxn.co.kr.

Made-with: Cursor
2026-04-08 17:31:55 +09:00
taekyoungc
6fddf15000 fix: keep selected menu type while applying site fallback
Preserve the selected site mt_idx in the UI and use a separate effective mt_idx for data fallback, so choosing site no longer appears as admin.

Made-with: Cursor
2026-04-08 17:29:40 +09:00
taekyoungc
b99c108aeb 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
2026-04-08 17:26:04 +09:00
taekyoungc
f68f135446 chore: add temporary menu debug diagnostics
Show current lg_idx and resolved menu type values on admin menu page when debug=1 to diagnose empty menu rendering.

Made-with: Cursor
2026-04-08 17:23:10 +09:00
taekyoungc
0d512bd21d fix: normalize legacy menu type query parameter
Map legacy /admin/menus?mt_idx=2 requests to the actual site menu type id and apply the same normalization to JSON list responses.

Made-with: Cursor
2026-04-08 17:14:19 +09:00
taekyoungc
12cd052c40 chore: revert logo label suffix
Remove the temporary "1" suffix from the header brand label and title.

Made-with: Cursor
2026-04-08 15:52:47 +09:00
taekyoungc
aaf7b4c66e chore: update dashboard logo label text
Append "1" to the bag dashboard logo-adjacent "종량제 시스템" label across dashboard variants for consistent UI wording.

Made-with: Cursor
2026-04-08 15:51:08 +09:00
5 changed files with 202 additions and 35 deletions

View File

@@ -30,18 +30,34 @@ class Menu extends BaseController
->with('error', '메뉴를 관리하려면 먼저 지자체를 선택하세요.'); ->with('error', '메뉴를 관리하려면 먼저 지자체를 선택하세요.');
} }
$types = $this->typeModel->orderBy('mt_sort', 'ASC')->findAll(); $types = $this->typeModel->orderBy('mt_sort', 'ASC')->findAll();
$mtIdx = (int) ($this->request->getGet('mt_idx') ?? 0); $requestedMtIdx = (int) ($this->request->getGet('mt_idx') ?? 0);
if ($mtIdx <= 0 && ! empty($types)) { $mtIdx = $this->resolveMtIdx($requestedMtIdx, $types);
// 기본 선택: 사이트 메뉴(mt_code=site), 없으면 첫 번째 타입 $effectiveMtIdx = $mtIdx;
$siteType = $this->typeModel->where('mt_code', 'site')->first(); $debugMode = $this->request->getGet('debug') === '1';
$mtIdx = $siteType ? (int) $siteType->mt_idx : (int) $types[0]->mt_idx; $fallbackApplied = false;
} $list = $effectiveMtIdx > 0 ? $this->menuModel->getAllByType($effectiveMtIdx, $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 ($effectiveMtIdx > 0 && empty($list)) {
$this->menuModel->copyDefaultsFromLg($mtIdx, 1, $lgIdx); $this->menuModel->copyDefaultsFromLg($effectiveMtIdx, 1, $lgIdx);
$list = $this->menuModel->getAllByType($mtIdx, $lgIdx); $list = $this->menuModel->getAllByType($effectiveMtIdx, $lgIdx);
}
// 운영 DB 불일치 대응: site 타입인데 mt_idx 매핑이 어긋난 경우(예: menu_type=2, menu는 4 사용)
if (empty($list) && $currentTypeCode === 'site' && $effectiveMtIdx !== 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)) {
$effectiveMtIdx = $fallbackMtIdx;
$list = $fallbackList;
$fallbackApplied = true;
}
} }
// 트리 순서대로 상위 메뉴 바로 아래에 하위 메뉴가 오도록 평탄화 // 트리 순서대로 상위 메뉴 바로 아래에 하위 메뉴가 오도록 평탄화
@@ -50,16 +66,24 @@ class Menu extends BaseController
$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_info' => [
'lg_idx' => $lgIdx,
'requested_mt_idx' => $requestedMtIdx,
'resolved_mt_idx' => $mtIdx,
'effective_mt_idx' => $effectiveMtIdx,
'resolved_mt_code' => $currentTypeCode,
'list_count' => count($list),
'fallback_applied' => $fallbackApplied ? 'Y' : 'N',
],
]), ]),
]); ]);
} }
@@ -73,7 +97,9 @@ class Menu extends BaseController
if ($lgIdx === null) { if ($lgIdx === null) {
return $this->response->setJSON(['status' => 0, 'msg' => '지자체를 선택하세요.']); return $this->response->setJSON(['status' => 0, 'msg' => '지자체를 선택하세요.']);
} }
$mtIdx = (int) $this->request->getGet('mt_idx'); $types = $this->typeModel->orderBy('mt_sort', 'ASC')->findAll();
$requestedMtIdx = (int) $this->request->getGet('mt_idx');
$mtIdx = $this->resolveMtIdx($requestedMtIdx, $types);
if ($mtIdx <= 0) { if ($mtIdx <= 0) {
return $this->response->setJSON(['status' => 0, 'msg' => 'mt_idx required']); return $this->response->setJSON(['status' => 0, 'msg' => 'mt_idx required']);
} }
@@ -210,4 +236,34 @@ class Menu extends BaseController
return implode(',', array_values($levels)); return implode(',', array_values($levels));
} }
/**
* 요청된 mt_idx를 현재 DB 상태에 맞게 보정.
* - 유효한 mt_idx면 그대로 사용
* - 레거시 site 값(2) 요청 시 site 타입의 실제 mt_idx로 치환
* - 그 외 미지정/잘못된 값은 site 우선, 없으면 첫 타입으로 보정
*
* @param array<int,object> $types
*/
private function resolveMtIdx(int $requestedMtIdx, array $types): int
{
if (empty($types)) {
return 0;
}
$validTypeIds = array_map(static fn ($t): int => (int) ($t->mt_idx ?? 0), $types);
if ($requestedMtIdx > 0 && in_array($requestedMtIdx, $validTypeIds, true)) {
return $requestedMtIdx;
}
$siteType = $this->typeModel->where('mt_code', 'site')->first();
if ($siteType !== null) {
// 과거 링크(/admin/menus?mt_idx=2) 호환
if ($requestedMtIdx === 2 || $requestedMtIdx <= 0 || ! in_array($requestedMtIdx, $validTypeIds, true)) {
return (int) $siteType->mt_idx;
}
}
return (int) $types[0]->mt_idx;
}
} }

View File

@@ -331,6 +331,7 @@ class Bag extends BaseController
{ {
$lgIdx = $this->lgIdx(); $lgIdx = $this->lgIdx();
$packagingUnits = []; $packagingUnits = [];
$dbDiag = null;
if ($lgIdx) { if ($lgIdx) {
try { try {
$packagingUnits = model(PackagingUnitModel::class)->where('pu_lg_idx', $lgIdx)->orderBy('pu_bag_code', 'ASC')->findAll(); $packagingUnits = model(PackagingUnitModel::class)->where('pu_lg_idx', $lgIdx)->orderBy('pu_bag_code', 'ASC')->findAll();
@@ -339,7 +340,34 @@ class Bag extends BaseController
} }
} }
return $this->render('포장 단위', 'bag/packaging_units', ['packagingUnits' => $packagingUnits]); if ($this->request->getGet('db_diag') === '1') {
$dbDiag = [
'lg_idx' => $lgIdx,
'db_name' => null,
'packaging_unit' => null,
'code_kind' => null,
'code_detail' => null,
'error' => null,
];
try {
$db = db_connect();
$dbDiag['db_name'] = $db->database;
$dbDiag['packaging_unit'] = (int) $db->table('packaging_unit')->where('pu_lg_idx', (int) $lgIdx)->countAllResults();
$dbDiag['code_kind'] = (int) $db->table('code_kind')->countAllResults();
$dbDiag['code_detail'] = (int) $db->table('code_detail')->countAllResults();
} catch (\Throwable $e) {
$dbDiag['error'] = $e->getMessage();
log_message('error', '[packagingUnits][db_diag] {type}: {message}', [
'type' => $e::class,
'message' => $e->getMessage(),
]);
}
}
return $this->render('포장 단위', 'bag/packaging_units', [
'packagingUnits' => $packagingUnits,
'dbDiag' => $dbDiag,
]);
} }
/** /**
@@ -349,13 +377,27 @@ class Bag extends BaseController
{ {
$kindModel = model(CodeKindModel::class); $kindModel = model(CodeKindModel::class);
$detailModel = model(CodeDetailModel::class); $detailModel = model(CodeDetailModel::class);
$kinds = $kindModel->orderBy('ck_code', 'ASC')->findAll(); $kinds = [];
$lgIdx = $this->lgIdx();
$countMap = []; $countMap = [];
foreach ($kinds as $row) { $lgIdx = $this->lgIdx();
$countMap[$row->ck_idx] = (int) $detailModel->where('cd_ck_idx', $row->ck_idx) try {
->filterByTenantScope($lgIdx) $kinds = $kindModel->orderBy('ck_code', 'ASC')->findAll();
->countAllResults(); foreach ($kinds as $row) {
$countMap[$row->ck_idx] = (int) $detailModel->where('cd_ck_idx', $row->ck_idx)
->filterByTenantScope($lgIdx)
->countAllResults();
}
} catch (\Throwable $e) {
log_message('error', '[codeKinds] 실패: {type} {message} @ {file}:{line} / lg={lg}, user={user}, level={level}', [
'type' => $e::class,
'message' => $e->getMessage(),
'file' => $e->getFile(),
'line' => $e->getLine(),
'lg' => $lgIdx !== null ? (string) $lgIdx : 'null',
'user' => (string) (session()->get('mb_id') ?? ''),
'level' => (string) (session()->get('mb_level') ?? ''),
]);
session()->setFlashdata('error', '기본코드 조회 중 오류가 발생했습니다. 관리자에게 로그 확인을 요청해 주세요.');
} }
$level = (int) session()->get('mb_level'); $level = (int) session()->get('mb_level');
@@ -374,18 +416,46 @@ class Bag extends BaseController
{ {
$kindModel = model(CodeKindModel::class); $kindModel = model(CodeKindModel::class);
$detailModel = model(CodeDetailModel::class); $detailModel = model(CodeDetailModel::class);
$kind = $kindModel->find($ckIdx); $kind = null;
try {
$kind = $kindModel->find($ckIdx);
} catch (\Throwable $e) {
log_message('error', '[codeDetails] kind 조회 실패: {type} {message} @ {file}:{line} / ck={ck}, user={user}, level={level}', [
'type' => $e::class,
'message' => $e->getMessage(),
'file' => $e->getFile(),
'line' => $e->getLine(),
'ck' => (string) $ckIdx,
'user' => (string) (session()->get('mb_id') ?? ''),
'level' => (string) (session()->get('mb_level') ?? ''),
]);
return redirect()->to(site_url('bag/code-kinds'))->with('error', '세부코드 조회 중 오류가 발생했습니다. 관리자에게 로그 확인을 요청해 주세요.');
}
if ($kind === null) { if ($kind === null) {
return redirect()->to(site_url('bag/code-kinds'))->with('error', '코드 종류를 찾을 수 없습니다.'); return redirect()->to(site_url('bag/code-kinds'))->with('error', '코드 종류를 찾을 수 없습니다.');
} }
$lgIdx = $this->lgIdx(); $lgIdx = $this->lgIdx();
$list = $detailModel->where('cd_ck_idx', $ckIdx) try {
->filterByTenantScope($lgIdx) $list = $detailModel->where('cd_ck_idx', $ckIdx)
->orderBy('cd_sort', 'ASC') ->filterByTenantScope($lgIdx)
->orderBy('cd_idx', 'ASC') ->orderBy('cd_sort', 'ASC')
->paginate(20); ->orderBy('cd_idx', 'ASC')
$pager = $detailModel->pager; ->paginate(20);
$pager = $detailModel->pager;
} catch (\Throwable $e) {
log_message('error', '[codeDetails] list 조회 실패: {type} {message} @ {file}:{line} / ck={ck}, lg={lg}, user={user}, level={level}', [
'type' => $e::class,
'message' => $e->getMessage(),
'file' => $e->getFile(),
'line' => $e->getLine(),
'ck' => (string) $ckIdx,
'lg' => $lgIdx !== null ? (string) $lgIdx : 'null',
'user' => (string) (session()->get('mb_id') ?? ''),
'level' => (string) (session()->get('mb_level') ?? ''),
]);
return redirect()->to(site_url('bag/code-kinds'))->with('error', '세부코드 조회 중 오류가 발생했습니다. 관리자에게 로그 확인을 요청해 주세요.');
}
helper('admin'); helper('admin');
$level = (int) session()->get('mb_level'); $level = (int) session()->get('mb_level');

View File

@@ -151,17 +151,30 @@ if (! function_exists('get_site_nav_tree')) {
{ {
try { try {
$lgIdx = resolve_site_menu_lg_idx(); $lgIdx = resolve_site_menu_lg_idx();
$typeRow = model(\App\Models\MenuTypeModel::class)->getByCode('site');
if (! $typeRow) {
return [];
}
$mbLevel = (int) session()->get('mb_level'); $mbLevel = (int) session()->get('mb_level');
$menuModel = model(\App\Models\MenuModel::class); $menuModel = model(\App\Models\MenuModel::class);
$flat = $menuModel->getVisibleByLevel((int) $typeRow->mt_idx, $mbLevel, (int) $lgIdx); $typeRow = model(\App\Models\MenuTypeModel::class)->getByCode('site');
$siteMtIdx = $typeRow ? (int) $typeRow->mt_idx : 0;
if ($siteMtIdx <= 0) {
// 운영 DB 불일치 대비: menu_type 누락 시 legacy site mt_idx(4)로 시도
$siteMtIdx = 4;
}
$flat = $menuModel->getVisibleByLevel($siteMtIdx, $mbLevel, (int) $lgIdx);
// 현재 지자체에 site 메뉴가 없으면, 기본 지자체(1)의 메뉴를 한 번 복사한 뒤 다시 시도 // 현재 지자체에 site 메뉴가 없으면, 기본 지자체(1)의 메뉴를 한 번 복사한 뒤 다시 시도
if (empty($flat)) { if (empty($flat)) {
$menuModel->copyDefaultsFromLg((int) $typeRow->mt_idx, 1, (int) $lgIdx); $menuModel->copyDefaultsFromLg($siteMtIdx, 1, (int) $lgIdx);
$flat = $menuModel->getVisibleByLevel((int) $typeRow->mt_idx, $mbLevel, (int) $lgIdx); $flat = $menuModel->getVisibleByLevel($siteMtIdx, $mbLevel, (int) $lgIdx);
}
// site 타입 매핑 불일치(예: menu_type=2, menu 데이터=4) 보정
if (empty($flat) && $siteMtIdx !== 4) {
$legacyMtIdx = 4;
$flat = $menuModel->getVisibleByLevel($legacyMtIdx, $mbLevel, (int) $lgIdx);
if (empty($flat)) {
$menuModel->copyDefaultsFromLg($legacyMtIdx, 1, (int) $lgIdx);
$flat = $menuModel->getVisibleByLevel($legacyMtIdx, $mbLevel, (int) $lgIdx);
}
} }
if (empty($flat)) { if (empty($flat)) {
return []; return [];

View File

@@ -4,6 +4,8 @@ $list = $list ?? [];
$mtIdx = (int) ($mtIdx ?? 0); $mtIdx = (int) ($mtIdx ?? 0);
$mtCode = (string) ($mtCode ?? ''); $mtCode = (string) ($mtCode ?? '');
$levelNames = $levelNames ?? []; $levelNames = $levelNames ?? [];
$debugMode = (bool) ($debug_mode ?? false);
$debugInfo = is_array($debug_info ?? null) ? $debug_info : [];
helper('admin'); helper('admin');
$adminMenusNavPath = current_nav_request_path(); $adminMenusNavPath = current_nav_request_path();
@@ -44,6 +46,19 @@ $adminMenuListResolveHref = static function (string $rawLink) use ($adminMenusNa
</div> </div>
</section> </section>
<?php if ($debugMode): ?>
<section class="mt-2 border border-amber-300 bg-amber-50 text-amber-900 rounded p-2 text-xs">
<strong>[DEBUG]</strong>
lg_idx=<?= esc((string) ($debugInfo['lg_idx'] ?? '')) ?>,
requested_mt_idx=<?= esc((string) ($debugInfo['requested_mt_idx'] ?? '')) ?>,
resolved_mt_idx=<?= esc((string) ($debugInfo['resolved_mt_idx'] ?? '')) ?>,
effective_mt_idx=<?= esc((string) ($debugInfo['effective_mt_idx'] ?? '')) ?>,
resolved_mt_code=<?= esc((string) ($debugInfo['resolved_mt_code'] ?? '')) ?>,
list_count=<?= esc((string) ($debugInfo['list_count'] ?? '')) ?>,
fallback_applied=<?= esc((string) ($debugInfo['fallback_applied'] ?? 'N')) ?>
</section>
<?php endif; ?>
<div class="flex gap-4 mt-2 flex-wrap"> <div class="flex gap-4 mt-2 flex-wrap">
<div class="border border-gray-300 bg-white rounded p-4 flex-1 min-w-0" style="min-width: 320px;"> <div class="border border-gray-300 bg-white rounded p-4 flex-1 min-w-0" style="min-width: 320px;">
<h3 class="text-sm font-bold text-gray-700 mb-2">메뉴 목록</h3> <h3 class="text-sm font-bold text-gray-700 mb-2">메뉴 목록</h3>

View File

@@ -1,4 +1,17 @@
<div class="space-y-4"> <div class="space-y-4">
<?php if (isset($dbDiag) && is_array($dbDiag)): ?>
<section class="rounded border border-amber-300 bg-amber-50 px-3 py-2 text-xs text-amber-900">
<div class="font-semibold mb-1">DB 진단 모드</div>
<div>lg_idx: <?= esc((string) ($dbDiag['lg_idx'] ?? 'null')) ?></div>
<div>database: <?= esc((string) ($dbDiag['db_name'] ?? '')) ?></div>
<div>packaging_unit(현재 lg): <?= esc((string) ($dbDiag['packaging_unit'] ?? 'null')) ?></div>
<div>code_kind: <?= esc((string) ($dbDiag['code_kind'] ?? 'null')) ?></div>
<div>code_detail: <?= esc((string) ($dbDiag['code_detail'] ?? 'null')) ?></div>
<?php if (! empty($dbDiag['error'])): ?>
<div class="mt-1 text-red-700">error: <?= esc((string) $dbDiag['error']) ?></div>
<?php endif; ?>
</section>
<?php endif; ?>
<p class="text-sm text-gray-600"> <p class="text-sm text-gray-600">
<a href="<?= base_url('bag/basic-info') ?>" class="text-blue-600 hover:underline">&larr; 기본정보관리</a> <a href="<?= base_url('bag/basic-info') ?>" class="text-blue-600 hover:underline">&larr; 기본정보관리</a>
<span class="mx-2 text-gray-300">|</span> <span class="mx-2 text-gray-300">|</span>