Compare commits

2 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
2 changed files with 97 additions and 14 deletions

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,14 +377,28 @@ 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 = [];
$lgIdx = $this->lgIdx();
try {
$kinds = $kindModel->orderBy('ck_code', 'ASC')->findAll();
foreach ($kinds as $row) { foreach ($kinds as $row) {
$countMap[$row->ck_idx] = (int) $detailModel->where('cd_ck_idx', $row->ck_idx) $countMap[$row->ck_idx] = (int) $detailModel->where('cd_ck_idx', $row->ck_idx)
->filterByTenantScope($lgIdx) ->filterByTenantScope($lgIdx)
->countAllResults(); ->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 = null;
try {
$kind = $kindModel->find($ckIdx); $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();
try {
$list = $detailModel->where('cd_ck_idx', $ckIdx) $list = $detailModel->where('cd_ck_idx', $ckIdx)
->filterByTenantScope($lgIdx) ->filterByTenantScope($lgIdx)
->orderBy('cd_sort', 'ASC') ->orderBy('cd_sort', 'ASC')
->orderBy('cd_idx', 'ASC') ->orderBy('cd_idx', 'ASC')
->paginate(20); ->paginate(20);
$pager = $detailModel->pager; $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

@@ -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>