Info
- 10 posts
- 4 voices
- Started 3 years ago by wiseacre
- Latest reply from pierig
- This topic is not a support question
Permanently deleting topics and posts
-
- Posted 3 years ago #
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); -
- Posted 3 years ago #
You could easily turn this into a more standardized script by starting the code with
require('./bb-load.php');to load the bbPress code and check user authorization, and thenif (!bb_current_user_can(administrate)) {exit;}The
mysql_query(would become$bbdb->query(and you'd have to do aglobal $bbdb;once at the top too. Just for completeness you might want to look at some of the functions inbb-do-counts.phpin bb-admin.Actually it would be fairly easy to turn it into a full blown plugin for the admin menu.
-
- Posted 3 years ago #
I'm not a php-programmer... Where I can add the code from topic starter to make it work?
-
- Posted 3 years ago #
The procedure written by wiseacre:
-1 The script starts with <?php and finishes with ?>
0 Change lines 1 and 2 with you user, host, password and database name
1 Save to file filename.php
2 Upload to your forum directory
3 Start it. For example - open http://example.com/bbpress/filename.phpThanks for this script, unfortunetly I receive "Table 'bbpress.bb1_meta' doesn't exist"
I adjust your script, because I've renamed all tables to bb1_ instead of bb_Any idea?
Thanks -
- Posted 3 years ago #
Also be EXTREMELY careful when tampering with the auto-increment.
If you re-use any topic id # you are guaranteed to break some plugins. -
- Posted 3 years ago #
Bump it.. I would really appreciate if somebody can show me how to delete permanently deleted posts..
Or how are you doing the tests. I have a test user, login with it and make test posts..Thx
pierig -
- Posted 3 years ago #
Sorry about delay, guys.
@pierig - What about your bbpress version?
NOTE: Please have in mind this script is tested with not respect any plugins.
-
- Posted 3 years ago #
Never mind!
I use version 0.9.0.4
Thanks for the note, everybody should do anyway a backup before testing a script out of the web.Happy monday
ps. sorry for my bad english, it's monday morning..
-
- Posted 3 years ago #
I have tested with Alfa 2+. There was some changes in DB structure. bb_meta is one of them. It's time for ( :( )
NOTE 2: this script is compatible with trunk
If your database size is not a big problem you can wait for next bbpress version.
-
- Posted 3 years ago #
I see. Ok then, I'll wait for the next version.
Thanks anyway.greetz from paris
-
You must log in to post.