The flag plugin for Heartbeat doesn't clean up the database properly which can lead to issues. Specifically, when a heartbeat activity is deleted it deletes the flag (from the flag_content table) but not the entry in the flag_counts table.

Compare the behaviour of the hook_node_delete() in flag module with the corresponding code in the heartbeat flag plugin:

/**
 * Implements hook_node_delete().
 */
function flag_node_delete($node) {
  foreach (flag_get_flags('node') as $flag) {
    // If the flag is being tracked by translation set and the node is part
    // of a translation set, don't delete the flagging record.
    // Instead, data will be updated in the 'translation_change' op, below.
    if (!$flag->i18n || empty($node->tnid)) {
      db_delete('flag_content')
        ->condition('fid', $flag->fid)
        ->condition('content_id', $node->nid);
      db_delete('flag_counts')
        ->condition('fid', $flag->fid)
        ->condition('content_id', $node->nid);
    }
  }
}
 /**
   * activityRemoved()
   */
  public function activityRemoved($uaids, $all) {

    $query = db_delete('flag_content');
    $query->condition('content_type', 'heartbeat_activity');

    if (!empty($uaids) && $all == FALSE) {
      $query->condition('content_id', $uaids, 'IN');
    }

    $query->execute();
  }

Note that when nodes are deleted, it cleans up the flag_counts table too.

Patch to follow shortly.

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

seddonym’s picture

Here it is.

seddonym’s picture

Issue summary: View changes

Clarification.