Permanently deleting topics and posts
-
Hi. This si not a true plugin – just a stupid script for removing “deleted” topics and posts from the DB. Thanks in advance for any feedback.
$link=mysql_connect("host","user","password");
mysql_select_db("database");
//delete topics metadata
$res=mysql_query("SELECT topic_id FROM bb_topics WHERE topic_status>0;") or die(mysql_error());
while($row=mysql_fetch_row($res)) {
mysql_query("DELETE bb_meta.* FROM bb_meta WHERE object_type='bb_topic' AND object_id=$row[0];") or die(mysql_error());
};
mysql_free_result($res);
//delete posts metadata
$res=mysql_query("SELECT post_id FROM bb_posts WHERE post_status>0;") or die(mysql_error());
while($row=mysql_fetch_row($res)) {
mysql_query("DELETE bb_meta.* FROM bb_meta WHERE object_type='bb_post' AND object_id=$row[0];") or die(mysql_error());
};
mysql_free_result($res);
//delete topics & posts
mysql_query("DELETE bb_topics.* FROM bb_topics WHERE topic_status>0;") or die(mysql_error());
mysql_query("DELETE bb_posts.* FROM bb_posts WHERE post_status>0;") or die(mysql_error());
mysql_query("DELETE bb_meta.* FROM bb_meta WHERE meta_key='deleted_posts';") or die(mysql_error());
//some extras - attempt to "correct" autoincrement
$row=mysql_fetch_row(mysql_query("SELECT MAX(topic_id) FROM bb_topics;"));
if($row[0]!="") {
$correct=$row[0];
}
else {
$correct=1;
};
mysql_query("ALTER TABLE bb_topics AUTO_INCREMENT=$correct;") or die(mysql_error());
$row=mysql_fetch_row(mysql_query("SELECT MAX(post_id) FROM bb_posts;"));
if($row[0]!="") {
$correct=$row[0];
}
else {
$correct=1;
};
mysql_query("ALTER TABLE bb_posts AUTO_INCREMENT=$correct;") or die(mysql_error());
$row=mysql_fetch_row(mysql_query("SELECT MAX(meta_id) FROM bb_meta;"));
if($row[0]!="") {
$correct=$row[0];
}
else {
$correct=1;
};
mysql_query("ALTER TABLE bb_meta AUTO_INCREMENT=$correct;") or die(mysql_error());
mysql_close($link);
Viewing 9 replies - 1 through 9 (of 9 total)
Viewing 9 replies - 1 through 9 (of 9 total)
- You must be logged in to reply to this topic.