자동글삭제 소스인데... 공지도 계속 삭제가 됩니다...

자동글삭제 소스인데... 공지도 계속 삭제가 됩니다...

QA

자동글삭제 소스인데... 공지도 계속 삭제가 됩니다...

본문

<?php
if (!defined('_GNUBOARD_')) exit; // 개별 페이지 접근 불가

// 특정 게시판에 적용하고 싶을 때 Start
$ttable = array('free');

foreach ($ttable as $tbo_table) {

    // 공지사항 wr_id를 제외하고 삭제
    $bo_notice = [];
    if (!empty($board['bo_notice'])) {
        $tmp_array = explode(",", $board['bo_notice']);
        foreach ($tmp_array as $tmp_wr_id) {
            $tmp_wr_id = trim($tmp_wr_id);
            if (is_numeric($tmp_wr_id)) { // ID가 숫자인지 확인
                $bo_notice[] = intval($tmp_wr_id); // 정수로 변환하여 추가
            }
        }
    }

    // 공지사항 ID 배열이 비어있는지 확인하고, 삭제 조건 생성
    $notice_condition = "";
    if (!empty($bo_notice)) {
        $notice_condition = "AND wr_id NOT IN (" . implode(",", $bo_notice) . ")";
    }

    // 오래된 글 중 공지사항을 제외하고 삭제
    $delete_query = "DELETE FROM {$g5['write_prefix']}{$tbo_table} WHERE wr_datetime < DATE_ADD(NOW(), INTERVAL -10080 MINUTE) {$notice_condition}";
    
    // 디버깅: 삭제 쿼리를 확인
    // echo $delete_query; exit; // 필요할 때 주석을 해제하여 쿼리를 출력

    sql_query($delete_query);

    // 새글 테이블에서도 오래된 글 삭제
    $delete_new_query = "DELETE FROM {$g5['board_new_table']} WHERE wr_datetime < DATE_ADD(NOW(), INTERVAL -10080 MINUTE) AND bo_table = '{$tbo_table}'";
    sql_query($delete_new_query);

    // 게시판의 글 수와 코멘트 수를 한 번에 가져오기
    $sql = "SELECT 
                SUM(CASE WHEN wr_is_comment = 0 THEN 1 ELSE 0 END) AS cnt_write,
                SUM(CASE WHEN wr_is_comment = 1 THEN 1 ELSE 0 END) AS cnt_comment
            FROM {$g5['write_prefix']}{$tbo_table}";
    $row = sql_fetch($sql);
    $bo_count_write = $row['cnt_write'];
    $bo_count_comment = $row['cnt_comment'];

    // 댓글 수 업데이트
    if (isset($_POST['proc_count'])) {
        $sql = "SELECT a.wr_id, (COUNT(b.wr_parent) - 1) AS cnt 
                FROM {$g5['write_prefix']}{$tbo_table} a
                JOIN {$g5['write_prefix']}{$tbo_table} b 
                ON a.wr_id = b.wr_parent AND a.wr_is_comment = 0 
                GROUP BY a.wr_id";
        $result = sql_query($sql);
        while ($row = sql_fetch_array($result)) {
            sql_query("UPDATE {$g5['write_prefix']}{$tbo_table} SET wr_comment = '{$row['cnt']}' WHERE wr_id = '{$row['wr_id']}'");
        }
    }

    // 공지사항 업데이트
    $sql = "UPDATE {$g5['board_table']} SET 
                bo_notice = '" . implode(",", $bo_notice) . "', 
                bo_count_write = '{$bo_count_write}', 
                bo_count_comment = '{$bo_count_comment}' 
            WHERE bo_table = '{$tbo_table}'";
    sql_query($sql);
}
?>
 

 

free게시판에서 일주일 지난 게시글 자동 삭제하는 소슨데, 문제는 공지사항도 마찬가지로 삭제가 되어버리네요. 혹시 소스에서 문제가 있는 부분이 있을까요 ㅠㅠ?

이 질문에 댓글 쓰기 :

답변 2


