반응형
게시글 평점 모듈을 사용 중, 게시글을 삭제해도 평점이 데이터가 DB에 남아 있어
삭제하는 트리거를 추가했습니다.
1. starpoint.controller.php (신규추가)
- 역할: 게시글 삭제 트리거 처리
/**
* @brief 게시글 삭제 시 별점 데이터 삭제 트리거
* @param object $obj 삭제된 게시글 정보
* @return object
*/
public function triggerDeleteDocument($obj)
{
if (!$obj->document_srl) {
return new BaseObject();
}
$oStarPointModel = getModel('starpoint');
$output = $oStarPointModel->deleteDocumentStar($obj->document_srl);
return $output;
}
파일 최하단에 추가하시면 됩니다.
1.5 버전 기준 {109-124} 라인
2. starpoint.model.php (신규 추가)
- 역할: 별점 데이터 삭제 실행
/**
* @brief 게시글 삭제 시 해당 게시글의 모든 별점 데이터 삭제
* @param int $document_srl 문서 일련번호
* @return object
*/
public static function deleteDocumentStar($document_srl) {
$args = new stdClass();
$args->document_srl = $document_srl;
$output = executeQuery('starpoint.deleteDocumentStar', $args);
return $output;
}
파일 최하단에 추가하시면 됩니다.
1.5 버전 기준 {116-127} 라인
3. starpoint.class.php (트리거 등록 추가)
- moduleInstall() - 56번 줄:
// 게시글 삭제 시 별점 데이터 삭제 트리거
$oModuleController->insertTrigger('document.deleteDocument', 'starpoint', 'controller', 'triggerDeleteDocument', 'after');
- checkUpdate() - 80-82번 줄:
// 게시글 삭제 시 별점 데이터 삭제 트리거 확인
if(!$oModuleModel->getTrigger('document.deleteDocument', 'starpoint', 'controller', 'triggerDeleteDocument', 'after'))
return true;
- moduleUpdate() - 110-112번 줄:
// 게시글 삭제 시 별점 데이터 삭제 트리거 등록
if(!$oModuleModel->getTrigger('document.deleteDocument', 'starpoint', 'controller', 'triggerDeleteDocument', 'after'))
$oModuleController->insertTrigger('document.deleteDocument', 'starpoint', 'controller', 'triggerDeleteDocument', 'after');
4. queries/deleteDocumentStar.xml (신규 생성)
<?xml version="1.0" encoding="utf-8"?>
<query id="deleteDocumentStar" action="delete">
<tables>
<table name="document_star" />
</tables>
<conditions>
<condition operation="equal" column="document_srl" var="document_srl" filter="number" notnull="notnull" />
</conditions>
</query>
- 역할: 게시글별 별점 데이터 삭제 쿼리
반응형