vendorModel = new VendorModel(); $this->userModel = new UserModel(); $this->vendorInfluencerModel = new VendorInfluencerMappingModel(); } /** * 외래키 제약조건 디버깅용 메서드 */ public function debugForeignKey() { try { $mappingSeq = 2; $processedBy = 8; // 1. USER_LIST에서 SEQ 8번 사용자 확인 $user = $this->userModel->where('SEQ', $processedBy)->first(); $debugInfo = [ 'user_exists' => !empty($user), 'user_data' => $user, 'user_count' => $this->userModel->where('SEQ', $processedBy)->countAllResults() ]; // 2. VENDOR_INFLUENCER_MAPPING에서 SEQ 2번 레코드 확인 $mapping = $this->vendorInfluencerModel->where('SEQ', $mappingSeq)->first(); $debugInfo['mapping_exists'] = !empty($mapping); $debugInfo['mapping_data'] = $mapping; // 3. 현재 APPROVED_BY 필드 상태 확인 if ($mapping) { $debugInfo['current_approved_by'] = $mapping['APPROVED_BY']; $debugInfo['current_status'] = $mapping['STATUS']; } // 4. 외래키 제약조건 확인 $db = \Config\Database::connect(); $foreignKeys = $db->query(" SELECT CONSTRAINT_NAME, COLUMN_NAME, REFERENCED_TABLE_NAME, REFERENCED_COLUMN_NAME FROM INFORMATION_SCHEMA.KEY_COLUMN_USAGE WHERE TABLE_NAME = 'VENDOR_INFLUENCER_MAPPING' AND TABLE_SCHEMA = DATABASE() AND REFERENCED_TABLE_NAME IS NOT NULL ")->getResultArray(); $debugInfo['foreign_keys'] = $foreignKeys; // 5. 실제 업데이트 시도해보기 (트랜잭션 롤백) $db->transStart(); try { $updateData = [ 'STATUS' => 'APPROVED', 'APPROVED_BY' => $processedBy, 'RESPONSE_MESSAGE' => 'debug test', 'RESPONSE_DATE' => date('Y-m-d H:i:s') ]; $result = $this->vendorInfluencerModel->update($mappingSeq, $updateData); $debugInfo['update_attempted'] = true; $debugInfo['update_result'] = $result; $debugInfo['update_error'] = null; } catch (\Exception $e) { $debugInfo['update_attempted'] = true; $debugInfo['update_result'] = false; $debugInfo['update_error'] = $e->getMessage(); } // 항상 롤백 $db->transRollback(); // 6. 다른 사용자 SEQ들 확인 $otherUsers = $this->userModel ->select('SEQ, NICK_NAME, EMAIL, IS_ACT, USER_TYPE') ->where('IS_ACT', 'Y') ->orderBy('SEQ') ->findAll(10); $debugInfo['sample_active_users'] = $otherUsers; return $this->response->setJSON([ 'success' => true, 'debug_info' => $debugInfo ]); } catch (\Exception $e) { return $this->response->setStatusCode(500)->setJSON([ 'success' => false, 'message' => '디버깅 중 오류가 발생했습니다.', 'error' => $e->getMessage() ]); } } /** * 간단한 업데이트 테스트 */ public function testSimpleUpdate() { try { $mappingSeq = 2; $processedBy = 8; // 직접 SQL로 업데이트 시도 $db = \Config\Database::connect(); $sql = "UPDATE VENDOR_INFLUENCER_MAPPING SET APPROVED_BY = ? WHERE SEQ = ?"; try { $result = $db->query($sql, [$processedBy, $mappingSeq]); return $this->response->setJSON([ 'success' => true, 'message' => '직접 SQL 업데이트 성공', 'affected_rows' => $db->affectedRows() ]); } catch (\Exception $e) { return $this->response->setJSON([ 'success' => false, 'message' => '직접 SQL 업데이트 실패', 'error' => $e->getMessage(), 'sql_state' => $db->error() ]); } } catch (\Exception $e) { return $this->response->setStatusCode(500)->setJSON([ 'success' => false, 'message' => '테스트 중 오류가 발생했습니다.', 'error' => $e->getMessage() ]); } } }