feat: 메뉴 등록/수정 시 상위·하위 위치 선택 + 지자체 동기화 성능 개선
- 등록/수정 폼에 상위/하위 선택(상위 메뉴 지정), 기존 메뉴도 상위↔하위 이동 가능 - 하위 보유 메뉴의 하위 변경 차단 등 검증 - syncTypeToAllLgs를 dep별 batch insert로 재작성 → 메뉴 저장 시 원격 DB 왕복 급감(30초 타임아웃 해소) Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This commit is contained in:
@@ -210,7 +210,41 @@ class Menu extends BaseController
|
||||
'mm_level' => $this->normalizeMmLevel((int) $row->mt_idx),
|
||||
'mm_is_view' => $this->request->getPost('mm_is_view') ? 'Y' : 'N',
|
||||
];
|
||||
|
||||
// 위치(상위↔하위) 변경 지원: mm_pidx 가 바뀌면 상위/하위로 이동
|
||||
$oldPidx = (int) $row->mm_pidx;
|
||||
$newPidx = (int) $this->request->getPost('mm_pidx');
|
||||
$newDep = $newPidx > 0 ? 1 : 0;
|
||||
$positionChanged = $newPidx !== $oldPidx;
|
||||
if ($positionChanged) {
|
||||
if ($newPidx === $id) {
|
||||
return $this->menusRedirect((int) $row->mt_idx)->with('error', '자기 자신을 상위 메뉴로 지정할 수 없습니다.');
|
||||
}
|
||||
// 하위 메뉴를 보유한 상위 메뉴는 하위로 변경 불가(2단 구조 유지)
|
||||
$childCnt = $this->menuModel->where('mt_idx', (int) $row->mt_idx)->where('lg_idx', $lgIdx)->where('mm_pidx', $id)->countAllResults();
|
||||
if ($newPidx > 0 && $childCnt > 0) {
|
||||
return $this->menusRedirect((int) $row->mt_idx)->with('error', '하위 메뉴가 있는 상위 메뉴는 하위로 변경할 수 없습니다. 먼저 하위 메뉴를 옮겨 주세요.');
|
||||
}
|
||||
if ($newPidx > 0) {
|
||||
$parent = $this->menuModel->find($newPidx);
|
||||
if (! $parent || (int) $parent->lg_idx !== $lgIdx || (int) $parent->mt_idx !== (int) $row->mt_idx || (int) $parent->mm_dep !== 0) {
|
||||
return $this->menusRedirect((int) $row->mt_idx)->with('error', '올바른 상위 메뉴를 선택해 주세요.');
|
||||
}
|
||||
}
|
||||
$data['mm_pidx'] = $newPidx;
|
||||
$data['mm_dep'] = $newDep;
|
||||
$data['mm_num'] = $this->menuModel->getNextNum((int) $row->mt_idx, $lgIdx, $newPidx, $newDep);
|
||||
}
|
||||
|
||||
$this->menuModel->update($id, $data);
|
||||
if ($positionChanged) {
|
||||
if ($oldPidx > 0) {
|
||||
$this->menuModel->updateCnode($oldPidx, -1);
|
||||
}
|
||||
if ($newPidx > 0) {
|
||||
$this->menuModel->updateCnode($newPidx, 1);
|
||||
}
|
||||
}
|
||||
$this->menuModel->pruneInventoryManagementMenus((int) $row->mt_idx, $lgIdx);
|
||||
$this->menuModel->syncTypeToAllLgs((int) $row->mt_idx, $lgIdx);
|
||||
return $this->menusRedirect((int) $row->mt_idx)->with('success', '메뉴가 수정되었습니다.');
|
||||
|
||||
Reference in New Issue
Block a user