자동삭제 소스 삽질해서 만들었는데 뭐가 잘못된건지 확인부탁드립니다.

자동삭제 소스 삽질해서 만들었는데 뭐가 잘못된건지 확인부탁드립니다.

QA

자동삭제 소스 삽질해서 만들었는데 뭐가 잘못된건지 확인부탁드립니다.

답변 1

본문

이것저것 삽질해서 만들었는데 도무지 알수가 없네요....

그누버전 Version 5.4.2.5 이구요.

글등록하면 500에러뜨구요....글목록에서 클릭하면 500에러가 뜨네요.

시간지나도 삭제도 안되고....고수님들 도와주세요...

 


<?php
if (!defined('_GNUBOARD_')) exit; // 개별 페이지 접근 불가
$count_write = 0;
$count_comment = 0;
$wr_time = "wr_datetime < date_add(now(), interval -2 minute) and ca_name = '삭제대기'";
$tmp_array = array();
if ($wr_id) // 건별삭제
 $sql = " select wr_id from {$g5['write_prefix']}{$bo_table} where wr_is_comment = 0 and $wr_time";
    $tmp_array[0] = sql_query($sql);
$chk_count = count($tmp_array);
// 거꾸로 읽는 이유는 답변글부터 삭제가 되어야 하기 때문임
for ($i=$chk_count-1; $i>=0; $i--)
{
    $write = sql_fetch(" select * from $write_table where wr_id = '$tmp_array[$i]' ");
    $len = strlen($write['wr_reply']);
    if ($len < 0) $len = 0;
    $reply = substr($write['wr_reply'], 0, $len);
    // 원글만 구한다.
    $sql = " select count(*) as cnt from $write_table
                where wr_reply like '$reply%'
                and wr_id <> '{$write['wr_id']}'
                and wr_num = '{$write['wr_num']}'
                and wr_is_comment = 0 ";
    $row = sql_fetch($sql);
    if ($row['cnt'])
            continue;
    $sql = " select wr_id, mb_id, wr_is_comment, wr_content from $write_table where wr_parent = '{$write['wr_id']}' order by wr_id ";
    $result = sql_query($sql);
    while ($row = sql_fetch_array($result))
    {
        // 원글이라면
        if (!$row['wr_is_comment'])
        {
            // 업로드된 파일이 있다면
            $sql2 = " select * from {$g5['board_file_table']} where bo_table = '$bo_table' and wr_id = '{$row['wr_id']}' ";
            $result2 = sql_query($sql2);
            while ($row2 = sql_fetch_array($result2)) {
                // 파일삭제
                $delete_file = run_replace('delete_file_path', G5_DATA_PATH.'/file/'.$bo_table.'/'.str_replace('../', '',$row2['bf_file']), $row2);
                if( file_exists($delete_file) ){
                    @unlink($delete_file);
                }
                // 썸네일삭제
                if(preg_match("/\.({$config['cf_image_extension']})$/i", $row2['bf_file'])) {
                    delete_board_thumbnail($bo_table, $row2['bf_file']);
                }
            }
            // 에디터 썸네일 삭제
            delete_editor_thumbnail($row['wr_content']);
            // 파일테이블 행 삭제
            sql_query(" delete from {$g5['board_file_table']} where bo_table = '$bo_table' and wr_id = '{$row['wr_id']}' ");
            $count_write++;
        }
    }
    // 게시글 삭제
    sql_query(" delete from $write_table where wr_parent = '{$write['wr_id']}' ");
    // 최근게시물 삭제
    sql_query(" delete from {$g5['board_new_table']} where bo_table = '$bo_table' and wr_parent = '{$write['wr_id']}' ");
    // 스크랩 삭제
    sql_query(" delete from {$g5['scrap_table']} where bo_table = '$bo_table' and wr_id = '{$write['wr_id']}' ");
    $bo_notice = board_notice($board['bo_notice'], $write['wr_id']);
    sql_query(" update {$g5['board_table']} set bo_notice = '$bo_notice' where bo_table = '$bo_table' ");
    $board['bo_notice'] = $bo_notice;
}
// 글숫자 감소
if ($count_write > 0 || $count_comment > 0)
    sql_query(" update {$g5['board_table']} set bo_count_write = bo_count_write - '$count_write', bo_count_comment = bo_count_comment - '$count_comment' where bo_table = '$bo_table' ");
//delete_cache_latest($bo_table);
//run_event('bbs_delete_all', $tmp_array, $board);
?>

이 질문에 댓글 쓰기 :

답변 1

8~9줄을 아래와 같이 수정해보세요..

$sql = " select wr_id from {$g5['write_prefix']}{$bo_table} where wr_is_comment = 0 and $wr_time";
$result = sql_query($sql);

while($row = sql_fetch_array($result)) {

  $tmp_array[] = $row['wr_id'];

}

 

 

답변을 작성하시기 전에 로그인 해주세요.
QA 내용 검색
질문등록
전체 19
© SIRSOFT
현재 페이지 제일 처음으로