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.

CommentFileSizeAuthor
#1 patch_18.patch988 bytesbwynants

Comments

bwynants’s picture

StatusFileSize
new988 bytes

Patch attached

bwynants’s picture

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);
	    }
	  }
    }
Gman’s picture

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.

bwynants’s picture

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.

Gman’s picture

Status: Active » Fixed

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

Anonymous’s picture

Status: Fixed » Closed (fixed)

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

bwynants’s picture

Version: 5.x-1.x-dev » 6.x-1.x-dev
Status: Closed (fixed) » Active

same issue in 6.0 verions

Gman’s picture

Status: Active » Fixed

Committed. THank you.

Status: Fixed » Closed (fixed)

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