일정 기간 지난 게시물 자동 삭제하기 > 그누4 질문답변

그누4 질문답변

그누보드4 관련 질문은 QA 로 이전됩니다. QA 그누보드4 바로가기
기존 게시물은 열람만 가능합니다.

일정 기간 지난 게시물 자동 삭제하기 정보

일정 기간 지난 게시물 자동 삭제하기

본문

특정그룹 혹은 다수의 게시판에서 일정기간이 지난후 삭제하려고 합니다.

현재 참조중인 자료는..

http://www.sir.co.kr/bbs/tb.php/cm_free/55366

http://www.sir.co.kr/bbs/tb.php/self_program/1320

이상 두개입니다.

자연스럽게 관리자 혹은 작성자가 지운것처럼 bbs/delete.php의 소스파일과 함께 사용하려 합니다.

혼자서 버벅거리면서 만들기가 참 힘드네요..

혹시 도움주실분 안계신가요?
  • 복사

댓글 전체

다음 글도 참고하시고 코멘트의 링크 따라 가보시기 바랍니다
해결책은 아닙니다만 비슷한 내용이 있어서 참고하시라고 알려드립니다.
http://www.sir.co.kr/bbs/board.php?bo_table=g4_qa&wr_id=14881&sca=&sfl=wr_subject%7C%7Cwr_content&stx=1%BD%C3%B0%A3&sop=and
아래는 제가 크론으로 돌리려고 여기저기서 짜깁기 한후 테스트중인 코드입니다...
코드가 지저분한점 양해바랍니다. ^^;
아래 코드는 작동은 하지 않고 에러만 신나게 보여주네요..^^;;

<?

// 몇일지난 게시물을 삭제?
$days = 7;

/***********************************************

$days 일 지난 광고물을 자동 삭제시키는 프로그램

***********************************************/
include_once ("dbconfig.php");
include_once ("./config.php");
include_once ("./_common.php");
include_once ("./lib/connect.lib.php");


function delete_by_wr_id($wr_id,$write_table,$bo_table){


// 나라오름님 수정 : 원글과 코멘트수가 정상적으로 업데이트 되지 않는 오류를 잡아 주셨습니다.
$sql = " select wr_id, mb_id, wr_is_comment from $write_table where wr_parent = '$wr_id' order by wr_id ";
$result = sql_query($sql);
$count_write = 0; // by Ted (set number of list to count)
$count_comment = 0; // by Ted (sometimes total count of bulletin becomes less than zero)
while ($row = sql_fetch_array($result))
{

// 업로드된 파일이 있다면 파일삭제
$sql2 = " select * from $g4[board_file_table] where bo_table = '$bo_table' and wr_id = '$row[wr_id]' ";
$result2 = sql_query($sql2);

while ($row2 = sql_fetch_array($result2)){
    @unlink("$g4[path]/data/file/$bo_table/$row2[bf_file]");
    @unlink("$g4[path]/data/file/$bo_table/$row2[bf_file].thum"); // by Ted (it locates here rather than within skin file to be sure working perfectly)
}

// 파일테이블 행 삭제
sql_query(" delete from $g4[board_file_table] where bo_table = '$bo_table' and wr_id = '$row[wr_id]' ");

$count_write++;
}

echo $wr_id.",".$write_table;
// 게시글 삭제
sql_query(" delete from $write_table where wr_parent = '$write[wr_id]' ");

// 최근게시물 삭제
sql_query(" delete from $g4[board_new_table] where bo_table = '$bo_table' and wr_parent = '$write[wr_id]' ");

// 스크랩 삭제
sql_query(" delete from $g4[scrap_table] where bo_table = '$bo_table' and wr_id = '$write[wr_id]' ");

// 공지사항 삭제
$notice_array = explode("\n", trim($board[bo_notice]));
$bo_notice = "";
for ($k=0; $k<count($notice_array); $k++)
    if ((int)$write[wr_id] != (int)$notice_array[$k])
        $bo_notice .= $notice_array[$k] . "\n";
$bo_notice = trim($bo_notice);
sql_query(" update $g4[board_table] set bo_notice = '$bo_notice' where bo_table = '$bo_table' ");

// 글숫자 감소
if ($count_write > 0 || $count_comment > 0)
    sql_query(" update $g4[board_table] set bo_count_write = bo_count_write - '$count_write', bo_count_comment = bo_count_comment - '$count_comment' where bo_table = '$bo_table' ");
}



function delete_run($bo_table){
$write_table = $g4[write_prefix].$bo_table; // 게시판 테이블 전체이름

$connect = @mysql_connect($mysql_host, $mysql_user, $mysql_pass);
$select_db = @mysql_select_db($connect, $connect);
if (!$select_db) {
    echo "DB 접속 오류";
    exit;
}
echo "1";
$today = $g4[time_ymd];
$now = $g4[time_his];

$gap = date("Y-m-d", time() - 86400 * $days);

$sql = "select wr_id from $write_table where wr_datetime < '$gap'";
$result = sql_query($sql);

while ($row = mysql_fetch_array($result)) {
delete_by_wr_id($row[wr_id],$write_table,$bo_table);
}
}
delete_run('tip');
delete_run('notice');
delete_run('gallery');
delete_run('test');
?>
© SIRSOFT
현재 페이지 제일 처음으로