revisions not cleared correct

bwynants - October 8, 2007 - 14:24
Project:Revision Deletion
Version:6.x-1.x-dev
Component:Code
Category:bug report
Priority:critical
Assigned:Unassigned
Status:closed
Description

revision_deletion_delete_rev has wrong order of execution.

  db_query("DELETE FROM {node_revisions} WHERE nid = %d AND vid = %d", $data->nid, $data->vid);
  $node = node_load($data->nid, $data->vid);
  node_invoke_nodeapi($node, 'delete revision');

should be

  $node = node_load($data->nid, $data->vid);
  db_query("DELETE FROM {node_revisions} WHERE nid = %d AND vid = %d", $data->nid, $data->vid);
  node_invoke_nodeapi($node, 'delete revision');

since node_load will return false in case the entry from the node_revisions table is deleted before node_load is called.

#1

bwynants - October 8, 2007 - 14:44

Patch attached

AttachmentSize
patch_18.patch 988 bytes

#2

bwynants - October 8, 2007 - 16:26

how to clear dangling table entries ?

    $tables = Array("book");
    $types = content_types();
    foreach ($types as $type) {
  $tables[] = _content_tablename($type['type'], CONTENT_DB_STORAGE_PER_CONTENT_TYPE);
    }
    $fields = content_fields();
    foreach ($fields as $field) {
      if (empty($field['db_storage'])) {
    $tables[] = 'content_'.$field['field_name'];
  }
    } 
    foreach ($tables as $table) {
      $result = db_query("SELECT t.nid, t.vid FROM {$table} t");
      while ($res = db_fetch_object($result)) {
    $temp = db_fetch_object(db_query("SELECT nr.nid, nr.vid FROM {node_revisions} nr WHERE nr.vid = %d", $res->vid));
    if (!is_object($temp)) {
      watchdog('content', 'Dangling '.$table. ' revision ' . $res->vid. ' deleted');
          db_query('DELETE FROM {'. $table .'} WHERE vid = %d', $res->vid);
    }
  }
    }

#3

Gman - October 8, 2007 - 18:39

Great post. Let me review this issue and the follow up attachment to remove dangling entries. I will use the install_hook to execute the above code during an update.php cycle.

#4

bwynants - October 8, 2007 - 19:25

yeah, problem is that it's impossible to know ALL tables that have dandling entries and after executing you should also clear the cache tables.

#5

Gman - October 28, 2007 - 01:17
Status:active» fixed

Sorry for the long delay. I have finally updated this in the Drupal 5 and 4.7 branches.

#6

Anonymous - November 12, 2007 - 22:42
Status:fixed» closed

Automatically closed -- issue fixed for two weeks with no activity.

#7

bwynants - December 16, 2008 - 20:15
Version:5.x-1.x-dev» 6.x-1.x-dev
Status:closed» active

same issue in 6.0 verions

#8

Gman - January 5, 2009 - 19:29
Status:active» fixed

Committed. THank you.

#9

System Message - January 19, 2009 - 19:30
Status:fixed» closed

Automatically closed -- issue fixed for two weeks with no activity.

 
 

Drupal is a registered trademark of Dries Buytaert.