📖
그누보드5 게시글 정렬 및 참조 동기화 도구
페이지 정보
본문
✅ 구성 개요
파일명: reset_post_ids.php
🔄 전체 반영 목록
📌 g5_write_테이블 (wr_id, wr_parent, wr_num 원본 게시글 및 댓글 포함 전체 정렬)
📌 g5_board_new (wr_id, wr_parent 새글 목록 동기화)
📌 g5_point (po_id (게시글 ID) 포인트 기록 연결 동기화)
📌 g5_scrap (wr_id 스크랩된 글 ID 동기화)
📌 g5_board (bo_notice 공지사항 글 ID 목록 재매핑)
📌 g5_board_file (wr_id 게시글에 첨부된 파일 정보)
📌 g5_good (wr_id 추천/비추천 정보 테이블)
✅ UI + 실행 코드 (PHP)[code]<?php
include_once('./_common.php');//경로확인 실제 경로로 변경 하세요
if (!defined('_GNUBOARD_')) exit;
// 관리자 권한 체크
if ($is_admin !== 'super') {
alert('최고관리자만 접근 가능합니다.');
}
if ($_SERVER['REQUEST_METHOD'] === 'POST') {
$bo_table = $_POST['bo_table'];
$write_table = $g5['write_prefix'] . $bo_table;
$sql = "SELECT wr_id FROM {$write_table} ORDER BY wr_id ASC";
$res = sql_query($sql);
$id_map = [];
$num_map = [];
$new_id = 1;
while ($row = sql_fetch_array($res)) {
$old_id = $row['wr_id'];
$id_map[$old_id] = $new_id;
$num_map[$old_id] = -$new_id;
$new_id++;
}
foreach ($id_map as $old_id => $new_id) {
$row = sql_fetch("SELECT wr_parent FROM {$write_table} WHERE wr_id = '{$old_id}'");
$old_parent = $row['wr_parent'];
$new_parent = $id_map[$old_parent] ?? 0;
$new_num = $num_map[$old_id];
sql_query("UPDATE {$write_table}
SET wr_id = '{$new_id}', wr_parent = '{$new_parent}', wr_num = '{$new_num}'
WHERE wr_id = '{$old_id}'");
}
foreach ($id_map as $old_id => $new_id) {
$old_parent = get_wr_parent($old_id, $write_table);
$new_parent = $id_map[$old_parent] ?? 0;
sql_query("UPDATE g5_board_new
SET wr_id = '{$new_id}', wr_parent = '{$new_parent}'
WHERE bo_table = '{$bo_table}' AND wr_id = '{$old_id}'");
sql_query("UPDATE g5_point
SET po_id = '{$new_id}'
WHERE po_rel_table = '{$bo_table}' AND po_id = '{$old_id}'");
sql_query("UPDATE g5_scrap
SET wr_id = '{$new_id}'
WHERE bo_table = '{$bo_table}' AND wr_id = '{$old_id}'");
sql_query("UPDATE g5_board_file
SET wr_id = '{$new_id}'
WHERE bo_table = '{$bo_table}' AND wr_id = '{$old_id}'");
sql_query("UPDATE g5_good
SET wr_id = '{$new_id}'
WHERE bo_table = '{$bo_table}' AND wr_id = '{$old_id}'");
}
$board = sql_fetch("SELECT bo_notice FROM g5_board WHERE bo_table = '{$bo_table}'");
$notice_ids = explode(',', $board['bo_notice']);
$new_notice_ids = [];
foreach ($notice_ids as $nid) {
$nid = trim($nid);
if (isset($id_map[$nid])) {
$new_notice_ids[] = $id_map[$nid];
}
}
$new_notice_str = implode(',', $new_notice_ids);
sql_query("UPDATE g5_board SET bo_notice = '{$new_notice_str}' WHERE bo_table = '{$bo_table}'");
echo "<script>alert('📢 {$bo_table} 게시판 정렬 및 동기화 완료!'); location.href='".$_SERVER['PHP_SELF']."';</script>";
exit;
}
// 게시판 목록 조회
$boards = sql_query("SELECT bo_table, bo_subject FROM g5_board ORDER BY bo_table ASC");
function get_wr_parent($wr_id, $table) {
$row = sql_fetch("SELECT wr_parent FROM {$table} WHERE wr_id = '{$wr_id}'");
return $row['wr_parent'];
}
?>
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>게시글 정렬/동기화 도구</title>
<style>
body { font-family: sans-serif; padding: 2em; }
form { max-width: 400px; margin: auto; border: 1px solid #ccc; padding: 20px; border-radius: 10px; }
select, button { width: 100%; padding: 10px; margin-top: 10px; font-size: 16px; }
h2 { text-align: center; }
</style>
</head>
<body>
<h2>게시글 정렬 및 참조 동기화 도구</h2>
<form method="post" onsubmit="return confirm('⚠️ 중요 작업 안내 ⚠️\n이 작업은 wr_id, wr_parent, wr_num을 재정렬하며\n📌 g5_board_new, g5_point, g5_scrap, g5_board_file, g5_good\n등 여러 연관 테이블에 영향을 줍니다.\n\n💾 반드시 데이터베이스 백업을 먼저 완료했는지 확인해주세요!\n\n✅ 백업을 완료했다면 [확인]을 눌러 진행하시고\n❌ 그렇지 않다면 [취소]를 눌러 중단해주세요.');">
<label for="bo_table">게시판 선택:</label>
<select name="bo_table" id="bo_table" required>
<option value="">:: 게시판 선택 ::</option>
<?php while ($row = sql_fetch_array($boards)) { ?>
<option value="<?= $row['bo_table'] ?>"><?= $row['bo_table'] ?> (<?= $row['bo_subject'] ?>)</option>
<?php } ?>
</select>
<button type="submit">정렬 및 동기화 실행</button>
</form>
</body>
</html>[/code]
✅ 요약
g5_write_테이블, g5_board_new, g5_point, g5_scrap, g5_board, g5_board_file, g5_good 모두 자동 반영됩니다.
파일명: reset_post_ids.php
🔄 전체 반영 목록
📌 g5_write_테이블 (wr_id, wr_parent, wr_num 원본 게시글 및 댓글 포함 전체 정렬)
📌 g5_board_new (wr_id, wr_parent 새글 목록 동기화)
📌 g5_point (po_id (게시글 ID) 포인트 기록 연결 동기화)
📌 g5_scrap (wr_id 스크랩된 글 ID 동기화)
📌 g5_board (bo_notice 공지사항 글 ID 목록 재매핑)
📌 g5_board_file (wr_id 게시글에 첨부된 파일 정보)
📌 g5_good (wr_id 추천/비추천 정보 테이블)
✅ UI + 실행 코드 (PHP)[code]<?php
include_once('./_common.php');//경로확인 실제 경로로 변경 하세요
if (!defined('_GNUBOARD_')) exit;
// 관리자 권한 체크
if ($is_admin !== 'super') {
alert('최고관리자만 접근 가능합니다.');
}
if ($_SERVER['REQUEST_METHOD'] === 'POST') {
$bo_table = $_POST['bo_table'];
$write_table = $g5['write_prefix'] . $bo_table;
$sql = "SELECT wr_id FROM {$write_table} ORDER BY wr_id ASC";
$res = sql_query($sql);
$id_map = [];
$num_map = [];
$new_id = 1;
while ($row = sql_fetch_array($res)) {
$old_id = $row['wr_id'];
$id_map[$old_id] = $new_id;
$num_map[$old_id] = -$new_id;
$new_id++;
}
foreach ($id_map as $old_id => $new_id) {
$row = sql_fetch("SELECT wr_parent FROM {$write_table} WHERE wr_id = '{$old_id}'");
$old_parent = $row['wr_parent'];
$new_parent = $id_map[$old_parent] ?? 0;
$new_num = $num_map[$old_id];
sql_query("UPDATE {$write_table}
SET wr_id = '{$new_id}', wr_parent = '{$new_parent}', wr_num = '{$new_num}'
WHERE wr_id = '{$old_id}'");
}
foreach ($id_map as $old_id => $new_id) {
$old_parent = get_wr_parent($old_id, $write_table);
$new_parent = $id_map[$old_parent] ?? 0;
sql_query("UPDATE g5_board_new
SET wr_id = '{$new_id}', wr_parent = '{$new_parent}'
WHERE bo_table = '{$bo_table}' AND wr_id = '{$old_id}'");
sql_query("UPDATE g5_point
SET po_id = '{$new_id}'
WHERE po_rel_table = '{$bo_table}' AND po_id = '{$old_id}'");
sql_query("UPDATE g5_scrap
SET wr_id = '{$new_id}'
WHERE bo_table = '{$bo_table}' AND wr_id = '{$old_id}'");
sql_query("UPDATE g5_board_file
SET wr_id = '{$new_id}'
WHERE bo_table = '{$bo_table}' AND wr_id = '{$old_id}'");
sql_query("UPDATE g5_good
SET wr_id = '{$new_id}'
WHERE bo_table = '{$bo_table}' AND wr_id = '{$old_id}'");
}
$board = sql_fetch("SELECT bo_notice FROM g5_board WHERE bo_table = '{$bo_table}'");
$notice_ids = explode(',', $board['bo_notice']);
$new_notice_ids = [];
foreach ($notice_ids as $nid) {
$nid = trim($nid);
if (isset($id_map[$nid])) {
$new_notice_ids[] = $id_map[$nid];
}
}
$new_notice_str = implode(',', $new_notice_ids);
sql_query("UPDATE g5_board SET bo_notice = '{$new_notice_str}' WHERE bo_table = '{$bo_table}'");
echo "<script>alert('📢 {$bo_table} 게시판 정렬 및 동기화 완료!'); location.href='".$_SERVER['PHP_SELF']."';</script>";
exit;
}
// 게시판 목록 조회
$boards = sql_query("SELECT bo_table, bo_subject FROM g5_board ORDER BY bo_table ASC");
function get_wr_parent($wr_id, $table) {
$row = sql_fetch("SELECT wr_parent FROM {$table} WHERE wr_id = '{$wr_id}'");
return $row['wr_parent'];
}
?>
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>게시글 정렬/동기화 도구</title>
<style>
body { font-family: sans-serif; padding: 2em; }
form { max-width: 400px; margin: auto; border: 1px solid #ccc; padding: 20px; border-radius: 10px; }
select, button { width: 100%; padding: 10px; margin-top: 10px; font-size: 16px; }
h2 { text-align: center; }
</style>
</head>
<body>
<h2>게시글 정렬 및 참조 동기화 도구</h2>
<form method="post" onsubmit="return confirm('⚠️ 중요 작업 안내 ⚠️\n이 작업은 wr_id, wr_parent, wr_num을 재정렬하며\n📌 g5_board_new, g5_point, g5_scrap, g5_board_file, g5_good\n등 여러 연관 테이블에 영향을 줍니다.\n\n💾 반드시 데이터베이스 백업을 먼저 완료했는지 확인해주세요!\n\n✅ 백업을 완료했다면 [확인]을 눌러 진행하시고\n❌ 그렇지 않다면 [취소]를 눌러 중단해주세요.');">
<label for="bo_table">게시판 선택:</label>
<select name="bo_table" id="bo_table" required>
<option value="">:: 게시판 선택 ::</option>
<?php while ($row = sql_fetch_array($boards)) { ?>
<option value="<?= $row['bo_table'] ?>"><?= $row['bo_table'] ?> (<?= $row['bo_subject'] ?>)</option>
<?php } ?>
</select>
<button type="submit">정렬 및 동기화 실행</button>
</form>
</body>
</html>[/code]
✅ 요약
g5_write_테이블, g5_board_new, g5_point, g5_scrap, g5_board, g5_board_file, g5_good 모두 자동 반영됩니다.
댓글목록
등록된 댓글이 없습니다.
![]() ![]() |