Skip to:
Content
Pages
Categories
Search
Top
Bottom

Permanently deleting topics and posts

  • @wiseacre

    Member

    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)
  • @_ck_

    Participant

    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 then if (!bb_current_user_can(administrate)) {exit;}

    The mysql_query( would become $bbdb->query( and you’d have to do a global $bbdb; once at the top too. Just for completeness you might want to look at some of the functions in bb-do-counts.php in bb-admin.

    Actually it would be fairly easy to turn it into a full blown plugin for the admin menu.

    @vertus

    Member

    I’m not a php-programmer… Where I can add the code from topic starter to make it work?

    @pierig

    Member

    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.php

    Thanks 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

    @_ck_

    Participant

    Also be EXTREMELY careful when tampering with the auto-increment.

    If you re-use any topic id # you are guaranteed to break some plugins.

    @pierig

    Member

    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

    @wiseacre

    Member

    Sorry about delay, guys.

    @pierig – What about your bbpress version?

    NOTE: Please have in mind this script is tested with not respect any plugins.

    @pierig

    Member

    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..

    @wiseacre

    Member

    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.

    @pierig

    Member

    I see. Ok then, I’ll wait for the next version.

    Thanks anyway.

    greetz from paris

Viewing 9 replies - 1 through 9 (of 9 total)
  • You must be logged in to reply to this topic.
Skip to toolbar