<?php if (!defined('_GNUBOARD_')) exit;
$ttable = array('free');
foreach ($ttable as $tbo_table) {
$bo_notice = [];
if (!empty($board['bo_notice'])) {
$tmp_array = explode(",", $board['bo_notice']);
foreach ($tmp_array as $tmp_wr_id) {
$tmp_wr_id = trim($tmp_wr_id);
if (is_numeric($tmp_wr_id)) {
$bo_notice[] = intval($tmp_wr_id);
}
}
}
 
$notice_condition = "";
if (!empty($bo_notice)) {
$notice_condition = "AND wr_id NOT IN (" . implode(",", $bo_notice) . ")";
}
 
$delete_query = "DELETE FROM {$g5['write_prefix']}{$tbo_table} WHERE wr_datetime < DATE_ADD(NOW(), INTERVAL -10080 MINUTE) {$notice_condition}";
sql_query($delete_query);
 
$delete_new_query = "DELETE FROM {$g5['board_new_table']} WHERE wr_datetime < DATE_ADD(NOW(), INTERVAL -10080 MINUTE) AND bo_table = '{$tbo_table}'";
sql_query($delete_new_query);
 
$sql = "SELECT SUM(CASE WHEN wr_is_comment = 0 THEN 1 ELSE 0 END) AS cnt_write, SUM(CASE WHEN wr_is_comment = 1 THEN 1 ELSE 0 END) AS cnt_comment FROM {$g5['write_prefix']}{$tbo_table}";
$row = sql_fetch($sql);
$bo_count_write = $row['cnt_write'];
$bo_count_comment = $row['cnt_comment'];
 
if (isset($_POST['proc_count'])) {
$sql = "SELECT a.wr_id, (COUNT(b.wr_parent) - 1) AS cnt FROM {$g5['write_prefix']}{$tbo_table} a JOIN {$g5['write_prefix']}{$tbo_table} b ON a.wr_id = b.wr_parent AND a.wr_is_comment = 0 GROUP BY a.wr_id";
$result = sql_query($sql);
while ($row = sql_fetch_array($result)) {
sql_query("UPDATE {$g5['write_prefix']}{$tbo_table} SET wr_comment = '{$row['cnt']}' WHERE wr_id = '{$row['wr_id']}'");
}
}
 
$sql = "UPDATE {$g5['board_table']} SET bo_notice = '" . implode(",", $bo_notice) . "', bo_count_write = '{$bo_count_write}', bo_count_comment = '{$bo_count_comment}' WHERE bo_table = '{$tbo_table}'";
sql_query($sql);
}
?>

다시 해보시겠나요 수정 해드렸습니다.


<?php if (!defined('_GNUBOARD_')) exit; 
$ttable = array('free');
foreach ($ttable as $tbo_table) {
    $bo_notice = [];     
    if (!empty($board['bo_notice'])) {         
        $tmp_array = explode(",", $board['bo_notice']);         
        foreach ($tmp_array as $tmp_wr_id) {                 
            $tmp_wr_id = trim($tmp_wr_id);                 
            if (is_numeric($tmp_wr_id)) {                     
                $bo_notice[] = intval($tmp_wr_id);                 
            }             
        }     
    }

    $notice_condition = "";     
    if (!empty($bo_notice)) {         
        $notice_condition = "AND wr_id NOT IN (" . implode(",", $bo_notice) . ")";     
    }

    $delete_query = "DELETE FROM {$g5['write_prefix']}{$tbo_table} WHERE wr_datetime < DATE_ADD(NOW(), INTERVAL -10080 MINUTE) {$notice_condition}";     
    sql_query($delete_query);

    $delete_new_query = "DELETE FROM {$g5['board_new_table']} WHERE wr_datetime < DATE_ADD(NOW(), INTERVAL -10080 MINUTE) AND bo_table = '{$tbo_table}'";     
    sql_query($delete_new_query);

    $sql = "SELECT SUM(CASE WHEN wr_is_comment = 0 THEN 1 ELSE 0 END) AS cnt_write, SUM(CASE WHEN wr_is_comment = 1 THEN 1 ELSE 0 END) AS cnt_comment FROM {$g5['write_prefix']}{$tbo_table}";     
    $row = sql_fetch($sql);     
    $bo_count_write = $row['cnt_write'];     
    $bo_count_comment = $row['cnt_comment'];

    if (isset($_POST['proc_count'])) {         
        $sql = "SELECT a.wr_id, (COUNT(b.wr_parent) - 1) AS cnt FROM {$g5['write_prefix']}{$tbo_table} a JOIN {$g5['write_prefix']}{$tbo_table} b ON a.wr_id = b.wr_parent AND a.wr_is_comment = 0 GROUP BY a.wr_id";         
        $result = sql_query($sql);         
        while ($row = sql_fetch_array($result)) {             
            sql_query("UPDATE {$g5['write_prefix']}{$tbo_table} SET wr_comment = '{$row['cnt']}' WHERE wr_id = '{$row['wr_id']}'");         
        }     
    }

    $sql = "UPDATE {$g5['board_table']} SET bo_notice = '" . implode(",", $bo_notice) . "', bo_count_write = '{$bo_count_write}', bo_count_comment = '{$bo_count_comment}' WHERE bo_table = '{$tbo_table}'";     
    sql_query($sql); 
}
?>

