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
Patch attached
#2
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
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
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
Sorry for the long delay. I have finally updated this in the Drupal 5 and 4.7 branches.
#6
Automatically closed -- issue fixed for two weeks with no activity.
#7
same issue in 6.0 verions
#8
Committed. THank you.
#9
Automatically closed -- issue fixed for two weeks with no activity.