function flag_update_7202 in Flag 7.3
Same name and namespace in other branches
- 7.2 flag.install \flag_update_7202()
Clean-up flag records for deleted nodes and comments.
File
- ./
flag.install, line 425 - Flag module install/schema/update hooks.
Code
function flag_update_7202() {
// These queries can't use db_delete() because that doesn't support a
// subquery: see http://drupal.org/node/1267508.
// Clean-up for nodes.
db_query("DELETE FROM {flag_content} WHERE content_type = 'node' AND NOT EXISTS (SELECT 1 FROM {node} n WHERE content_id = n.nid)");
db_query("DELETE FROM {flag_counts} WHERE content_type = 'node' AND NOT EXISTS (SELECT 1 FROM {node} n WHERE content_id = n.nid)");
// Clean-up for comments. Do not use module_exists() because comment module
// could be disabled.
if (db_table_exists('comment')) {
db_query("DELETE FROM {flag_content} WHERE content_type = 'comment' AND NOT EXISTS (SELECT 1 FROM {comment} c WHERE content_id = c.cid)");
db_query("DELETE FROM {flag_counts} WHERE content_type = 'comment' AND NOT EXISTS (SELECT 1 FROM {comment} c WHERE content_id = c.cid)");
}
}