회사라; 테스트 안해보고 답변 드리는점 양해부탁드립니다 ㄷㄷ:


<?php if (!defined('_GNUBOARD_')) exit;

$ttable = array('free');

foreach ($ttable as $tbo_table) {
    $bo_notice = [];     
    if (!empty($board['bo_notice'])) {         
        $tmp_array = explode(",", $board['bo_notice']);         
        foreach ($tmp_array as $tmp_wr_id) {                 
            $tmp_wr_id = trim($tmp_wr_id);                 
            if (is_numeric($tmp_wr_id)) {                     
                $bo_notice[] = intval($tmp_wr_id);                 
            }         
        }     
    }

    $notice_condition = "";     
    if (!empty($bo_notice)) {         
        $notice_condition = "AND wr_id NOT IN (" . implode(",", $bo_notice) . ")";     
    }

    $delete_query = "DELETE FROM {$g5['write_prefix']}{$tbo_table} WHERE wr_datetime < DATE_ADD(NOW(), INTERVAL -10080 MINUTE) {$notice_condition}"; 
    sql_query($delete_query);

    $delete_new_query = "DELETE FROM {$g5['board_new_table']} WHERE wr_datetime < DATE_ADD(NOW(), INTERVAL -10080 MINUTE) AND bo_table = '{$tbo_table}'"; 
    sql_query($delete_new_query);

    $sql = "SELECT SUM(CASE WHEN wr_is_comment = 0 THEN 1 ELSE 0 END) AS cnt_write, SUM(CASE WHEN wr_is_comment = 1 THEN 1 ELSE 0 END) AS cnt_comment FROM {$g5['write_prefix']}{$tbo_table}"; 
    $row = sql_fetch($sql);     
    $bo_count_write = $row['cnt_write'];     
    $bo_count_comment = $row['cnt_comment'];

    if (isset($_POST['proc_count'])) {         
        $sql = "SELECT a.wr_id, (COUNT(b.wr_parent) - 1) AS cnt 
                FROM {$g5['write_prefix']}{$tbo_table} a 
                JOIN {$g5['write_prefix']}{$tbo_table} b 
                ON a.wr_id = b.wr_parent AND a.wr_is_comment = 0 
                GROUP BY a.wr_id";         
        $result = sql_query($sql);         
        while ($row = sql_fetch_array($result)) {             
            sql_query("UPDATE {$g5['write_prefix']}{$tbo_table} SET wr_comment = '{$row['cnt']}' WHERE wr_id = '{$row['wr_id']}'");         
        }     
    }

    $sql = "UPDATE {$g5['board_table']} SET 
                bo_notice = '" . implode(",", $bo_notice) . "', 
                bo_count_write = '{$bo_count_write}', 
                bo_count_comment = '{$bo_count_comment}' 
                WHERE bo_table = '{$tbo_table}'"; 

    sql_query($sql); 
}
?>


    // 공지사항 wr_id를 제외하고 삭제
    $bo_notice = [];
    if (!empty($board['bo_notice'])) {
        $tmp_array = explode(",", $board['bo_notice']);
        foreach ($tmp_array as $tmp_wr_id) {
            $tmp_wr_id = trim($tmp_wr_id);
            if (is_numeric($tmp_wr_id)) { // ID가 숫자인지 확인
                $bo_notice[] = intval($tmp_wr_id); // 정수로 변환하여 추가
            }
        }
    }

->


  $board = sql_fetch(" select * from {$g5['board_table']} where bo_table = '{$tbo_table}' ");
  
  // 공지사항 wr_id 배열 생성
  $bo_notice = array();
  if ($board['bo_notice']) {
    $tmp_array = explode(',', $board['bo_notice']);
    foreach ($tmp_array as $val) {
      if (trim($val))
        $bo_notice[] = (int)$val;
    }
  }
답변을 작성하시기 전에 로그인 해주세요.
전체 61,328
QA 내용 검색

회원로그인

(주)에스아이알소프트 / 대표:홍석명 / (06211) 서울특별시 강남구 역삼동 707-34 한신인터밸리24 서관 1404호 / E-Mail: admin@sir.kr
사업자등록번호: 217-81-36347 / 통신판매업신고번호:2014-서울강남-02098호 / 개인정보보호책임자:김민섭(minsup@sir.kr)
© SIRSOFT