The MU forums have moved to WordPress.org

is it safe to delete "inherit" files (15 posts)

  1. rudy3107
    Member
    Posted 13 years ago #

    Version wp-mu 2.6.5

    Every time when i write a Article it Autosave files with every changes i do. sometimes if i take time to write it save upto 10 copies of same file in Database, which make Database big. so i searched mysql database in "wp-post" table for the word "inherit" and found 5 times more files than actual posts.

    anyone know is it safe to delete these files

  2. SteveAtty
    Member
    Posted 13 years ago #

    There is a plugin to restrict how many drafts you can have which is a bit restrictive because its totally site wide.

    I'd really like it if after I'd published there was a clean up of the revision and autosaves. It does seem silly that post 205 in my blog has about 10 205-revision-x and 205-autosave posts associated with it.

  3. andrea_r
    Moderator
    Posted 13 years ago #

    Yes, you can delete the revisions of posts from the database.

    There's an option in Site Admin to limit number of revisions sitewide (2 or 3 is good) but I can't remember if that was via a plugin or not.

  4. rudy3107
    Member
    Posted 13 years ago #

    THANK YOU.
    So its safe to delete these Posts;

    i can run sql command from Mysql and delete all inherit posts weekly or so.

  5. SteveAtty
    Member
    Posted 13 years ago #

    I wondering if there is call for a tiny plugin that hooks into the publish post hook and deletes the old records for that post?

  6. andrea_r
    Moderator
    Posted 13 years ago #

    Oh probably quite a few people would find it useful.

  7. santsif
    Member
    Posted 13 years ago #

    Past weekend I went through our database pruning all 'inherit's from wp-[ID]-post. One of our users got in touch today to say her images have disappeared throughout her blog.

    To troubleshoot I created a new post, uploaded an image and saved a few drafts. Checking in the database showed that the drafts were tagged as 'inherit' as expected, but the uploaded image was also tagged 'inherit'.

    Having looked through random posts across our blog community I've noticed that most images are still appearing on a blog but not appearing in the media library associated with that blog. And, looking in the database, some uploaded images are not tagged 'inherit'.

    At the moment I'm mostly confused about why some images continue to display but others don't (in both cases, images do not display in the media library).

    Anybody have an idea of what's going on here, please?

  8. SteveAtty
    Member
    Posted 13 years ago #

    Its slightly more complicated than just inherit in the post_status.

    Images are :
    post_status=inherit
    and
    post_name=img_

    Drafts and and autosaves are:

    Post_status=Inherit
    Post_name=post_id-autosave
    or
    Post_name=post_id-revision(-id)

    So you only want to delete where the post_status of the post_id is published, so if you were running it basically as an event when the post is published you'd need something like:

    delete from wp_id_posts where post_status='inherit' and (post_name like 'post_id-autosave%' or postname='post_id-revision%')

    Where of course the post_id would have been replaced by the appropriate post_id

  9. rudy3107
    Member
    Posted 13 years ago #

    Yea we cann`t just delete all posts which has tag INHERIT;

    As i wrote before i deleted all post of INHERIT; and now i foundout some posts showing only half others only header; i think all inherit files are linked to each other.

    and its impossible to delete one by one where we have thousands of posts.

    it is better if WORDPRESS guys make some update in their next update to clear this junk out of Database, so we can trim and reduce size of DB.

  10. SteveAtty
    Member
    Posted 13 years ago #

    I agree, once a post has been published the drafts/autosaves aren't needed so they really should be deleted.

  11. Ovidiu
    Member
    Posted 13 years ago #

    what about that small plugin you offered? ;-)

    besides, versioning can be disabled in wp-config.php while as far as I know autosafe can't. I remember in wp-config.php one can only specify the amount of time between autosaves :-(

  12. SteveAtty
    Member
    Posted 13 years ago #

    I've been job hunting, and I had the parents to stay for a couple of days. I've worked out the code, just got to find right hook - is there a "post_publish" hook?

  13. SteveAtty
    Member
    Posted 13 years ago #

    OK here we go.

    Don't blame me if this breaks anything, it probably needs more testing:

    Simply save as something like trim_drafts.php in your mu plugins folder:

    <?php
    
    function trim_revisions($post) {
    global $wpdb;
    $sql="delete from ".$wpdb->posts." where post_status='inherit' and (post_name like '".$post->ID."-autosave%' or post_name like '".$post->ID."-revision%')";
    $wpdb->query($sql);
    }
    
    add_action('new_to_publish', 'trim_revisions');
    add_action('pending_to_publish', 'trim_revisions');
    add_action('draft_to_publish', 'trim_revisions');
    add_action('private_to_publish', 'trim_revisions');
    
    ?>

    Then if you are really confident, or mad you save the following in your top level directory as something like delete_stuff.php

    <?php
    require( dirname(__FILE__) . '/wp-config.php' );
    global $wpdb;
    $prefix="wp_";
    $blog_list = $wpdb->get_results( "SELECT blog_id FROM " . $wpdb->blogs);
    foreach ($blog_list as $bloglist) {
    $sql="delete from ".$prefix.$bloglist->blog_id."_posts where post_status='inherit' and (post_name like '%autosave%' or post_name like '%revision%')";
    $wpdb->query($sql);
    }
    ?>

    Then access it from your browser.

    Dont forget to backup your DB first and to delete the file you created in the second part afterwards.

  14. SteveAtty
    Member
    Posted 13 years ago #

    Oh, and don't forget that the second chunk of code is rather crude and will wipe out anything, published, or unpublished, that is an autosave or a manual save so you need to be totally sure that you're not going to delete anything that hasn't been published. To do that you'd need a slightly more complicated query.

  15. SteveAtty
    Member
    Posted 13 years ago #

    And here's an updated bit of code to do the tidy up. Again ensure you back up your DB first and I'm not responsible for any disaster;

    <?php
    require( dirname(__FILE__) . '/wp-config.php' );
    global $wpdb;
    $prefix="wp_";
    $blog_list = $wpdb->get_results( "SELECT blog_id FROM " . $wpdb->blogs);
    foreach ($blog_list as $bloglist) {
      $post_list = $wpdb->get_results( "SELECT id FROM " . $prefix.$bloglist->blog_id."_posts where post_status='publish'");
      foreach ($post_list as $postlist) {
        $sql="delete from ".$prefix.$bloglist->blog_id."_posts where post_status='inherit' and (post_name like '".$postlist->id."-autosave%' or post_name like '".$postlist->id."-revision%')";
        $wpdb->query($sql);
      }
    }
    ?>

About this Topic

  • Started 13 years ago by rudy3107
  • Latest reply from SteveAtty