You are here

function flag_update_7202 in Flag 7.2

Same name and namespace in other branches
  1. 7.3 flag.install \flag_update_7202()

Clean-up flag records for deleted nodes and comments.

File

./flag.install, line 470
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)");
  }
}